Expand description
MCP tools from an OpenAPI 3.x document (18.19.0, #66): each operation
becomes a tool whose input schema holds its path, query and header
parameters and its JSON body, and OpenApiTool::request turns a
call’s arguments back into the HTTP request.
use rust_web_server::mcp::openapi_tools::{tools, ToolOptions};
let spec = r#"{"openapi":"3.1.0","info":{"title":"Billing","version":"1"},
"paths":{"/invoices/{id}":{"get":{"operationId":"getInvoice","summary":"Get an invoice",
"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer"}}]}}}}"#;
let found = tools(spec, &ToolOptions::default()).unwrap();
assert_eq!("getInvoice", found[0].name);
let call = found[0].request(r#"{"id": 42}"#).unwrap();
assert_eq!(("GET", "/invoices/42"), (call.method.as_str(), call.path_and_query.as_str()));Local $refs (#/components/...) are inlined, a cycle or more than
MAX_REF_DEPTH levels becomes {}; remote refs are refused. Only
GET operations become tools unless ToolOptions::include names
others: writes are an explicit choice.
Structs§
- Open
ApiTool - One operation as an MCP tool.
- Tool
Options - Which operations become tools, and how they’re named.
- Tool
Request - The HTTP request for one call.
Enums§
- Location
- Where a parameter goes.
Constants§
- MAX_
REF_ DEPTH $refs nested deeper than this become{}.- MAX_
SCHEMA_ DEPTH - Inlined schemas nest at most this deep and hold at most this many
values; past either the rest becomes
{}(a document whose refs fan out would otherwise grow exponentially). - MAX_
SCHEMA_ NODES - MAX_
SPEC_ BYTES - Documents larger than this are refused.
Functions§
- tools
- Every operation of
spec(OpenAPI 3.0 or 3.1, JSON) as a tool.