Skip to content

Connect StdioClientServer does not terminate when errors occurs. #107

@adamglin0

Description

@adamglin0

Describe the bug

When connecting to StdioClientServer, if an error occurs in the Process, the connect method never returns and there are no error logs.

To Reproduce

RUN THIS CODE

connectFileSystemServer()
private suspend fun connectFileSystemServer() {
    val client = Client(
        clientInfo = Implementation(name = "example", version = "1.0.0"),
    )

    val transport =
        defaultStdioTransport(ProcessBuilder("npx", "-y", "@modelcontextprotocol/server-filesystem", "/fold-is-not-exists/111").start())
    client.connect(transport)

    client.listTools()?.tools?.forEach { tool ->
        println(tool.toString())
    }
}

Expected behavior
Should return immediately when an error occurs and report the error.

If we run in bash

npx -y @modelcontextprotocol/server-filesystem /fold-is-not-exists/111
Error accessing directory /fold-is-not-exists/111: Error: ENOENT: no such file or directory, stat '/fold-is-not-exists/111'
    at async Object.stat (node:internal/fs/promises:1031:18)
    at async file:///Users/adamglin/.npm/_npx/a3241bba59c344f5/node_modules/@modelcontextprotocol/server-filesystem/dist/index.js:33:23
    at async Promise.all (index 0)
    at async file:///Users/adamglin/.npm/_npx/a3241bba59c344f5/node_modules/@modelcontextprotocol/server-filesystem/dist/index.js:31:1 {
  errno: -2,
  code: 'ENOENT',
  syscall: 'stat',
  path: '/fold-is-not-exists/111'
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions