Spring AI MCP using Streamable-HTTP
The Streamable HTTP transport enables MCP servers to run as independent processes that support multiple client connections via HTTP POST…
Spring AI MCP using Streamable-HTTP
The Streamable HTTP transport enables MCP servers to run as independent processes that support multiple client connections via HTTP POST and GET requests. It also provides optional Server-Sent Events (SSE) for streaming multiple server messages, serving as a replacement for the older SSE transport.
Introduced in spec version 2025–03–26, this transport is particularly well-suited for applications that need to push dynamic updates about tools, resources, or prompts to connected clients.
MCP Server
pom.xml
<properties>
<java.version>25</java.version>
<spring-ai.version>1.1.0-M2</spring-ai.version>
</properties>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-mcp-server-webmvc</artifactId>
</dependency>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-bom</artifactId>
<version>${spring-ai.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
- Create tool: Here, i am creating a simple addition tool
@Component
public class CalculatorTools {
@McpTool(name = "add", description = "Add two numbers together")
public int add(
@McpToolParam(description = "First number", required = true) int a,
@McpToolParam(description = "Second number", required = true) int b) {
System.out.println("Adding " + a + " and " + b);
return a + b;
}
}
Update application.properties
spring.application.name=mcp-server
server.port=9091
spring.ai.mcp.server.type=sync
spring.ai.mcp.server.annotation-scanner.enabled=true
spring.ai.mcp.server.protocol=streamable
spring.ai.mcp.server.streamable-http.keep-alive-interval=30s
MCP Client
An MCP client with the Streamable API is basically a client application (like an IDE, web app, or agent) that connects to an MCP server using the Streamable HTTP transport.
Here’s what it means in practice:
- Client role → The MCP client is the consumer. It makes HTTP
POSTandGETrequests to the MCP server to invoke tools, fetch resources, or interact with prompts. - Streamable API → Instead of waiting for a single response per request, the client can receive multiple messages over time from the server. This is possible because of Server-Sent Events (SSE) support in the Streamable transport.
- Why it matters → The client isn’t limited to one-off request/response cycles. The server can push updates dynamically (e.g., tool status changes, resource updates, or new prompts), and the client can handle them in near real time.
- Example use case:
- An MCP client in a developer IDE subscribes to a code analysis tool.
- The MCP server sends incremental analysis results via SSE.
- The client UI updates continuously without polling
So, an MCP client with the Streamable API is just a client that speaks HTTP + SSE with an MCP server and can handle ongoing streams of server events, not just single-shot responses.
<properties>
<java.version>25</java.version>
<spring-ai.version>1.1.0-M2</spring-ai.version>
</properties>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-mcp-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-openai</artifactId>
</dependency>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-bom</artifactId>
<version>${spring-ai.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Update application.properties
spring.application.name=mcp-client
server.port=9092
spring.ai.mcp.client.streamable-http.connections.server1.url=http://localhost:9091
spring.ai.mcp.client.streamable-http.connections.server1.endpoint=/mcp
spring.ai.openai.api-key=
Use ChatClient with openai to call mcp server add tool
@Bean
CommandLineRunner commandLineRunner( SyncMcpToolCallbackProvider toolCallbackProvider, ChatClient.Builder chatClientBuilder) {
return args -> {
ToolCallback[] toolCallbacks = toolCallbackProvider.getToolCallbacks();
ChatClient chatClient = chatClientBuilder.defaultToolCallbacks(toolCallbacks)
.build();
String response = chatClient.prompt("Using add tool, calculate 2 + 2 ?")
.call()
.content();
System.out.println(response);
};
}
Github link: https://github.com/siddharth223437/spring-ai-example-apps
메타데이터
- post_id
- f3446d2c2079
- slug
- spring-ai-mcp-using-streamable-http-f3446d2c2079
- url
- https://medium.com/@sarathesid/spring-ai-mcp-using-streamable-http-f3446d2c2079
- canonical_url
- https://medium.com/@sarathesid/spring-ai-mcp-using-streamable-http-f3446d2c2079
- author_url
- https://medium.com/@sarathesid
- status
- ok
- fetched_at
- 2026-07-09 05:26:43