Skip to main content
Glama

scaffold_producer

Generate MCP tool producer schemas from consumer code usage. Creates tool definitions based on how client applications call the tool.

Instructions

Generate producer schema stub from consumer usage. Creates MCP tool definition based on how client code calls it.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
consumerDirYesPath to consumer source directory
toolNameYesName of the tool to scaffold producer for
includeHandlerNoInclude handler stub

Implementation Reference

  • Core handler function that generates a producer schema stub from traced consumer usage, inferring input schema and providing a handler template.
    export function scaffoldProducerFromConsumer(
      consumer: ConsumerSchema,
      options: { includeHandler?: boolean } = {}
    ): ScaffoldResult {
      const { includeHandler = true } = options;
      const toolName = consumer.toolName;
      const args = consumer.argumentsProvided;
      
      // Infer types from argument values (basic inference)
      const inferredSchema = inferSchemaFromArgs(args);
      
      const code = `
    import { z } from 'zod';
    
    // Tool: ${toolName}
    // Scaffolded from consumer at ${consumer.callSite.file}:${consumer.callSite.line}
    // @trace-contract PRODUCER (scaffolded)
    
    server.tool(
      '${toolName}',
      'TODO: Add description',
      {
    ${Object.entries(inferredSchema)
      .map(([key, type]) => `    ${key}: ${type},`)
      .join('\n')}
      },
    ${includeHandler ? `  async (args) => {
        // TODO: Implement handler
        // Consumer expects these properties: ${consumer.expectedProperties.join(', ')}
        return {
          content: [{
            type: 'text',
            text: JSON.stringify({
    ${consumer.expectedProperties.map(p => `          ${p}: null, // TODO`).join('\n')}
            })
          }]
        };
      }` : '  async (args) => { /* TODO */ }'}
    );
    `.trim();
    
      return {
        code,
        suggestedFilename: `${toKebabCase(toolName)}-tool.ts`,
        example: `// This tool is called by:\n// ${consumer.callSite.file}:${consumer.callSite.line}`,
      };
    }
  • MCP server dispatch handler for the scaffold_producer tool: validates input, traces consumer usages, finds the matching consumer, calls the core scaffold function, and formats the response.
    case 'scaffold_producer': {
      const input = ScaffoldProducerInput.parse(args);
      log(`Scaffolding producer for tool: ${input.toolName}`);
      
      // Trace consumer usage to find the requested tool
      const consumers = await traceConsumerUsage({ rootDir: input.consumerDir });
      const consumer = consumers.find(c => c.toolName === input.toolName);
      
      if (!consumer) {
        throw new Error(`Tool "${input.toolName}" not found in consumer code at ${input.consumerDir}`);
      }
      
      const result = scaffoldProducerFromConsumer(consumer, {
        includeHandler: input.includeHandler ?? true,
      });
      
      log(`Generated producer schema stub`);
      
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify({
              success: true,
              toolName: input.toolName,
              suggestedFilename: result.suggestedFilename,
              code: result.code,
              example: result.example,
            }, null, 2),
          },
        ],
      };
    }
  • Zod input schema validation for the scaffold_producer tool arguments.
    const ScaffoldProducerInput = z.object({
      consumerDir: z.string().describe('Path to consumer source directory'),
      toolName: z.string().describe('Name of the tool to scaffold producer for'),
      includeHandler: z.boolean().optional().describe('Include handler stub (default: true)'),
    });
  • src/index.ts:208-220 (registration)
    Tool metadata registration in the listTools response, including name, description, and JSON schema for input validation.
    {
      name: 'scaffold_producer',
      description: 'Generate producer schema stub from consumer usage. Creates MCP tool definition based on how client code calls it.',
      inputSchema: {
        type: 'object',
        properties: {
          consumerDir: { type: 'string', description: 'Path to consumer source directory' },
          toolName: { type: 'string', description: 'Name of the tool to scaffold producer for' },
          includeHandler: { type: 'boolean', description: 'Include handler stub' },
        },
        required: ['consumerDir', 'toolName'],
      },
    },
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool generates/creates something, implying a write operation, but doesn't clarify if this is destructive (e.g., overwrites files), requires specific permissions, or has side effects like file creation. It also omits details on output format, error handling, or rate limits, leaving significant gaps for a tool that likely modifies project structure.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise with two sentences that directly state the tool's function. It's front-loaded with the core purpose and avoids unnecessary details. However, it could be slightly more structured by explicitly separating the action from the source, but overall it's efficient with minimal waste.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of generating code stubs and the lack of annotations and output schema, the description is incomplete. It doesn't explain what the output looks like (e.g., file paths, format), potential errors, or how it integrates with the project context hinted by sibling tools. For a tool that likely creates or modifies files, more behavioral and output details are needed to guide effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the input schema already documents all three parameters (consumerDir, toolName, includeHandler) with descriptions. The description adds no additional meaning beyond what the schema provides, such as explaining relationships between parameters or usage examples. With high schema coverage, the baseline score of 3 is appropriate as the description doesn't compensate but also doesn't detract.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Generate producer schema stub from consumer usage' and 'Creates MCP tool definition based on how client code calls it.' This specifies both the verb (generate/create) and resource (producer schema stub/MCP tool definition) with the source (consumer usage/client code calls). However, it doesn't explicitly differentiate from sibling tools like scaffold_consumer, which appears related but has a different direction (consumer vs producer).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing existing consumer code), exclusions, or compare it to sibling tools such as scaffold_consumer or extract_schemas. The context is implied through the action but lacks explicit usage instructions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Mnehmos/mnehmos.trace.mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server