Boilerplate MCP Server
A foundation for developing custom Model Context Protocol (MCP) servers in TypeScript. Provides a complete layered architecture pattern, working example tools, and developer infrastructure to connect AI assistants with external APIs and data sources.
Why Use This Boilerplate?
Production-Ready Architecture: Follows the same pattern used in published MCP servers, with clean separation between CLI, tools, controllers, and services
Type Safety: Built with TypeScript for improved developer experience, code quality, and maintainability
Working Example: Includes fully implemented tools demonstrating the complete pattern from CLI to API integration
Testing Framework: Ready-to-use testing infrastructure for unit and CLI integration tests, with coverage reporting
Complete Developer Tooling: Pre-configured ESLint, Prettier, TypeScript, and CI/CD workflows
What is MCP?
Model Context Protocol (MCP) is an open standard for securely connecting AI systems to external tools and data sources. This boilerplate implements the MCP specification with a clean, layered architecture that can be extended to build custom MCP servers for any API or data source.
Prerequisites
Node.js (>=18.x): Download
Git: For version control
Quick Start
Architecture Overview
Layered Architecture
The boilerplate follows a clean, layered architecture that promotes maintainability and clear separation of concerns:
1. CLI Layer (src/cli/*.cli.ts
)
Purpose: Command-line interfaces that parse arguments and call controllers
Pattern: Use
commander
for argument parsing, call controllers, handle errors withhandleCliError
Naming:
<feature>.cli.ts
2. Tools Layer (src/tools/*.tool.ts
)
Purpose: MCP tool definitions exposed to AI assistants
Pattern: Use
zod
for schema validation, call controllers, format responses for MCPNaming:
<feature>.tool.ts
with types in<feature>.types.ts
3. Controllers Layer (src/controllers/*.controller.ts
)
Purpose: Business logic orchestration, error handling, response formatting
Pattern: Return standardized
ControllerResponse
objects, throw errors with contextNaming:
<feature>.controller.ts
with optional<feature>.formatter.ts
4. Services Layer (src/services/*.service.ts
)
Purpose: External API interactions and data handling
Pattern: Pure API calls with minimal logic, return raw data
Naming:
<feature>.service.ts
orvendor.<vendor>.<feature>.service.ts
5. Utils Layer (src/utils/*.util.ts
)
Purpose: Shared functionality across the application
Key Utils: Logging, error handling, formatting, configuration
Developer Guide
Development Scripts
Debugging Tools
MCP Inspector: Visual tool for testing your MCP tools
Run server with
npm run dev:server
Open http://localhost:5173 in your browser
Server Logs: Enable with
DEBUG=true npm run dev:server
or in config
Create ~/.mcp/configs.json
:
Building Custom Tools
1. Define Service Layer
Create a new service in src/services/
to interact with your external API:
2. Create Controller
Add a controller in src/controllers/
to handle business logic:
3. Implement MCP Tool
Create a tool definition in src/tools/
:
4. Add CLI Support
Create a CLI command in src/cli/
:
5. Register Components
Update the entry points to register your new components:
Publishing Your MCP Server
Update package.json with your details:
{ "name": "your-mcp-server-name", "version": "1.0.0", "description": "Your custom MCP server", "author": "Your Name", // Other fields... }Update README.md with your tool documentation
Build:
npm run build
Test:
npm run start:server
Publish:
npm publish
Testing Best Practices
Unit Tests: Test utils and pure functions in isolation
Controller Tests: Test business logic with mocked service calls
Integration Tests: Test CLI with real dependencies
Coverage Goal: Aim for >80% test coverage
License
Resources
This server cannot be installed
A foundation for developing custom Model Context Protocol servers in TypeScript that connects AI assistants with external APIs and data sources using a complete layered architecture pattern.
Related MCP Servers
- AsecurityFlicenseAqualityA TypeScript-based template for developing Model Context Protocol servers with features like dependency injection and service-based architecture, facilitating the creation and integration of custom data processing tools.Last updated -114
- -securityAlicense-qualityA TypeScript implementation of a Model Context Protocol server that provides a frictionless framework for developers to build and deploy AI tools and prompts, focusing on developer experience with zero boilerplate and automatic tool registration.Last updated -68214MIT License
- AsecurityFlicenseAqualityA TypeScript template for creating Model Context Protocol servers that enable AI models to utilize external tools, including example operations and simple number addition functionality.Last updated -22
- -securityFlicense-qualityA TypeScript-based starter template for building Model Context Protocol servers that enables AI assistants to dynamically call tools, interpret prompts, and manage resources through modular architecture with support for multiple transport methods.