# Spring AI

MillionShort search for a Spring AI ChatClient, through the MCP client starter.

MCP · Java · Nothing of ours to install · Works with no key · Checked 2026-11-19

> **For agents.** Read the API key from the `MILLIONSHORT_API_KEY` environment variable. Never print it; where a client needs it in a settings file, use a file that is not committed.
> The MCP address is https://mcp.millionshort.com/mcp (streamable HTTP; send `Authorization: Bearer <key>`, or no header for the no-key mode).
> On `INSUFFICIENT_CREDITS` stop and ask a person; on `RATE_LIMITED` or `CAPACITY` wait the `Retry-After` seconds, then retry once.
> Set-up steps written for agents: https://millionshort.com/docs/auth.md. Every integration: https://millionshort.com/docs/integrations.md.

Spring AI's MCP client Boot starter connects to the servers named in your application properties, discovers their tools and exposes them as a `SyncMcpToolCallbackProvider` bean. Add the MillionShort MCP server as a streamable HTTP connection, add the key with a request customizer, and pass the provider to a `ChatClient`; the model then gets the server's tools: `search`, `get_domain_info`, `list_sources` and the tools of the other endpoints, such as `extract`, `places`, `map` and `crawl` ([the MCP page](https://millionshort.com/docs/mcp#tools) lists them all).

## 1. Install

Add the MCP client starter (its version comes from the Spring AI BOM; 2.0.2 is current) next to the starter for your model:

```text Maven
<dependency>
  <groupId>org.springframework.ai</groupId>
  <artifactId>spring-ai-starter-mcp-client</artifactId>
</dependency>
```

```bash
export MILLIONSHORT_API_KEY=ms-YOUR_API_KEY
```

This starter uses the JDK `HttpClient`. Spring recommends the WebFlux starter, `spring-ai-starter-mcp-client-webflux`, for production; its headers are set differently (see Settings below). Get a MillionShort key in the [dashboard](https://millionshort.com/app/).

## 2. Connect the server

Name the connection under `streamable-http`. Spring builds the address from `url` and `endpoint` (default `/mcp`); the endpoint is an absolute path, so it replaces the path of `url`, and the full address works as `url`:

```yaml application.yml
spring:
  ai:
    mcp:
      client:
        streamable-http:
          connections:
            millionshort:
              url: https://mcp.millionshort.com/mcp
              endpoint: /mcp
```

The connection properties carry no headers. With the `spring-ai-starter-mcp-client` starter, the key goes in a `McpSyncHttpClientRequestCustomizer` bean, which sees every request the HttpClient transports send, so it checks the address before adding the key. Without a key, leave the bean out.

```text Java
import io.modelcontextprotocol.client.transport.customizer.McpSyncHttpClientRequestCustomizer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
class MillionShortMcpConfig {

    @Bean
    McpSyncHttpClientRequestCustomizer millionshortAuth(@Value("${MILLIONSHORT_API_KEY}") String apiKey) {
        return (builder, method, endpoint, body, context) -> {
            if ("https://mcp.millionshort.com/mcp".equals(endpoint.toString())) {
                builder.header("Authorization", "Bearer " + apiKey);
            }
        };
    }
}
```

## 3. Give the tools to a ChatClient

Spring does not add MCP tools to a `ChatClient` by itself. Inject the provider and pass it as default tools, or per call with `.tools(mcpTools)`:

```text Java
@Autowired SyncMcpToolCallbackProvider mcpTools;

ChatClient chatClient = ChatClient.builder(chatModel)
    .defaultTools(mcpTools)
    .build();

String answer = chatClient.prompt()
    .user("Find independent blogs about home espresso, without the 1,000 most popular sites.")
    .call()
    .content();
```

## 4. Check it works

Start the application: the starter connects to `millionshort` at startup. `mcpTools.getToolCallbacks()` should hold `search`, `get_domain_info`, `list_sources` and the tools of the other endpoints ([the MCP page](https://millionshort.com/docs/mcp#tools) lists them); with no key, fewer, `search` and `list_sources` among them. Spring adds a prefix to a tool's name only when two connections have tools of the same name. Then ask the question in step 3: the answer should cite pages. If the model answers from memory, say when to search in its system prompt:

> Use the MillionShort `search` tool for anything recent, niche, or that needs a source. To reach lesser-known sites, set `remove_top_sites` (for example 1000). Cite the URLs it returns.

## MCP configuration

The same address for every client: `https://mcp.millionshort.com/mcp`, streamable HTTP.

| Mode | How | What the agent gets |
|---|---|---|
| API key | Send `Authorization: Bearer ms-YOUR_API_KEY` | Every tool, at your plan's limits; calls use your credits |
| No key | Send no `Authorization` header | `search`, `list_sources` and a few more; one source and up to 5 results a search, 10 free searches a day |

## Tools

| Tool | What it does | Without a key | Cost |
|---|---|---|---|
| `search` | Searches the web and the specialist sources, with the popularity, domain, page-type, topic, site and date filters | Yes: one source, up to 5 results | 1 credit per source searched, first 10 results |
| `get_domain_info` | Popularity and risk for up to 25 sites | No | 1 credit |
| `list_sources` | The sources, page types and topics `search` accepts | Yes: source names | Free |
| The tools of the other endpoints | `extract`, `map`, `crawl`, `places` and more: [the MCP page](https://millionshort.com/docs/mcp#tools) lists them | A few, such as `places` | What the API call behind each costs |

## Settings

| Variable | Meaning |
|---|---|
| `MILLIONSHORT_API_KEY` | Your key, read by the customizer bean as a Spring property. Leave the bean out for the no-key mode |

With the WebFlux starter, Spring's docs say to configure a `WebClient.Builder` bean (for example with an `ExchangeFilterFunction`) instead of the customizer; they show it for OAuth only, so we do not give a sample. The client is application-scoped: one MCP session per connection, shared by every request, which is fine for our stateless server.

## Costs and limits

A tool call costs what the API call behind it costs: 1 credit per source searched for the first 10 results, 1 credit for a domain lookup, nothing for the list of sources, the price of the endpoint for the other tools, and nothing at all in the no-key mode. An agent that loops can make many calls: give it a step limit, and ask for fewer results when a few will do. [Credits and limits](https://millionshort.com/docs/credits-and-limits) has the numbers.

## When it fails

| What you see | Why | Fix |
|---|---|---|
| The server does not connect, or no tools are listed | The address or the transport is not the one the server speaks | Use exactly `https://mcp.millionshort.com/mcp` and the streamable HTTP transport (often called `http`), not SSE |
| `401` or "unauthorized" | The key is wrong, or it was sent without `Bearer ` | Send `Authorization: Bearer ms-...`, or leave the header out to use the no-key mode |
| "10 free searches a day without a key" | The no-key mode's daily searches are used up | Add a key: it is free in the [dashboard](https://millionshort.com/app/) |
| `INSUFFICIENT_CREDITS` | The plan's credits are used up | Stop and add credits; retrying does not help |
| The agent answers from memory, or uses another search | Nothing told it when to use this one | Turn off its own search where it can be (this page says how), and add the line for its instructions |
| The model never sees the tools | The provider was not passed to the `ChatClient` | Pass `mcpTools` with `.defaultTools(...)` or `.tools(...)` |
| Requests go out with no key | The customizer is for the HttpClient starter, and you use the WebFlux one | Set the header on the `WebClient.Builder` instead |

## Related

- [Agent tool use](https://millionshort.com/docs/search/guides/agent-tool-use): when to give a model tools, and what to tell it.
- [LangChain](https://millionshort.com/docs/integrations/langchain) and [Genkit](https://millionshort.com/docs/integrations/genkit): the same server in other frameworks.
- [MCP server](https://millionshort.com/docs/mcp) and [Filters for agents](https://millionshort.com/docs/search/filters).
- Spring AI's own documentation, read on 2026-11-19: [MCP Client Boot Starter](https://docs.spring.io/spring-ai/reference/api/mcp/mcp-client-boot-starter-docs.html), [MCP Security](https://docs.spring.io/spring-ai/reference/api/mcp/mcp-security.html), [Tool Calling](https://docs.spring.io/spring-ai/reference/api/tools.html).
