Token导航 LogoToken导航TokenDH.com
Sage MCP Server Example logo
AI代理未说明官方级别未说明来源级核验

Sage MCP Server Example

MCP Server

一个基于Spring Boot构建的简单MCP服务器示例,用于展示如何通过MCP协议与AI工具交互。

工具数

0

提示词数

0

GitHub Stars

0

资源数

0
JavaSpring BootSession认证

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

NCAR

提供方

NCAR

最后核验

2026/5/17 20:20

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

详细介绍

sage mcp服务器示例

一个非常简单的例子,一个内置于spring boot中的mcp服务器。

受到这个例子的启发:

将你的AI连接到一切:Spring AI的MCP启动程序

模型上下文协议

生命周期,官方文件。

工具,官方文件。

春天

流式HTTP MCP服务器,Spring AI文档。

Docker镜像

$ docker build -t sage-mcp-server-example:latest --build-arg APP_JAR=target/sage-mcp-server-example-1.0-SNAPSHOT.jar .

卷发请求

MCP初始化

需要建立mcp会话id http标头属性。

curl -v -X POST http://localhost:8080/mcp \
  -H "Accept: application/json, text/event-stream" \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "initialize",
    "params": {
      "protocolVersion": "2025-03-26",
      "capabilities": {
        "tools": {},
        "resources": {},
        "prompts": {}
      },
      "clientInfo": {
        "name": "test-client",
        "version": "1.0.0"
      }
    }
  }'

输出:

Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /mcp HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/8.1.2
> Accept: application/json, text/event-stream
> Content-Type: application/json
> Content-Length: 318
>
" \
  -H "Accept: application/json, text/event-stream" \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/list",
    "params": {
      },
      "clientInfo": {
        "name": "test-client",
        "version": "1.0.0"
      }
    }
  }'

输出示例:

{
  "jsonrpc":"2.0",
  "id":1,
  "result":{
    "tools":[
      {
        "name":"getCurrentTime",
        "title":"getCurrentTime",
        "description":"Get the time from the server.",
        "inputSchema":{
          "type":"object",
          "properties":{
            
          },
          "required":[
            
          ]
        },
        "annotations":{
          "title":"",
          "readOnlyHint":false,
          "destructiveHint":true,
          "idempotentHint":false,
          "openWorldHint":true
        }
      },
      {
        "name":"getTemperature",
        "title":"getTemperature",
        "description":"Get the temperature (in celsius) for a specific location",
        "inputSchema":{
          "type":"object",
          "properties":{
            "latitude":{
              "type":"number",
              "format":"double",
              "description":"The location latitude"
            },
            "longitude":{
              "type":"number",
              "format":"double",
              "description":"The location longitude"
            }
          },
          "required":[
            "latitude",
            "longitude"
          ]
        },
        "annotations":{
          "title":"",
          "readOnlyHint":false,
          "destructiveHint":true,
          "idempotentHint":false,
          "openWorldHint":true
        }
      }
    ]
  }
}

调用温度MCP工具

curl -X POST http://localhost:8080/mcp \
  -H "Mcp-Session-Id: e4e5f549-97f7-4792-88f9-3dfa7d246257" \
  -H "Accept: application/json, text/event-stream" \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/call",
    "params": {
        "name": "getTemperature",
        "arguments": {
          "latitude": 39.9783,
          "longitude": 105.2750
        }
      },
      "clientInfo": {
        "name": "test-client",
        "version": "1.0.0"
      }
    }
  }'

输出示例:

{
  "jsonrpc":"2.0",
  "id":1,
  "result":{
    "content":[
      {
        "type":"text",
        "text":"{\"current\":{\"time\":\"2025-12-04T19:45:00\",\"interval\":900,\"temperature_2m\":-4.6},\"current_units\":{\"time\":\"iso8601\",\"interval\":\"seconds\",\"temperature_2m\":\"°C\"}}"
      }
    ],
    "isError":false
  }
}

调用当前时间MCP工具

curl -X POST http://localhost:8080/mcp \
  -H "Mcp-Session-Id: e4e5f549-97f7-4792-88f9-3dfa7d246257" \
  -H "Accept: application/json, text/event-stream" \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/call",
    "params": {
        "name": "getCurrentTime",
        "arguments": {
        }
      },
      "clientInfo": {
        "name": "test-client",
        "version": "1.0.0"
      }
    }
  }'

输出示例:

{
  "jsonrpc":"2.0",
  "id":1,
  "result":{
    "content":[
      {
        "type":"text",
        "text":"\"2025-12-04T12:57:16.190039\""
      }
    ],
    "isError":false
  }
}

目录标签

目录标签

JavaSpring BootSession认证MCP协议本地部署SpringBootAI工具交互服务器示例

接入字段

传输方式(transport,传输协议)

未说明

鉴权方式(authType,认证方式)

session

工具数量(toolCount,工具数)

0

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

未说明session部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

仍需确认:installCommand

来源信息

继续浏览同类 MCP