The AIDocumentLibraryChat project has been updated to have a Mcp Client and Server. The project now has a Mcp Server in the Gradle project mcp-server. It has to be started as a standalone Spring Boot application and provides Spring AI Tools. The AIDocumentLibraryChat project has the Mcp Client and runs the AI model.
Architecture
The goal of the Mcp Protocol is to decouple the tools from the application that uses the AI. The AI application becomes the client to possibly multiple Mcp Servers. The workflow looks like this:

Step 1: Send the Prompt to the LLM.
Step 2: The LLM decides what Mcp Server to use based on the prompt.
Step 3: The application sends the request to the selected Mcp Server.
Step 4: The Mcp Server returns the requested data.
Step 5: The LLM is prompted with the data of the Mcp Server
Step 6: The LLM generates the final response based on the provided data.
This architecture is used to decouple the data sources(Mcp Servers) from the application that calls the LLM. The Mcp protocol enables the use of Mcp Servers that are provided by other parties. That means the internet search Mcp Server can be implemented by a search provider and the url and the credentials are configured and then the service can be used. With the Sprint AI Tools the service access had to implemented in the application. That is no longer the case. Mcp decouples the implementation of the data access tool from the LLM calling application. That decoupling enables a market place for Mcp Server services provided by different software providers that can be accessed via an Api.
For example a Share Point Mcp Server. Could parse and vectorize the documents inside Share Point and provide a tool interface to search for the right document in the vector database and then return the best matching documents to the client application. That would hide all the implementation of the embedding based search for Share Point in the Mcp Server. The Mcp Client calls only the Tool Api defined by the server.
Spring AI Mcp Clients and Servers
The Mcp Client
Spring AI provides support to create Mcp clients. It is used in the LocalMcpClient class:
@Service public class LocalMcpClient { private final List<McpSyncClient> mcpSyncClients; private final ChatClient chatClient; public LocalMcpClient(List<McpSyncClient> mcpSyncClients, Builder builder, ChatModel chatModel) { this.mcpSyncClients = mcpSyncClients; var advisor = ChatModelCallAdvisor.builder() .chatModel(chatModel).build(); this.chatClient = builder.defaultAdvisors(List.of(advisor)).build(); } public McpResponseDto createResponse(McpRequestDto requestDto) { var result = this.chatClient.prompt(requestDto.question()) .toolCallbacks(new SyncMcpToolCallbackProvider(mcpSyncClients)).call(); var resultText = Optional.ofNullable(result.chatResponse()) .stream().map(value -> value.getResult().getOutput().getText()) .findFirst().orElse(""); var toolCalls = Optional.ofNullable(result.chatResponse()) .stream().map(value -> value.getResult().getOutput().getToolCalls()) .findFirst().orElse(List.of()); var responseDto = new McpResponseDto(resultText, toolCalls); return responseDto; } } The ‘McpSyncClient’ is used by the AIDocumentLibraryChat project. Spring AI also provides an async client but we have virtual threads in Java now. The method ‘createResponse(…)’ gets the user question in the ‘McpRequestDto’. The ChatClient api of provides the ‘toolCallbacks(…)’ method to get the tools available to the LLM. The ‘SyncMcpToolCallbackProvider(…)’ is used to present the tools of the Mcp Servers to the ChatClient api. The ‘call()’ method executes the request to the LLM and also the tool calls and generates the response. The response and the used tools are returned in the response Dto.
The configuration for the ‘McpSyncClient’ is in the application.properties file:
spring.ai.mcp.client.sse.connections.server1.url=http://localhost:8081 spring.ai.mcp.client.sse.connections.server1.name=my-book-movie-server spring.ai.mcp.client.enabled=true The Mcp Server uses a Sse connection to be able to deploy it on a different server. With file IO it needs to be on the same server. The name is for the identification of the Mcp Server and the client needs to be enabled. In the project the client is disabled by default. To test the Mcp Client/Servers the property needs to be enabled.
With this configuration Spring AI connects to the Mcp Server and requests the available tools provided by the Mcp Server and adds them to the tools api in the chatclient api to be used by the LLM. Spring AI uses the Mcp Server to request the data required by the LLM for the response.
Conclusion
Spring AI has used the existing Tool support to add Mcp clients. That makes adding the Mcp Clients easy. The required configuration of the Mcp Servers is simple and the LLM treats the tools of the Mcp Servers as tools. That makes reasoning about the tools easy.
Mcp Server
The server is a standalone Spring Boot application that can be found in the mcp-server directory. As Gradle subproject it is integrated in the Gradle build but needs to be started separately. It provides the tools to the rest endpoints to the movie and book data. The McpServerApplication class looks like this:
@SpringBootApplication public class McpServerApplication { public static void main(String[] args) { SpringApplication.run(McpServerApplication.class, args); } @Bean public ToolCallbackProvider myTools(FunctionConfig functionConfig) { return MethodToolCallbackProvider.builder() .toolObjects(functionConfig).build(); } @Bean public RestClient createRestClient() { return RestClient.builder().build(); } } The application class provides the ‘RestClient’ and ‘ToolCallbackProvider’ as Spring Beans.
The FunctionConfig class provides the tools of the Mcp Server:
@Service public class FunctionConfig { private final OpenLibraryClient openLibraryClient; private final TmdbClient tmdbClient; public static final String OPEN_LIBRARY_CLIENT = "openLibraryClient"; public static final String THE_MOVIE_DATABASE_CLIENT = "theMovieDatabaseClient"; public FunctionConfig(OpenLibraryClient openLibraryClient, TmdbClient tmdbClient) { this.openLibraryClient = openLibraryClient; this.tmdbClient = tmdbClient; } @Tool(description = "Search for books by author, title or subject.") public OpenLibraryClient.Response openLibraryClient( OpenLibraryClient.Request request) { return this.openLibraryClient.loadBooks(request); } @Tool(description = "Search for movies by title.") public TmdbClient.Response theMovieDatabaseClient( TmdbClient.Request request) { return this.tmdbClient.loadMovies(request); } } The methods ‘openLibraryClient(…)’ and ‘theMovieDatabaseClient(…)’ provide the tools of the Mcp Server. The descriptions of the tools are in the ‘@Tool’ annotations and the ‘@ToolParam’ annotations in the ‘OpenLibrary.Request’ or ‘TmdbClient.Request’ records.
The application.properties looks like this:
server.port=8081 spring.ai.mcp.server.request-timeout=60s spring.ai.mcp.server.name=my-book-movie-server spring.ai.mcp.server.version=0.0.1 logging.file.name=./log/starter-webmvc-server.log The server port is set to a different port than 8080 to not interfere with the UI of the Mcp Client application. The ‘spring.ai.mcp.server.name’ is set to identify the Mcp Server by name. The ‘logging.file.name’ property is set to have a separate log file to the Mcp Client application.
Conclusion
Spring AI uses the Tool support to create Mcp Servers. That make creating the Mcp Servers simple. Being able to create a Mcp Server with so little code is an impressive achievement by the Spring Team.
Mcp Client/Server Conclusion
The support of Spring AI for Mcp Clients and Servers is very good. The Mcp protocol decouples the tools provided to the LLM from the application using the LLM. That makes the Mcp Servers reusable. With a market place for Mcp Servers the LLM based applications can get access to much more tools(Spring AI Tools). That can reduce the effort of creating LLM based applications. With access to much more data the LLMs can become more useful as integrated search tool for company data in different silos. Each information silo needs to provide a Mcp Server and the LLM base Mcp Client can act as integration layer above the information silos to provide access to all. Access controls need to be checked of course.