A TypeScript library for creating Model Context Protocol (MCP) servers with a simple API, full type safety, built-in parameter validation using Zod, and seamless MCP compatibility.
Unlock the full potential of MCPKit through LangDB's AI Gateway. Get enterprise-grade security, analytics, and seamless integration with zero configuration.
Free tier available • No credit card required
A simple TypeScript library for creating MCP (Model Context Protocol) servers.
npm install simple-mcp
import { McpServer } from 'simple-mcp'; import { z } from 'zod'; // Create a server instance const server = new McpServer({ name: 'my-server' }); // Register the tool with the server server.tool({ name: 'greet', parameters: { name: z.string().describe('Person\'s name') }, execute: async ({ name }) => { return { content: [ { type: 'text', text: `Hello, ${name}! Nice to meet you.` } ] }; } }); // Start the server server.start({ transportType: 'stdio' });
You can also implement MCP tools using classes:
import { McpServer, type McpTool } from 'simple-mcp'; import { z, ZodObject } from 'zod'; const parameters = { name: z.string().describe('The name is required'), }; class GreetTool implements McpTool { public readonly name = 'greet'; public readonly parameters = parameters; public async execute({ name }: z.infer>) { return { content: [ { type: 'text', text: `Hello, ${name}! Nice to meet you.`, }, ], }; } } // Initialize a new MCP server with the name 'greet-server' const server = new McpServer({ name: 'greet-server' }); // Create an instance of the GreetTool class const greetTool = new GreetTool(); // Register the tool with the server server.tool(greetTool); // Start the server using stdio as the transport method server.start({ transportType: 'stdio' });
Check out the examples directory for more complete examples:
Contributions are welcome! Feel free to open issues or submit pull requests.
MIT
Discover shared experiences
Shared threads will appear here, showcasing real-world applications and insights from the community. Check back soon for updates!