Create TypeScript-based MCP server templates with tools, testing, and MCP SDK integration
The MCP (Model Context Protocol) Server Template is a robust, fully TypeScript-supported foundation for developing servers that integrate seamlessly with Model Context Protocol clients like Claude Desktop, Continue, Cursor, and more. This template leverages modern development tools and practices to ensure high-quality, maintainable code while providing essential features such as container-based dependency injection, service architecture, automated testing, and compatibility with the latest MCP standards.
The core strengths of the MCP Server Template lie in its comprehensive support for building MCP-compatible servers. Key features include:
The architecture of an MCP server built from this template revolves around a service-based design that adheres closely to the Model Context Protocol. This involves:
The server is structured using services, each handling specific functionalities. For example, DataProcessor
serves as the interface for all tool implementations, ensuring consistent behavior and communication.
Using dependency injection, tools can be easily swapped out or extended without modifying the core codebase, enhancing flexibility and maintainability.
The MCP protocol implementation ensures seamless communication between the server and any compatible MCP client. This involves:
src/tools/
, where custom implementations must mimic the format provided as examples.Install Dependencies
npm install
Start the Development Server:
npm run dev
Build the Project:
npm run build
Run Tests:
npm test
Start the Production Server:
npm start
Export Your Tools and Handlers:
// In your-tool.ts
export const YOUR_TOOLS = [
{
name: "your-tool-name",
description: "Your tool description",
parameters: {
// Your tool parameters schema
},
},
];
export const YOUR_HANDLERS = {
"your-tool-name": async (request) => {
// Your tool handler implementation
return {
toolResult: {
content: [{ type: "text", text: "Result" }],
},
};
},
};
Register Your Tool:
// In src/index.ts
import { YOUR_TOOLS, YOUR_HANDLERS } from "./tools/your-tool.js";
const ALL_TOOLS = [...EXAMPLE_TOOLS, ...YOUR_TOOLS];
const ALL_HANDLERS = { ...EXAMPLE_HANDLERS, ...YOUR_HANDLERS };
The server automatically:
Imagine an AI application that needs real-time feedback from various data sources. By integrating with this MCP server, the application can seamlessly query tools like weather forecasts or financial analytics directly within its workflow.
For machine learning models needing fresh data periodically, using this server can provide a robust mechanism for continuous update, ensuring that training datasets are always up-to-date and accurate.
The template includes integration support for popular MCP clients like Claude Desktop. The compatibility matrix below highlights current client support:
MCP Client | Resources | Tools | Prompts |
---|---|---|---|
Claude Desktop | ✅ | ✅ | ✅ |
Continue | ✅ | ✅ | ✅ |
Cursor | ❌ | ✅ | ❌ |
This section outlines the performance and compatibility matrix of the template, ensuring it aligns with various development needs:
Advanced configuration options are available to tailor the server’s behavior. Key aspects include:
graph TD
A[AI Application] -->|MCP Client| B[MCP Protocol]
B --> C[MCP Server]
C --> D[Data Source/Tool]
style A fill:#e1f5fe
style C fill:#f3e5f5
style D fill:#e8f5e8
{
"mcpServers": {
"[server-name]": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/your-server"],
"env": {
"API_KEY": "your-api-key"
}
}
}
}
Integrating your custom tool involves defining it within src/tools/
and ensuring its handlers are exported correctly. Refer to the example in example.ts
.
The template includes basic examples but allows for easy extension by adding new tools through similar patterns.
The MCP protocol standardizes data formats, ensuring consistent handling of complex data types across all clients.
Yes, it can. Ensure you configure multiple servers within your main application.
Always return structured error responses to maintain consistency and allow better debugging.
Contributions are welcome! To get started:
Fork the Repository:
Clone Your Fork:
git clone https://github.com/your-username/mcp-server-template.git
Install Dependencies:
npm install
Make Changes & Test:
npm run test
to check for errors.Commit and Push:
git commit -am 'Added a new tool'
git push origin main
Create an Issue or Pull Request:
Explore the broader MCP ecosystem and resources:
By leveraging the MCP Server Template, you can build powerful and flexible AI applications that seamlessly integrate into various workflows and environments.
RuinedFooocus is a local AI image generator and chatbot image server for seamless creative control
Learn to set up MCP Airflow Database server for efficient database interactions and querying airflow data
Build stunning one-page websites track engagement create QR codes monetize content easily with Acalytica
Simplify MySQL queries with Java-based MysqlMcpServer for easy standard input-output communication
Explore CoRT MCP server for advanced self-arguing AI with multi-LLM inference and enhanced evaluation methods
Access NASA APIs for space data, images, asteroids, weather, and exoplanets via MCP integration