simple-mcp
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

Simple MCP

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 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' });

Class-based Implementation

You can also implement MCP tools using classes:

import { McpServer, type McpTool } from 'simple-mcp';
import { z } from 'zod';

const parameters = z.object({
  name: z.string().describe('The name is required'),
});

class GreetTool implements McpTool<typeof parameters.shape> {
  public readonly name = 'greet';
  public readonly parameters = parameters.shape;

  public async execute({ name }: z.infer<typeof parameters>) {
    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' });

Examples

Check out the examples directory for more complete examples:

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

License

MIT

Package Sidebar

Install

npm i simple-mcp

Weekly Downloads

14

Version

0.0.2

License

MIT

Unpacked Size

19.5 kB

Total Files

9

Last publish

Collaborators

  • ribeirogab