关于配置mcp服务端sse-message-endpoint和sse-endpoint的注意点

在spring ai配置mcp服务时,这里的pom配置如下(alibaba的配置不用管):

java 复制代码
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.ai</groupId>
    <artifactId>mcp-server</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>21</maven.compiler.source>
        <maven.compiler.target>21</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.5.9</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.ai</groupId>
            <artifactId>spring-ai-starter-mcp-server-webmvc</artifactId>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.ai</groupId>
                <artifactId>spring-ai-bom</artifactId>
                <version>1.1.8</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <dependency>
                <groupId>com.alibaba.cloud.ai</groupId>
                <artifactId>spring-ai-alibaba-bom</artifactId>
                <version>1.1.2.2</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <dependency>
                <groupId>com.alibaba.cloud.ai</groupId>
                <artifactId>spring-ai-alibaba-extensions-bom</artifactId>
                <version>1.1.2.2</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <releases>
                <enabled>false</enabled>
            </releases>
        </repository>
        <repository>
            <name>Central Portal Snapshots</name>
            <id>central-portal-snapshots</id>
            <url>https://central.sonatype.com/repository/maven-snapshots/</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>

</project>

application.yml配置如下:

java 复制代码
spring:
  application:
    name: mcp-server
  ai:
    mcp:
      server:
        name: mcp-server1
        version: 1.0.0
        type: SYNC
        # sse消息端点路径
        sse-message-endpoint: /api/v1/mcp/message
        # sse端点路径
        sse-endpoint: /api/v1/sse
        # url访问前缀
#        base-url: /api/v1
        stdio: false

server:
  port: 8085

这里可以看到有一个base_url的配置,这个配置目前感觉是没有多大的作用,我在客户端访问MCP服务端的时候这个base_url的配置主要作用在sse-message-endpoint链接前缀,但是当客户端连接上sse-endpoint端点的时候访问的/api/v1/mcp/message出现404的错误,但是当把base_url注释掉,直接把sse-message-endpoint端点修改为/api/v1/mcp/message就可以正常访问了,客户端的配置如下:

java 复制代码
spring:
  ai:
    mcp:
      client:
        mcp-server:
           url: http://localhost:8085
           sse-endpoint: /api/v1/sse
相关推荐
考虑考虑17 小时前
记一次@Async生产事故
spring boot·后端·spring
Danny转行做跨境19 小时前
跨境 CLI 实战:一个工具调 61 个数据接口
跨境电商·mcp·sorftime
xrlfreedom1 天前
MCP 面试高频考点:企业内网统一管理多个 MCP Server,stdio 与 TypeScript SDK 怎么答到位?
mcp·stdio 传输·typescript mcp sdk
Wellijohn1 天前
让 AI 能改数据库,但不能背着你改:我给 MCP Server 装了一道审批闸
python·架构·mcp
Mr.Java.1 天前
JetCache自定义序列化实战,Kryo/Protostuff编解码器一步接入
java·spring boot·spring
Wellijohn2 天前
我把公司内部的 12 个 CRUD 接口交给了 AI Agent,然后省出了两周
人工智能·python·mcp
CoderYanger2 天前
Java EE 进阶:9.MyBatis 操作数据库(进阶)(第八弹):MyBatis Generator
java·数据库·spring boot·spring·java-ee·tomcat·mybatis
Thanks_ks2 天前
AI Agent 开发入门:用 Function Calling 让大模型学会 “动手干活”,附订单查询机器人实战
python·ai·大模型·openai·agent·通义千问·mcp
jaysee-sjc2 天前
【黑马点评】Day02:优惠券秒杀与分布式锁
java·分布式·nginx·spring·node.js·tomcat·maven
xrlfreedom2 天前
MCP 面试高频考点:给 MCP Server 加日志、指标和分布式追踪,OAuth 2.1 与 JSON Schema 怎么配合?
json schema·mcp·oauth 2.1