Introduction
In the part 2 of the series, we ran Model Context Protocol (MCP) server with the defined tools and used Model Context Protocol Inspector and Amazon Q Developer plugin in the Visual Studio Code as MCP clients to list the available tools range and to talk to our application using the natural language and to search for the conferences by topic and start date range. We focused on the STDIO transport protocol.
In the part 3 of the series, we focused on the SSE transport protocol.
By the time I've finished my work on that article, SSE transport protocol usage in MCP mainly became deprecated. We move towards using Streamable HTTP transport protocol. Luckily, Spring AI already provides support for Streamable-HTTP MCP Servers currently available in the Spring AI 1.1.0-SNAPSHOT version which we'll explore in this part of this series.
Sample Application
You can find the sample application spring-mcp-conference-search in my GitHub account. This is the same application that we implemented in the part 2. The are differences in the dependencies and in the configuration and how we run this application. Let's explore them.
As MCP Server Streamable HTTP transport protocol support is the part of Spring AI 1.1 release, its current preview is available in the 1.1-SNAPSHOT. Snapshot releases are available on the Spring Snapshots portals. That's why we need to make some changes in the pom.xml. First, let's declare those snapshot repositories:
<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>
Later, when Spring AI 1.1 will be released, we can remove these snapshot repository declarations.
Also, we need to set the Spring AI version to 1.1.0-SNAPSHOT in the pom.xml.
<properties>
<java.version>21</java.version>
<spring-ai.version>1.1.0-SNAPSHOT</spring-ai.version>
</properties>
In the application.properties please enable only properties related to the MCP Streamable HTTP configuration. The complete version is extra provided as application-streamable-http.properties. Below is the list of these properties we need to define according the current documentation:
# MCP STREAMABLE config
spring.ai.mcp.client.enabled=true
spring.ai.mcp.client.name=spring-mcp-conference-search-streamable-http
spring.ai.mcp.client.version=0.0.1
spring.ai.mcp.client.request-timeout=59s
#spring.ai.mcp.client.type=ASYNC
spring.ai.mcp.client.type=SYNC
spring.ai.mcp.server.protocol=STREAMABLE
spring.ai.mcp.client.toolcallback.enabled=true
server.port=8081
logging.level.root=INFO
logging.level.org.springframework.ai.mcp=DEBUG
Please be aware that the implementation and configuration may change until the stable 1.1 Spring Gen AI release.
We enable MCP client, set it server protocol to STREAMABLE and client request type to SYNC and enable tool callback. As we run our application as a server, we enable logging and set the port number on which we run our application to 8081 (you can use the default port 8080 if you wish). By default, our Spring Boot MCP Server exposes /mcp as the sse endpoint (as url suffix) to use for the connection from the MCP Client, see Streamable Transport Properties, but you can override it as described in the mentioned article.
MCP HTTP Streamable transport protocol also supports the ASYNC client type in parallel to the SYNC one. To enable the asynchronous version, we'll have to set spring.ai.mcp.client.type=ASYNC and use the spring-ai-starter-mcp-server-webflux dependency in pom.xml instead of currently in use spring-ai-starter-mcp-server-webmvc:
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-mcp-server-webflux</artifactId>
</dependency>
We’re done with the implementation (we don't need any more changes!), so let's now build the application with mvn clean package
and run it locally with java -jar target/spring-mcp-conference-search-0.0.1-SNAPSHOT.jar
.
Let's first use MCP Inspector to inspect our tools. I refer to part 2 where I described how to install and run the inspector. The only difference is that we select Streamable HTTP Transport Type and use http://localhost://8081/mcp as URL. Please use the same port number as configured in the server.port property in the application.properties.
Then we can connect to the server and go to the Tools section, list and use them. This works the same as described in parts 2 and 3.
Let's now use Amazon Q Developer and its MCP Client to talk to our MCP server using natural language. Once again, I refer to part 2 for the description how to do it. The only difference is how to configure the MCP server. We give the MCP server a name, select http as Transport and use http://localhost://8081/mcp as URL. Please use the same port number as configured in the server.port property in the application.properties.
Alternatively, you can adjust and copy the content of the mcp-streamable-http.json file which in my case looks like this:
{
"mcpServers": {
"conference-search-tool-streamable-http": {
"url": "http://localhost:8081/mcp",
"disabled": false,
"timeout": 60000
}
}
}
We can hit the "Save" button as we configured everything and then we can see 3 exposed tools:
I refer to parts 2 and 3 of this series where we gave examples of how to talk to our MCP server using natural language. As this is the same application we can ask the same questions.
Of course, I deployed application locally, in the real scenarios I'll need to host the application the way that it can be accessed publicly. Here is for example the Guidance for Deploying Model Context Protocol Servers on AWS. This example covers mainly deploying MCP server on the AWS Elastic Container Service (ECS) service, but you can do it on Amazon Elastic Kubernetes Service (EKS), Amazon EC2 or even on AWS Lambda as well. In such a case don't forget to replace the URL http://localhost://8081/mcp with the proper one.
Securing our sample application
It's beyond the scope of this article, but you need to think about Securing Spring AI MCP servers. We'll provide a list of resources which describe how to achieve this goal (with the Spring Security framework).
- Securing Spring AI MCP servers with OAuth2
- MCP Authorization in practice with Spring AI and OAuth2
- Securing Spring AI MCP servers with OAuth2
Conclusion
In this part of the series, we ran Model Context Protocol (MCP) server with the defined tools and used Model Context Protocol Inspector and Amazon Q Developer plugin in the Visual Studio Code as MCP clients to list the available tools range and to talk to our application using the natural language and to search for the conferences by topic and start date range. We focused on the Streamable HTTP transport protocol, which is currently a part of the 1.1-SNAPSHOT version, which is not stable.
This series will continue. In the next part of it, we'll further explore other Spring AI Amazon Bedrock Converse API features like Multimodality and Retrieval Augmented Generation.
Top comments (0)