xinghao-mcp-server
A modular MCP server built with Python and FastMCP, providing tools, prompts, and resources, plus a reusable async client for external API integrations.
README
Xinghao MCP Server
A small, modular Model Context Protocol (MCP) server built with Python and FastMCP. It includes working examples of tools, prompts, and resources, plus a reusable async client for connecting to external APIs.
This repository is intended as a practical starting point for developing a custom MCP server.
Features
- Python 3.11+ and the official MCP Python SDK
stdio,sse, andstreamable-httptransports- Centralized configuration through environment variables
- Explicit registration for tools, prompts, and resources
- Async
httpxclient base for external API integrations - Docker and Docker Compose support
- Registry and tool tests with pytest
Built-in MCP Capabilities
| Type | Name or URI | Description |
|---|---|---|
| Tool | health_check |
Returns the service status and current UTC time |
| Tool | add |
Adds two numbers |
| Tool | subtract |
Subtracts the second number from the first |
| Prompt | welcome_prompt |
Creates a prompt for welcoming a new team member |
| Resource | server://info |
Returns basic server information as JSON |
Project Structure
.
├── app/
│ ├── base/ # Shared API client and result types
│ ├── prompts/ # MCP prompt implementations and registration
│ ├── resources/ # MCP resource implementations and registration
│ ├── tools/ # MCP tool implementations and registration
│ ├── config.py # Environment-based settings
│ └── server.py # FastMCP instance and component registration
├── tests/ # Registry and tool tests
├── .env.example # Environment variable template
├── docker-compose.yaml
├── Dockerfile
├── main.py # Application entry point
└── pyproject.toml # Package metadata and dependencies
Getting Started
1. Create a virtual environment
python -m venv .venv
Activate it on macOS or Linux:
source .venv/bin/activate
Activate it on Windows PowerShell:
.\.venv\Scripts\Activate.ps1
2. Install the project
For local development, install the package and test dependencies in editable mode:
python -m pip install -e ".[dev]"
3. Configure the environment
Copy .env.example to .env, then adjust the values if needed:
MCP_TRANSPORT=stdio
MCP_HOST=127.0.0.1
MCP_PORT=8000
MCP_API_BASE_URL=
MCP_API_KEY=
| Variable | Default | Description |
|---|---|---|
MCP_TRANSPORT |
stdio |
Transport: stdio, sse, or streamable-http |
MCP_HOST |
127.0.0.1 |
Bind address for network transports |
MCP_PORT |
8000 |
Bind port for network transports |
MCP_API_BASE_URL |
Empty | Base URL used by the reusable external API client |
MCP_API_KEY |
Empty | Optional API key sent as the X-API-Key header |
The external API settings are only needed by tools that use app.base.api_client.APIClient.
4. Run the server
The default stdio transport is suitable for local MCP clients:
python main.py
To start a network transport, update MCP_TRANSPORT in .env. For example:
MCP_TRANSPORT=streamable-http
MCP_HOST=127.0.0.1
MCP_PORT=8000
Then run:
python main.py
The Streamable HTTP endpoint is available at http://127.0.0.1:8000/mcp.
Connect an MCP Client
For a client that launches local MCP servers over stdio, use a configuration like this and replace the paths with absolute paths on your machine:
{
"mcpServers": {
"xinghao-mcp-server": {
"command": "/absolute/path/to/.venv/bin/python",
"args": ["/absolute/path/to/xinghao-mcp-server/main.py"]
}
}
}
On Windows, the command typically points to .venv\\Scripts\\python.exe.
Docker
The Compose configuration starts the server with Streamable HTTP on port 8000:
docker compose up --build
After startup, connect to:
http://localhost:8000/mcp
Stop the service with:
docker compose down
Extending the Server
Add a tool
- Define a typed function in
app/tools/. - Import it in
app/tools/__init__.py. - Register it inside
register_tools()withmcp.tool().
FastMCP uses the function signature and docstring to generate the tool schema and description.
Add a prompt
Define the prompt function in app/prompts/, then register it in register_prompts() with mcp.prompt().
Add a resource
Define the resource function in app/resources/, then register it in register_resources() with a URI such as mcp.resource("example://item").
Call an external API
Use or extend app.base.api_client.APIClient for async JSON GET and POST requests. It reads the configured base URL and can attach an API key through the X-API-Key header.
Testing
Run the test suite:
python -m pytest
The current tests verify the built-in tool behavior and confirm that all tools, prompts, and resources are registered.
License
No license file is currently included. Add a license before distributing or reusing this project outside its intended scope.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。