liveBook · Manning

Chapter 7: Applying Model Context Protocol

What you will learn in chapter 7 of Spring AI in Action

Introduces MCP as a way to package related tools for sharing across AI applications, in contrast to coding tools into one Spring AI application.

After this chapter you will be able to

What it builds on

Section by section

Introduction

Introduces MCP as a way to package related tools for sharing across AI applications, in contrast to coding tools into one Spring AI application.

Key terms: Model Context Protocol (MCP), tools, Spring AI application

7.1 Introducing Model Context Protocol

Introduces MCP’s client-server model, its transport options, and a Claude Desktop example of using an existing MCP Server.

Key terms: MCP Server, MCP Client, tools, prompt’s context, STDIO, HTTP+SSE, Streamable HTTP, Spring AI 1.0.0, Claude Desktop, Google Maps MCP Server

7.2 Working with MCP Clients

This section shows how to connect a Spring AI application to an existing Filesystem MCP Server and make its tools available to a ChatClient.

Key terms: MCP Client, STDIO transport, spring.ai.mcp.client, command, args, Spring-style configuration, Claude Desktop–compatible JSON, servers-configuration, ChatClient, ToolCallbackProvider

7.3 Creating your own MCP Server

This section motivates a board-game MCP Server whose tools expose structured game data for questions that rulebook-based RAG handles poorly.

Key terms: RAG, document chunks, database, API, Spring AI, MCP Server, tools, client application

7.3.1 Building the server

This subsection explains how to initialize a Spring Boot project for a database-backed custom MCP Server and why it needs no LLM dependency.

Key terms: Model Context Protocol Server, Spring Data JDBC, PostgreSQL Driver, Docker Compose Support, LLM-specific dependency

7.3.2 Setting up the database

This section sets up a PostgreSQL database for the MCP Server and defines the Spring Data JDBC types used to query its game data.

Key terms: Docker Compose, PostgreSQL, compose.yaml, schema.sql, data.sql, spring.sql.init.mode, Spring Data JDBC, GameRepository, CrudRepository, count()

7.3.3 Creating the MCP Server tools

This section shows how repository-backed tool methods become MCP Server tools, why a STDIO server must keep standard output free of unrelated text, and how the built server is run.

Key terms: @Tool, GameTools, GameRepository, ToolCallbackProvider, toolCallbackProvider(), Spring AI auto-configuration, STDIO transport, standard output, Spring Boot’s ASCII art banner

7.3.4 Inspecting the MCP Server

Shows how to connect MCP Inspector to the executable MCP Server and check that its tools are exposed and respond.

Key terms: MCP Inspector, executable JAR, SPRING_DOCKER_COMPOSE_FILE, compose.yaml, Tools tab, List Tools, GameTools, Run Tool

7.3.5 Using the server in a client application

Shows how to connect a Spring AI client to the custom Board Game DB MCP Server, try it through the /ask endpoint, and understand why its STDIO setup may be worth changing.

Key terms: MCP Client, Board Game DB MCP Server, application.yaml, Claude Desktop configuration, JAVA_HOME, MCP_SERVER_PATH, STDIO transport, standard input, standard output, Filesystem MCP Server

7.4 Working with the HTTP+SSE transport

This section contrasts STDIO with HTTP+SSE for MCP communication and explains why the book uses HTTP+SSE despite its deprecation.

Key terms: STDIO transport, HTTP+SSE transport, MCP Server, Streamable HTTP transport, Spring AI, Java MCP SDK, HTTP+SSE, properties, build dependency

7.4.1 Configuring an HTTP+SSE in the MCP Server

This section explains how to switch an MCP Server from STDIO to HTTP+SSE using a Spring starter, choose between MVC and WebFlux implementations, and restore settings appropriate for a web server.

Key terms: MCP Server, HTTP+SSE transport, starter dependency, autoconfiguration, Spring MVC, Spring WebFlux, Tomcat, Netty, reactive, STDIO transport

7.4.2 Inspecting the MCP Server

Shows how to start an HTTP+SSE-enabled MCP Server and verify its tools with MCP Inspector.

Key terms: MCP Inspector, HTTP+SSE client transport, SSE, List Tools, Run Tool

7.4.3 Configuring the client to use an HTTP+SSE server

This subsection shows how to connect an MCP Client to an HTTP+SSE server and identifies the resulting independence between server and client.

Key terms: HTTP+SSE, MCP Client, Spring configuration properties, spring.ai.mcp.client.sse.connections, url, reactive client, MCP Server, independently

7.5 Exposing prompts and resources

Explains how an MCP Server can supply predefined prompts and domain data to an application, and identifies how Spring AI declares them.

Key terms: MCP Server, predefined prompts, UI, LLM, resources, textual, binary data, Spring AI’s MCP module, Spring configuration, @Bean-annotated methods

7.5.1 Declaring prompt and resource-exposing beans

This section shows how to expose prompts and a repository-backed resource from a Spring AI MCP Server by declaring specification-list beans.

Key terms: prompt specification, prompt definition, prompt result, SyncPromptSpecification, AsyncPromptSpecification, resource specification, GameRepository, Game List resource

7.5.2 Applying annotation-driven prompts and resources

This section shows how a community annotation project defines MCP prompts and resources in service methods, then exposes them through simpler specification beans.

Key terms: mcp-annotations, incubating, @McpPrompt, @McpArg, PromptMessage, @McpResource, TextResourceContents, BlobResourceContents, GameRepository, @Bean

7.6 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 6: Activating tool-driven generation Chapter 8: Generating with voice and pictures →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.