Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:8beeeaaat Touchdesigner mcp Schema Introspection For Tool Manifest

From Leeroopedia
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.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment