关于配置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
相关推荐
凤山老林4 小时前
Spring Boot 集成 Spring Modulith:搭一个能拆微服务的模块化单体
spring boot·spring·微服务
xrlfreedom5 小时前
MCP 面试高频考点:如何给 Tool 调用加上身份认证、最小权限与提示注入防护
tools·resources·mcp·提示注入防护
小陈phd6 小时前
深入理解agent学习笔记(五)——KV Cache友好的上下文设计
笔记·学习·spring
萧瑟余晖7 小时前
Spring Web综合实战与性能调优详解
java·spring
点纭7 小时前
spring ai1.0实战:ChatClient(2)
java·后端·spring
小马过河R7 小时前
EdgeOne深度解析:从原理、适用场景到COS接入的技术逻辑
java·开发语言·前端·spring·cos
deepseek239 小时前
MCP SSRF 连环漏洞拆解:从 Google 到 mcp-server-fetch,Agent 的信任链如何变成攻击链
安全·漏洞分析·ssrf·ai agent·mcp
一条泥憨鱼10 小时前
拦截器与过滤器:一次请求穿过 Spring 时,会先经过谁呢
java·开发语言·后端·spring
m0_5873830019 小时前
广州 24 小时自助健身房解决方案技术实现与实战指南
java·spring·小程序·架构·需求分析
唠点键盘之外的21 小时前
26 向量数据库实战:从 0 搭一条能用的检索链路(pgvector + Spring AI)
数据库·人工智能·spring