远程-MCP 是一个远程模型上下文协议的解决方案,可实现远程访问和集中管理模型上下文,为模型上下文协议提供了强大的扩展能力。
npm install @remote-mcp/client
import { MCPRouter, LogLevel } from "@remote-mcp/client";
const mcpRouter = new MCPRouter({
logLevel: LogLevel.DEBUG,
name: "example-client",
version: "1.0.0",
});
// 添加自定义工具或命令
mcpRouter.addTool(
"calculator",
{
description: "Perform basic calculations.",
schema: z.object({
operation: z.enum(["add", "subtract", "multiply", "divide"]),
a: z.string(),
b: z.string(),
}),
},
async (args) => {
// 处理计算逻辑
return {
content: [{ type: "text", text: `${result}` }],
};
}
);
// 启动服务
mcpRouter.listen(9512);
npm install @remote-mcp/server
import { MCPRouter, LogLevel } from "@remote-mcp/server";
import { createHTTPServer } from '@trpc/server/adapters/standalone';
const mcpRouter = new MCPRouter({
logLevel: LogLevel.DEBUG,
name: "example-server",
version: "1.0.0",
capabilities: {
logging: {},
},
});
// 添加示例工具
mcpRouter.addTool(
"calculator",
{
description:
"Perform basic calculations. Add, subtract, multiply, divide.",
schema: z.object({
operation: z.enum(["add", "subtract", "multiply", "divide"]),
a: z.string(),
b: z.string(),
}),
},
async (args) => {
const a = Number(args.a);
const b = Number(args.b);
switch (args.operation) {
case "add":
return { content: [{ type: "text", text: `${a + b}` }] };
case "subtract":
return { content: [{ type: "text", text: `${a - b}` }] };
// 其他操作...
}
}
);
// 启动 HTTP 服务
createHTTPServer({
router: mcpRouter,
}).start({ port: 9512 });
以下是远程-MCP 的示例架构图:
当前的 MCP 实现仅限于本地使用,无法满足远程访问和集中管理的需求。远程-MCP 解决了这一痛点,为模型上下文协议提供了扩展能力,支持更多高级功能。
欢迎社区成员参与项目!
本项目仅为实验性质,不适用于生产环境。使用前请仔细阅读文档并确保充分测试。
项目遵循 MIT 许可证,具体条款详见 LICENSE 文件。