Skip to main content
Glama

scaffold_producer

Generate MCP tool definitions from client usage patterns to create producer schema stubs based on how consumer code calls 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 implementation of scaffolding producer schema stub from consumer usage traces. Generates Zod schema and optional handler stub based on observed arguments and expected properties.
    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 request handler for the 'scaffold_producer' tool. Parses input, traces consumer usage in the directory, finds the tool usage, and invokes the core scaffolding function.
    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 schema defining the input parameters for 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)
    Registration of the 'scaffold_producer' tool in the MCP server's listTools response, including name, description, and input schema.
    { 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'], }, },

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