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. Every synthesized ToolInfo carries an input_schema with "type": "object", an explicit properties map, a required array, and "additionalProperties": false. Unknown argument keys are rejected by pmcp’s request-validation path at tools/call time — defence-in-depth against arg-injection (threat T-83-05-02).
  • 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_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_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_scripts
Synthesize single-call AND script [[tools]] against a wired HttpConnector plus a shared HttpCodeExecutor + ExecutionConfig (Phase 90 OAPI-02b / D-01 / D-02).

Type Aliases§

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