Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions crates/tinymcp-bus/src/errors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ pub const ENDPOINT_RESOLUTION: &str = "ai.tinyhumans.tinymcp.Error.EndpointResol
/// A server negotiated a protocol version the client does not speak.
pub const UNSUPPORTED_PROTOCOL_VERSION: &str =
"ai.tinyhumans.tinymcp.Error.UnsupportedProtocolVersion";
/// A stdio server's launcher was found but its process could not be started
/// (an unrunnable script on Windows, a permission error, a jail that refused
/// it). Added in contract 1.32; before it, these were `MALFORMED_RESPONSE`.
pub const LAUNCH_FAILED: &str = "ai.tinyhumans.tinymcp.Error.LaunchFailed";
/// A response was not the shape the protocol requires.
pub const MALFORMED_RESPONSE: &str = "ai.tinyhumans.tinymcp.Error.MalformedResponse";
/// A server returned a JSON-RPC error object.
Expand Down Expand Up @@ -125,6 +129,7 @@ pub const ALL: &[&str] = &[
INVALID_ARGUMENTS,
REGISTRY_TIMEOUT,
RESOURCE_TOO_LARGE,
LAUNCH_FAILED,
];

#[cfg(test)]
Expand Down
4 changes: 3 additions & 1 deletion crates/tinymcp-bus/src/version/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
/// and public unless the operator declared that server local.
/// 1.31 adds `McpRegistryAuthConfig::curated_servers` (`CuratedServerEntry`):
/// host-supplied curated servers, never badged official.
pub const CONTRACT_VERSION: (u32, u32) = (1, 31);
/// 1.32 adds the `LaunchFailed` error name: a stdio server whose process could
/// not be started, previously reported as `MalformedResponse`.
pub const CONTRACT_VERSION: (u32, u32) = (1, 32);

/// Returns whether a host holding [`CONTRACT_VERSION`] can bind to a module
/// reporting `module`.
Expand Down
2 changes: 1 addition & 1 deletion crates/tinymcp-bus/src/version/mod_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::{CONTRACT_VERSION, binds, is_compatible};

#[test]
fn the_shipped_contract_version_is_pinned() {
assert_eq!(CONTRACT_VERSION, (1, 31));
assert_eq!(CONTRACT_VERSION, (1, 32));
}

#[test]
Expand Down
14 changes: 14 additions & 0 deletions crates/tinymcp/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,19 @@ pub enum Error {
version: String,
},

/// A stdio server's process could not be started: the launcher exists but
/// the operating system or the jail refused to run it (Windows os error
/// 193 for a script without a runnable extension, a permission error, a
/// sandbox that cannot host it). Not a protocol failure, and nothing was
/// said to or by the server.
#[error("launching `{command}` failed: {detail}")]
LaunchFailed {
/// The configured command.
command: String,
/// Why the launch was refused.
detail: String,
},

/// A response was not the shape the protocol requires.
#[error("malformed mcp response: {detail}")]
MalformedResponse {
Expand Down Expand Up @@ -451,6 +464,7 @@ impl Error {
Self::EndpointResolution { .. } => errors::ENDPOINT_RESOLUTION,
Self::RegistryTimeout { .. } => errors::REGISTRY_TIMEOUT,
Self::UnsupportedProtocolVersion { .. } => errors::UNSUPPORTED_PROTOCOL_VERSION,
Self::LaunchFailed { .. } => errors::LAUNCH_FAILED,
Self::MalformedResponse { .. } => errors::MALFORMED_RESPONSE,
Self::Rpc { .. } => errors::RPC,
Self::MissingAuthChallenge => errors::MISSING_AUTH_CHALLENGE,
Expand Down
4 changes: 4 additions & 0 deletions crates/tinymcp/src/error/mod_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ fn assorted_other_errors() -> Vec<Error> {
action: "writing credentials".into(),
detail: "the vault is sealed".into(),
},
Error::LaunchFailed {
command: "npx".into(),
detail: "%1 is not a valid Win32 application. (os error 193)".into(),
},
Error::MalformedResponse {
detail: "no result member".into(),
},
Expand Down
22 changes: 14 additions & 8 deletions crates/tinymcp/src/transport/stdio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,12 @@ impl McpStdioClient {
///
/// # Errors
///
/// Returns [`Error::MalformedResponse`] when the command cannot be found on
/// the resolved path, when the child cannot be spawned, or when the reply
/// is not the shape the protocol requires; and
/// [`Error::UnsupportedProtocolVersion`] when the server settles on a
/// version this client does not speak.
/// Returns [`Error::MissingRuntime`] when the command cannot be found on
/// the resolved path; [`Error::LaunchFailed`] when it is found but the
/// child cannot be started (or the jail refuses it);
/// [`Error::MalformedResponse`] when the reply is not the shape the
/// protocol requires; and [`Error::UnsupportedProtocolVersion`] when the
/// server settles on a version this client does not speak.
///
/// Boxed at the method boundary so the async body is compiled once, inside
/// this crate, rather than re-instantiated by every downstream crate or
Expand Down Expand Up @@ -336,9 +337,14 @@ impl McpStdioClient {
env,
cwd: self.cwd.clone(),
};
let process = self.spawner.spawn_process(launch).await.map_err(|error| {
Error::malformed(format!("spawning `{}` failed: {error}", self.command))
})?;
let process =
self.spawner
.spawn_process(launch)
.await
.map_err(|error| Error::LaunchFailed {
command: self.command.clone(),
detail: error.to_string(),
})?;

let mut session = StdioSession {
handle: process.handle,
Expand Down
15 changes: 15 additions & 0 deletions crates/tinymcp/src/transport/stdio/mod_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,21 @@ mod against_a_fake_server {
assert!(format!("{error}").contains("jail refused"), "{error:?}");
}

#[tokio::test]
async fn a_process_that_cannot_be_started_is_a_launch_failure_not_a_bad_response() {
// Windows' os error 193 and a jail's refusal both arrive here; the
// server never ran, so nothing it said can have been malformed.
let client = client_for(responder(&[&initialize_reply()])).with_spawner(Arc::new(Refusing));

let error = client.initialize().await.expect_err("a refused launch");

assert!(
matches!(&error, Error::LaunchFailed { detail, .. } if detail.contains("jail refused")),
"{error:?}"
);
assert_eq!(error.wire_name(), tinymcp_bus::errors::LAUNCH_FAILED);
}

#[tokio::test]
async fn a_server_negotiating_an_unknown_version_fails_the_handshake() {
// The HTTP transport always checked this; the subprocess one did not.
Expand Down
Loading