get_stats_list_csv
Retrieve statistical table information from Japan's e-Stat portal in CSV format for data analysis and processing.
Instructions
統計表情報をCSVで取得する.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| search_word | No | ||
| survey_years | No | ||
| stats_field | No | ||
| stats_code | No | ||
| gov_code | No | ||
| open_years | No | ||
| stats_name_list | No | ||
| start_position | No | ||
| updated_date | No | ||
| limit | No |
Input Schema (JSON Schema)
{
"properties": {
"gov_code": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null
},
"limit": {
"default": 10,
"type": "integer"
},
"open_years": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null
},
"search_word": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null
},
"start_position": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"default": null
},
"stats_code": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null
},
"stats_field": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null
},
"stats_name_list": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null
},
"survey_years": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null
},
"updated_date": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null
}
},
"type": "object"
}
Implementation Reference
- e_stats_mcp/tools/stats.py:340-370 (handler)The main asynchronous handler function for the 'get_stats_list_csv' tool. It builds parameters using _build_stats_list_params and calls _make_request to fetch CSV data from the e-Stat API's getSimpleStatsList endpoint.async def get_stats_list_csv( search_word: str | None = None, survey_years: str | None = None, stats_field: str | None = None, stats_code: str | None = None, gov_code: str | None = None, open_years: str | None = None, stats_name_list: str | None = None, start_position: int | None = None, updated_date: str | None = None, limit: int = 10, ) -> str: """統計表情報をCSVで取得する.""" params = _build_stats_list_params( search_word=search_word, survey_years=survey_years, stats_field=stats_field, stats_code=stats_code, gov_code=gov_code, open_years=open_years, stats_name_list=stats_name_list, start_position=start_position, updated_date=updated_date, limit=limit, ) response = await _make_request( "getSimpleStatsList", params, format="csv", ) return cast(str, response)
- e_stats_mcp/main.py:45-45 (registration)Registration of the get_stats_list_csv tool using the FastMCP mcp.tool() decorator.mcp.tool()(get_stats_list_csv)
- e_stats_mcp/tools/stats.py:114-152 (helper)Helper function to construct query parameters for the stats list API endpoints, shared with the JSON version.def _build_stats_list_params( *, search_word: str | None = None, survey_years: str | None = None, stats_field: str | None = None, stats_code: str | None = None, gov_code: str | None = None, open_years: str | None = None, stats_name_list: str | None = None, start_position: int | None = None, updated_date: str | None = None, limit: int = 10, ) -> dict: """getStatsList系の共通パラメータを組み立てる.""" params = { "lang": "J", "limit": str(min(limit, 100)), } if search_word: params["searchWord"] = search_word if survey_years: params["surveyYears"] = survey_years if stats_field: params["statsField"] = stats_field if stats_code: params["statsCode"] = stats_code if gov_code: params["governmentCode"] = gov_code if open_years: params["openYears"] = open_years if stats_name_list: params["statsNameList"] = stats_name_list if start_position: params["startPosition"] = str(start_position) if updated_date: params["updatedDate"] = updated_date return params
- e_stats_mcp/tools/stats.py:17-66 (helper)Core helper function that performs the actual HTTP request to the e-Stat API, supporting both JSON and CSV formats, GET/POST methods.async def _make_request( endpoint: str, params: dict | None = None, *, method: str = "GET", format: str = "json", data: dict | None = None, ) -> dict[str, Any] | str: """e-Stat APIへのリクエストを実行する. Args: endpoint: APIエンドポイント(例: \"json/getStatsList\") params: クエリパラメータ method: HTTPメソッド(GET/POST) format: レスポンス形式(\"json\" または \"csv\") data: POST時のフォームデータ Returns: JSONの場合はdict、CSVの場合は文字列 Raises: ValueError: APIキーが設定されていない場合 httpx.HTTPError: API通信エラー """ settings = get_settings() if not settings.E_STAT_APP_ID: raise ValueError( "E_STAT_APP_ID環境変数が設定されていません。" "https://www.e-stat.go.jp/api/ からアプリケーションIDを取得してください。" ) url = f"{E_STAT_API_BASE}/{endpoint}" request_params = {"appId": settings.E_STAT_APP_ID, **(params or {})} http_method = method.upper() async with httpx.AsyncClient() as client: if http_method == "POST": response = await client.post( url, params=request_params, data=data, timeout=DEFAULT_TIMEOUT ) else: response = await client.get( url, params=request_params, timeout=DEFAULT_TIMEOUT ) response.raise_for_status() if format == "csv": return response.text return response.json()