关于 Simple MCP
Simple MCP 是用于构建 MCP 服务的 TypeScript 库,提供精简 API 和基于 Zod 的参数验证,并支持直接或基于类的工具实现。
主要功能
- 01精简的服务创建 API
- 02TypeScript 类型安全
- 03Zod 参数验证
- 04直接定义或通过类定义工具
适用场景
- 01用少量代码创建 MCP 服务
- 02使用 Zod 验证工具参数
- 03在 TypeScript 中以类实现工具
MCP 相关
该库实现 Model Context Protocol,提供创建 MCP 服务和注册工具的 API。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
暂未收录安装方式
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
还没有获取到工具列表
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
Simple MCP
一个用于创建 MCP(模型上下文协议)服务的简单 TypeScript 库。
功能
- 简单的 API:只需少量代码即可创建 MCP 服务
- 类型安全:全面集成 TypeScript
- 参数验证:内置 Zod 验证
- 兼容 MCP:完整实现模型上下文协议
安装
npm install simple-mcp
快速入门
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' });
基于类的实现
你也可以使用类实现 MCP 工具:
import { McpServer, type McpTool } from 'simple-mcp';
import { z, ZodObject } from 'zod';
const parameters = {
name: z.string().describe('The name is required'),
};
class GreetTool implements McpTool<typeof parameters> {
public readonly name = 'greet';
public readonly parameters = parameters;
public async execute({ name }: z.infer<ZodObject<typeof this.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' });
示例
请查看 示例目录,了解更多完整示例:
贡献
欢迎贡献!你可以提交问题或拉取请求。
许可证
评论
支持 Markdown
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。