Skip to main content
Glama

yapi-get-interface-by-url

Retrieve API interface details from YApi documentation by providing a direct YApi URL. This tool extracts comprehensive API specifications including endpoints, parameters, and responses for development reference.

Instructions

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

Input Schema

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

Input Schema (JSON Schema)

{ "properties": { "url": { "description": "YApi接口URL,例如:http://localhost:40001/project/11/interface/api/23", "type": "string" } }, "required": [ "url" ], "type": "object" }

Implementation Reference

  • The main handler function that parses the provided YApi URL to extract the interface ID using regex, then fetches and returns the interface details via yapiClient.getInterface.
    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, }; } }
  • Defines the tool's input schema, specifying the required 'url' parameter of type string.
    "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 tool (among others from YApiTools) with the MCP server by providing tool definitions in response to ListTools requests.
    server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: Object.values(yapiTools.getToolDefinitions()), }; });
  • Dispatches tool calls to the specific handler based on toolName, routing 'yapi-get-interface-by-url' to getInterfaceByUrl.
    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}`); } }

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