Spring AI and X MCP servers: client setup tutorial

Build a Spring Boot 4.1 and Spring AI 2.0 client for X documentation and live post search, with bearer authentication and tool call logging.

Player not loading? Watch on YouTube

Dan Vega builds a Spring AI client that connects to two remote X MCP servers: one for developer documentation and another for X API calls. He first tests the documentation connector in Claude, asking how to retrieve a user's follower count, then implements a similar request in Java.

The project uses Maven, Spring Boot 4.1.0 and Spring AI 2.0. Vega runs JDK 26 and states that Boot 4.1 requires at least JDK 17. The demonstration uses Anthropic and an API key supplied through an environment variable. He also mentions open source models through Ollama as an alternative, but does not demonstrate a local LLM setup.

The walkthrough configures streamable HTTP connections and creates a shared ChatClient with MCP tool callbacks. A documentation controller asks for an endpoint and query parameters. A second controller searches recent X posts about a supplied topic, defaulting to Spring Boot 4.1.

Authentication differs between the servers. The documentation connection needs no authentication in the example; live API access requires an application bearer token from the X developer portal. Vega uses a client customizer to send that token only to api.x.com, explaining that Spring AI 2.0 lacks per-connection header configuration. The example uses read-only access and leaves the broader OAuth bridge setup unexplored. Console logs show the search tool call behind the returned summary. Both examples depend on remote services.