refactor: Improve MCP documentation and transport interfaces

- Add ClientMcpTransport and ServerMcpTransport marker interfaces
- Update client/server implementations to use appropriate transport interfaces
- Reorganize documentation structure and improve content clarity
- Move documentation images to mcp-docs/antora directory
- Update README files with links to online documentation

Resolves #44
This commit is contained in:
Christian Tzolov 2025-01-03 15:48:30 +01:00
commit c469f790b3
13 changed files with 407 additions and 750 deletions

View file

@ -26,14 +26,13 @@ import reactor.core.publisher.Mono;
import reactor.core.publisher.Sinks;
import reactor.core.scheduler.Schedulers;
import org.springframework.ai.mcp.spec.ClientMcpTransport;
import org.springframework.ai.mcp.spec.McpSchema;
import org.springframework.ai.mcp.spec.McpTransport;
import org.springframework.ai.mcp.spec.McpSchema.JSONRPCMessage;
import org.springframework.ai.mcp.spec.McpSchema.JSONRPCNotification;
import org.springframework.ai.mcp.spec.McpSchema.JSONRPCRequest;
@SuppressWarnings("unused")
public class MockMcpTransport implements McpTransport {
public class MockMcpTransport implements ClientMcpTransport {
private final AtomicInteger inboundMessageCount = new AtomicInteger(0);

View file

@ -27,6 +27,7 @@ import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import reactor.test.StepVerifier;
import org.springframework.ai.mcp.spec.ClientMcpTransport;
import org.springframework.ai.mcp.spec.McpSchema;
import org.springframework.ai.mcp.spec.McpSchema.CallToolRequest;
import org.springframework.ai.mcp.spec.McpSchema.ClientCapabilities;
@ -56,13 +57,13 @@ public abstract class AbstractMcpAsyncClientTests {
private McpAsyncClient mcpAsyncClient;
protected McpTransport mcpTransport;
protected ClientMcpTransport mcpTransport;
private static final Duration TIMEOUT = Duration.ofSeconds(20);
private static final String ECHO_TEST_MESSAGE = "Hello MCP Spring AI!";
abstract protected McpTransport createMcpTransport();
abstract protected ClientMcpTransport createMcpTransport();
protected void onStart() {
}

View file

@ -24,6 +24,7 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.ai.mcp.spec.ClientMcpTransport;
import org.springframework.ai.mcp.spec.McpSchema;
import org.springframework.ai.mcp.spec.McpSchema.CallToolRequest;
import org.springframework.ai.mcp.spec.McpSchema.CallToolResult;
@ -38,7 +39,6 @@ import org.springframework.ai.mcp.spec.McpSchema.SubscribeRequest;
import org.springframework.ai.mcp.spec.McpSchema.TextContent;
import org.springframework.ai.mcp.spec.McpSchema.Tool;
import org.springframework.ai.mcp.spec.McpSchema.UnsubscribeRequest;
import org.springframework.ai.mcp.spec.McpTransport;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
@ -58,9 +58,9 @@ public abstract class AbstractMcpSyncClientTests {
private static final String TEST_MESSAGE = "Hello MCP Spring AI!";
protected McpTransport mcpTransport;
protected ClientMcpTransport mcpTransport;
abstract protected McpTransport createMcpTransport();
abstract protected ClientMcpTransport createMcpTransport();
abstract protected void onStart();

View file

@ -20,7 +20,7 @@ import org.junit.jupiter.api.Timeout;
import org.springframework.ai.mcp.client.transport.ServerParameters;
import org.springframework.ai.mcp.client.transport.StdioClientTransport;
import org.springframework.ai.mcp.spec.McpTransport;
import org.springframework.ai.mcp.spec.ClientMcpTransport;
/**
* Tests for the {@link McpAsyncClient} with {@link StdioClientTransport}.
@ -32,7 +32,7 @@ import org.springframework.ai.mcp.spec.McpTransport;
class McpAsyncClientTests extends AbstractMcpAsyncClientTests {
@Override
protected McpTransport createMcpTransport() {
protected ClientMcpTransport createMcpTransport() {
ServerParameters stdioParams = ServerParameters.builder("npx")
.args("-y", "@modelcontextprotocol/server-everything", "dir")
.build();

View file

@ -23,7 +23,7 @@ import org.junit.jupiter.api.Timeout;
import org.springframework.ai.mcp.client.transport.ServerParameters;
import org.springframework.ai.mcp.client.transport.StdioClientTransport;
import org.springframework.ai.mcp.spec.McpTransport;
import org.springframework.ai.mcp.spec.ClientMcpTransport;
import static org.assertj.core.api.Assertions.assertThat;
@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class McpSyncClientTests extends AbstractMcpSyncClientTests {
@Override
protected McpTransport createMcpTransport() {
protected ClientMcpTransport createMcpTransport() {
ServerParameters stdioParams = ServerParameters.builder("npx")
.args("-y", "@modelcontextprotocol/server-everything", "dir")
.build();

View file

@ -21,7 +21,7 @@ import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.springframework.ai.mcp.client.transport.SseClientTransport;
import org.springframework.ai.mcp.spec.McpTransport;
import org.springframework.ai.mcp.spec.ClientMcpTransport;
import org.springframework.web.reactive.function.client.WebClient;
/**
@ -42,7 +42,7 @@ class SseMcpAsyncClientTests extends AbstractMcpAsyncClientTests {
.waitingFor(Wait.forHttp("/").forStatusCode(404));
@Override
protected McpTransport createMcpTransport() {
protected ClientMcpTransport createMcpTransport() {
return new SseClientTransport(WebClient.builder().baseUrl(host));
}

View file

@ -21,7 +21,7 @@ import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.springframework.ai.mcp.client.transport.SseClientTransport;
import org.springframework.ai.mcp.spec.McpTransport;
import org.springframework.ai.mcp.spec.ClientMcpTransport;
import org.springframework.web.reactive.function.client.WebClient;
/**
@ -42,7 +42,7 @@ class SseMcpSyncClientTests extends AbstractMcpSyncClientTests {
.waitingFor(Wait.forHttp("/").forStatusCode(404));
@Override
protected McpTransport createMcpTransport() {
protected ClientMcpTransport createMcpTransport() {
return new SseClientTransport(WebClient.builder().baseUrl(host));
}

View file

@ -39,6 +39,7 @@ import org.springframework.ai.mcp.spec.McpSchema.Resource;
import org.springframework.ai.mcp.spec.McpSchema.ServerCapabilities;
import org.springframework.ai.mcp.spec.McpSchema.Tool;
import org.springframework.ai.mcp.spec.McpTransport;
import org.springframework.ai.mcp.spec.ServerMcpTransport;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
@ -58,7 +59,7 @@ public abstract class AbstractMcpAsyncServerTests {
private static final String TEST_PROMPT_NAME = "test-prompt";
abstract protected McpTransport createMcpTransport();
abstract protected ServerMcpTransport createMcpTransport();
protected void onStart() {
}

View file

@ -23,11 +23,11 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.ai.mcp.spec.McpSchema;
import org.springframework.ai.mcp.server.McpServer.PromptRegistration;
import org.springframework.ai.mcp.server.McpServer.ResourceRegistration;
import org.springframework.ai.mcp.server.McpServer.ToolRegistration;
import org.springframework.ai.mcp.spec.McpError;
import org.springframework.ai.mcp.spec.McpSchema;
import org.springframework.ai.mcp.spec.McpSchema.CallToolResult;
import org.springframework.ai.mcp.spec.McpSchema.GetPromptResult;
import org.springframework.ai.mcp.spec.McpSchema.Prompt;
@ -37,6 +37,7 @@ import org.springframework.ai.mcp.spec.McpSchema.Resource;
import org.springframework.ai.mcp.spec.McpSchema.ServerCapabilities;
import org.springframework.ai.mcp.spec.McpSchema.Tool;
import org.springframework.ai.mcp.spec.McpTransport;
import org.springframework.ai.mcp.spec.ServerMcpTransport;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
@ -56,7 +57,7 @@ public abstract class AbstractMcpSyncServerTests {
private static final String TEST_PROMPT_NAME = "test-prompt";
abstract protected McpTransport createMcpTransport();
abstract protected ServerMcpTransport createMcpTransport();
protected void onStart() {
}

View file

@ -22,7 +22,7 @@ import reactor.netty.DisposableServer;
import reactor.netty.http.server.HttpServer;
import org.springframework.ai.mcp.server.transport.SseServerTransport;
import org.springframework.ai.mcp.spec.McpTransport;
import org.springframework.ai.mcp.spec.ServerMcpTransport;
import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter;
import org.springframework.web.reactive.function.server.RouterFunctions;
@ -42,7 +42,7 @@ class SseMcpAsyncServerTests extends AbstractMcpAsyncServerTests {
private DisposableServer httpServer;
@Override
protected McpTransport createMcpTransport() {
protected ServerMcpTransport createMcpTransport() {
var transport = new SseServerTransport(new ObjectMapper(), MESSAGE_ENDPOINT);
HttpHandler httpHandler = RouterFunctions.toHttpHandler(transport.getRouterFunction());

View file

@ -22,7 +22,7 @@ import reactor.netty.DisposableServer;
import reactor.netty.http.server.HttpServer;
import org.springframework.ai.mcp.server.transport.SseServerTransport;
import org.springframework.ai.mcp.spec.McpTransport;
import org.springframework.ai.mcp.spec.ServerMcpTransport;
import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter;
import org.springframework.web.reactive.function.server.RouterFunctions;
@ -44,7 +44,7 @@ class SseMcpSyncServerTests extends AbstractMcpSyncServerTests {
private SseServerTransport transport;
@Override
protected McpTransport createMcpTransport() {
protected ServerMcpTransport createMcpTransport() {
transport = new SseServerTransport(new ObjectMapper(), MESSAGE_ENDPOINT);
return transport;
}

View file

@ -19,7 +19,7 @@ package org.springframework.ai.mcp.server;
import org.junit.jupiter.api.Timeout;
import org.springframework.ai.mcp.server.transport.StdioServerTransport;
import org.springframework.ai.mcp.spec.McpTransport;
import org.springframework.ai.mcp.spec.ServerMcpTransport;
/**
* Tests for {@link McpAsyncServer} using {@link StdioServerTransport}.
@ -30,7 +30,7 @@ import org.springframework.ai.mcp.spec.McpTransport;
class StdioMcpAsyncServerTests extends AbstractMcpAsyncServerTests {
@Override
protected McpTransport createMcpTransport() {
protected ServerMcpTransport createMcpTransport() {
return new StdioServerTransport();
}

View file

@ -19,7 +19,7 @@ package org.springframework.ai.mcp.server;
import org.junit.jupiter.api.Timeout;
import org.springframework.ai.mcp.server.transport.StdioServerTransport;
import org.springframework.ai.mcp.spec.McpTransport;
import org.springframework.ai.mcp.spec.ServerMcpTransport;
/**
* Tests for {@link McpSyncServer} using {@link StdioServerTransport}.
@ -30,7 +30,7 @@ import org.springframework.ai.mcp.spec.McpTransport;
class StdioMcpSyncServerTests extends AbstractMcpSyncServerTests {
@Override
protected McpTransport createMcpTransport() {
protected ServerMcpTransport createMcpTransport() {
return new StdioServerTransport();
}