MCP Data API

MCP Data API

A FastMCP-based server that provides tools for API discovery and execution, hierarchical category management, and SQL query execution through the Model Context Protocol.

Category
访问服务器

README

MCP Data API

A Model Context Protocol (MCP) server that provides access to data APIs, category management, and SQL query execution capabilities.

Overview

MCP Data API is a FastMCP-based server that exposes various data access tools through the Model Context Protocol. It enables AI agents and applications to interact with backend services for API discovery, execution, and database queries.

Features

  • Category Management: Browse and navigate API categories in a hierarchical structure
  • API Discovery: Search and retrieve API definitions by category or name
  • API Execution: Execute APIs with dynamic parameters
  • SQL Query Execution: Run SQL queries against configured databases
  • MCP Protocol Support: Full compatibility with MCP clients and AI agents

Architecture

The service acts as a bridge between MCP clients and backend services:

MCP Client → MCP Data API Server → Backend Services
                                    ├── chatgpt-api-service
                                    ├── chatdb-visual-service
                                    └── llm-workflow-service

Installation

Prerequisites

  • Python 3.10 or higher
  • pip package manager

Setup

  1. Clone the repository:
git clone <repository-url>
cd mcp_data_api
  1. Install dependencies:
pip install -e ".[dev]"
  1. Configure environment variables (optional):
cp .env.example .env
# Edit .env with your configuration

Configuration

The MCP server requires the following headers for authentication:

  • app_id: Application identifier (e.g., "984")
  • dbName: Database name (e.g., "hc_data_center")

MCP Client Configuration

Add the following to your MCP client configuration:

{
  "mcpServers": {
    "api-data-server": {
      "url": "http://127.0.0.1:32001/data/api/mcp",
      "header": {
        "app_id": "984",
        "dbName": "hc_data_center"
      }
    }
  }
}

Usage

Starting the Server

# Development mode
python -m src.main

# Production mode with uvicorn
uvicorn src.main:app --host 0.0.0.0 --port 32001

Using with MCP Clients

Python Client Example

from fastmcp import Client
from fastmcp.client.transports import SSETransport

# Configure transport with headers
transport = SSETransport(
    url="http://127.0.0.1:32001/data/api/mcp",
    headers={
        "app_id": "984",
        "dbName": "hc_data_center"
    }
)

# Create client
client = Client(transport)

async with client:
    # List available tools
    tools = await client.list_tools()
    print(f"Available tools: {[t.name for t in tools]}")

    # Call a tool
    result = await client.call_tool("get_categories", {})
    print(result)

Available Tools

1. get_categories

Retrieves the hierarchical list of API categories.

Parameters:

  • None

Returns: List of Category objects with flattened hierarchy

2. get_apis_by_category

Gets all APIs belonging to a specific category.

Parameters:

  • category_id (integer): The category ID

Returns: List of APIBasic objects

3. get_api_details

Retrieves detailed information for specific APIs.

Parameters:

  • api_names (string): Comma-separated list of API names

Returns: List of detailed API objects with parameter definitions

4. execute_api

Executes a single API with provided parameters.

Parameters:

  • api_name (string): Name of the API to execute
  • parameters (object): JSON object containing API parameters

Returns: API execution result

5. execute_sql

Executes a SQL query against the configured database.

Parameters:

  • sql (string): SQL query to execute

Returns: Query results in standardized format

Testing

Run Unit Tests

pytest tests/unit -v

Run Integration Tests

# Ensure the MCP server is running first
pytest tests/integration -v

Manual Testing

Run the integration test script directly:

python tests/integration/test_mcp_client.py

Project Structure

mcp_data_api/
├── src/
│   ├── models/          # Data models
│   ├── services/        # Business logic services
│   ├── tools/           # MCP tool implementations
│   ├── data_access/     # Data access layer
│   ├── cache/           # Caching implementations
│   └── utils/           # Utility functions
├── tests/
│   ├── unit/            # Unit tests
│   ├── integration/     # Integration tests
│   └── mock_data/       # Test data
├── docs/
│   └── API_DOCUMENTATION.md  # Detailed API documentation
├── pyproject.toml       # Project configuration
└── README.md           # This file

API Documentation

For detailed API documentation, see API_DOCUMENTATION.md.

Development

Code Style

The project uses:

  • Black for code formatting
  • Ruff for linting
  • pytest for testing

Format code:

black src tests

Lint code:

ruff check src tests

Adding New Tools

  1. Define the tool in src/tools/
  2. Implement the service logic in src/services/
  3. Add tests in tests/unit/ and tests/integration/
  4. Update documentation

Troubleshooting

Connection Issues

If you encounter connection errors:

  1. Verify the MCP server is running
  2. Check that the URL and port are correct
  3. Ensure headers (app_id, dbName) are properly configured
  4. Verify backend services are accessible

405 Method Not Allowed

This error typically means:

  • The MCP server is not running at the specified URL
  • The endpoint path is incorrect
  • The server doesn't support the MCP protocol at that endpoint

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

License

[Specify your license here]

Support

For issues and questions:

  • Create an issue in the repository
  • Contact the development team

Changelog

Version 0.1.0 (2026-02-05)

  • Initial release
  • MCP server implementation
  • Category and API management tools
  • SQL query execution
  • Integration tests

推荐服务器

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

官方
精选