|
| 1 | +/* |
| 2 | + * Copyright 2023-2025 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.ai.docker.compose.service.connection.docker; |
| 18 | + |
| 19 | +import org.springframework.ai.mcp.client.autoconfigure.McpSseClientConnectionDetails; |
| 20 | +import org.springframework.ai.mcp.client.autoconfigure.properties.McpSseClientProperties; |
| 21 | +import org.springframework.boot.docker.compose.core.RunningService; |
| 22 | +import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory; |
| 23 | +import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource; |
| 24 | + |
| 25 | +import java.util.Map; |
| 26 | + |
| 27 | +/** |
| 28 | + * A {@link DockerComposeConnectionDetailsFactory} implementation that creates |
| 29 | + * {@link McpSseClientConnectionDetails} for a Docker Agent Gateway instance running in a |
| 30 | + * Docker container. |
| 31 | + * |
| 32 | + * @author Eddú Meléndez |
| 33 | + */ |
| 34 | +class DockerAgentsGatewayDockerComposeConnectionDetailsFactory |
| 35 | + extends DockerComposeConnectionDetailsFactory<McpSseClientConnectionDetails> { |
| 36 | + |
| 37 | + private static final int GATEWAY_PORT = 8811; |
| 38 | + |
| 39 | + protected DockerAgentsGatewayDockerComposeConnectionDetailsFactory() { |
| 40 | + super("docker/agents_gateway"); |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + protected McpSseClientConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) { |
| 45 | + return new DockerAgentsGatewayContainerConnectionDetails(source.getRunningService()); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * {@link McpSseClientConnectionDetails} backed by a {@code Docker Agents Gateway} |
| 50 | + * {@link RunningService}. |
| 51 | + */ |
| 52 | + static class DockerAgentsGatewayContainerConnectionDetails extends DockerComposeConnectionDetails |
| 53 | + implements McpSseClientConnectionDetails { |
| 54 | + |
| 55 | + private final String url; |
| 56 | + |
| 57 | + DockerAgentsGatewayContainerConnectionDetails(RunningService service) { |
| 58 | + super(service); |
| 59 | + this.url = String.format("http://%s:%d", service.host(), service.ports().get(GATEWAY_PORT)); |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + public Map<String, McpSseClientProperties.SseParameters> getConnections() { |
| 64 | + return Map.of("gateway", new McpSseClientProperties.SseParameters(url, "/sse")); |
| 65 | + } |
| 66 | + |
| 67 | + } |
| 68 | + |
| 69 | +} |
0 commit comments