Spring AI
    June 10, 2026

    Spring AI — MCP & Agents

    Use the Model Context Protocol with Spring AI to expose and consume tools, then compose agentic workflows with loops, orchestration, and reliable control.

    Share

    Tool calling lets one app's model use that app's tools. MCP (Model Context Protocol) standardises this across processes — so any MCP client can use your tools, and your app can consume any MCP server. Spring AI ships starters for both sides.

    MCP in one picture

    flowchart LR subgraph Your app Client[Spring AI MCP client] --> Agent[ChatClient / agent] end Client -->|MCP| S1[Your MCP server - order tools] Client -->|MCP| S2[3rd-party MCP server] S1 --> DB[(Systems / DB)]

    Instead of wiring every tool into every app, you build/consume standard servers. One integration, many clients.

    Exposing tools (MCP server)

    <dependency>
      <groupId>org.springframework.ai</groupId>
      <artifactId>spring-ai-starter-mcp-server</artifactId>
    </dependency>

    Your @Tool beans become MCP tools any client can discover:

    @Bean
    ToolCallbackProvider tools(OrderTools orderTools) {
        return MethodToolCallbackProvider.builder().toolObjects(orderTools).build();
    }

    Consuming tools (MCP client)

    Add the client starter, point it at one or more servers (stdio or SSE/HTTP), and the discovered tools become available to your ChatClient just like local @Tools.

    From tools to agents

    An agent is the model in a loop: reason → call a tool → observe → repeat → answer. With Spring AI you give the ChatClient tools and let it iterate. The discipline is in the controls around it:

    • Termination: cap iterations and define stop conditions in code (never rely on the model to stop).
    • Approval gates: require human/confirmation before irreversible actions.
    • Idempotency: make tool actions safe to retry.
    • Scoped context & tools per agent: smaller choice space → better selection. For complex goals, use an orchestrator that routes sub-tasks to specialist agents.
    flowchart TD O[Orchestrator] --> A1[Research agent] O --> A2[Action agent] A1 --> O A2 --> O O --> R[Composed result]

    Best practices & anti-patterns

    • ✅ Publish a deliberate, well-described tool set from your MCP server; authenticate and rate-limit it like any API.
    • ✅ Validate all tool inputs server-side — the model (and other clients) are untrusted.
    • ❌ One agent with 25 tools → split into specialists or trim.
    • ❌ Unbounded agent loops with no cap → runaway cost and behaviour.

    Next: pick the right model and integrate any provider → Choosing & Integrating LLMs →

    Ask about this article

    Get answers grounded in this post. AI-generated — based on this article, and may be imperfect.

    Scaled AI Weekly

    Enjoyed this? Get more like it every Monday.

    Real architecture decisions, LLMOps patterns that survive production, and engineering leadership advice — from 12+ years of building at enterprise scale. Free. No spam. Unsubscribe anytime.

    Join engineers building production AI systems