Skip to content

get_diagnostics can abort stdio server for file paths containing URI-reserved chars #150

@dergachoff

Description

@dergachoff

Summary

get_diagnostics can abort the mcpls stdio server when the target file path contains URI-reserved characters such as [ and ].

This happens with common framework route filenames like:

routes/api/[...].ts

The client then sees the MCP transport close instead of receiving an error response.

Reproduction

Call get_diagnostics for an existing file whose path contains brackets, for example:

/tmp/project/routes/api/[...].ts

Using an MCP stdio probe against mcpls, the process aborts before returning a tool response.

Observed behavior

mcpls panics while converting the filesystem path to an LSP URI:

thread 'tokio-rt-worker' panicked at crates/mcpls-core/src/bridge/state.rs:
failed to create URI from path: ParseError { ... kind: UnexpectedChar }

From the MCP client side this appears as a closed stdio transport.

Expected behavior

mcpls should create a valid percent-encoded LSP file:// URI, return diagnostics normally, or return a structured tool error without aborting the server.

Suspected root cause

path_to_uri formats file URIs directly as file://{path}. That leaves URI-reserved path characters raw. lsp_types::Uri::from_str rejects the raw brackets, and the following expect panics.

Local validation

A local patch that builds the file URL with Url::from_file_path, percent-encodes the remaining RFC3986-invalid path characters, and adds bracketed-path round-trip coverage fixes the crash.

Validated locally with:

cargo +nightly fmt --check
cargo +1.95 test -p mcpls-core path_to_uri
cargo +1.95 test -p mcpls-core
cargo +1.95 clippy -p mcpls-core --all-targets --all-features -- -D warnings

A post-fix MCP stdio probe against the same bracketed path returned a normal get_diagnostics response instead of aborting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions