MCP Boilerplate
A minimal, production-ready MCP server with a simple addition calculator tool that demonstrates integration with the Model Context Protocol.
README
MCP Boilerplate
A minimal, production-ready MCP (Model Context Protocol) server boilerplate with a simple addition calculator tool. Built with TypeScript, Zod validation, and comprehensive error handling.
✨ Features
- Simple Calculator Tool: Addition tool demonstrating MCP integration
- Type Safety: Full TypeScript support with strict type checking
- Input Validation: Zod schemas with security-first validation
- Error Handling: Comprehensive error handling with McpError
- Production Ready: Proper process management and graceful shutdown
- Extensible: Clean architecture for adding more tools
🚀 Quick Start
# Clone and install
git clone <your-repo-url>
cd mcp-boilerplate
npm install
# Build and run
npm run build
npm start
📋 Requirements
- Node.js 18.x or higher
- npm or yarn package manager
🏗️ Project Structure
mcp-boilerplate/
├── src/
│ ├── index.ts # Server entry point
│ ├── server.ts # MCP server setup
│ ├── tools/ # Tool implementations
│ │ ├── index.ts # Tool registry
│ │ └── calculator.ts # Addition tool
│ ├── schemas/ # Zod validation schemas
│ │ ├── index.ts # Schema exports
│ │ └── calculator.ts # Calculator schemas
│ ├── types/ # TypeScript definitions
│ │ ├── index.ts # Type exports
│ │ └── tools.ts # Tool interfaces
│ └── utils/ # Utility functions
│ ├── index.ts # Utility exports
│ ├── errors.ts # Error handling
│ └── validation.ts # Validation helpers
├── dist/ # Compiled JavaScript (generated)
├── docs/ # Documentation and research
└── package.json # Dependencies and scripts
🛠️ Available Scripts
npm run build- Compile TypeScript to JavaScriptnpm run dev- Watch mode compilationnpm start- Start the MCP servernpm run lint- Run ESLintnpm run lint:fix- Fix linting issuesnpm run format- Format code with Prettiernpm run clean- Remove compiled files
🔧 Claude Desktop Integration
-
Build the project:
npm run build -
Add to your Claude Desktop configuration (
claude_desktop_config.json):{ "mcpServers": { "mcp-boilerplate": { "command": "node", "args": ["/absolute/path/to/mcp-boilerplate/dist/index.js"], "env": { "NODE_ENV": "production" } } } } -
Restart Claude Desktop
-
Test the calculator tool:
- "Add 5 and 3"
- "What is 1.5 + 2.7?"
- "Calculate -2 plus 7"
🧪 Testing
The server has been tested with the following scenarios:
✅ Successful Operations
- Basic Addition:
5 + 3 = 8 - Negative Numbers:
-2 + 7 = 5 - Decimal Numbers:
1.5 + 2.7 = 4.2 - Zero Values:
0 + 5 = 5
✅ Error Handling
- Invalid Input: String inputs return validation errors
- Missing Parameters: Missing 'a' or 'b' parameters return required field errors
- Out of Bounds: Numbers outside safe range are rejected
🛡️ Security Features
- Input Validation: Comprehensive Zod schemas prevent malicious input
- Number Safety: Finite number validation prevents NaN/Infinity injection
- Bounds Checking: Reasonable limits prevent DoS attacks
- Error Sanitization: Production errors don't expose internal details
📊 Tool Reference
calculator_add
Adds two numbers together with comprehensive validation.
Parameters:
a(number): First number to add (-10,000,000,000 to 10,000,000,000)b(number): Second number to add (-10,000,000,000 to 10,000,000,000)
Returns:
- Success:
{ content: [{ type: 'text', text: 'a + b = result' }] } - Error: MCP error with validation details
Example:
{
"name": "calculator_add",
"arguments": { "a": 5, "b": 3 }
}
🔄 Extending the Boilerplate
Adding a New Tool
-
Create the schema in
src/schemas/:export const MyToolSchema = z.object({ param1: z.string().min(1), }).strict(); export type MyToolInput = z.infer<typeof MyToolSchema>; -
Implement the tool in
src/tools/:export const myTool: ToolDefinition<MyToolInput> = { name: 'my_tool', description: 'Description of what the tool does', inputSchema: MyToolSchema, execute: async (params) => { // Tool implementation return { content: [{ type: 'text', text: 'Result' }] }; }, }; -
Register the tool in
src/tools/index.ts:export const tools = { calculator_add: calculatorTool, my_tool: myTool, // Add your tool here } as const; -
Rebuild and test:
npm run build npm start
🐛 Troubleshooting
Server Won't Start
- Check Node.js version (requires 18.x+)
- Run
npm run buildto compile TypeScript - Check for port conflicts
Tool Not Found
- Verify tool is registered in
src/tools/index.ts - Rebuild with
npm run build - Check tool name matches exactly
Validation Errors
- Check input parameter types match schema
- Verify required fields are provided
- Check number bounds (-1e10 to 1e10)
📝 License
MIT License - see LICENSE file for details.
🤝 Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Built with TypeScript, MCP SDK v1.17.0, and Zod validation
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。