Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2025-2025 the original author or authors.
*
* Licensed 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
*
* https://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.springframework.ai.mcp.client.common.autoconfigure;

import java.util.Map;

import org.springframework.ai.mcp.client.common.autoconfigure.properties.McpSseClientProperties;
import org.springframework.boot.autoconfigure.service.connection.ConnectionDetails;

/**
* Connection details for an MCP client.
*
* @author Eddú Meléndez
*/
public interface McpSseClientConnectionDetails extends ConnectionDetails {

Map<String, McpSseClientProperties.SseParameters> getConnections();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2025-2025 the original author or authors.
*
* Licensed 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
*
* https://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.springframework.ai.mcp.client.common.autoconfigure;

import java.util.Map;

import org.springframework.ai.mcp.client.common.autoconfigure.properties.McpSseClientProperties;

public class PropertiesMcpSseClientConnectionDetails implements McpSseClientConnectionDetails {

private final McpSseClientProperties properties;

public PropertiesMcpSseClientConnectionDetails(McpSseClientProperties properties) {
this.properties = properties;
}

@Override
public Map<String, McpSseClientProperties.SseParameters> getConnections() {
return this.properties.getConnections();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
import io.modelcontextprotocol.client.transport.customizer.McpSyncHttpClientRequestCustomizer;
import io.modelcontextprotocol.spec.McpSchema;

import org.springframework.ai.mcp.client.common.autoconfigure.McpSseClientConnectionDetails;
import org.springframework.ai.mcp.client.common.autoconfigure.NamedClientMcpTransport;
import org.springframework.ai.mcp.client.common.autoconfigure.PropertiesMcpSseClientConnectionDetails;
import org.springframework.ai.mcp.client.common.autoconfigure.properties.McpClientCommonProperties;
import org.springframework.ai.mcp.client.common.autoconfigure.properties.McpSseClientProperties;
import org.springframework.ai.mcp.client.common.autoconfigure.properties.McpSseClientProperties.SseParameters;
Expand Down Expand Up @@ -73,6 +75,11 @@ public class SseHttpClientTransportAutoConfiguration {

private static final LogAccessor logger = new LogAccessor(SseHttpClientTransportAutoConfiguration.class);

@Bean
PropertiesMcpSseClientConnectionDetails mcpSseClientConnectionDetails(McpSseClientProperties sseProperties) {
return new PropertiesMcpSseClientConnectionDetails(sseProperties);
}

/**
* Creates a list of HTTP client-based SSE transports for MCP communication.
*
Expand All @@ -84,7 +91,8 @@ public class SseHttpClientTransportAutoConfiguration {
* <li>ObjectMapper for JSON processing
* <li>A sync or async HTTP request customizer. Sync takes precedence.
* </ul>
* @param sseProperties the SSE client properties containing server configurations
* @param connectionDetails the SSE client connection details containing server
* configurations
* @param objectMapperProvider the provider for ObjectMapper or a new instance if not
* available
* @param syncHttpRequestCustomizer provider for
Expand All @@ -94,7 +102,7 @@ public class SseHttpClientTransportAutoConfiguration {
* @return list of named MCP transports
*/
@Bean
public List<NamedClientMcpTransport> sseHttpClientTransports(McpSseClientProperties sseProperties,
public List<NamedClientMcpTransport> sseHttpClientTransports(McpSseClientConnectionDetails connectionDetails,
ObjectProvider<ObjectMapper> objectMapperProvider,
ObjectProvider<McpSyncHttpClientRequestCustomizer> syncHttpRequestCustomizer,
ObjectProvider<McpAsyncHttpClientRequestCustomizer> asyncHttpRequestCustomizer) {
Expand All @@ -103,7 +111,7 @@ public List<NamedClientMcpTransport> sseHttpClientTransports(McpSseClientPropert

List<NamedClientMcpTransport> sseTransports = new ArrayList<>();

for (Map.Entry<String, SseParameters> serverParameters : sseProperties.getConnections().entrySet()) {
for (Map.Entry<String, SseParameters> serverParameters : connectionDetails.getConnections().entrySet()) {

String baseUrl = serverParameters.getValue().url();
String sseEndpoint = serverParameters.getValue().sseEndpoint() != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import io.modelcontextprotocol.client.transport.WebFluxSseClientTransport;

import org.springframework.ai.mcp.client.common.autoconfigure.McpSseClientConnectionDetails;
import org.springframework.ai.mcp.client.common.autoconfigure.NamedClientMcpTransport;
import org.springframework.ai.mcp.client.common.autoconfigure.PropertiesMcpSseClientConnectionDetails;
import org.springframework.ai.mcp.client.common.autoconfigure.properties.McpClientCommonProperties;
import org.springframework.ai.mcp.client.common.autoconfigure.properties.McpSseClientProperties;
import org.springframework.ai.mcp.client.common.autoconfigure.properties.McpSseClientProperties.SseParameters;
Expand Down Expand Up @@ -63,6 +65,11 @@
matchIfMissing = true)
public class SseWebFluxTransportAutoConfiguration {

@Bean
PropertiesMcpSseClientConnectionDetails mcpSseClientConnectionDetails(McpSseClientProperties sseProperties) {
return new PropertiesMcpSseClientConnectionDetails(sseProperties);
}

/**
* Creates a list of WebFlux-based SSE transports for MCP communication.
*
Expand All @@ -73,14 +80,14 @@ public class SseWebFluxTransportAutoConfiguration {
* <li>ObjectMapper for JSON processing
* <li>Server connection parameters from properties
* </ul>
* @param sseProperties the SSE client properties containing server configurations
* @param connectionDetails the SSE client properties containing server configurations
* @param webClientBuilderProvider the provider for WebClient.Builder
* @param objectMapperProvider the provider for ObjectMapper or a new instance if not
* available
* @return list of named MCP transports
*/
@Bean
public List<NamedClientMcpTransport> sseWebFluxClientTransports(McpSseClientProperties sseProperties,
public List<NamedClientMcpTransport> sseWebFluxClientTransports(McpSseClientConnectionDetails connectionDetails,
ObjectProvider<WebClient.Builder> webClientBuilderProvider,
ObjectProvider<ObjectMapper> objectMapperProvider) {

Expand All @@ -89,7 +96,7 @@ public List<NamedClientMcpTransport> sseWebFluxClientTransports(McpSseClientProp
var webClientBuilderTemplate = webClientBuilderProvider.getIfAvailable(WebClient::builder);
var objectMapper = objectMapperProvider.getIfAvailable(ObjectMapper::new);

for (Map.Entry<String, SseParameters> serverParameters : sseProperties.getConnections().entrySet()) {
for (Map.Entry<String, SseParameters> serverParameters : connectionDetails.getConnections().entrySet()) {
var webClientBuilder = webClientBuilderTemplate.clone().baseUrl(serverParameters.getValue().url());
String sseEndpoint = serverParameters.getValue().sseEndpoint() != null
? serverParameters.getValue().sseEndpoint() : "/sse";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ The following service connection factories are provided in the `spring-ai-spring

| `WeaviateConnectionDetails`
| Containers named `semitechnologies/weaviate`, `cr.weaviate.io/semitechnologies/weaviate`

| `McpSseClientConnectionDetails`
| Containers named `docker/mcp-gateway`
|====

More service connections are provided by the spring boot module `spring-boot-docker-compose`. Refer to the https://docs.spring.io/spring-boot/reference/features/dev-services.html#features.dev-services.docker-compose[Docker Compose Support] documentation page for the full list.
14 changes: 14 additions & 0 deletions spring-ai-spring-boot-docker-compose/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-autoconfigure-mcp-client-httpclient</artifactId>
<version>${project.version}</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-autoconfigure-mcp-client-webflux</artifactId>
<version>${project.version}</version>
<optional>true</optional>
</dependency>

<!-- production dependencies -->

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2023-2025 the original author or authors.
*
* Licensed 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
*
* https://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.springframework.ai.docker.compose.service.connection.docker;

import java.util.Map;

import org.springframework.ai.mcp.client.common.autoconfigure.McpSseClientConnectionDetails;
import org.springframework.ai.mcp.client.common.autoconfigure.properties.McpSseClientProperties;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;

/**
* A {@link DockerComposeConnectionDetailsFactory} implementation that creates
* {@link McpSseClientConnectionDetails} for a Docker MCP Gateway instance running in a
* Docker container.
*
* @author Eddú Meléndez
*/
class DockerMcpGatewayDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<McpSseClientConnectionDetails> {

private static final int GATEWAY_PORT = 8811;

protected DockerMcpGatewayDockerComposeConnectionDetailsFactory() {
super("docker/mcp-gateway");
}

@Override
protected McpSseClientConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new DockerAgentsGatewayContainerConnectionDetails(source.getRunningService());
}

/**
* {@link McpSseClientConnectionDetails} backed by a {@code Docker MCP Gateway}
* {@link RunningService}.
*/
static class DockerAgentsGatewayContainerConnectionDetails extends DockerComposeConnectionDetails
implements McpSseClientConnectionDetails {

private final String url;

DockerAgentsGatewayContainerConnectionDetails(RunningService service) {
super(service);
this.url = String.format("http://%s:%d", service.host(), service.ports().get(GATEWAY_PORT));
}

@Override
public Map<String, McpSseClientProperties.SseParameters> getConnections() {
return Map.of("gateway", new McpSseClientProperties.SseParameters(this.url, "/sse"));
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

org.springframework.boot.autoconfigure.service.connection.ConnectionDetailsFactory=\
org.springframework.ai.docker.compose.service.connection.chroma.ChromaDockerComposeConnectionDetailsFactory,\
org.springframework.ai.docker.compose.service.connection.docker.DockerMcpGatewayDockerComposeConnectionDetailsFactory,\
org.springframework.ai.docker.compose.service.connection.mongo.MongoDbAtlasLocalDockerComposeConnectionDetailsFactory,\
org.springframework.ai.docker.compose.service.connection.ollama.OllamaDockerComposeConnectionDetailsFactory,\
org.springframework.ai.docker.compose.service.connection.opensearch.AwsOpenSearchDockerComposeConnectionDetailsFactory,\
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2023-2024 the original author or authors.
*
* Licensed 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
*
* https://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.springframework.ai.docker.compose.service.connection.docker;

import org.junit.jupiter.api.Test;
import org.testcontainers.utility.DockerImageName;

import org.springframework.ai.mcp.client.common.autoconfigure.McpSseClientConnectionDetails;
import org.springframework.boot.docker.compose.service.connection.test.AbstractDockerComposeIT;

import static org.assertj.core.api.Assertions.assertThat;

class DockerMcpGatewayDockerComposeConnectionDetailsFactoryIT extends AbstractDockerComposeIT {

protected DockerMcpGatewayDockerComposeConnectionDetailsFactoryIT() {
super("docker-agents-gateway-compose.yaml", DockerImageName.parse("docker/mcp-gateway"));
}

@Test
void runCreatesConnectionDetails() {
McpSseClientConnectionDetails connectionDetails = run(McpSseClientConnectionDetails.class);
assertThat(connectionDetails.getConnections()).hasSize(1);
assertThat(connectionDetails.getConnections().get("gateway").url()).startsWith("http://");
assertThat(connectionDetails.getConnections().get("gateway").sseEndpoint()).contains("/sse");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
mcp-gateway:
image: '{imageName}'
ports:
- 8811
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
command:
- --transport=sse