generate_request_template
Create path, query, and body templates for ACOMO API requests using operationId. Simplifies API interaction by generating structured request formats for backend services.
Instructions
operationIdからpath/query/body雛形を生成
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| operationId | Yes |
Implementation Reference
- src/server.ts:121-136 (handler)The handler function for the 'generate_request_template' tool. It fetches the operation schemas using getOperationSchemas and generates the request template using buildRequestTemplate, then returns it as JSON text content.async ({ operationId }: { operationId: string }) => { const schemas = await getOperationSchemas(operationId); if (!schemas) return { content: [ { type: "text", text: `Unknown operationId: ${operationId}` }, ], isError: true, }; const tmpl = buildRequestTemplate(schemas); return { content: [ { type: "text", text: JSON.stringify(tmpl, null, 2) }, ], }; }
- src/server.ts:116-120 (schema)The input schema definition for the tool, specifying 'operationId' as a required string using Zod validation.{ title: "Generate API request template", description: "operationIdからpath/query/body雛形を生成", inputSchema: { operationId: z.string() }, },
- src/server.ts:114-137 (registration)The registration of the 'generate_request_template' tool with the MCP server, including title, description, input schema, and handler function.server.registerTool( "generate_request_template", { title: "Generate API request template", description: "operationIdからpath/query/body雛形を生成", inputSchema: { operationId: z.string() }, }, async ({ operationId }: { operationId: string }) => { const schemas = await getOperationSchemas(operationId); if (!schemas) return { content: [ { type: "text", text: `Unknown operationId: ${operationId}` }, ], isError: true, }; const tmpl = buildRequestTemplate(schemas); return { content: [ { type: "text", text: JSON.stringify(tmpl, null, 2) }, ], }; } );
- src/openapi.ts:120-142 (helper)Core helper function that builds the request template object from operation schemas, extracting path/query params and generating body skeleton.export function buildRequestTemplate(opSchemas: { operationId: string; method: string; path: string; parameters: any[]; requestBody?: any; }) { const pathParams: Record<string, string> = {}; const query: Record<string, any> = {}; for (const p of opSchemas.parameters ?? []) { if (p.in === 'path') pathParams[p.name] = `<${p.name}>`; if (p.in === 'query') query[p.name] = `<${p.name}>`; } const body = opSchemas.requestBody ? buildBodySkeleton(opSchemas.requestBody) : undefined; return { operationId: opSchemas.operationId, method: opSchemas.method, path: opSchemas.path, pathParams, query: Object.keys(query).length ? query : undefined, body, }; }
- src/openapi.ts:84-118 (helper)Helper function that retrieves detailed schemas for parameters, requestBody, and responses for a given operationId, used by the tool handler.export async function getOperationSchemas(operationId: string): Promise<{ operationId: string; method: string; path: string; parameters: any[]; // path/query/header requestBody?: any; // schema if available responses?: Record<string, any>; // status -> schema/desc } | null> { const found = await findOperationById(operationId); if (!found) return null; const op = found.raw || {}; const parameters = op.parameters ?? []; let requestBody: any | undefined; if (op.requestBody?.content) { // prefer application/json const json = op.requestBody.content['application/json'] || Object.values(op.requestBody.content)[0]; requestBody = json?.schema ?? json; } const responses: Record<string, any> = {}; if (op.responses) { for (const [code, res] of Object.entries(op.responses)) { const content = (res as any)?.content; const json = content?.['application/json'] || (content && Object.values(content)[0]); responses[code] = json?.schema ?? (res as any)?.description ?? res; } } return { operationId, method: found.method, path: found.path, parameters, requestBody, responses, }; }