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,
        };
      }
    });
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states what the tool does (get interface details from a URL) but doesn't describe behavioral traits like error handling, authentication requirements, rate limits, or what '接口详情' (interface details) includes in the response. For a tool with no annotations, this leaves significant gaps in understanding its operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise and front-loaded: a single sentence stating the purpose followed by a concrete example. Every word earns its place with no redundancy or unnecessary elaboration, making it efficient and easy to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has no annotations and no output schema, the description is incomplete. It explains what the tool does but lacks crucial context: what '接口详情' (interface details) returns, error conditions, or how it differs from the sibling tool. For a tool with minimal structured data, the description should provide more operational context to be fully helpful.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, with the parameter 'url' fully documented in the schema. The description adds an example URL format ('http://localhost:40001/project/11/interface/api/23'), which provides context but doesn't add significant semantic meaning beyond what the schema already specifies. This meets the baseline score of 3 for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: '根据YApi URL获取接口详情' (Get interface details based on YApi URL). It specifies the verb '获取' (get) and resource '接口详情' (interface details), but doesn't distinguish from the sibling tool 'yapi-get-interface' which likely has a different parameter approach. The description provides a concrete example of the URL format, making the purpose specific and actionable.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It mentions the sibling tool 'yapi-get-interface' in the context signals, but the description itself doesn't explain the difference (e.g., this tool uses a URL parameter while the sibling might use ID-based parameters). There are no usage prerequisites, exclusions, or comparisons stated.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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

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