Sitemap

Spring AI Recipe: Creating an MCP Client

3 min readMay 1, 2026

--

Press enter or click to view image in full size

In previous recipes, we created MCP servers and exposed tools using both STDIO and Streamable HTTP transports.

Now it’s time to complete the picture.

How does an agent use those tools?

The answer is an MCP client.

NOTE: This recipe has been updated since it’s original publication to reflect changes in Spring AI 2.0.0.

What is an MCP Client?

An MCP client connects to one or more MCP servers and makes their tools available to your application.

It’s worth noting that front-end agents such as Cursor, Claude Code, Claude Desktop, and Goose can act as clients for MCP servers, integrating the MCP server’s capabilities into the chat-style interaction. That is a valuable use-case for MCP servers. This recipe, however, focuses on creating your own MCP client, which is likely an agent that needs some tools to do its job.

In Spring AI, an MCP server’s tools are automatically exposed to the ChatClient, allowing the LLM to invoke them as needed.

Adding the MCP Client

Starting with the chat loop application from an earlier recipe, add the MCP client starter:

implementation 'org.springframework.ai:spring-ai-starter-mcp-client'

Configuring MCP Connections

You can configure connections for one or more MCP servers in application.yml. The configuration is only slightly different depending on whether you are configuring connections to STDIO or Streamable HTTP servers.

STDIO Configuration

spring:
ai:
mcp:
client:
stdio:
root-change-notification: false
connections:
weathermcp:
command: '/path/to/java'
args:
- '-jar'
- '/path/to/stdio-mcp-server.jar'

This configuration launches the MCP server as a subprocess and communicates over STDIN/STDOUT.

Streamable HTTP Configuration

spring:
ai:
mcp:
client:
streamable-http:
connections:
weathermcp:
url: http://localhost:3000/mcp

This connects to a remotely accessible MCP server over HTTP.

Multiple Servers

Even though this recipe’s example only configures a single MCP server connection, you can configure multiple MCP servers under connections.

Each entry is:

  • a name you choose (“weathermcp” in this recipe’s example)
  • paired with connection details

This allows your agent to access tools from multiple sources.

Attaching Tools to the ChatClient

Spring AI automatically discovers tools from MCP servers and exposes them via a ToolCallbackProvider. All that’s left is to attach them:

@Bean
ChatClientCustomizer addMcpTools(ToolCallbackProvider mcpToolCallbacks) {
return builder ->
builder.defaultToolCallbacks(mcpToolCallbacks);
}

At this point, all MCP tools are available to the agent.

Trying It Out

Run the application and ask a question:

How can I help?

> What is the weather in Jal, New Mexico?

- Current conditions for Jal, NM (zip 88252): heavy rain (“raining cats and dogs”) with a temperature of 78°F (≈26°C).

Even though the prompt does not include a zipcode, the LLM can:

  • infer the correct zipcode
  • select the appropriate tool
  • invoke the MCP server
  • return the result

What’s Happening Behind the Scenes

When you ask the question:

  1. The LLM determines that external data is needed
  2. It selects a tool exposed by the MCP server
  3. It resolves missing parameters (like zipcode)
  4. It invokes the tool
  5. It incorporates the result into the response

All of this happens automatically once the tools are connected.

Key Takeaway

With just a small amount of configuration, you’ve enabled your agent to:

  • discover external capabilities
  • select the right tool
  • execute it
  • and use the result

This is where agents move beyond reasoning into action.

Get the code for this recipe and other Spring AI recipes at https://github.com/habuma/spring-ai-recipes.

If you’re exploring Spring AI, I’ve written a book (Spring AI in Action) that covers the core foundations — and I’ll continue sharing newer patterns like this here as the ecosystem evolves. You can find my book on the publisher’s website, at Amazon, or anywhere you buy technical books.

--

--

Craig Walls
Craig Walls

Written by Craig Walls

Author Spring AI in Action, Spring in Action, and Build Talking Apps for Alexa