Skip to main content
Glama

yapi_get_interface_by_url

Retrieve detailed API interface specifications from YApi documentation by providing the complete URL. Supports both public and private projects with optional authentication tokens.

Instructions

通过YApi接口URL获取详细信息。支持直接粘贴YApi链接,如: https://yapi.example.com/project/100/interface/api/12345

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesYApi接口完整URL,例如: https://yapi.example.com/project/100/interface/api/12345
tokenNo访问令牌(可选,用于访问私有项目)

Implementation Reference

  • The main handler function for the 'yapi_get_interface_by_url' tool. It parses the provided YApi URL, temporarily sets the YApi base URL from the parsed URL, fetches the interface details, formats them, adds source URL info, and returns the JSON-formatted result. Handles errors appropriately.
    async (args: { url: string; token?: string }) => {
      try {
        // 解析URL
        const parsed = YApiUrlParser.parseInterfaceUrl(args.url);
        
        if (!parsed) {
          return {
            content: [
              {
                type: 'text',
                text: '错误: 无法解析YApi URL。请确保URL格式正确,例如: https://yapi.example.com/project/100/interface/api/12345',
              },
            ],
            isError: true,
          };
        }
    
        // 临时切换到URL中的baseUrl
        const originalBaseUrl = yapiClient['baseUrl'];
        yapiClient['baseUrl'] = parsed.baseUrl;
        yapiClient['client'].defaults.baseURL = parsed.baseUrl;
    
        try {
          const interfaceData = await yapiClient.getInterfaceDetails(
            parsed.interfaceId,
            args.token
          );
          const formatted = InterfaceFormatter.formatInterfaceDetails(interfaceData);
    
          // 添加URL信息
          const result = {
            ...formatted,
            source_url: args.url,
            yapi_server: parsed.baseUrl,
          };
    
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify(result, null, 2),
              },
            ],
          };
        } finally {
          // 恢复原始baseUrl
          yapiClient['baseUrl'] = originalBaseUrl;
          yapiClient['client'].defaults.baseURL = originalBaseUrl;
        }
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `错误: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
          isError: true,
        };
      }
    }
  • Input schema definition using Zod for the tool, specifying 'url' as required string and 'token' as optional string.
      description: '通过YApi接口URL获取详细信息。支持直接粘贴YApi链接,如: https://yapi.example.com/project/100/interface/api/12345',
            inputSchema: {
        url: z.string().describe('YApi接口完整URL,例如: https://yapi.example.com/project/100/interface/api/12345'),
        token: z.string().optional().describe('访问令牌(可选,用于访问私有项目)'),
      },
    },
  • src/index.ts:382-452 (registration)
    Registration of the 'yapi_get_interface_by_url' tool on the MCP server using server.registerTool, including name, schema, and inline handler.
    server.registerTool(
      'yapi_get_interface_by_url',
      {
        description: '通过YApi接口URL获取详细信息。支持直接粘贴YApi链接,如: https://yapi.example.com/project/100/interface/api/12345',
              inputSchema: {
          url: z.string().describe('YApi接口完整URL,例如: https://yapi.example.com/project/100/interface/api/12345'),
          token: z.string().optional().describe('访问令牌(可选,用于访问私有项目)'),
        },
      },
      async (args: { url: string; token?: string }) => {
        try {
          // 解析URL
          const parsed = YApiUrlParser.parseInterfaceUrl(args.url);
          
          if (!parsed) {
            return {
              content: [
                {
                  type: 'text',
                  text: '错误: 无法解析YApi URL。请确保URL格式正确,例如: https://yapi.example.com/project/100/interface/api/12345',
                },
              ],
              isError: true,
            };
          }
    
          // 临时切换到URL中的baseUrl
          const originalBaseUrl = yapiClient['baseUrl'];
          yapiClient['baseUrl'] = parsed.baseUrl;
          yapiClient['client'].defaults.baseURL = parsed.baseUrl;
    
          try {
            const interfaceData = await yapiClient.getInterfaceDetails(
              parsed.interfaceId,
              args.token
            );
            const formatted = InterfaceFormatter.formatInterfaceDetails(interfaceData);
    
            // 添加URL信息
            const result = {
              ...formatted,
              source_url: args.url,
              yapi_server: parsed.baseUrl,
            };
    
            return {
              content: [
                {
                  type: 'text',
                  text: JSON.stringify(result, null, 2),
                },
              ],
            };
          } finally {
            // 恢复原始baseUrl
            yapiClient['baseUrl'] = originalBaseUrl;
            yapiClient['client'].defaults.baseURL = originalBaseUrl;
          }
        } catch (error) {
          return {
            content: [
              {
                type: 'text',
                text: `错误: ${error instanceof Error ? error.message : String(error)}`,
              },
            ],
            isError: true,
          };
        }
      }
    );
  • YApiUrlParser.parseInterfaceUrl static method: Parses YApi interface URL to extract baseUrl, projectId, and interfaceId. Used in the handler to parse the input URL.
    static parseInterfaceUrl(url: string): { baseUrl: string; projectId: string; interfaceId: string } | null {
      try {
        const urlObj = new URL(url);
        const baseUrl = `${urlObj.protocol}//${urlObj.host}`;
        
        // 匹配路径: /project/{projectId}/interface/api/{interfaceId}
        const match = urlObj.pathname.match(/\/project\/(\d+)\/interface\/api\/(\d+)/);
        
        if (match) {
          return {
            baseUrl,
            projectId: match[1],
            interfaceId: match[2],
          };
        }
        
        return null;
      } catch (error) {
        return null;
      }
    }
  • InterfaceFormatter.formatInterfaceDetails static method: Formats raw YApi interface data into a structured object with request/response details. Called in the handler after fetching data.
    static formatInterfaceDetails(interfaceData: any): any {
      const requestParams = this.extractRequestParams(interfaceData);
      const responseInfo = this.extractResponseInfo(interfaceData);
    
      return {
        id: interfaceData._id,
        title: interfaceData.title,
        method: interfaceData.method,
        path: interfaceData.path,
        description: interfaceData.desc || '',
        status: interfaceData.status || 'undone',
        request: {
          params: requestParams,
          headers: this.extractHeaders(interfaceData),
          body: this.extractRequestBody(interfaceData),
        },
        response: responseInfo,
        markdown: interfaceData.markdown || '',
        project_id: interfaceData.project_id,
        catid: interfaceData.catid,
        uid: interfaceData.uid,
        add_time: interfaceData.add_time,
        up_time: interfaceData.up_time,
      };
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions that the token parameter is '可选' (optional) for accessing private projects, which adds some context about authentication needs. However, it doesn't describe what '详细信息' (detailed information) includes, potential rate limits, error conditions, or whether this is a read-only operation (though '获取' implies reading).

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

Conciseness4/5

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

The description is appropriately concise with two sentences. The first sentence states the purpose, and the second provides usage guidance with a concrete example. There's no wasted text, and information is front-loaded. It could be slightly more structured by explicitly separating purpose from usage.

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

Completeness3/5

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

Given the tool has 2 parameters with full schema coverage but no annotations and no output schema, the description is minimally adequate. It covers the basic purpose and usage but lacks details about what '详细信息' includes in the response, error handling, or behavioral constraints. For a tool that fetches data, more context about the return format would be 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%, so both parameters are already documented in the schema. The description adds minimal value beyond the schema: it reinforces the URL format example and mentions the token is for private projects. Since the schema does the heavy lifting, the baseline score of 3 is appropriate.

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 detailed information through YApi interface URL). It specifies the verb '获取' (get) and resource '详细信息' (detailed information) for YApi interfaces. However, it doesn't explicitly differentiate from sibling tools like 'yapi_get_interface' (which likely uses ID instead of URL) or 'yapi_search_interface'.

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

Usage Guidelines3/5

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

The description provides implied usage guidance by stating it '支持直接粘贴YApi链接' (supports directly pasting YApi links) with an example URL format. This suggests when to use this tool (when you have a full URL). However, it doesn't explicitly state when NOT to use it or mention alternatives like 'yapi_get_interface' (which might use an ID parameter instead).

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

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