使用说明
mcp服务器
[!重要] 我们将项目转移到 代理 更好地组织人工智能开发人员的工具和服务。我们鼓励您使用新软件包并关注 Agentico的GitHub仓库.
MCP服务器是一个简单的服务器,它实现了模型上下文协议(MCP),以提供 更简单的API 以与模型上下文协议交互。
为什么要使用此服务器?
在“La Rebellion“我们正在开发一套工具和服务,以简化流程和工作流程,从而获得更好、更高效的开发人员体验。此服务器是一套工具的一部分。
MCP很神奇,但开始时可能会有点困惑。我们创建了一个 立面 以简化创建实现模型上下文协议的服务器的过程。模式很简单,你只需要创建 tools 使用您自己的逻辑,注册工具并启动服务器。
创建新服务器的步骤
将来,我们将提供一个CLI来创建类似于以下内容的新服务器 MCP创建服务器,但现在您可以根据以下步骤进行操作 创建服务器的官方文档.
mkdir -p my-server/src
cd my-server/
yarn init -y
yarn add @modelcontextprotocol/sdk zod zod-to-json-schema
yarn add -D @types/node typescript
# Here lies the magic
yarn add @la-rebelion/mcp-server
您需要更新 package.json 文件并创建 tsconfig.json 文件。
入门指南
使用自定义逻辑实现您的工具,并在MCPServer中注册它们。以下是一个简单的示例 echo 工具:
import { Tool, ToolSchema } from "@la-rebelion/mcp-server";
export class EchoTool extends Tool {
toolSchema: ToolSchema = {
name: "echo",
description: "Echoes the input message",
schema: { // the schema for the parameters needed by the tool
type: "object",
properties: {
message: { type: "string" },
},
required: ["message"],
},
};
/**
* Your logic here, implement the execute method to define the tool behavior
* @param input The input message - use the schema to define the input type
* @returns In the example, we are echoing the message
*/
async execute(input: any): Promise<any> {
// This is a simple echo tool demo, nothing fancy, just echoing the message
return Promise.resolve({
content: [
{
type: "text",
text: `${input.message}`
}
]
});
}
}
创建一个 index.ts 包含以下内容的文件:
#!/usr/bin/env node
import { MCPServer } from '@la-rebelion/mcp-server'
import { EchoTool } from "./tools/EchoTool.js";
const myServer = new MCPServer('My MCP Server', '1.0.0');
async function main() {
// Register tools
myServer.registerTool("echo", EchoTool);
await myServer.run();
}
main().catch((error) => {
console.error("Server error:", error);
process.exit(1);
});
就是这样!您已经创建了一个实现模型上下文协议的简单服务器。用以下方式进行测试 克劳德桌面 或支持MCP的任何其他客户端。
使用以下命令构建项目:
yarn build
您可以启动服务器,但还没有逻辑,您可以使用以下命令对其进行测试:
yarn start
# or
node build/index.js
就是这样,开始创建自己的工具和服务,以简化您的工作流程和流程。
去反抗! ✊🏻
UML图
- MCP服务器:注册服务器将使用的工具。
- 工具:所有工具的基类,包含通用属性和方法。
execute是调用工具时将调用的方法,请在此处实现您的逻辑。 - EchoTool:工具的具体实现,扩展tool类并定义其自己的模式和初始化逻辑。
- EchoSchema:定义EchoTool的输入结构。
- 回声输入:基于架构的输入类型定义。
此模式允许使用MCPServer和Tool类以灵活和可扩展的方式管理和实现工具。
支持我们
如果你觉得这很有用,请考虑通过主演这个存储库、为项目做出贡献或成为赞助商来支持我们。
您可以在以下网址找到有关如何支持我们的更多信息 La Rebelion GitHub赞助商.还有 给我们买杯咖啡, 贝宝 是支持我们或购买的好方法 “La Rebellion”商品.
许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
