Learn how to build and extend a manageable MCP Server using Anthropic's Model Context Protocol in Node.js
TestMcpServer is an MCP (Model Context Protocol) Server example built to streamline the integration of AI applications with various data sources and tools through a standardized protocol. Inspired by the need for clearer, more comprehensible examples, this server offers developers a straightforward approach to building their own MCP Servers. It supports popular AI applications such as Claude Desktop, Continue, and Cursor. By following the provided guidelines, users can easily add new tools or customize existing ones, enhancing the functionality of both their servers and connected applications.
TestMcpServer encapsulates key features essential for robust MCP implementations:
maths
, where each tool has a unique definition. This ensures scalability and maintainability.The architecture follows a strict adherence to the Model Context Protocol:
/src/definitions
, these files outline the operation of each tool./src/controllers
, handlers implement the actual logic for executing tools.To get started with TestMcpServer, ensure you have Node.js and npm installed on your system. After cloning the repository, run npm install
. For ease of development, you can use npm run dev
to watch for changes and automatically build and run the server.
# Cloning the repository
git clone https://github.com/your-repo/TestMcpServer.git
# Navigate into the project directory and install dependencies
cd TestMcpServer
npm install
# Start the development environment
npm run dev
Imagine integrating a text summarization tool directly from within an AI application, like Claude Desktop, or using Cursor to manage complex workflows involving multiple data points.
Using the addition
and subtraction
tools defined in TestMcpServer, you can create dynamic financial analysis dashboards. For instance:
// Example tool definition
import { Tool } from "@modelcontextprotocol/sdk/types.js";
export const ADDITION = {
name: "addition",
description: "Add two numbers together",
};
class FinancialController {
async handleAddition(a: number, b: number) {
const result = a + b;
return {
content: [
{ type: "text", text: `Sum: ${result}` },
],
isError: false,
};
}
}
This tool can be easily added to the server and accessed by any MCP client, enabling real-time financial calculations directly within the application.
With TestMcpServer, you can source contextual data from various APIs or local tools. For example, integrating a weather API tool allows AI applications to dynamically generate content based on current conditions:
// Example controller and handler method
import { Tool } from "@modelcontextprotocol/sdk/types.js";
export const WEATHER_FETCH = {
name: "weather_fetch",
description: "Fetch live weather data.",
};
class WeatherController {
async handleWeatherFetch() {
// Fetching external API data
try {
const response = await fetch("https://api.openweathermap.org/data/2.5/weather");
const data = await response.json();
return { content: [{ text: "Current temperature is " + data.main.temp }], isError: false };
} catch (error) {
return { isError: true, content: [{ text: `Error fetching weather data` }] };
}
}
}
This setup allows content generation to be contextually relevant and up-to-date.
To integrate TestMcpServer with popular MCP clients:
For example, with Cursor:
TestMcpServer
node <absolute path to project>\build\index.js
Once configuration is done, the tool should be ready for use within your AI application ecosystem.
TestMcpServer ensures seamless compatibility with multiple MCP clients through its versatile architecture:
Configuring and securing TestMcpServer involves several steps:
API_KEY
.{
"mcpServers": {
"TestMcpServer": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-test"],
"env": {
"API_KEY": "your-api-key"
}
}
}
}
How do I add a new tool? Follow the guidelines provided in this documentation:
toolRegistry.ts
.Which MCP clients are compatible with TestMcpServer? The compatibility matrix shows full support from Claude Desktop and Continue, while Cursor supports tools but not prompts.
How can I optimize performance? Consider caching results where appropriate, using efficient database queries, and optimizing network requests.
Can I customize the server's appearance or branding?
Yes, you can modify the files under /src
to suit your branding needs.
Are there any known issues with TestMcpServer? While we strive for stability, issues may arise due to changes in MCP specifications. Regular updates and testing are recommended.
Contributors can help enhance TestMcpServer by:
For more information about Model Context Protocol, visit:
Explore the wider MCP ecosystem for additional use cases and integrations.
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
graph TD
A[MCP Client] --> B[Tool Request]
B --> C[MCP Server]
C --> D[Database/Tool]
style A fill:#e1f5fe
style C fill:#f3e5f5
style D fill:#e8f5e8
Create Tool Definition - Define the tool in a TypeScript file:
import { Tool } from "@modelcontextprotocol/sdk/types.js";
export const ADDITION = {
name: "addition",
description: "Add two numbers together",
inputSchema: {
type: "object",
properties: {
a: {
type: "number",
description: "First number to add",
},
b: {
type: "number",
description: "Second number to add",
},
},
required: ["a", "b"],
},
};
Add Tool to Controller - Implement the logic in a controller:
class FinancialController {
async handleAddition(a: number, b: number) {
const result = a + b;
return { content: [{ text: `Sum: ${result}` }], isError: false };
}
}
Register Tool in Registry - Map the tool to its controller method:
import { ToolRegistry } from "@modelcontextprotocol/server-test";
const addTool = ToolRegistry.register({
name: "addition",
handler: new FinancialController().handleAddition,
});
Server Configuration - Set up the server to use the registry:
import { Server } from "@modelcontextprotocol/server-test";
const server = new Server();
server.registerTools(ToolRegistry.get());
server.start();
By following these steps, developers can seamlessly integrate TestMcpServer into their AI application ecosystems.
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
Simplify MySQL queries with Java-based MysqlMcpServer for easy standard input-output communication
Build stunning one-page websites track engagement create QR codes monetize content easily with Acalytica
Access NASA APIs for space data, images, asteroids, weather, and exoplanets via MCP integration
Explore CoRT MCP server for advanced self-arguing AI with multi-LLM inference and enhanced evaluation methods