Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ count.
- **STDIO** (default): For Claude Desktop integration. Uses stdin/stdout for communication. Spring Web disabled.
- **HTTP**: For MCP Inspector and remote access. Servlet-based with optional OAuth2 security.

Both transports speak the 2025 MCP revisions by default (`stateless` HTTP, `streamable`
STDIO; up to 2025-11-25). `MCP_PROTOCOL=modern` switches either one to the 2026-07-28
revision, served by the modern server in MCP Java SDK 2.2.0 (the first GA SDK release
with it) that Spring AI 2.1.0 auto-configures. It is opt-in because the revisions are not
wire-compatible. See [docs/modern-protocol.md](docs/modern-protocol.md).

Configuration files: `application-stdio.properties`, `application-http.properties`

### SBOM Architecture
Expand Down Expand Up @@ -298,7 +304,10 @@ buildpacks (`bootBuildImage -Pnative`). Key configuration:
`--spring.profiles.active=$nativeProfile` where `nativeProfile` is `stdio`
by default or `http` if `-Pprofile=http` is passed. Activating both profiles
during AOT picks `servlet` and forces Tomcat regardless of runtime
`PROFILES`, breaking stdio — hence one native image per profile.
`PROFILES`, breaking stdio — hence one native image per profile. The MCP
protocol revision is frozen the same way: Spring AI picks the modern server
with `@ConditionalOnProperty`, so `MCP_PROTOCOL` at runtime has no effect on a
native image (see [docs/modern-protocol.md](docs/modern-protocol.md)).
- **Cross-platform builds:** `bootBuildImage` compiles inside a Linux builder
container, so it works on any host OS (macOS, Linux, Windows). Multi-arch
(amd64+arm64) is handled in CI via a GitHub Actions matrix; local builds
Expand Down Expand Up @@ -490,6 +499,9 @@ Remaining known differences from Solr 9:
Environment variables:
- `SOLR_URL`: Solr URL (default: `http://localhost:8983/solr/`)
- `PROFILES`: Transport mode (`stdio` or `http`)
- `MCP_PROTOCOL`: MCP spec revision. Unset = 2025 revisions (`stateless` HTTP, `streamable`
STDIO); `modern` = 2026-07-28. Sets `spring.ai.mcp.server.protocol`; fixed at build time in
native images.
- `OAUTH2_ISSUER_URI`: OAuth2 issuer URL (HTTP mode only)
- `OTEL_SAMPLING_PROBABILITY`: trace sampling rate (default `1.0`)
- `OTEL_TRACES_URL` / `OTEL_METRICS_URL` / `OTEL_LOGS_URL`: OTLP/HTTP endpoints
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Apache Solr MCP 1.0.0 is the project's first release: a Model Context Protocol (
- **Schema inspection and additive changes**: `get-schema`, `list-fields` (the fields that hold data, from Solr's Luke handler), `add-fields` and `add-field-types`. The schema tools only add; they never change or remove existing fields or field types.
- **Prompts, resources and completions**: guided prompts (`explore-collections`, `setup-collection`, `search-collection`, `index-data`, `view-schema`, `design-schema`), the `solr://collections`, `solr://{collection}/schema` and `solr://{collection}/fields` resources, and collection-name completion for their arguments.
- **STDIO and HTTP transports**: STDIO is the default; `PROFILES=http` serves stateless streamable HTTP.
- **MCP 2026-07-28 protocol, opt-in**: `MCP_PROTOCOL=modern` serves the newest MCP spec revision (no `initialize` handshake or session, `server/discover`, `Mcp-Method`/`Mcp-Name` headers) over HTTP or STDIO, with every tool, resource, prompt and completion. Built on the modern server in MCP Java SDK 2.2.0, the SDK's first GA release with this revision. The default stays on the 2025 revisions that current clients speak.
- **OAuth2 security for HTTP, on by default**: JWT bearer tokens from the issuer in `OAUTH2_ISSUER_URI`, with audience validation and configurable CORS origins (`MCP_CORS_ALLOWED_ORIGINS`). Setup guides cover Auth0 and Keycloak.
- **Docker images**: `apache/solr-mcp`, a JVM image (amd64 and arm64) that serves both transports, and GraalVM native images for each transport (`<version>-native-stdio`, `<version>-native-http`) on GHCR.
- **Observability in HTTP mode**: OpenTelemetry traces, metrics and logs exported over OTLP/HTTP, with a span for every tool call and logs correlated to the trace they were written in.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ The server reads configuration from environment variables. The essentials:
|----------|-------------|---------|
| `SOLR_URL` | Solr base URL | `http://localhost:8983/solr/` |
| `PROFILES` | Transport mode: `stdio` (default, for Claude Desktop) or `http` (remote / multi-client) | `stdio` |
| `MCP_PROTOCOL` | MCP spec revision: the 2025 revisions today's clients speak (default), or `modern` for the [2026-07-28 revision](docs/modern-protocol.md) | `stateless` (HTTP), `streamable` (STDIO) |

Running in **HTTP mode** — OAuth2, CORS, and the `HTTP_SECURITY_ENABLED` toggle (secured by default) — is covered in the [security docs](docs/security/). Tracing, metrics and log-export env vars (`OTEL_SAMPLING_PROBABILITY`, `OTEL_TRACES_URL`, `OTEL_METRICS_URL`, `OTEL_LOGS_URL`) are covered in [Observability](docs/observability.md).

Expand All @@ -216,6 +217,7 @@ Running in **HTTP mode** — OAuth2, CORS, and the `HTTP_SECURITY_ENABLED` toggl
- [Quick start](#quick-start) · [Client setup](docs/clients/) — Claude Desktop, Claude Code, Codex, ChatGPT, VS Code, Cursor, JetBrains, Zed, MCP Inspector
- [Tutorial: your first collection](docs/tutorial.md) — index a dataset twice, schemaless then with a designed schema, and see why field types matter
- [Observability](docs/observability.md) — OpenTelemetry traces, metrics, logs
- [MCP 2026-07-28 protocol (`MCP_PROTOCOL=modern`)](docs/modern-protocol.md) — opting in to the newest spec revision, and what it changes for clients
- Security: [Deployment model (single-tenant)](docs/security/deployment-model.md) · [STDIO model](docs/security/stdio.md) · [HTTP model](docs/security/http.md) · OAuth2 setup: [Auth0](docs/security/auth0.md) · [Keycloak](docs/security/keycloak.md)

**Developing it**
Expand Down
5 changes: 3 additions & 2 deletions THREAT_MODEL.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,12 @@ reaching the backend Solr directly, bypassing this server, is out of model (§3)
| `PROFILES` | `stdio` | Selects transport. `stdio` = no network listener, OS-user trust. `http` = network listener, OAuth2. The two are **different threat models**; this document covers both. | Q-transport |
| `HTTP_SECURITY_ENABLED` | `true` | HTTP mode is **secured by default**. `false` activates an unsecured filter chain — every MCP/actuator endpoint anonymous. Documented as "local development only… unsafe on any network-reachable deployment." | Q-httpsec |
| `OAUTH2_ISSUER_URI` | empty (placeholder) | With HTTP security on and no issuer, the chain still returns 401/403 on every non-permitted endpoint (locked down, no token validator). A real issuer enables JWT signature/issuer/exp/**audience** validation. | Q-httpsec |
| `MCP_PROTOCOL` | unset (`stateless` HTTP, `streamable` STDIO; 2025 revisions) | `modern` serves the MCP 2026-07-28 revision (MCP Java SDK 2.2.0's modern server): no `initialize`/session, `server/discover`, `Mcp-Method`/`Mcp-Name` headers (added to the CORS header allowlist). The same `@PreAuthorize` checks guard every entry point. Multi-round-trip requests return a sealed `requestState`, keyed per instance unless `spring.ai.mcp.server.modern.request-state-secret` is set. Fixed at build time in native images. | *(documented — [docs/modern-protocol.md](docs/modern-protocol.md))* |
| `MCP_CORS_ALLOWED_ORIGINS` | MCP Inspector localhost proxy | Explicit CORS allowlist; wildcard-with-credentials is rejected by construction (`setAllowedOrigins`, not patterns). | *(documented)* |
| `SOLR_USERNAME` / `SOLR_PASSWORD` | unset | When both set, static HTTP Basic Auth to backend Solr on every request; when unset, unauthenticated backend calls. | Q-backendcreds |

**How HTTP mode enforces auth** *(maintainer — Q-transport.)*: the transport
is streamable HTTP running in **stateless** mode
**How HTTP mode enforces auth** *(maintainer — Q-transport.)*: by default the
transport is streamable HTTP running in **stateless** mode
(`spring.ai.mcp.server.protocol=stateless`), so there is no sampling, progress
or elicitation channel and no per-request context feature. `/mcp` is
`permitAll()` at the filter-chain level; authentication is enforced instead by
Expand Down
7 changes: 7 additions & 0 deletions dev-docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ Additional Jib benefits:
- Requires additional security measures for production
- Useful for testing and remote deployments

#### MCP protocol revision

Both transports speak the 2025 MCP revisions by default. `MCP_PROTOCOL=modern` serves the
2026-07-28 revision instead (no `initialize` handshake or session, `server/discover`), using
the modern server in MCP Java SDK 2.2.0 that Spring AI 2.1.0 auto-configures. The tools,
resources and prompts are the same in both. See [modern-protocol.md](../docs/modern-protocol.md).

### Document Processing

The document creator pattern allows for:
Expand Down
7 changes: 7 additions & 0 deletions dev-docs/graalvm-native-image.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ This is also why the JVM Jib image can be dual-mode while the native images
cannot: the JVM image makes the `web-application-type` decision at *runtime*
from the `PROFILES` env var; the native image already made it at *build time*.

The MCP protocol revision is frozen the same way. Spring AI chooses between the
2025-revision servers and the 2026-07-28 ("modern") server with
`@ConditionalOnProperty` on `spring.ai.mcp.server.protocol`, which `MCP_PROTOCOL`
sets, so a native image serves whichever revision was in effect when `processAot`
ran (the 2025 revisions by default) and ignores `MCP_PROTOCOL` at `docker run`
time. See [docs/modern-protocol.md](../docs/modern-protocol.md#native-images).

## Why Jib for JVM, Paketo for native

- **Jib (JVM image).** Plain `java -jar` entrypoint, no launcher script, so
Expand Down
102 changes: 102 additions & 0 deletions docs/modern-protocol.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# MCP 2026-07-28 protocol (`MCP_PROTOCOL=modern`)

Solr MCP Server can serve the
[2026-07-28 revision](https://modelcontextprotocol.io/specification/2026-07-28) of the
Model Context Protocol. The server is the modern one in MCP Java SDK 2.2.0, the first GA
SDK release to support that revision, as auto-configured by Spring AI 2.1.0.

It is **opt-in**. The 2026-07-28 revision is not wire-compatible with the 2025 revisions,
and most clients in use today (MCP Inspector, Claude Desktop, the Java, Python and TypeScript
SDK clients) still speak the 2025 revisions. Turn it on only when your clients speak the new
revision.

| Transport | Default (`MCP_PROTOCOL` unset) | `MCP_PROTOCOL=modern` |
|-----------|--------------------------------|-----------------------|
| HTTP (`PROFILES=http`) | `stateless` streamable HTTP, 2025 revisions | 2026-07-28 revision on `POST /mcp` |
| STDIO (default profile) | `streamable`, 2025 revisions | 2026-07-28 revision, newline-delimited JSON-RPC |

## Turning it on

```bash
# HTTP
PROFILES=http MCP_PROTOCOL=modern SOLR_URL=http://localhost:8983/solr/ \
java -jar build/libs/solr-mcp-<version>.jar

# STDIO
MCP_PROTOCOL=modern SOLR_URL=http://localhost:8983/solr/ \
java -jar build/libs/solr-mcp-<version>.jar
```

`MCP_PROTOCOL` sets `spring.ai.mcp.server.protocol`, so
`-Dspring.ai.mcp.server.protocol=modern` works the same way.

Every tool, resource, resource template, prompt and completion is served unchanged in
either mode, and the `@PreAuthorize` scopes on tools apply the same way.

## What changes for clients

- **No `initialize` handshake and no session.** A client calls `server/discover` to learn
the server's capabilities, `serverInfo` and instructions. There is no `Mcp-Session-Id`,
and `ping` is gone.
- **Every request carries `_meta`** with the protocol version, the client's capabilities and
the client's info:

```json
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "list-collections",
"arguments": {},
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientCapabilities": {},
"io.modelcontextprotocol/clientInfo": { "name": "my-client", "version": "1.0.0" }
}
}
}
```

- **Over HTTP, requests carry routing headers.** `MCP-Protocol-Version: 2026-07-28` and
`Mcp-Method` on every request, plus `Mcp-Name` (the tool, prompt or resource URI) on
`tools/call`, `prompts/get` and `resources/read`. A header that doesn't match the body is
rejected with HTTP 400 and JSON-RPC error `-32020`.

## CORS

The HTTP profile's CORS configuration allows the `Mcp-Method`, `Mcp-Name` and
`MCP-Protocol-Version` headers, so browser-based clients can send them from the allowed
origins.

## Running more than one instance

When a request takes more than one round trip, the modern server seals a `requestState`
for the client to send back. Unless a secret is set, each instance seals it with its own
random key, so the follow-up must reach the same instance. Behind a load balancer, give every
instance the same secret of at least 32 bytes:

```properties
spring.ai.mcp.server.modern.request-state-secret=${MCP_REQUEST_STATE_SECRET}
```

## Native images

The transport is chosen by `@ConditionalOnProperty` conditions, which a GraalVM native image
fixes at build time. To get a native image that serves the modern protocol, set
`MCP_PROTOCOL=modern` when running `nativeCompile`. This has not been tested yet.

## Spring AI 2.1 STDIO workaround

In Spring AI 2.1.0, the modern STDIO transport has two problems
when the server runs without a web server, as it does in the STDIO profile:

1. The SDK's stdin reader runs on daemon threads and Spring AI does not block on it, so the
JVM exits as soon as startup finishes and the first request gets no answer.
2. The reader starts before the application context has finished starting, so a request sent
right at launch can fail with `-32602` (`clientCapabilities is malformed`), `-32603`, or no
answer at all.

`ModernStdioTransportConfiguration` replaces the transport bean in modern STDIO mode only. It
starts reading stdin once the application is ready and keeps the JVM alive on a non-daemon
thread until stdin closes. It can be removed once Spring AI fixes both upstream.
4 changes: 3 additions & 1 deletion docs/security/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ The CORS allowlist is intentionally narrow:
credentials is the [classic CWE-942 misconfiguration](https://cwe.mitre.org/data/definitions/942.html).
- **Methods**: `GET, POST, DELETE, OPTIONS` — the methods used by the MCP
Streamable HTTP transport.
- **Headers**: `Authorization, Content-Type, Mcp-Session-Id, MCP-Protocol-Version, Last-Event-ID`.
- **Headers**: `Authorization, Content-Type, Mcp-Session-Id, MCP-Protocol-Version, Last-Event-ID`,
plus `Mcp-Method, Mcp-Name`, the routing headers of the
[2026-07-28 revision](../modern-protocol.md) (`MCP_PROTOCOL=modern`).
- **Credentials**: allowed (Bearer-token flows).

Add origins via `MCP_CORS_ALLOWED_ORIGINS` (comma-separated). Real production
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.mcp.server.config;

import io.modelcontextprotocol.json.jackson3.JacksonMcpJsonMapper;
import io.modelcontextprotocol.modern.server.McpServer;
import io.modelcontextprotocol.modern.server.transport.StdioMcpTransport;
import java.util.concurrent.atomic.AtomicBoolean;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.publisher.Mono;
import reactor.core.publisher.Sinks;
import tools.jackson.databind.json.JsonMapper;

/**
* Makes the STDIO server on the MCP 2026-07-28 revision ({@code MCP_PROTOCOL=modern}) reliable.
*
* <p>Spring AI 2.1.0 starts the SDK's modern {@link StdioMcpTransport} as soon as its lifecycle
* bean starts, which is before the application context has finished refreshing, and the transport
* runs on daemon threads only. Measured against the packaged jar, that causes two failures a
* desktop client hits on its very first request:
*
* <ul>
* <li>A request written to stdin straight after launch, as clients do, is read while the context
* is still starting. The answer is then random: the correct result, {@code -32602
* clientCapabilities is malformed}, {@code -32603 Internal error}, or nothing at all. The
* same request sent a few seconds later always succeeds.
* <li>STDIO is a non-web application, so once {@code main} returns no non-daemon thread holds the
* JVM open. The process exits a moment after startup and a request still in flight is dropped
* without a response.
* </ul>
*
* <p>This transport therefore starts reading stdin only once the application is ready, and holds
* one non-daemon thread until the session ends (the client closes stdin, or the context shuts
* down). It replaces the auto-configured transport, which is {@code @ConditionalOnMissingBean}.
* Remove this class once Spring AI defers and keeps alive the modern STDIO transport itself.
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(name = "spring.ai.mcp.server.stdio", havingValue = "true")
@ConditionalOnProperty(name = "spring.ai.mcp.server.protocol", havingValue = "modern")
class ModernStdioTransportConfiguration {

static final String KEEP_ALIVE_THREAD_NAME = "solr-mcp-stdio-keep-alive";

@Bean
StdioMcpTransport mcpModernStdioTransport(
McpServer mcpServer, @Qualifier("mcpServerJsonMapper") JsonMapper jsonMapper) {
return new ReadyStdioMcpTransport(mcpServer, new JacksonMcpJsonMapper(jsonMapper));
}

/**
* A modern STDIO transport that starts reading on {@link ApplicationReadyEvent} and keeps a
* non-daemon thread alive for the length of the session.
*/
static final class ReadyStdioMcpTransport extends StdioMcpTransport
implements ApplicationListener<ApplicationReadyEvent> {

private final Sinks.Empty<Void> session = Sinks.empty();

private final AtomicBoolean started = new AtomicBoolean();

ReadyStdioMcpTransport(McpServer server, JacksonMcpJsonMapper jsonMapper) {
super(server, jsonMapper);
}

/** Called by Spring AI's lifecycle during refresh; reading waits for the ready event. */
@Override
public Mono<Void> start() {
return session.asMono();
}

@Override
public void onApplicationEvent(ApplicationReadyEvent event) {
if (!started.compareAndSet(false, true)) {
return;
}
Mono<Void> reading = super.start();
Thread keepAlive =
new Thread(
() -> {
reading.onErrorComplete().block();
session.tryEmitEmpty();
},
KEEP_ALIVE_THREAD_NAME);
keepAlive.setDaemon(false);
keepAlive.start();
}
}
}
Loading