MCP server/search

e-Stat MCP Server

MCP server for Japan's official government statistics portal

ajtgjmdjp/estat-mcp ↗by ajtgjmdjpupdated
1

Add it to Claude Code

claude mcp add -e "ESTAT_APP_ID=${ESTAT_APP_ID}" estat-mcp -- uvx estat-mcp serve
Required:ESTAT_APP_ID
2

Make your agent remember this setup

estat-mcp's config, env vars, and the gotchas you hit — recalled in every future Claude Code, Cursor, and Codex session.

npx conare@latest

Free · one command · indexes the sessions already on disk. Set up in the browser instead →

What it does

  • Search 3,000+ official Japanese statistical tables by keyword
  • Retrieve detailed table metadata including structure and time periods
  • Fetch statistical data with automatic pagination for large datasets
  • Built-in rate limiting for API compliance
  • Type-safe data handling with support for Polars/pandas export

Tools 4

search_statisticsSearch for statistical tables using keywords
get_statistic_metaRetrieve table structure including classifications, time periods, and regions
get_statistic_dataFetch statistical data with support for filtering and pagination
get_all_statistic_dataFetch all pages of statistical data with a safety limit

Environment Variables

ESTAT_APP_IDrequiredAPI key obtained from the e-Stat portal

Try it

Search for the latest population statistics for Japan.
What is the current Consumer Price Index (CPI) trend in Tokyo?
Get the metadata for the latest GDP statistical table.
Fetch the statistical data for regional labor force participation in 2024.
Original README from ajtgjmdjp/estat-mcp

estat-mcp

e-Stat (政府統計の総合窓口) API client and MCP server for Japanese government statistics.

📝 日本語チュートリアル: Claude に聞くだけで GDP や CPI がわかる (Zenn)

What is this?

estat-mcp provides programmatic access to Japan's official statistics portal (e-Stat), which hosts 3,000+ statistical tables covering population, economy, prices, labor, agriculture, and regional data. It exposes these as both a Python async client and an MCP server for AI assistants.

  • Search statistics by keyword (人口, GDP, CPI, etc.)
  • Retrieve metadata to understand table structure (表章事項, 分類事項, 時間軸, 地域)
  • Fetch statistical data with automatic pagination for large datasets
  • Type-safe Pydantic models with Polars/pandas DataFrame export
  • Rate limiting built-in for API compliance
  • MCP server with 4 tools for Claude Desktop and other AI tools

Quick Start

Installation

pip install estat-mcp
# or
uv add estat-mcp

Get an API Key

Register (free) at e-Stat API and set:

export ESTAT_APP_ID=your_app_id_here

30-Second Example

import asyncio
from estat_mcp import EstatClient

async def main():
    async with EstatClient() as client:
        # Search for population statistics
        tables = await client.search_stats("人口")
        print(tables[0].name)  # 人口推計

        # Get metadata
        meta = await client.get_meta(tables[0].id)
        print(f"Time periods: {[t.name for t in meta.time_items]}")

        # Fetch data (Tokyo, 2024)
        data = await client.get_data(
            tables[0].id,
            cd_area="13000",   # Tokyo
            cd_time="2024000", # 2024
            limit=100
        )
        
        # Export as DataFrame
        df = data.to_polars()
        print(df)

asyncio.run(main())

CLI Quick Start

# Test API connectivity
estat-mcp test

# Search for CPI statistics
estat-mcp search "消費者物価指数" --limit 10

# Fetch data for a table
estat-mcp data 0003410379 --cd-area 13000 --format table

# Start MCP server
estat-mcp serve

MCP Server

Add to your AI tool's MCP config:

<details> <summary><b>Claude Desktop</b> (~⁠/Library/Application Support/Claude/claude_desktop_config.json)</summary>
{
  "mcpServers": {
    "estat": {
      "command": "uvx",
      "args": ["estat-mcp", "serve"],
      "env": {
        "ESTAT_APP_ID": "your_app_id_here"
      }
    }
  }
}
</details> <details> <summary><b>Cursor</b> (~⁠/.cursor/mcp.json)</summary>
{
  "mcpServers": {
    "estat": {
      "command": "uvx",
      "args": ["estat-mcp", "serve"],
      "env": {
        "ESTAT_APP_ID": "your_app_id_here"
      }
    }
  }
}
</details>

Then ask your AI: "日本の人口統計を教えて" or "東京の最新CPIは?"

Available MCP Tools

Tool Description
search_statistics キーワードで統計テーブルを検索
get_statistic_meta テーブル構造(表章事項・分類事項・時間軸・地域)を取得
get_statistic_data 統計データを取得(フィルタ・ページネーション対応)
get_all_statistic_data 全ページ自動取得(max_pages制限付き)

Python API

Search → Metadata → Data Flow

import asyncio
from estat_mcp import EstatClient

async def main():
    async with EstatClient() as client:
        # 1. Search for statistics tables
        tables = await client.search_stats("消費者物価指数", limit=5)
        # → [StatsTable(id="0003410379", name="消費者物価指数", ...), ...]

        stats_id = tables[0].id

        # 2. Get metadata to understand structure
        meta = await client.get_meta(stats_id)
        print(f"Table items: {[i.name for i in meta.table_items]}")
        print(f"Time periods: {[t.name for t in meta.time_items]}")
        print(f"Areas: {[a.name for a in meta.area_items]}")

        # 3. Fetch data with filters
        data = await client.get_data(
            stats_id,
            cd_area="13000",      # Tokyo only
            cd_time="2024000",    # 2024 only
            limit=1000
        )

        # 4. Export to DataFrame
        df = data.to_polars()
        print(df)

asyncio.run(main())

Automatic Pagination

For large datasets, use get_all_data() to automatically fetch all pages:

# Fetch up to 10 pages (safety limit)
all_data = await client.get_all_data(
    stats_id,
    max_pages=10,
    cd_cat01="100"  # Filter by classification
)
print(f"Fetched {len(all_data.values)} / {all_data.total_count} records")

Polars Export

# Requires: pip install estat-mcp[polars]
d

Frequently Asked Questions

What are the key features of e-Stat MCP?

Search 3,000+ official Japanese statistical tables by keyword. Retrieve detailed table metadata including structure and time periods. Fetch statistical data with automatic pagination for large datasets. Built-in rate limiting for API compliance. Type-safe data handling with support for Polars/pandas export.

What can I use e-Stat MCP for?

Researchers analyzing Japanese economic trends and inflation data. Data analysts needing programmatic access to official government demographics. AI assistants providing real-time insights into regional Japanese statistics. Automating the retrieval of large-scale government datasets for reporting.

How do I install e-Stat MCP?

Install e-Stat MCP by running: pip install estat-mcp

What MCP clients work with e-Stat MCP?

e-Stat MCP works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Conare · memory for coding agents

Turn this server into reusable context

Keep e-Stat MCP docs, env vars, and workflow notes in Conare so your agent carries them across sessions.

Set up free$npx conare@latest