Absurdly easy Model Context Protocol Servers in Typescript
Absurdly easy Model Context Protocol Servers in Typescript
EasyMCP is usable but in beta. Please report any issues you encounter.
EasyMCP is the simplest way to create Model Context Protocol (MCP) servers in TypeScript.
It hides the plumbing, formatting, and other boilerplate definitions behind simple declarations.
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.
To install EasyMCP, run the following command in your project directory:
bun installAlso see examples/express-decorators.ts or run bun start:decorators
EasyMCP's decorator API is dead simple and infers types and input configuration automatically.
But it's experimental and may change or have not-yet-discovered problems.
import EasyMCP from "./lib/EasyMCP";
import { Tool, Resource, Prompt } from "./lib/experimental/decorators";
class MyMCP extends EasyMCP {
@Resource("greeting/{name}")
getGreeting(name: string) {
return `Hello, ${name}!`;
}
@Prompt()
greetingPrompt(name: string) {
return `Generate a greeting for ${name}.`;
}
@Tool()
greet(name: string, optionalContextFromServer: Context) {
optionalContextFromServer.info(`Greeting ${name}`);
return `Hello, ${name}!`;
}
}
const mcp = new MyMCP({ version: "1.0.0" });See examples/express-express.ts or run bun start:express
…Also see examples/example-minimal.ts or run bun start:express
This API is more verbose and less magical, but it's more stable and tested.
…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.
EasyMCP provides decorators for a more concise and declarative way to define your MCP server components. Here's an overview of the available decorators:
@Tool(config?: ToolConfig)Defines a method as a tool. The method will take in any arguments you declare and infer types and input configurations based on your TS annotations. An optional context argument can be added as the last argument to access MCP capabilities.
config: Optional configuration object for the tool.description: Optional description of the tool.optionals: Optional array of parameter names that should be marked as optional.parameters: Optional array of parameter definitions for full control over the input schema.Example:
@Tool({
description: "Greets a person",
optionals: ["title"],
})
greet(name: string, title?: string, optionalContext: Context) {
return `Hello, ${title ? title + " " : ""}${name}!`;
}@Resource(uri: string, config?: Partial)Defines a method as a resource or resource template. A resource template is defined by using handlebars in the URI.
uri: The URI or URI template for the resource.config: Optional configuration object for the resource.name: Optional name for the resource.description: Optional description of the resource.mimeType: Optional MIME type of the resource.Example:
@Resource("greeting/{name}")
getGreeting(name: string) {
return `Hello, ${name}!`;
}@Prompt(config?: PromptDefinition)Defines a method as a prompt.
config: Optional configuration object for the prompt.name: Optional name for the prompt (defaults to method name).description: Optional description of the prompt.args: Optional array of argument definitions.Example:
@Prompt({
description: "Generates a greeting prompt",
args: [
{ name: "name", description: "Name to greet", required: true },
],
})
greetingPrompt(name: string) {
return `Generate a friendly greeting for ${name}.`;
}@Root(uri: string, config?: { name?: string })Defines a root directory for the MCP server. This decorator is applied to the class, not to a method.
uri: The URI of the root directory.config: Optional configuration object.name: Optional name for the root.Example:
@Root("/my-sample-dir/photos")
@Root("/my-root-dir", { name: "My laptop's root directory" })
class MyMCP extends EasyMCP {
// ...
}When using decorators, EasyMCP will automatically infer types and create appropriate configurations for your tools, resources, prompts, and roots. This can significantly reduce boilerplate code and make your MCP server definition more concise.
But... the decorator API is experimental and may have bugs or unexpected changes
Contributions are welcome! Just submit a PR.
This project is licensed under the MIT License.
EasyMCP was created by Zach Caceres but inspired by FastMCP by kjlowin, a library for Python MCP servers.
No open issues yet, or sync has not completed.