MoSPI MCP Server

MoSPI MCP Server

MCP server for accessing India's Ministry of Statistics and Programme Implementation (MoSPI) data APIs. Enables natural language queries for economic, demographic, and social indicators via a 4-tool workflow.

Category
访问服务器

README

MoSPI MCP Server

License: MIT Python 3.11+ FastMCP

MCP (Model Context Protocol) server for accessing India's Ministry of Statistics and Programme Implementation (MoSPI) data APIs. Built with FastMCP 3.0.


Table of Contents


Overview

This server provides AI-ready access to official Indian government statistics through the Model Context Protocol (MCP). It acts as a bridge between AI assistants (Claude, ChatGPT, Cursor, etc.) and MoSPI's open data APIs, enabling natural language queries for economic, demographic, and social indicators.

Key Features:

  • 7 statistical datasets covering employment, inflation, industrial production, GDP, and energy
  • Sequential 4-tool workflow designed for LLM consumption
  • Swagger-driven parameter validation
  • Full OpenTelemetry integration for observability
  • Production-ready Docker deployment

If you want to connect your AI agent of choice with the MCP server, you can directly connect it with MOSPI's MCP server. Instructions are available at https://www.datainnovation.mospi.gov.in/mospi-mcp. Instructions to connect ChatGPT or Claude to MCP are available here: https://www.datainnovation.mospi.gov.in/mospi-mcp


Datasets

Dataset Full Name Use For
PLFS Periodic Labour Force Survey Jobs, unemployment, wages, workforce participation
CPI Consumer Price Index Retail inflation, cost of living, commodity prices
IIP Index of Industrial Production Industrial growth, manufacturing output
ASI Annual Survey of Industries Factory performance, industrial employment
NAS National Accounts Statistics GDP, economic growth, national income
WPI Wholesale Price Index Wholesale inflation, producer prices
ENERGY Energy Statistics Energy production, consumption, fuel mix
<!-- NMKN National Namkeen Consumption Index

MCP Tools

The server exposes 4 tools that follow a sequential workflow:

1_know_about_mospi_api  →  2_get_indicators  →  3_get_metadata  →  4_get_data
Step Tool Description
1 1_know_about_mospi_api() Overview of all datasets. Start here to find the right dataset.
2 2_get_indicators(dataset) List available indicators for the chosen dataset.
3 3_get_metadata(dataset, ...) Get valid filter values (states, years, categories) and API parameters.
4 4_get_data(dataset, filters) Fetch data using filter key-value pairs from metadata.

Important: Tools must be called in order. Skipping 3_get_metadata will result in invalid filter codes.


Quick Start

If you want to connect your AI agent of choice with the MCP server, you can directly connect it with MOSPI's MCP server. Instructions are available at https://www.datainnovation.mospi.gov.in/mospi-mcp. Instructions to connect ChatGPT or Claude to MCP are available here: https://www.datainnovation.mospi.gov.in/mospi-mcp

Below instructions are for self-hosting the MCP server.

Installation

# Clone the repository
git clone https://github.com/your-org/mospi-mcp-api.git
cd mospi-mcp-api

# Create virtual environment (recommended)
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

Running the Server

# HTTP transport (remote access)
python mospi_server.py

# OR using FastMCP CLI
fastmcp run mospi_server.py:mcp --transport http --port 8000

# stdio transport (local MCP clients)
fastmcp run mospi_server.py:mcp

Server runs at http://localhost:8000/mcp

Connecting from an MCP Client

import asyncio
from fastmcp import Client

async def main():
    async with Client("http://localhost:8000/mcp") as client:
        # Step 1: Get dataset overview
        overview = await client.call_tool("1_know_about_mospi_api", {})
        print(overview)

        # Step 2: Get indicators for PLFS
        indicators = await client.call_tool("2_get_indicators", {
            "dataset": "PLFS",
            "user_query": "unemployment rate"
        })
        print(indicators)

asyncio.run(main())

Deployment

Docker

# Build the image
docker build -t mospi-mcp .

# Run the container
docker run -d -p 8000:8000 --name mospi-server mospi-mcp

Docker Compose

Includes Jaeger for distributed tracing visualization:

docker-compose up -d

Services:

  • MoSPI Server: http://localhost:8000/mcp
  • Jaeger UI: http://localhost:16686

FastMCP Cloud

  1. Push code to GitHub
  2. Sign in to FastMCP Cloud
  3. Create project with entrypoint mospi_server.py:mcp

Architecture

mospi-mcp-api/
├── mospi_server.py          # FastMCP server - tools, validation, routing
├── mospi/
│   └── client.py            # MoSPI API client - HTTP requests to api.mospi.gov.in
├── swagger/                 # Swagger YAML specs per dataset (source of truth for params)
│   └── swagger_user_*.yaml
├── observability/
│   └── telemetry.py         # OpenTelemetry middleware for tracing
├── tests/                   # Per-dataset test files
├── Dockerfile               # Production container with OTEL instrumentation
├── docker-compose.yml       # Full stack with Jaeger
└── requirements.txt

Design Principles

Principle Implementation
Swagger as Source of Truth API parameters validated against YAML specs in swagger/, not hardcoded
Auto-routing CPI routes to Group/Item endpoint based on filters; IIP routes to Annual/Monthly
Validation First All filters validated before API calls with clear error messages
LLM-Optimized Tool docstrings contain explicit rules and workflow instructions

Configuration

Environment variables for OpenTelemetry:

Variable Description Default
OTEL_SERVICE_NAME Service name in traces mospi-mcp-server
OTEL_EXPORTER_OTLP_ENDPOINT OTLP collector endpoint http://localhost:4317
OTEL_EXPORTER_OTLP_PROTOCOL Protocol (grpc or http/protobuf) grpc
OTEL_TRACES_EXPORTER Exporter type (otlp, console, none) otlp

See .env.example for full configuration options.


Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines on:

  • Adding new datasets
  • Project structure
  • Development setup
  • Code style

Resources


License

This project is licensed under the MIT License - see the LICENSE file for details.


DIID

The Data Innovation Lab aims to promote innovation and the use of Information Technology in official statistics, including modernizing survey methods. It seeks to address the current challenges faced by the National Statistical System (NSS). The lab will serve as a platform for testing and developing new ideas through proof-of-concept projects. It will foster collaboration with a wide range of participants such as entrepreneurs, researchers, start-ups, academic institutions, and renowned national and international organizations. By creating an open and dynamic environment, the lab will support the advancement of statistical systems and help improve the quality and efficiency of data collection and analysis.

Know more: https://www.datainnovation.mospi.gov.in/home

Acknowledgments

Made in partnership with Bharat Digital in pursuit of modernising and humanising how government's use technology in service of the public.

<!-- Geek spotted! Respect for reading the raw markdown. You're the kind of person India's open data movement needs. -->

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选