使用说明
基本流式HTTP MCP服务器教程
嘿!这是设置Streamable HTTP MCP服务器的基本教程。在本教程中,我们将介绍以下内容:
- 设置基本的流式HTTP MCP服务器
- 添加基本工具
- 添加API工具
- (即将推出)添加身份验证
设置
- 克隆存储库
- 跑
npm install安装依赖项 - 跑
npm run dev启动服务器 - 使用打开检查器
DANGEROUSLY_OMIT_AUTH=true npx @modelcontextprotocol/inspector@latest http://localhost:3040
添加基本工具
- 打开
src/server.ts - 在服务器中添加一个工具
McpServer类已定义
server.tool(
"add",
"Use this tool to add two numbers together.",
{
a: z.number().describe("The first number to add"),
b: z.number().describe("The second number to add"),
},
async ({ a, b }) => {
// FILL THIS IN YOURSELF
}
);
- 在检查器中刷新并调用工具
添加API工具
- 打开
src/server.ts - 我们将使用此api来测试添加api工具,因为它没有身份验证,可以免费使用 Curreny费率API
- 让我们尝试对工具进行“vibe”编码。首先复制github readme的上下文,并将其粘贴到游标中的内联聊天中:
- 如果这不起作用,您始终可以使用解决方案文件作为参考。解决方案文件位于
solutions文件夹。
添加身份验证
有一天会到来——解决方案文件包含具有身份验证的服务器
