Test MCP Server
A dual-transport MCP server that exposes your API as tools to LLM clients, supporting both stdio transport for local clients like Claude Desktop and HTTP/SSE transport for remote clients like OpenAI's Responses API.
README
Test MCP Server
A dual-transport Model Context Protocol (MCP) server that exposes your API as tools to LLM clients.
Supports two transports:
- Stdio (local): For Claude Desktop, Cursor, Windsurf
- HTTP/SSE (remote): For OpenAI Responses API and web clients
What is MCP?
The Model Context Protocol (MCP) is a standard that connects AI systems with external tools and data sources. MCP servers expose tools (functions), resources (data), and prompts that LLMs can use via a JSON-RPC interface over stdio.
Architecture
This is a proper MCP server that:
- ✅ Supports dual transports: stdio (local) and HTTP/SSE (remote)
- ✅ Uses the official MCP Python SDK (
mcppackage) for stdio - ✅ Uses FastAPI for HTTP/SSE transport
- ✅ Can be launched by MCP clients (Claude Desktop, Cursor, Windsurf)
- ✅ Can be called remotely by OpenAI Responses API
- ✅ Exposes tools with strict JSON schemas for deterministic behavior
- ✅ Includes authentication, rate limiting, and security best practices
- ✅ Follows SOLID principles with clean separation of concerns
Project Structure
windsurf-project/
├── main.py # Entry point for stdio transport (local)
├── main_http.py # Entry point for HTTP/SSE transport (remote)
├── requirements.txt # Python dependencies
├── mcp_config.json # Configuration for local MCP clients
├── .env.example # Environment variables template
├── README.md # This file
├── REMOTE_DEPLOYMENT.md # Guide for deploying as remote server
├── ThingsIveLearned.md # Project patterns and insights
└── test_mcp/ # Main package
├── __init__.py # Package initialization
├── server.py # MCP server (stdio transport)
├── http_server.py # MCP server (HTTP/SSE transport)
├── tools.py # Tool implementations (shared)
├── config.py # Configuration settings
└── handlers.py # Legacy handlers (can be removed)
Installation
- Install dependencies:
pip install -r requirements.txt
- Configure environment (optional):
cp .env.example .env
# Edit .env with your API credentials if needed
Available Tools
1. search_items
Search for items with pagination support.
Input Schema:
{
"query": "search term", // required
"limit": 10, // optional, 1-50, default 10
"cursor": "pagination_token" // optional
}
Output:
{
"items": [
{
"id": "item_001",
"title": "Item Title",
"summary": "Brief description",
"score": 0.95
}
],
"nextCursor": "next_page_token",
"total": 42
}
2. get_item
Retrieve detailed information about a single item.
Input Schema:
{
"id": "item_001" // required
}
Output:
{
"id": "item_001",
"title": "Item Title",
"body": "Full content...",
"createdAt": "2025-10-08T08:00:00Z",
"url": "https://example.com/items/item_001",
"metadata": {
"author": "Author Name",
"tags": ["tag1", "tag2"]
}
}
3. health
Check server health status.
Input Schema: {} (no parameters)
Output:
{
"status": "healthy",
"server": "test-mcp-server",
"version": "0.1.0",
"timestamp": "2025-10-08T08:43:00Z"
}
Usage
Local Usage (Stdio Transport)
Testing Manually
Run the stdio server:
python main.py
Then send a JSON-RPC request via stdin:
{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}
Connecting to Claude Desktop
-
Open your Claude Desktop config file:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
- macOS:
-
Add this server configuration:
{
"mcpServers": {
"test-mcp-server": {
"command": "python",
"args": [
"/Users/mokes/CascadeProjects/windsurf-project/main.py"
],
"env": {
"API_BASE_URL": "http://localhost:8000/api/v1",
"API_KEY": ""
}
}
}
}
-
Restart Claude Desktop
-
The tools will appear in Claude's tool palette
Connecting to Cursor/Windsurf
Add the server to your MCP configuration (similar process to Claude Desktop).
Remote Usage (HTTP/SSE Transport)
Quick Start
- Start the HTTP server:
python main_http.py
Server runs at http://localhost:8000
- Test with curl:
# List tools
curl -X POST http://localhost:8000/mcp \
-H "Content-Type: application/json" \
-d '{"action": "list_tools"}'
# Call a tool
curl -X POST http://localhost:8000/mcp \
-H "Content-Type: application/json" \
-d '{
"action": "call_tool",
"name": "search_items",
"arguments": {"query": "test", "limit": 5}
}'
Using with OpenAI Responses API
Once deployed to a public URL:
from openai import OpenAI
client = OpenAI()
resp = client.responses.create(
model="gpt-5",
tools=[{
"type": "mcp",
"server_label": "my-api",
"server_url": "https://api.yourdomain.com/mcp",
"authorization": "Bearer your_token",
"require_approval": "never"
}],
input="Search for items about AI"
)
print(resp.output_text)
See REMOTE_DEPLOYMENT.md for complete deployment guide.
Customizing for Your API
Option 1: Replace Mock Data with Real API Calls
Edit test_mcp/tools.py and uncomment the real API call examples:
async def search_items_tool(arguments: Dict[str, Any]) -> Dict[str, Any]:
query = arguments.get("query", "")
limit = arguments.get("limit", 10)
cursor = arguments.get("cursor")
# Call your actual API
params = {"q": query, "limit": limit}
if cursor:
params["cursor"] = cursor
data = await call_api("GET", "/search", params=params)
return {
"items": data.get("items", []),
"nextCursor": data.get("nextCursor"),
"total": data.get("total", 0)
}
Option 2: Add New Tools
- Define the tool schema in
test_mcp/server.py:
Tool(
name="create_item",
description="Create a new item",
inputSchema={
"type": "object",
"properties": {
"title": {"type": "string", "minLength": 1},
"body": {"type": "string"}
},
"required": ["title"]
}
)
- Implement the tool in
test_mcp/tools.py:
async def create_item_tool(arguments: Dict[str, Any]) -> Dict[str, Any]:
title = arguments.get("title")
body = arguments.get("body", "")
# Your implementation
data = await call_api("POST", "/items", json={"title": title, "body": body})
return data
- Wire it up in the
call_toolhandler:
elif name == "create_item":
result = await create_item_tool(arguments)
return [TextContent(type="text", text=json.dumps(result, indent=2))]
Best Practices
✅ DO:
- Keep tool outputs compact and stable - LLMs rely on predictable shapes
- Use opaque cursors for pagination (not page numbers)
- Validate inputs strictly with JSON schemas (min/max, enums, defaults)
- Return clear error messages - avoid HTML or stack traces
- Add timeouts and retries for external API calls
- Never expose secrets in tool outputs
❌ DON'T:
- Don't return huge blobs of data - summarize or paginate
- Don't use page numbers - use cursors for deterministic pagination
- Don't hardcode API keys - use environment variables
- Don't expose internal IDs or PII unless required
- Don't make tools that have side effects without idempotency keys
Key Patterns
-
Separation of Concerns:
server.py: MCP protocol handling (stdio, JSON-RPC)tools.py: Business logic and API callsconfig.py: Configuration management
-
Type Safety:
- Pydantic models for validation
- Python type hints throughout
- Strict JSON schemas for tool inputs
-
Error Handling:
- Graceful degradation
- Clear error messages
- Timeout handling
-
Determinism:
- Stable output formats
- Predictable pagination
- Consistent error codes
Troubleshooting
Server won't start
- Check Python version (3.10+)
- Verify all dependencies installed:
pip install -r requirements.txt - Check for syntax errors:
python -m py_compile main.py
Tools not appearing in Claude Desktop
- Verify the path in
claude_desktop_config.jsonis absolute - Check Claude Desktop logs for errors
- Restart Claude Desktop after config changes
API calls failing
- Verify
API_BASE_URLandAPI_KEYin environment - Check network connectivity
- Add logging to
tools.pyto debug
Environment Variables
API_BASE_URL: Base URL for your API (default:http://localhost:8000/api/v1)API_KEY: API authentication key (optional)ENVIRONMENT: Environment name (default:development)DEBUG: Enable debug logging (default:true)
License
MIT
Contributing
- Follow SOLID principles
- Add type hints to all functions
- Update
ThingsIveLearned.mdwith new patterns - Test with Claude Desktop before committing
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。