Skip to main content
Glama

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

NameRequiredDescriptionDefault
search_wordNo
survey_yearsNo
stats_fieldNo
stats_codeNo
gov_codeNo
open_yearsNo
stats_name_listNo
start_positionNo
updated_dateNo
limitNo

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

  • 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)
  • Registration of the get_stats_list_csv tool using the FastMCP mcp.tool() decorator.
    mcp.tool()(get_stats_list_csv)
  • 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
  • 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()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/koizumikento/e-stats-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server