NPE when using MCP streamable transport: ServerSentEvent.id(null) with Spring Boot 3.5.x (Spring 6.2)

Open
#6,274 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
62/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Domain
api, backend

Research direction

Start in WebFluxStreamableServerTransportProvider.java around sendMessage, line 394, and reproduce the failure with the provided streamable MCP configuration and curl request. Trace how the response reaches ServerSentEvent.Builder.id and verify the endpoint returns a valid SSE stream without an exception when the message has no ID.

Written by the indexing model from the issue text.

Description

status: waiting-for-triage

Bug description
When using MCP Server with streamable HTTP transport (SSE),
the /mcp endpoint returns:
`500 Server Error

java.lang.NullPointerException:
Cannot invoke "String.indexOf(int)" because "content" is null
java.lang.NullPointerException: Cannot invoke "String.indexOf(int)" because "content" is null
at org.springframework.http.codec.ServerSentEvent$BuilderImpl.checkEvent(ServerSentEvent.java:270)
at org.springframework.http.codec.ServerSentEvent$BuilderImpl.id(ServerSentEvent.java:257)
at io.modelcontextprotocol.server.transport.WebFluxStreamableServerTransportProvider$WebFluxStreamableMcpSessionTransport.lambda$sendMessage$1(WebFluxStreamableServerTransportProvider.java:394)
...
`

Environment
Spring Boot: 3.5.13
Spring Framework: 6.2.17
JDK: 21

Spring AI: 1.1.7
MCP Server: mcp-spring-webflux 0.18.2

Config:
spring.ai.mcp.server.protocol=streamable

Steps to reproduce

  1. Start MCP server
  ai:
    mcp:
      server:
        protocol: streamable
  1. Simple MCP Tool

@McpTool(name = "test")
public Mono<String> test() {
    return Mono.just("ok");
}

  1. Call API
curl -X POST http://localhost:8080/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/list"
  }'

Expected behavior
MCP should return valid SSE stream
No exception even if message has no ID

Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 10h
Merged PRs (30d)
5

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from spring-projects/spring-ai

All issues in spring-projects/spring-ai

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.