Skip to content

Commit

Permalink
Fix the docker.io/tzolov/mcp-everything-server:v1 url
Browse files Browse the repository at this point in the history
  • Loading branch information
tzolov committed Dec 15, 2024
1 parent bc281de commit 0ebb38c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ public class DefaultMcpSession implements McpSession {

private final McpTransport transport;

private final ConcurrentHashMap<String, RequestHandler> requestHandlers = new ConcurrentHashMap<>();

@FunctionalInterface
public interface RequestHandler {

Mono<Object> handle(Object params);

}

public DefaultMcpSession(Duration requestTimeout, ObjectMapper objectMapper, McpTransport transport) {

Assert.notNull(objectMapper, "The ObjectMapper can not be null");
Expand All @@ -70,7 +79,13 @@ public DefaultMcpSession(Duration requestTimeout, ObjectMapper objectMapper, Mcp
}
}
else if (message instanceof McpSchema.JSONRPCRequest request) {
logger.info("Client does not yet support server requests");
handleIncomingRequest(request).subscribe(response -> transport.sendMessage(response).subscribe(),
error -> {
var errorResponse = new McpSchema.JSONRPCResponse(McpSchema.JSONRPC_VERSION, request.id(),
null, new McpSchema.JSONRPCResponse.JSONRPCError(
McpSchema.ErrorCodes.INTERNAL_ERROR, error.getMessage(), null));
transport.sendMessage(errorResponse).subscribe();
});
}
else if (message instanceof McpSchema.JSONRPCNotification notification) {
logger.info("Notifications not yet supported");
Expand All @@ -82,6 +97,27 @@ else if (message instanceof McpSchema.JSONRPCNotification notification) {
this.transport.start();
}

private Mono<McpSchema.JSONRPCResponse> handleIncomingRequest(McpSchema.JSONRPCRequest request) {
return Mono.defer(() -> {
var handler = requestHandlers.get(request.method());
if (handler == null) {
return Mono.just(new McpSchema.JSONRPCResponse(McpSchema.JSONRPC_VERSION, request.id(), null,
new McpSchema.JSONRPCResponse.JSONRPCError(McpSchema.ErrorCodes.METHOD_NOT_FOUND,
"Method not found: " + request.method(), null)));
}

return handler.handle(request.params())
.map(result -> new McpSchema.JSONRPCResponse(McpSchema.JSONRPC_VERSION, request.id(), result, null))
.onErrorResume(error -> Mono.just(new McpSchema.JSONRPCResponse(McpSchema.JSONRPC_VERSION, request.id(),
null, new McpSchema.JSONRPCResponse.JSONRPCError(McpSchema.ErrorCodes.INTERNAL_ERROR,
error.getMessage(), null))));
});
}

public void registerRequestHandler(String method, RequestHandler handler) {
requestHandlers.put(method, handler);
}

@Override
public <T> Mono<T> sendRequest(String method, Object requestParams, TypeReference<T> typeRef) {
// TODO: UUID API is blocking. Consider non-blocking alternatives to generate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SseMcpAsyncClientTests extends AbstractMcpAsyncClientTests {

// Uses the https://github.com/tzolov/mcp-everything-server-docker-image
@SuppressWarnings("resource")
static GenericContainer<?> container = new GenericContainer<>("tzolov/mcp-everything-server:v1")
static GenericContainer<?> container = new GenericContainer<>("docker.io/tzolov/mcp-everything-server:v1")
.withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
.withExposedPorts(3001)
.waitingFor(Wait.forHttp("/").forStatusCode(404));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SseMcpSyncClientTests extends AbstractMcpSyncClientTests {

// Uses the https://github.com/tzolov/mcp-everything-server-docker-image
@SuppressWarnings("resource")
static GenericContainer<?> container = new GenericContainer<>("tzolov/mcp-everything-server:v1")
static GenericContainer<?> container = new GenericContainer<>("docker.io/tzolov/mcp-everything-server:v1")
.withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
.withExposedPorts(3001)
.waitingFor(Wait.forHttp("/").forStatusCode(404));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class SseServerTransportTests {
static String host = "http://localhost:3001";

@SuppressWarnings("resource")
static GenericContainer<?> container = new GenericContainer<>("tzolov/mcp-everything-server:v1")
static GenericContainer<?> container = new GenericContainer<>("docker.io/tzolov/mcp-everything-server:v1")
.withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
.withExposedPorts(3001)
.waitingFor(Wait.forHttp("/").forStatusCode(404));
Expand Down

0 comments on commit 0ebb38c

Please sign in to comment.