Skip to content

java mcp message endpoint error #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
a67793581 opened this issue Mar 26, 2025 · 6 comments
Open

java mcp message endpoint error #76

a67793581 opened this issue Mar 26, 2025 · 6 comments

Comments

@a67793581
Copy link
Contributor

Because the implementation of java mcp sdk does not handle the problem of messageEndpoint returning CompleteMessageEndpoint URI when splicing messageEndpoint and base URL, it simply splices, resulting in the phenomenon of http://localhost/mcphttp://localhost/mcp/message.

Here are the references:

https://github.com/modelcontextprotocol/java-sdk/releases/tag/v0.8.1

public Mono<Void> sendMessage(McpSchema.JSONRPCMessage message) {
    if (this.isClosing) {
        return Mono.empty();
    } else {
        try {
            if (!this.closeLatch.await(10L, TimeUnit.SECONDS)) {
                return Mono.error(new McpError("Failed to wait for the message endpoint"));
            }
        } catch (InterruptedException var5) {
            return Mono.error(new McpError("Failed to wait for the message endpoint"));
        }

        String endpoint = (String)this.messageEndpoint.get();
        if (endpoint == null) {
            return Mono.error(new McpError("No message endpoint available"));
        } else {
            try {
                String jsonText = this.objectMapper.writeValueAsString(message);
                HttpRequest request = HttpRequest.newBuilder().uri(URI.create(this.baseUri + endpoint)).header("Content-Type", "application/json").POST(BodyPublishers.ofString(jsonText)).build();
                return Mono.fromFuture(this.httpClient.sendAsync(request, BodyHandlers.discarding()).thenAccept((response) -> {
                    if (response.statusCode() != 200 && response.statusCode() != 201 && response.statusCode() != 202 && response.statusCode() != 206) {
                        logger.error("Error sending message: {}", response.statusCode());
                    }

                }));
            } catch (IOException var6) {
                return !this.isClosing ? Mono.error(new RuntimeException("Failed to serialize message", var6)) : Mono.empty();
            }
        }
    }
}
@a67793581
Copy link
Contributor Author

fix #75

@torkve
Copy link
Contributor

torkve commented Mar 27, 2025

Could you achieve the required behaviour by passing just an empty baseUrl? That way all the rendered URLs should be relative.

And I believe it should be fixed in Java SDK anyway.

@a67793581
Copy link
Contributor Author

Could you achieve the required behaviour by passing just an empty baseUrl? That way all the rendered URLs should be relative.

And I believe it should be fixed in Java SDK anyway.

I think giving choices is a better approach.

@a67793581
Copy link
Contributor Author

Java has not fixed this problem in 7 versions. We need to consider industry compatibility to ensure a wider audience, and I don't know how long it will take for the Java author to fix this problem.

@torkve
Copy link
Contributor

torkve commented Apr 2, 2025

Java has not fixed this problem in 7 versions.

I suppose it would be great for the cross-project references if you could link a relevant issue in Java SDK project.

@a67793581
Copy link
Contributor Author

OK, I'll go back and make a suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants