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/和后面的端点

相关推荐
fthux4 小时前
装闭 RenoPit 源码解析(07):装修闭坑知识库与AI Prompt构建
人工智能·ai·开源·github·open source·renopit
fthux7 小时前
装闭 RenoPit 源码解析(06):SSE如何实时推送AI装修分析进度
人工智能·ai·开源·github·open source·renopit
LyridRelan8 小时前
Skill Cli MCP 的三者关系以及部分Q&A
人工智能·ai·个人开发
兮动人9 小时前
AI 开始接管工作台:谁会成为下一代电脑入口?
人工智能·ai·chatgpt·codex·workbuddy
前端开发江鸟9 小时前
Agent 能跑通以后,我才发现代码不是交付物
agent
花椒技术9 小时前
一个人已经有 Agent 了,我们为什么还要建设统 Agent 平台
人工智能·agent·ai编程
百工蜂Agent10 小时前
万物皆工具
agent·ai编程
阿里云云原生11 小时前
AI Agent 的“自述”不可信:如何构建可取证、可评估、可进化的 Agent 生产流水线?
agent
Jodie同志12 小时前
第16~23天:持久化、HITL、流式、MCP与安全
前端·后端·agent
小当家.10512 小时前
Prompt工程与上下文管理实战:从模板到Agent Loop的演进
prompt·agent·上下文·loop agent