You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A simple TypeScript library for creating MCP (Model Context Protocol) servers.
Features
Simple API: Create MCP servers with minimal code
Type Safety: Full TypeScript integration
Parameter Validation: Built-in validation with Zod
MCP Compatible: Fully implements the Model Context Protocol
Installation
npm install simple-mcp
Quickstart
import{McpServer}from'simple-mcp';import{z}from'zod';// Create a server instanceconstserver=newMcpServer({name: 'my-server'});// Register the tool with the serverserver.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 serverserver.start({transportType: 'stdio'});
Class-based Implementation
You can also implement MCP tools using classes:
import{McpServer,typeMcpTool}from'simple-mcp';import{z,ZodObject}from'zod';constparameters={name: z.string().describe('The name is required'),};classGreetToolimplementsMcpTool<typeofparameters>{publicreadonlyname='greet';publicreadonlyparameters=parameters;publicasyncexecute({ name }: z.infer<ZodObject<typeofthis.parameters>>){return{content: [{type: 'text',text: `Hello, ${name}! Nice to meet you.`,},],};}}// Initialize a new MCP server with the name 'greet-server'constserver=newMcpServer({name: 'greet-server'});// Create an instance of the GreetTool classconstgreetTool=newGreetTool();// Register the tool with the serverserver.tool(greetTool);// Start the server using stdio as the transport methodserver.start({transportType: 'stdio'});