Easy Mcp

Easy Mcp

🚀 EasyMCP 中文文档

EasyMCP 是一款现代化工具,用于创建和管理 Minecraft 模组开发者协议(MCP)服务器。它极大简化了 MCP 服务器的定义与配置流程,支持装饰器 API 和 Express 类似 API 这两种主要接口,为开发者带来便捷。

🚀 快速开始

💻 使用示例

基础用法

使用装饰器 API 定义 MCP 组件:

@Tool({
description: "Greets a person",
optionals: ["title"],
})
greet(name: string, title?: string, optionalContext: Context) {
return `Hello, ${title ? title + " " : ""}${name}!`;
}

高级用法

使用 Express 类似 API 定义 MCP 组件:

import { EasyMCP } from "easy-mcp";

const mcp = new EasyMCP("MyMCP", {
version: "1.0",
});

mcp.resource({
uri: "greeting/{name}",
config: {
name: "Greeting Resource",
description: "Generates a greeting message for a given name.",
mimeType: "text/plain",
},
});

mcp.prompt({
name: "introduction",
description: "Generates an introduction",
args: [
{ 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!`;
},
});

await mcp.serve();

✨ 主要特性

支持两种主要接口:装饰器 API 和 Express 类似 API,使用装饰器 API 可以自动推断类型并为工具、资源、提示和根生成适当的配置,从而显著减少样板代码并使 MCP 服务器定义更加简洁。

📚 详细文档

装饰器 API

@Tool(config?: ToolConfig)

将方法定义为工具。该方法可以接受任意声明的参数,并根据 TypeScript 注解推断类型和输入配置。可以在最后一个参数中添加一个可选的 context 参数以访问 MCP 功能。

  • config:可选的工具配置对象。
    • description:工具的可选描述。
    • optionals:标记为可选的参数名称数组。
    • parameters:对输入架构进行全面控制的可选参数定义数组。

示例:

@Tool({
description: "Generates a greeting message",
optionals: ["title"],
})
greet(name: string, title?: string) {
return `Hello, ${title ? `${title} ` : ""}${name}!`;
}

@Resource(uri: string, config?: Partial)

将方法定义为资源或资源模板。使用 Handlebars 在 URI 中定义资源模板。

  • uri:资源的 URI 或 URI 模板。
  • config:可选的资源配置对象。
    • name:资源的可选名称。
    • description:资源的可选描述。
    • mimeType:资源的可选 MIME 类型。

示例:

@Resource("greeting/{name}")
getGreeting(name: string) {
return `Hello, ${name}!`;
}

@Prompt(config?: PromptDefinition)

将方法定义为提示。

  • config:可选的提示配置对象。
    • name:提示的可选名称(默认为方法名称)。
    • description:提示的可选描述。
    • args:可选参数定义数组。

示例:

@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 })

将类定义为 MCP 服务器的根目录。此装饰器用于类,而不是方法。

  • uri:根目录的 URI。
  • config:可选配置对象。
    • name:根的可选名称。

示例:

@Root("/my-sample-dir/photos")
@Root("/my-root-dir", { name: "My laptop's root directory" })
class MyMCP extends EasyMCP {
// ...
}

🤝 贡献

欢迎贡献!只需提交 PR 即可。

📄 许可证

此项目在 MIT 许可证下发行。

👨‍💻 作者

EasyMCP 由 Zach Caceres 创建,灵感来自 kjlowin 的 FastMCP

  • 0 关注
  • 0 收藏,17 浏览
  • system 提出于 2025-09-18 15:03

相似服务问题

相关AI产品