Skip to main content
Glama

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
NameRequiredDescriptionDefault
operationIdYes
specIdYes

Implementation Reference

  • 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; } } );
  • Zod input schema for the tool: requires specId and operationId as strings.
    { specId: z.string(), operationId: z.string(), },
  • 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; } }
  • 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; }

Other Tools

Related 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/ReAPI-com/mcp-openapi'

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