Principle:8beeeaaat Touchdesigner mcp Schema Introspection For Tool Manifest
| Knowledge Sources | |
|---|---|
| Domains | Schema_Introspection, Tool_Manifest |
| Last Updated | 2026-10-28 00:00 GMT |
Overview
Deriving a tool manifest (parameter names, types, required flags) by runtime-introspecting the Zod object schema each tool registers, rather than maintaining a parallel hand-written metadata table.
Description
When MCP tools are defined with Zod input schemas, a separate hand-written manifest describing those parameters will inevitably drift from the schema. The schema introspection principle walks the live Zod object's shape at build time, peels optional/default/prefault/nullish/nullable wrappers to determine whether each field is required, and renders the base Zod type as a TypeScript-flavored type string (string, number, boolean, Array<...>, Record<...>, enum unions). Because the Zod schemas are themselves generated from the OpenAPI spec via Orval, the manifest is three steps removed from hand-editing — changing the spec regenerates schemas, which regenerate the manifest automatically.
Usage
Use this principle when you need to expose a self-describing tool list (e.g. describe_td_tools) to AI agents and want the parameter metadata to be a deterministic projection of the runtime schema with zero maintenance overhead.
Theoretical Basis
// Abstract algorithm (NOT real implementation)
function deriveParameters(schema: ZodObject): ParameterMetadata[] {
return Object.entries(schema.shape).map(([name, field]) => {
const { base, required, description } = unwrap(field);
return { name, type: renderType(base), required, description };
});
}
function unwrap(field) {
let node = field, required = true;
while (node.def) {
if (["optional","default","prefault","nullish"].includes(node.def.type))
required = false;
if (["optional","default","prefault","nullable","nullish"].includes(node.def.type))
{ node = node.def.innerType; continue; }
break;
}
return { base: node, required };
}
Key properties:
- Wrapper peeling: walks the Zod wrapper chain to the base type.
- Type rendering: maps Zod def types to readable TS-flavored strings.
- Single source of truth: the manifest is a pure function of the Zod schema.