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
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
E2B
Using MCP to run code via e2b.