Files
craft-libs/crates/mcp-server/src/lib.rs
T
Martin BallandClaude Sonnet 5.5 3e82d1719c craft-mcp-server: options for apps that report argument errors as tool results (#2061)
* craft-mcp-server: options for apps that report argument errors as tool results (#778)

Add `Options` (default = today's behaviour) and `Server::with_options`:

- `website_url`: sent as `serverInfo.websiteUrl` at `initialize`.
- `tool_errors_as_results`: a `tools/call` whose arguments fail the schema check, or whose tool
  is unknown, returns a tool result with `isError: true` and the message as text, not -32602.
- `strict_request_ids`: a request id that is not a string or number gets -32600 with a null id.

`Info` is unchanged, so existing struct-literal callers still compile. Tests cover each option on
and off, and hostile input with all options on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* craft-mcp-server: strict request ids also apply to the missing-method error (#778)

With strict_request_ids, a message without `method` echoed an object, array or
bool id in its -32600 reply. It now answers with a null id for any id that is
not a string or number, as the later strict check does. Valid ids, absent ids
and incoming responses behave as before.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 14:45:52 -05:00

22 lines
1.1 KiB
Rust

//! MCP server machinery any app may share: JSON-RPC 2.0 over stdio (newline-delimited), the MCP
//! lifecycle, the tools, resources, prompts and completion methods, tool schemas with the check of
//! a call's arguments against them, and the content blocks tools reply with (text, images).
//!
//! An app implements [`Tools`]: what its tools are, how each one runs, its instructions, and the
//! resources, resource templates and prompts it serves, if any. [`Server`] speaks the protocol
//! around them and tells a client at `initialize` only what the app serves. Nothing here knows any
//! app's design, engine or renderer.
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]
#![forbid(unsafe_code)]
mod content;
mod schema;
mod server;
pub use content::{Contents, base64, image_result, text_result};
pub use schema::{Effect, check_arguments, object, string, tool};
pub use server::{Incoming, Info, Options, PROTOCOL_VERSION, Reference, SUPPORTED_VERSIONS, Server, Tools, read_message, response};
#[cfg(test)]
mod tests;