Skip to main content
Glama

scaffold_consumer

Generate consumer code from producer schemas to create TypeScript functions, React hooks, or Zustand actions that correctly call MCP tools, preventing runtime errors by validating contracts during development.

Instructions

Generate consumer code from a producer schema. Creates TypeScript functions, React hooks, or Zustand actions that correctly call MCP tools.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
producerDirYesPath to MCP server source directory
toolNameYesName of the tool to scaffold consumer for
targetNoOutput target format
includeErrorHandlingNoInclude try/catch error handling
includeTypesNoInclude TypeScript type definitions

Implementation Reference

  • Zod schema defining the input parameters for the scaffold_consumer tool, used for validation.
    const ScaffoldConsumerInput = z.object({
      producerDir: z.string().describe('Path to MCP server source directory'),
      toolName: z.string().describe('Name of the tool to scaffold consumer for'),
      target: z.enum(['typescript', 'javascript', 'react-hook', 'zustand-action']).optional().describe('Output target format (default: typescript)'),
      includeErrorHandling: z.boolean().optional().describe('Include try/catch error handling (default: true)'),
      includeTypes: z.boolean().optional().describe('Include TypeScript type definitions (default: true)'),
    });
  • src/index.ts:194-207 (registration)
    Tool registration in the list of available tools returned by ListToolsRequestHandler, including name, description, and inputSchema.
      name: 'scaffold_consumer',
      description: 'Generate consumer code from a producer schema. Creates TypeScript functions, React hooks, or Zustand actions that correctly call MCP tools.',
      inputSchema: {
        type: 'object',
        properties: {
          producerDir: { type: 'string', description: 'Path to MCP server source directory' },
          toolName: { type: 'string', description: 'Name of the tool to scaffold consumer for' },
          target: { type: 'string', enum: ['typescript', 'javascript', 'react-hook', 'zustand-action'], description: 'Output target format' },
          includeErrorHandling: { type: 'boolean', description: 'Include try/catch error handling' },
          includeTypes: { type: 'boolean', description: 'Include TypeScript type definitions' },
        },
        required: ['producerDir', 'toolName'],
      },
    },
  • Main handler for the scaffold_consumer tool call, which extracts the producer schema, invokes the scaffolding function, and formats the response.
    case 'scaffold_consumer': {
      const input = ScaffoldConsumerInput.parse(args);
      log(`Scaffolding consumer for tool: ${input.toolName}`);
      
      // Extract producer schemas to find the requested tool
      const producers = await extractProducerSchemas({ rootDir: input.producerDir });
      const producer = producers.find(p => p.toolName === input.toolName);
      
      if (!producer) {
        throw new Error(`Tool "${input.toolName}" not found in ${input.producerDir}`);
      }
      
      const result = scaffoldConsumerFromProducer(producer, {
        target: input.target || 'typescript',
        includeErrorHandling: input.includeErrorHandling ?? true,
        includeTypes: input.includeTypes ?? true,
        includeJSDoc: true,
      });
      
      log(`Generated ${input.target || 'typescript'} consumer code`);
      
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify({
              success: true,
              toolName: input.toolName,
              target: input.target || 'typescript',
              suggestedFilename: result.suggestedFilename,
              code: result.code,
              types: result.types,
              example: result.example,
            }, null, 2),
          },
        ],
      };
    }
  • Core helper function that generates consumer code (TypeScript/JS/React/Zustand) from a producer schema based on the specified target.
    export function scaffoldConsumerFromProducer(
      producer: ProducerSchema,
      options: ScaffoldOptions = { target: 'typescript' }
    ): ScaffoldResult {
      const { target, includeErrorHandling = true, includeTypes = true, functionPrefix = '', includeJSDoc = true } = options;
      
      const toolName = producer.toolName;
      const functionName = `${functionPrefix}${toCamelCase(toolName)}`;
      const inputProps = producer.inputSchema.properties || {};
      const requiredArgs = producer.inputSchema.required || [];
      
      // Generate TypeScript interface for args
      const argsInterface = generateArgsInterface(toolName, inputProps, requiredArgs);
      
      // Generate the function based on target
      let code: string;
      let types: string | undefined;
      let example: string;
      
      switch (target) {
        case 'react-hook':
          ({ code, types, example } = generateReactHook(toolName, functionName, inputProps, requiredArgs, { includeErrorHandling, includeTypes, includeJSDoc, producer }));
          break;
        case 'zustand-action':
          ({ code, types, example } = generateZustandAction(toolName, functionName, inputProps, requiredArgs, { includeErrorHandling, includeTypes, includeJSDoc, producer }));
          break;
        case 'javascript':
          const jsResult = generateJavaScript(toolName, functionName, inputProps, requiredArgs, { includeErrorHandling, includeJSDoc, producer });
          code = jsResult.code;
          example = jsResult.example;
          types = undefined;
          break;
        case 'typescript':
        default:
          ({ code, types, example } = generateTypeScript(toolName, functionName, inputProps, requiredArgs, { includeErrorHandling, includeTypes, includeJSDoc, producer }));
          break;
      }
      
      return {
        code,
        suggestedFilename: `use-${toKebabCase(toolName)}.${target === 'javascript' ? 'js' : 'ts'}`,
        types,
        example,
      };
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the tool 'Generates' code, implying a read-only or creation operation, but lacks details on permissions needed, whether it overwrites existing files, error handling behavior, or output format specifics. For a code generation tool with zero annotation coverage, this is a significant gap.

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?

The description is a single, well-structured sentence that efficiently conveys the tool's purpose, output formats, and goal. Every word earns its place with no redundancy or unnecessary details, making it easy to parse and understand quickly.

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?

Given the tool's complexity (code generation with multiple output targets) and no annotations or output schema, the description is adequate but incomplete. It covers the 'what' but lacks details on behavioral traits, error handling, or output structure. For a tool with 5 parameters and no structured safety hints, more context would be beneficial.

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 schema already documents all 5 parameters thoroughly. The description does not add any additional meaning beyond what the schema provides (e.g., it doesn't explain the relationship between producerDir and toolName or provide examples). Baseline 3 is appropriate when the schema does the heavy lifting.

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 consumer code') and resource ('from a producer schema'), specifying the output formats (TypeScript functions, React hooks, or Zustand actions) and their purpose ('correctly call MCP tools'). It distinguishes from siblings like scaffold_producer by focusing on consumer-side code generation rather than producer/server creation.

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 client-side code for MCP tools, but does not explicitly state when to use this tool versus alternatives (e.g., manually writing code or using other scaffolding tools). No exclusions or prerequisites are mentioned, leaving the context somewhat open-ended.

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