Skip to main content

Module tools

Module tools 

Source
Expand description

[[tools]] → ToolInfo + Arc<dyn ToolHandler> synthesizer.

Net-new code for Phase 83 TKIT-07. Turns curated [[tools]] config entries into complete pmcp ToolInfo + Arc<dyn ToolHandler> pairs with zero per-tool Rust handlers.

§Invariants enforced

  • JSON Schema object envelope, CHECKED HERE. Every synthesized ToolInfo carries an input_schema with "type": "object", an explicit properties map, a required array, and "additionalProperties": false (true only when [server.validation] additional_properties opts out). Unknown argument keys are refused by pmcp::server::schema_validation::validate_input, called from the ValidatingToolHandler decorator that enforce_input_schema wraps around every handler this module pushes — in the toolkit, before the backend call. Threat T-83-05-02.

    Both halves matter, and stating only the first is what made this comment a defect for two phases. Core pmcp’s tools/call dispatch does not validate request arguments against a tool’s declared inputSchema; that wiring is deliberately deferred (Phase 128 D-01), so a comment locating the enforcement “upstream” described a mitigation that did not exist. It exists now, and it exists here.

    Condition: the input-validation feature must be on. It is on via this crate’s default feature set and by that route ALONE — measured: http = ["dep:reqwest", "dep:url", "dep:openapiv3", "dep:serde_yaml", "dep:base64", "dep:regex", "dep:tokio", "pmcp/streamable-http"] and openapi-code-mode = ["http", "code-mode", "pmcp-code-mode/js-runtime"], neither of which names it. Those two umbrellas do NOT forward it, so a --no-default-features --features http build — exactly the shape a consumer reaches for — turns it off, and then enforce_input_schema is the identity function and says so in a tracing::warn!. Second condition: [server.validation] enforce_input_schema must not be false.

    Backed by tests/input_validation_acceptance.rs’s input_validation_refuses_undeclared_argument_without_contacting_upstream (row 10) and input_validation_refuses_absent_arguments_when_required_declared (row 9), each of which fails if the validate_input call is removed, plus input_validation_accepts_compliant_call_with_one_upstream_request (row 11) as the passing control that catches an over-refusing decorator.

  • handler.metadata() returns Some(ToolInfo). Phase 82’s tool_arc consumes handler.metadata() at registration; returning None would silently degrade the schema enforcement to “anything goes” (RESEARCH §Risks #2 — threat T-83-05-01).

  • Constructors, never struct-literals. Both ToolInfo and ToolAnnotations are #[non_exhaustive] (PATTERNS §Pattern C). The synthesizer uses ToolInfo::with_annotations / ToolInfo::new and the ToolAnnotations::new()-then-.with_* fluent builder.

  • Cognitive complexity ≤25 per function. Decomposed into [build_input_schema], [build_param_property], and [build_annotations] per Phase 75 D-03 + PATTERNS §Pattern G. No #[allow] annotations.

Functions§

synthesize_from_config
Synthesize one ToolInfo + handler per [[tools]] config entry.
synthesize_from_config_and_hooks
synthesize_from_config with registered E2 hooks (Phase 128).
synthesize_from_config_with_connector
Synthesize tools that execute against a wired SqlConnector (Phase 84 CONN-01 / D-06). ADDITIVE variant alongside synthesize_from_config — the existing API is unchanged and all P83 callers compile without modification.
synthesize_from_config_with_connector_and_hooks
synthesize_from_config_with_connector with registered E2 hooks (Phase 128).
synthesize_from_config_with_http_connector
Synthesize one ToolInfo + handler per single-call [[tools]] entry, executing against a wired HttpConnector (Phase 90 OAPI-02a / D-01).
synthesize_from_config_with_http_connector_and_hooks
synthesize_from_config_with_http_connector with registered E2 hooks (Phase 128).
synthesize_from_config_with_http_connector_and_scripts
Synthesize single-call AND script [[tools]] against a wired HttpConnector plus a shared HttpCodeExecutor + ExecutionConfig (Phase 90 OAPI-02b / D-01 / D-02).
synthesize_from_config_with_http_connector_and_scripts_and_hooks
synthesize_from_config_with_http_connector_and_scripts with registered E2 hooks (Phase 128).

Type Aliases§

SynthesizedTool
Type alias for one synthesized tool tuple: (name, ToolInfo, Arc<dyn ToolHandler>).