load-api-operation-by-operationId
Retrieve specific API operations by operationId to integrate with LLM-powered development tools, enabling direct interaction with OpenAPI specifications.
Instructions
Load an operation by operationId
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| operationId | Yes | ||
| specId | Yes |
Implementation Reference
- src/McpService.ts:141-172 (registration)Registration of the MCP tool 'load-api-operation-by-operationId'. Includes the tool name, description, input schema, and inline handler function.server.tool( "load-api-operation-by-operationId", "Load an operation by operationId", { specId: z.string(), operationId: z.string(), }, async (args, extra) => { try { this.logger.debug('Loading API operation by ID', { specId: args.specId, operationId: args.operationId }); const operation = await this.specExplorer.findOperationById( args.specId, args.operationId ); if (!operation) { this.logger.warn('Operation not found', { specId: args.specId, operationId: args.operationId }); } return { content: [ { type: "text", text: stringify(operation, { indent: 2 }) }, ], }; } catch (error) { this.logger.error('Failed to load API operation by ID', { error, specId: args.specId, operationId: args.operationId }); throw error; } } );
- src/McpService.ts:144-147 (schema)Zod input schema for the tool: requires specId and operationId as strings.{ specId: z.string(), operationId: z.string(), },
- src/McpService.ts:148-171 (handler)Handler function for the tool. Fetches the operation using specExplorer.findOperationById and returns it serialized as YAML in the MCP response format.async (args, extra) => { try { this.logger.debug('Loading API operation by ID', { specId: args.specId, operationId: args.operationId }); const operation = await this.specExplorer.findOperationById( args.specId, args.operationId ); if (!operation) { this.logger.warn('Operation not found', { specId: args.specId, operationId: args.operationId }); } return { content: [ { type: "text", text: stringify(operation, { indent: 2 }) }, ], }; } catch (error) { this.logger.error('Failed to load API operation by ID', { error, specId: args.specId, operationId: args.operationId }); throw error; } }
- src/core/SpecService.ts:439-463 (helper)Core helper method findOperationById that implements the logic to locate an OpenAPI operation by its operationId within a specific spec by iterating over paths and methods.async findOperationById( specId: string, operationId: string ): Promise<LoadOperationResult | null> { const spec = this.specs[specId]; if (!spec) { return null; } for (const path in spec.paths) { const pathItem = spec.paths[path]; for (const method in pathItem) { if (pathItem[method]["operationId"] === operationId) { return { path, method, operation: pathItem[method], specId, uri: `apis://${specId}/operations/${operationId}`, }; } } } return null; }