diff --git a/crates/tinymcp-bus/src/errors/mod.rs b/crates/tinymcp-bus/src/errors/mod.rs index 97a2cb02..9c91f338 100644 --- a/crates/tinymcp-bus/src/errors/mod.rs +++ b/crates/tinymcp-bus/src/errors/mod.rs @@ -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. @@ -125,6 +129,7 @@ pub const ALL: &[&str] = &[ INVALID_ARGUMENTS, REGISTRY_TIMEOUT, RESOURCE_TOO_LARGE, + LAUNCH_FAILED, ]; #[cfg(test)] diff --git a/crates/tinymcp-bus/src/version/mod.rs b/crates/tinymcp-bus/src/version/mod.rs index 6ff4775d..90fd3640 100644 --- a/crates/tinymcp-bus/src/version/mod.rs +++ b/crates/tinymcp-bus/src/version/mod.rs @@ -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`. diff --git a/crates/tinymcp-bus/src/version/mod_tests.rs b/crates/tinymcp-bus/src/version/mod_tests.rs index ea4c5fdc..d0d51eca 100644 --- a/crates/tinymcp-bus/src/version/mod_tests.rs +++ b/crates/tinymcp-bus/src/version/mod_tests.rs @@ -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] diff --git a/crates/tinymcp/src/error/mod.rs b/crates/tinymcp/src/error/mod.rs index af92446e..d014000f 100644 --- a/crates/tinymcp/src/error/mod.rs +++ b/crates/tinymcp/src/error/mod.rs @@ -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 { @@ -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, diff --git a/crates/tinymcp/src/error/mod_tests.rs b/crates/tinymcp/src/error/mod_tests.rs index 32493343..cc7159ec 100644 --- a/crates/tinymcp/src/error/mod_tests.rs +++ b/crates/tinymcp/src/error/mod_tests.rs @@ -61,6 +61,10 @@ fn assorted_other_errors() -> Vec { 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(), }, diff --git a/crates/tinymcp/src/transport/stdio/mod.rs b/crates/tinymcp/src/transport/stdio/mod.rs index 9be12e6c..76909f13 100644 --- a/crates/tinymcp/src/transport/stdio/mod.rs +++ b/crates/tinymcp/src/transport/stdio/mod.rs @@ -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 @@ -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, diff --git a/crates/tinymcp/src/transport/stdio/mod_tests.rs b/crates/tinymcp/src/transport/stdio/mod_tests.rs index b06912e9..efab321d 100644 --- a/crates/tinymcp/src/transport/stdio/mod_tests.rs +++ b/crates/tinymcp/src/transport/stdio/mod_tests.rs @@ -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.