Data Commons MCP Server

Data Commons MCP Server

Enables AI agents to query and retrieve public statistical data from Data Commons through search and observation tools. Provides access to demographic, economic, and other statistical indicators for analysis and research.

Category
访问服务器

README

Data Commons MCP Server

A fully functional Model Context Protocol (MCP) server for accessing public statistical data from Data Commons. This server is optimized for deployment on Railway.app and can be accessed remotely by MCP clients like Manus, Claude Desktop, and other MCP-enabled applications.

Overview

Data Commons is an open knowledge repository providing a unified view across multiple public datasets and statistics. This MCP server enables AI agents and applications to query the Data Commons knowledge graph through a standardized protocol.

Key Features

  • MCP-Compliant: Implements the Model Context Protocol for seamless agent integration
  • Data Commons Access: Fetches public statistics from the datacommons.org knowledge graph
  • Custom Instance Support: Can be configured to work with custom Data Commons instances
  • Railway-Ready: Pre-configured for one-click deployment on Railway.app
  • Remote Access: Accessible via HTTP for remote MCP clients
  • Comprehensive Tools: Includes tools for searching indicators and fetching observations

Architecture

The server provides two main MCP tools:

  1. search_indicators: Search and discover statistical variables (indicators) available in Data Commons
  2. get_observations: Fetch actual statistical data for specific variables and places

Quick Start

Prerequisites

  1. Data Commons API Key: Create one at apikeys.datacommons.org
  2. Python 3.11+: Required for local development
  3. Railway Account: For deployment (optional)

Local Development

  1. Clone the repository:

    git clone https://github.com/ARJ999/Data-Commons-mcp-server.git
    cd Data-Commons-mcp-server
    
  2. Set up environment:

    cp .env.example .env
    # Edit .env and add your DC_API_KEY
    
  3. Install dependencies:

    pip install -r requirements.txt
    
  4. Run the server:

    python -m datacommons_mcp.cli serve http --host 0.0.0.0 --port 8080
    
  5. Access the MCP endpoint:

    http://localhost:8080/mcp
    

Railway Deployment

One-Click Deploy

Deploy on Railway

Manual Deployment

  1. Create a new Railway project:

    • Go to railway.app
    • Click "New Project" → "Deploy from GitHub repo"
    • Select this repository
  2. Configure environment variables:

    • Add DC_API_KEY with your Data Commons API key
    • Railway automatically sets PORT
  3. Deploy:

    • Railway will automatically detect the configuration and deploy
    • Your MCP server will be available at: https://your-app.railway.app/mcp

Environment Variables

Variable Required Description
DC_API_KEY Yes Your Data Commons API key from apikeys.datacommons.org
DC_API_ROOT No Custom Data Commons instance URL (defaults to datacommons.org)
PORT No Server port (Railway sets this automatically)

Using with MCP Clients

Manus

Configure Manus to connect to your deployed MCP server:

{
  "mcpServers": {
    "datacommons": {
      "url": "https://your-app.railway.app/mcp",
      "transport": "http"
    }
  }
}

Claude Desktop

Add to your Claude Desktop MCP settings:

{
  "mcpServers": {
    "datacommons": {
      "command": "curl",
      "args": ["-X", "POST", "https://your-app.railway.app/mcp"]
    }
  }
}

Other MCP Clients

Any MCP-enabled client can connect using the HTTP endpoint:

  • Endpoint: https://your-app.railway.app/mcp
  • Transport: Streamable HTTP
  • Protocol: MCP (Model Context Protocol)

Available Tools

1. search_indicators

Search for statistical variables (indicators) in Data Commons.

Parameters:

  • query (string): Natural language search query
  • place_dcids (list, optional): Filter by specific place DCIDs
  • topic_dcids (list, optional): Filter by topic DCIDs

Example:

search_indicators(
    query="population growth rate",
    place_dcids=["country/USA"]
)

2. get_observations

Fetch statistical observations for a variable and place.

Parameters:

  • variable_dcid (string): Variable identifier from search_indicators
  • place_dcid (string): Place identifier
  • child_place_type (string, optional): Get data for child places
  • date (string, optional): Date filter ('latest', 'all', or specific date)
  • date_range_start (string, optional): Start of date range
  • date_range_end (string, optional): End of date range

Example:

get_observations(
    variable_dcid="Count_Person",
    place_dcid="country/USA",
    date="latest"
)

Project Structure

Data-Commons-mcp-server/
├── datacommons_mcp/          # Main package
│   ├── __init__.py
│   ├── server.py             # MCP server implementation
│   ├── cli.py                # Command-line interface
│   ├── clients.py            # Data Commons API client
│   ├── services.py           # Business logic
│   ├── settings.py           # Configuration
│   ├── data_models/          # Pydantic models
│   └── ...
├── requirements.txt          # Python dependencies
├── pyproject.toml           # Project metadata
├── Procfile                 # Railway start command
├── railway.json             # Railway configuration
├── runtime.txt              # Python version
├── .env.example             # Environment template
├── .gitignore              # Git ignore rules
└── README.md               # This file

Technical Details

Dependencies

  • FastAPI: Web framework for HTTP server
  • FastMCP: MCP protocol implementation
  • Uvicorn: ASGI server
  • datacommons-client: Official Data Commons Python client
  • Pydantic: Data validation and settings management

Transport Modes

The server supports two transport modes:

  1. Streamable HTTP (default for Railway):

    • Accessible via HTTP/HTTPS
    • Suitable for remote clients
    • Endpoint: /mcp
  2. stdio (for local integrations):

    • Communicates via standard input/output
    • Used by local MCP clients like Gemini CLI

Troubleshooting

Server won't start

  • Check API Key: Ensure DC_API_KEY is set correctly
  • Check Python Version: Must be 3.11 or 3.12
  • Check Dependencies: Run pip install -r requirements.txt

Can't connect from MCP client

  • Verify URL: Ensure you're using the correct Railway URL
  • Check Endpoint: URL should end with /mcp
  • Check Deployment: Verify the Railway deployment is successful

API Errors

  • Invalid API Key: Get a new key from apikeys.datacommons.org
  • Rate Limits: Data Commons may have rate limits; check their documentation

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

License

This project is based on the Data Commons Agent Toolkit and is licensed under the Apache License 2.0.

Resources

Support

For issues related to:


Built with ❤️ for the MCP ecosystem

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选