Test MCP Server
A simple learning-focused MCP server that demonstrates basic functionality with tools for mathematical operations, system information, and email validation, plus sample file resources. Perfect for understanding MCP protocol basics and testing integrations.
README
Test MCP Server
A simple MCP (Model Context Protocol) server for learning purposes. This server demonstrates basic MCP functionality including tools and resources with Zod validation.
What is MCP?
MCP (Model Context Protocol) is a protocol that allows AI models to interact with external tools and resources. It provides a standardized way for AI assistants to:
- Call tools (functions) to perform actions
- Read resources (files, data sources) to get information
- Provide structured responses with proper error handling
How MCP Works
- AI Model (like Cursor) wants to use a tool
- AI Model sends a JSON-RPC request to the MCP Server via stdio
- MCP Server processes the request and returns a response
- AI Model uses the response to help the user
The communication happens through JSON-RPC 2.0 over stdio - no web servers needed!
Features
This test server includes:
Tools (with Zod Validation)
echo: Echo back input text with validationadd_numbers: Add two numbers together with type checkingget_system_info: Get basic system information (Node.js platform details)validate_email: Validate email addresses using Zod's built-in email validation
Resources
file://example.txt: A sample text file with timestampfile://example.json: A sample JSON file with server metadata
Key Features
- ✅ Zod Validation: Runtime type checking for all tool inputs
- ✅ Error Handling: Clear error messages for invalid inputs
- ✅ JSON-RPC 2.0: Standard protocol communication
- ✅ Type Safety: TypeScript/JavaScript with proper schemas
- ✅ Resource Management: Both text and JSON resource examples
Setup
- Install dependencies:
npm install
- Make the server executable:
chmod +x server.js
Usage
Running the Server
The server can be run directly:
npm start
# or
node server.js
Testing with the Client
Run the test client to see the server in action:
npm test
# or
node test_client.js
Using with Cursor
- Copy the configuration from
mcp_config.jsonto your Cursor settings - Update the path to point to your local copy of this repository
Option 1: Using absolute path
{
"mcpServers": {
"test-server": {
"command": "node",
"args": ["/path/to/your/mcp-test/server.js"],
"env": {}
}
}
}
Option 2: Using working directory (recommended)
{
"mcpServers": {
"test-server": {
"command": "node",
"args": ["server.js"],
"cwd": "/path/to/your/mcp-test",
"env": {}
}
}
}
The mcp_config.json file in this repository serves as a template - copy it to your ~/.cursor/mcp.json and update the paths as needed.
How It Works
Server Architecture
- Server Initialization: Creates MCP server with capabilities
- Tool Registration: Tools are registered with Zod schemas for validation
- Resource Registration: Resources are registered with URIs and metadata
- Request Handling: Server processes JSON-RPC requests via stdio
- Response Generation: Responses are formatted according to MCP protocol
Communication Flow
Cursor → JSON-RPC Request → MCP Server → Zod Validation → Tool Execution → Response → Cursor
Example JSON-RPC Communication
Request:
{
"jsonrpc": "2.0",
"id": "1",
"method": "tools/call",
"params": {
"name": "add_numbers",
"arguments": {"a": 5, "b": 3}
}
}
Response:
{
"result": {
"content": [{"type": "text", "text": "Result: 5 + 3 = 8"}]
},
"jsonrpc": "2.0",
"id": "1"
}
Extending the Server
Adding New Tools
-
Define Zod Schema:
const MyToolInputSchema = z.object({ param1: z.string().describe('Description'), param2: z.number().optional() }); -
Add Tool Definition:
{ name: 'my_tool', description: 'My new tool', inputSchema: { /* JSON schema */ } } -
Implement Handler:
case 'my_tool': { const validatedArgs = MyToolInputSchema.parse(args); // Tool logic here return { content: [{ type: 'text', text: 'Result' }] }; }
Adding New Resources
-
Add Resource Definition:
{ uri: 'file://my-resource', name: 'My Resource', description: 'Description', mimeType: 'text/plain' } -
Implement Handler:
case 'file://my-resource': { return { contents: [{ type: 'text', text: 'Resource content', uri: 'file://my-resource' }] }; }
Troubleshooting
MCP Tools Not Appearing in Cursor
- Check configuration: Ensure
~/.cursor/mcp.jsonhas the correct path - Restart Cursor: MCP configuration changes require a restart
- Test server: Run
node server.jsto verify it starts without errors - Check logs: Look for error messages in Cursor's developer console
Common Issues
- Path issues: Use absolute paths in MCP configuration
- Permission errors: Ensure the server file is executable (
chmod +x server.js) - Dependency issues: Run
npm installto ensure all packages are installed - Port conflicts: MCP uses stdio, so no port conflicts possible
Testing Your Server
# Test server directly
node server.js
# Test with a simple client
echo '{"jsonrpc":"2.0","id":"1","method":"tools/list","params":{}}' | node server.js
Project Structure
mcp-test/
├── server.js # Main MCP server
├── package.json # Dependencies and scripts
├── mcp_config.json # MCP configuration template
├── README.md # This file
└── .gitignore # Git ignore rules
Contributing
- Fork the repository
- Create a feature branch
- Add your tools/resources
- Test thoroughly
- Submit a pull request
License
MIT License - feel free to use this as a starting point for your own MCP servers!
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。