Skip to main content
Glama

yapi-get-interface-by-url

Retrieve detailed API specifications from YApi documentation by providing a direct interface URL. This tool extracts complete endpoint information including parameters, responses, and descriptions for integration or testing purposes.

Instructions

根据YApi URL获取接口详情,支持格式如:http://localhost:40001/project/11/interface/api/23

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesYApi接口URL,例如:http://localhost:40001/project/11/interface/api/23

Implementation Reference

  • The primary handler function for 'yapi-get-interface-by-url'. It parses the provided YApi URL using a regex to extract the interface ID, fetches the interface details via yapiClient.getInterface, and returns the JSON stringified response or error.
    private async getInterfaceByUrl(url: string) { try { // 解析 YApi URL,提取接口ID // 支持多种格式: // http://localhost:40001/project/11/interface/api/23 // https://yapi.example.com/project/11/interface/api/23 // http://localhost:40001/interface/api/23 const urlPattern = /\/(?:project\/\d+\/)?interface\/api\/(\d+)/; const match = url.match(urlPattern); if (!match) { throw new Error(`Invalid YApi URL format. Expected format: http://host/project/XX/interface/api/XX or http://host/interface/api/XX`); } const interfaceId = parseInt(match[1], 10); if (isNaN(interfaceId)) { throw new Error(`Unable to extract interface ID from URL: ${url}`); } const interface_ = await this.yapiClient.getInterface(interfaceId); return { content: [ { type: "text", text: JSON.stringify(interface_, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error: ${error instanceof Error ? error.message : "Unknown error"}`, }, ], isError: true, }; } }
  • Tool definition including name, description, and inputSchema for validating the 'url' parameter.
    "yapi-get-interface-by-url": { name: "yapi-get-interface-by-url", description: "根据YApi URL获取接口详情,支持格式如:http://localhost:40001/project/11/interface/api/23", inputSchema: { type: "object", properties: { url: { type: "string", description: "YApi接口URL,例如:http://localhost:40001/project/11/interface/api/23", }, }, required: ["url"], }, },
  • src/index.ts:46-50 (registration)
    Registers the YApi tools (including 'yapi-get-interface-by-url') in the MCP server's ListTools handler by retrieving definitions from YApiTools instance.
    server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: Object.values(yapiTools.getToolDefinitions()), }; });
  • Tool dispatcher that routes 'yapi-get-interface-by-url' calls to the specific getInterfaceByUrl handler.
    async handleToolCall(toolName: string, args: any): Promise<any> { switch (toolName) { case "yapi-get-interface": return await this.getInterface(args.interfaceId); case "yapi-get-interface-by-url": return await this.getInterfaceByUrl(args.url); default: throw new Error(`Unknown tool: ${toolName}`); } }
  • src/index.ts:52-72 (registration)
    MCP server's CallTool handler that delegates tool execution to YApiTools.handleToolCall, enabling the 'yapi-get-interface-by-url' tool.
    server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; if (!name) { throw new Error("Tool name is required"); } try { return await yapiTools.handleToolCall(name, args); } catch (error) { return { content: [ { type: "text", text: `Error: ${error instanceof Error ? error.message : "Unknown error"}`, }, ], isError: true, }; } });

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/abeixiaolu/yapi-mcp'

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