模型上下文协议服务器

模型上下文协议服务器

提供工具的MCP服务器,支持SSE、stdio通信和工具调用。

快速入门

1. 克隆仓库

使用以下命令克隆项目:

git clone https://github.com/InnoBridge/ModelContextProtocolServer.git

2. 构建项目

运行以下命令生成Java构件:

./mvnw clean install

3. 启动服务器

使用stdio模式启动:

java -Dtransport.mode=stdio \
     -Dspring.main.web-application-type=none \
     -Dspring.main.banner-mode=off \
     -Dlogging.file.name=mcpserver.log \
     -jar target/mcpserver-0.0.1-SNAPSHOT.jar

4. 测试API

连接到SSE流:

curl -N -H "Accept: text/event-stream" http://localhost:8081/sse

调用计算器工具:

curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"calculator","arguments":{"operation":"+","a":2,"b":3}}}' http://localhost:8081/mcp/message

获取天气信息:

curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"get_current_weather","arguments":{"location":"San Francisco","format":"celsius"}}}' http://localhost:8081/mcp/