Artificial Intelligence 13 min read

Using Spring AI’s MCP Protocol: From Tool Calling to Server‑Client Integration

This article explains the evolution from Spring AI FunctionCall to the newer ToolCalling, introduces the Model Context Protocol (MCP), and provides step‑by‑step code examples for building MCP servers and clients in Java, demonstrating how to integrate large language models with backend services.

Rare Earth Juejin Tech Community
Rare Earth Juejin Tech Community
Rare Earth Juejin Tech Community
Using Spring AI’s MCP Protocol: From Tool Calling to Server‑Client Integration

In a previous post the author introduced Spring AI 1.0.0‑M3, covering RAG, Function Call, and vector databases. Since then Spring AI has progressed to version 1.0.0‑M6, deprecating FunctionCall in favor of the new Tool Calling API.

Tool Calling uses a different annotation but serves the same purpose; the article shows a Java example of binding a tool to a ChatClient and explains that the change supports the Model Context Protocol (MCP), which requires Prompt, Resource, and Tools.

The MCP (Model Context Protocol) is described as a "universal socket" for AI models, standardising how applications provide context to large language models (LLMs). It follows a client‑server architecture, enabling separation of tool implementation and invocation, similar to JDBC.

Two types of MCP servers are illustrated: standard IO and SSE (server‑sent events). The author predicts future backend development will interact directly with MCP rather than front‑end pages.

A demo is built to showcase MCP capabilities, using McpClient to let an LLM access a database and the local file system via open‑source MCP server implementations.

The tutorial then walks through installing npx (Node.js) and uvx (Python) to run TypeScript and Python MCP servers, respectively.

Next, the article presents Java configuration code ( @Configuration ) that registers tool callbacks, creates MCP clients for file‑system and database access, and injects them into a Spring ChatClient . The client is then used to stream responses from the model.

For building a custom MCP server, the author lists three Maven dependencies for standard IO, HTTP, and SSE communication, and explains the three core concepts: Resources, Tools, and Prompts. Sample configuration code shows how to register tools, resources, and prompts, and how to expose the server via application.yaml .

On the client side, the article details the new simplified configuration for Spring AI 1.0.0‑M6, including YAML settings for MCP client connections and the required Maven starter. A REST controller demonstrates how to inject the automatically configured McpClient and use defaultTools with a ChatClient to generate streaming responses.

Finally, the author notes that customisation such as timeout settings can be achieved through the McpSyncClientCustomizer interface, and encourages readers to try the demo, star the GitHub repository, and provide feedback.

backendJavaMCPSpring AIAI integrationTool Calling
Rare Earth Juejin Tech Community
Written by

Rare Earth Juejin Tech Community

Juejin, a tech community that helps developers grow.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.