使用说明
项目概述
此存储库包含两个主要组件:
1. user-api (去)
Go内置了一个简单的REST API,用于管理内存中存储的用户。
特征:
- 按ID或名称添加、列出和检索用户
- 内存数据存储(重启时数据丢失)
- JSON API响应
终点:
POST /users--添加新用户GET /users--列出所有用户(可选择按名称筛选)GET /users/{id}--按ID获取用户GET /health--健康检查
要运行:
cd user-api
make dev
API将于 http://localhost:8080.
2. mcp-server (Node.js/TypeScript)
一种MCP(模型上下文协议)服务器,将用户API公开为MCP工具,允许客户端通过MCP协议与用户API交互。
暴露的MCP工具:
getUsers--检索所有用户getUsersByName--按名称检索用户getUserById--按ID检索用户registerUser--注册新用户
它是如何工作的:
MCP服务器充当桥接器,将工具调用转发到运行于的REST API http://localhost:8080.
如何运行MCP服务器并与之交互
先决条件
- Node.js(参见
.tool-versions对于推荐版本) - 这
user-api服务器必须在上运行localhost:8080
步骤
-
启动用户api服务器:
cd user-api make dev # or: go run main.go -
安装依赖项并启动MCP服务器:
cd mcp-server yarn install yarn start # or: node src/index.tsMCP服务器将启动并通过stdio监听MCP协议连接。
-
与MCP服务器交互:
- 使用兼容MCP的客户端连接到服务器(例如,通过stdio)。
- 调用可用工具(
getUsers,getUsersByName,getUserById,registerUser)如MCP协议中所定义。
示例工具调用
Prompt: Liste os usuarios na user api
Aqui está a lista de usuários atualmente cadastrados na user-api:
Jane Smith — jane@example.com (ID: 565b21a7-56ed-433b-9cd4-c14025efdd04)
John Doe — johndoe@example.com (ID: bd9cf73e-7958-40ee-8688-d0db87f403e8)
Jane Smith — jane@example.com (ID: 83b20f4e-1624-4a23-b686-7b9894fda3d5)
John Doe — johndoe@example.com (ID: 997482dc-43c3-4d86-8e6a-b92aae556770)
Se precisar de mais detalhes ou quiser filtrar por nome ou ID, é só pedir!
注:
- MCP服务器希望用户api在以下位置运行并可访问
http://localhost:8080. - 所有用户数据都存储在内存中,当用户api服务器重新启动时将丢失。