Skip to main content
Glama

scaffold_producer

Generate MCP tool definitions by analyzing how client code calls them, creating producer schema stubs from consumer usage patterns.

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 implements the scaffold_producer tool logic: infers Zod schema from consumer arguments and generates MCP server.tool() code stub, optionally with a handler.
    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 'scaffold_producer' tool call: validates input, traces consumer usage, invokes core scaffoldProducerFromConsumer, and formats 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 for validating arguments to the scaffold_producer tool.
    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 registration metadata (name, description, inputSchema) returned by listTools request.
    {
      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'],
      },
    },
  • Re-export of scaffoldProducerFromConsumer function, imported into main index.ts for tool handler.
      scaffoldConsumerFromProducer,
      scaffoldProducerFromConsumer,
      type ScaffoldOptions,
      type ScaffoldResult,
    } from './scaffold.js';
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses the tool's generative behavior ('Creates MCP tool definition'), but doesn't specify output format, error handling, or side effects like file system changes, leaving gaps for a mutation tool.

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

Conciseness5/5

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

Two concise sentences front-load the core purpose and action, with zero wasted words. The structure efficiently communicates the tool's function without redundancy or unnecessary elaboration.

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

Completeness3/5

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

For a 3-parameter mutation tool with no annotations or output schema, the description is minimally adequate but incomplete. It covers the what and how at a high level but lacks details on behavioral traits, output expectations, or integration with sibling tools.

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 parameters are well-documented in the schema. The description adds no additional parameter semantics beyond implying that consumerDir and toolName relate to analyzing client code, which is already suggested by the schema descriptions.

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

Purpose5/5

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

The description clearly states the specific action ('Generate producer schema stub from consumer usage') and the resource ('MCP tool definition'), distinguishing it from siblings like scaffold_consumer by focusing on producer-side generation based on client code analysis.

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

Usage Guidelines3/5

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

The description implies usage when needing to create a tool definition from existing consumer code, but lacks explicit guidance on when to use this versus alternatives like scaffold_consumer or init_project, and doesn't mention prerequisites or exclusions.

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/trace-mcp'

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