Thanks to visit codestin.com
Credit goes to github.com

Skip to content

java mcp message endpoint error #103

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 Apr 2, 2025 · 3 comments
Open

java mcp message endpoint error #103

a67793581 opened this issue Apr 2, 2025 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@a67793581
Copy link

Expected Behavior

The implementation should properly handle cases where messageEndpoint already contains a protocol and host to avoid incorrect concatenation.

Current Behavior

Currently, the Java MCP SDK does not correctly handle messageEndpoint. Instead of properly resolving the full URL, it simply concatenates messageEndpoint with the base URL as a raw string. This results in malformed URLs, such as: http://localhost/mcphttp://localhost/mcp/message

Context
mark3labs/mcp-go#76 (comment)
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 a67793581 changed the title Expected Behavior java mcp message endpoint error Apr 2, 2025
@tzolov tzolov self-assigned this Apr 11, 2025
@tzolov tzolov added the enhancement New feature or request label Apr 11, 2025
@jpfortier
Copy link

Hi, do you know if there is a workaround? Is this due to a misconfiguration on my part? (seeing this error on a call that worked yesterday)

ashakirin pushed a commit to ashakirin/java-sdk that referenced this issue Apr 13, 2025
@a67793581
Copy link
Author

Hi, do you know if there is a workaround? Is this due to a misconfiguration on my part? (seeing this error on a call that worked yesterday)
Because the official Java MCP SDK does not open related options, we can only ensure that all other language MCP SDKs are configured to be compatible with the Java MCP SDK.

@Mukamik
Copy link

Mukamik commented May 9, 2025

I wonder if the InterruptedException is overly broad. Is it possible that a simple misconfiguration (like a port conflict) could be caught by this exception?

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

No branches or pull requests

4 participants