DEV Community

Vadym Kazulkin for AWS Heroes

Posted on

Spring AI with Amazon Bedrock - Part 3 Exploring Model Context Protocol SSE transport

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 this part of the series, we'll explore the Server-Sent Events (SSE) transport which enables HTTP-based communication between the MCP server and clients. It uses SSE for server-to-client messages and HTTP POST for client-to-server messages. With SSE we can expose our application as MCP Server to be accessible to everybody.

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 only difference will be in the configuration and how we run this application. Let's explore it.

In the application.properties please enable only properties related to the MCP SSE configuration. The complete version is extra provided as application-sse.properties. Below is the list of these properties:

# MCP SSE config

spring.ai.mcp.client.enabled=true
spring.ai.mcp.client.name=spring-mcp-conference-search-sse
spring.ai.mcp.client.version=0.0.1
spring.ai.mcp.client.request-timeout=59s
spring.ai.mcp.client.type=SYNC
spring.ai.mcp.client.toolcallback.enabled=true

server.port=8081

logging.level.root=INFO
logging.level.org.springframework.ai.mcp=DEBUG
Enter fullscreen mode Exit fullscreen mode

We enable mcp client, set client request type to SYNC (which means SSE) and enable tool callback. As we run our application as a server, we can enable logging (which wasn't the case for STDIO) and set the port number on which we run our application to 8081. By default our Spring Boot MCP Server exposes /sse as the sse endpoint (as url suffix) to use for the connection from the MCP Client, see SSE Transport Properties, but you can override it as described in the mentioned article.

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 the part 2 where I described how to install and run the inspector. The only difference is that we select SSE Transport Type and use http://localhost://8081/sse as URL. Please use the same port number as configured in the server.port property.

Then we can connect to the server and go to the Tools section, list and use them. This works the same as described in part 2.

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/sse as URL. Please use the same port number as configured in the server.port property.

Alternatively, you can adjust and copy the content of the mcp-sse.json file which in my case looks like this:

{
  "mcpServers": {
    "conference-search-tool-sse": {
       "url": "http://localhost:8081/sse",
        "disabled": false,
        "timeout": 60000
     }
  }
}
Enter fullscreen mode Exit fullscreen mode

Then we hit the "Save" button and we configured everything correctly then we can see 3 exposed tools:

I refer to part 2 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/sse 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).

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 SSE transport protocol.

By the time I've finished my work on this article, SSE transport protocol usage in MCP mainly became deprecated. We move towards using Streamable HTTP. 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 the next part of this series.

Top comments (0)