Skip to content

Absurdly easy Model Context Protocol Servers in Typescript

License

Notifications You must be signed in to change notification settings

zcaceres/easy-mcp

Repository files navigation

easy-mcp

EasyMCP is in beta, with a first release coming in January 2025. Please report any issues you encounter.

Easy MCP is the simplest way to create Model Context Protocol (MCP) servers in TypeScript.

It hides the plumbing and definitions behind simple, easy-to-use functions, allowing you to focus on building your server. Easy MCP strives to mimic the syntax of popular server frameworks like Express, making it easy to get started.

Easy MCP allows you to define the bare minimum of what you need to get started, or you can define more complex resources, templates, tools, and prompts.

Installation

To install easy-mcp, run the following command in your project directory:

pnpm install easy-mcp

Or if you're using bun:

bun add easy-mcp

Limitations

  • No support for sampling
  • No support for SSE

Usage

Here's a basic example of how to use easy-mcp:

import EasyMCP from "easy-mcp";

const mcp = EasyMCP.create("my-mcp-server", {
  version: "0.1.0",
});

// Define a resource
mcp.resource({
  uri: "dir://desktop",
  name: "Desktop Directory", // Optional
  description: "Lists files on the desktop", // Optional
  mimeType: "text/plain", // Optional
  fn: async () => {
    return "file://desktop/file1.txt\nfile://desktop/file2.txt";
  },
});

// Define a resource template
mcp.template({
  uriTemplate: "file://{filename}",
  name: "File Template", // Optional
  description: "Template for accessing files", // Optional
  mimeType: "text/plain", // Optional
  fn: async ({ filename }) => {
    return `Contents of ${filename}`;
  },
});

// Define a tool
mcp.tool({
  name: "greet",
  description: "Greets a person", // Optional
  inputs: [ // Optional
    {
      name: "name",
      type: "string",
      description: "The name to greet",
      required: true,
    },
  ],
  fn: async ({ name }) => {
    return `Hello, ${name}!`;
  },
});

// Define a prompt
mcp.prompt({
  name: "introduction",
  description: "Generates an introduction", // Optional
  args: [ // Optional
    {
      name: "name",
      type: "string",
      description: "Your name",
      required: true,
    },
  ],
  fn: async ({ name }) => {
    return `Hi there! My name is ${name}. It's nice to meet you!`;
  },
});

// Start the server
mcp.serve().catch(console.error);

API

EasyMCP.create(name: string, options: ServerOptions)

Creates a new EasyMCP instance.

  • name: The name of your MCP server.
  • options: Server options, including the version.

mcp.resource(config: ResourceConfig)

Defines a resource.

mcp.template(config: ResourceTemplateConfig)

Defines a resource template.

mcp.tool(config: ToolConfig)

Defines a tool.

mcp.prompt(config: PromptConfig)

Defines a prompt.

mcp.root(config: Root)

Defines a root.

mcp.serve()

Starts the MCP server.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.

Credits

Easy MCP was created by Zach Caceres but inspired by FastMCP by kjlowin, a library for Python MCP servers.