Skip to content

client: transport start failed will make listTools stuck #72

Open
@phodal

Description

@phodal

Describe the bug

Hi, according to README, I create follow code. When connect to a high version for MCP Java SDK (0.8.0), will stuck in connect, not run to listTools

val tools = try {
    client.connect(transport)
    val listTools = client.listTools()
    listTools?.tools?.forEach { tool ->
        toolClientMap[tool] = client
    }
    listTools?.tools ?: emptyList()
} catch (e: Exception) {
    logger<CustomMcpServerManager>().warn("Failed to list tools from ${entry.key}: $e")
    emptyList<Tool>()
}

To Reproduce
Steps to reproduce the behavior:

  1. create a Java server: https://github.com/unit-mesh/autodev-mcp-test/tree/master/java-mcp
  2. use Kotlin to connect Java server

Expected behavior

Should compatibility with Other language SDK, it not should throw issue in start or listTools

Logs

My case should be the different Schema between Java and Kotlin version. So when the server use latest version, will not correct identify params._meta and params.method from Kotlin version.

Image

Here is the log

{"jsonrpc":"2.0","id":4,"result":{"protocolVersion":"2024-11-05","capabilities":{"logging":{},"tools":{"listChanged":true}},"serverInfo":{"name":"mcp-server","version":"1.0.0"}}}
{"id":4,"method":"list/tool","params":{"protocolVersion":"2024-11-05","capabilities":{"experimental":{},"sampling":{}},"clientInfo":{"name":"weather","version":"1.0.0"},"_meta":{},"method":"initialize"},"jsonrpc":"2.0"}
{"jsonrpc":"2.0","id":4,"error":{"code":-32601,"message":"Method not found: list/tool"}}
{"id":4,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{"experimental":{},"sampling":{}},"clientInfo":{"name":"weather","version":"1.0.0"},"_meta":{},"method":"initialize"},"jsonrpc":"2.0"}
{"jsonrpc":"2.0","id":4,"error":{"code":-32603,"message":"Unrecognized field \"_meta\" (class io.modelcontextprotocol.spec.McpSchema$InitializeRequest), not marked as ignorable (3 known properties: \"protocolVersion\", \"clientInfo\", \"capabilities\"])\n at [Source: UNKNOWN; byte offset: #UNKNOWN] (through reference chain: io.modelcontextprotocol.spec.McpSchema$InitializeRequest[\"_meta\"])"}}

Additional context

Here maybe some info related to issue, first the e was now trowable

if (isActive) {
_onError.invoke(e)
logger.error(e) { "Error writing to output stream" }

secondly, the transport will be null in here,

withTimeout(timeout) {
LOGGER.trace { "Sending request message with id: $messageId" }
this@Protocol.transport?.send(message)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions