MCP相关配置

SpringAI配置相关MCP有这几种方式:SSE,Stdio,StreamableHTTP等方式

其中Stdio是本地进程间调用,需要本地有服务

Stdio

Stdio在SpringAI配置需要在mcp-servers.json中进行相关配置

复制代码
{
  "mcpServers": {
    "baidu-maps": {
      "command": "cmd",
      "args": [
        "/c",
        "npx",
        "-y",
        "@baidumap/mcp-server-baidu-map"
      ],
      "env": {
        "BAIDU_MAP_API_KEY": "xxxx"
      }
    }
  }
}

cmd /c是指启动后关闭cmd窗口并常驻后台

并且这种配置方式要求本地要有nodejs等相关环境

下面这种方式有时候启动失败,因此用cmd /c的方式

复制代码
{
  "mcpServers": {
    "baidu-maps": {
      "command": "npx",
      "args": [
        "-y",
        "@baidumap/mcp-server-baidu-map"
      ],
      "env": {
        "BAIDU_MAP_API_KEY": "xxxx"
      }
    }
  }
}

SSE和StreamableHTTP

这两个主要是远程调用,在SpringAI中不能用上面stdio的那种方式,而是需要在application.yml中进行配置

SSE配置

XML 复制代码
spring:
  ai:
    mcp:
      client:
        sse:
          connections:
            open-webSearch:
              url: https://mcp.api-inference.modelscope.net/
              sse-endpoint: 8a9d148xx/sse

StreamableHTTP配置

XML 复制代码
spring:
  ai:
    mcp:
      client:
        streamable-http:
          connections:
            open-webSearch:
              url: https://mcp.api-inference.modelscope.net/
              endpoint: 8a9d148xx/mcp

这里面有几个注意点:url是基础url,虽然地址是https://mcp.api-inference.modelscope.net/8a9df1ffb3e148/mcp,但是url不能这样写,要拆成https://mcp.api-inference.modelscope.net/和后面的端点

相关推荐
hpoenixf2 小时前
AI 说报告做好了,为什么用户还是打不开?
agent
hpoenixf3 小时前
AI 说“今天”,到底是哪一天?
agent
又过二十3 小时前
用 Electron 做的 AI 视频切片工作台:VClip 的技术选型与踩坑实录
ai·electron·aigc·funasr·视频切片
hpoenixf3 小时前
用户点了踩,Agent 就该学习吗?
agent
跨境Jacky3 小时前
亚马逊选品排名监控改造记:从手抄表格到MCP自动监控
跨境电商·mcp·sorftime
岁月宁静4 小时前
一个 AI 项目从本地到上线,要经过哪些步骤?全流程讲清楚
python·docker·agent
DO_Community5 小时前
WorkBuddy 接入自定义模型教程:接入 GPT、Claude 等大模型
人工智能·llm·agent
Deng桑6 小时前
SpringAI写第一个Agent-把工单循环跑起来
java·agent·工具调用·spring ai
威哥爱编程6 小时前
Python 智能体开发实战 02:你的 AI 助教说话像换了个模型?九成的 system prompt 都写错了
python·agent
威哥爱编程6 小时前
Python 智能体开发实战 01:装了三遍环境还在报错?虚拟环境和 DeepSeek 一次配到位
python·agent