toolfoundation Design Notes¶
Overview¶
toolfoundation provides the canonical data types that all other ApertureStack components depend on. It contains two packages: model for tool definitions and adapter for format conversion.
model Package¶
Design Decisions¶
-
MCP SDK Embedding: The
Tooltype embedsmcp.Toolfrom the official MCP Go SDK rather than reimplementing the fields. This ensures 1:1 spec compatibility while allowing extension. -
Namespace + Name (+ Version) = ID: Tool IDs are
namespace:name:versionwhen version is set (otherwisenamespace:name), providing stable identifiers across registry operations. -
Backend Abstraction:
ToolBackendsupports three kinds: local: In-process handler functionprovider: External tool provider-
mcp: Remote MCP server -
Tag Normalization: Tags are normalized (lowercase, trimmed, deduped) to ensure consistent search behavior.
Error Handling¶
Validate()returns descriptive errors for invalid tools- Schema validation uses JSON Schema draft 2020-12
- Empty names, invalid characters, and missing schemas are rejected
Schema Validation Policy¶
The default validator supports the following dialects:
- JSON Schema 2020-12 (default)
- JSON Schema draft-07
External $ref resolution is disabled to prevent network access during validation. Validation behavior is deterministic and does not perform I/O.
Limitations (from the underlying jsonschema-go implementation):
formatis treated as annotation (not validated)contentEncodingandcontentMediaTypeare not validated
adapter Package¶
Design Decisions¶
-
Canonical Intermediate: All conversions go through
CanonicalTool, a protocol-agnostic intermediate representation. -
Pure Transforms: Conversions have no I/O or side effects. Same input always produces same output.
-
Feature Loss Warnings: When the target format doesn't support a feature (e.g.,
$refin OpenAI), warnings are returned instead of errors. -
Minimal Dependencies: The MCP adapter depends on the MCP SDK. OpenAI and Anthropic adapters use self-contained types.
Supported Formats¶
| Format | Adapter | Notes |
|---|---|---|
| MCP | MCPAdapter | Full spec support |
| OpenAI | OpenAIAdapter | Strict mode support |
| Anthropic | AnthropicAdapter | Full spec support |
Feature Compatibility¶
| Feature | MCP | OpenAI | Anthropic |
|---|---|---|---|
$ref/$defs | Yes | No | No |
anyOf/oneOf | Yes | No | Yes |
pattern | Yes | Yes* | Yes |
enum/const | Yes | Yes | Yes |
*OpenAI supports pattern only in strict mode.
Feature Loss Warnings¶
Adapters emit FeatureLossWarning entries when the target format does not support a schema feature used by the source. Conversions still succeed, but consumers should review warnings before exposing the converted tool to users.
Dependencies¶
github.com/modelcontextprotocol/go-sdk/mcp- MCP type definitionsgithub.com/santhosh-tekuri/jsonschema- Schema validation (optional)