Skip to main content
Glama

yapi_get_interface

Retrieve detailed API interface specifications from YApi, including request parameters, response data, and usage examples, to facilitate integration and development workflows.

Instructions

获取YApi接口的详细信息,包括请求参数、响应参数、请求示例等

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
interface_idYesYApi接口ID
tokenNo访问令牌(可选,用于访问私有项目)

Implementation Reference

  • The main handler function for the 'yapi_get_interface' tool. It fetches interface details from YApi using the provided interface_id and optional token, formats the data using InterfaceFormatter, and returns it as JSON string in the response content.
    async (args: { interface_id: string; token?: string }) => {
      try {
        const interfaceData = await yapiClient.getInterfaceDetails(
          args.interface_id,
          args.token
        );
        const formatted = InterfaceFormatter.formatInterfaceDetails(interfaceData);
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(formatted, null, 2),
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `错误: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
          isError: true,
        };
      }
    }
  • src/index.ts:455-492 (registration)
    The registration of the 'yapi_get_interface' tool using server.registerTool, including name, description, input schema, and handler function.
    server.registerTool(
      'yapi_get_interface',
      {
        description: '获取YApi接口的详细信息,包括请求参数、响应参数、请求示例等',
              inputSchema: {
          interface_id: z.string().describe('YApi接口ID'),
          token: z.string().optional().describe('访问令牌(可选,用于访问私有项目)'),
        },
      },
      async (args: { interface_id: string; token?: string }) => {
        try {
          const interfaceData = await yapiClient.getInterfaceDetails(
            args.interface_id,
            args.token
          );
          const formatted = InterfaceFormatter.formatInterfaceDetails(interfaceData);
    
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify(formatted, null, 2),
              },
            ],
          };
        } catch (error) {
          return {
            content: [
              {
                type: 'text',
                text: `错误: ${error instanceof Error ? error.message : String(error)}`,
              },
            ],
            isError: true,
          };
        }
      }
    );
  • The input schema definition for the tool using Zod, specifying interface_id as required string and token as optional string.
          inputSchema: {
      interface_id: z.string().describe('YApi接口ID'),
      token: z.string().optional().describe('访问令牌(可选,用于访问私有项目)'),
    },
  • YApiClient.getInterfaceDetails method: Core helper that makes API call to retrieve raw interface details from YApi server.
    async getInterfaceDetails(interfaceId: string, token?: string): Promise<any> {
      try {
        const params: any = { id: interfaceId };
        
        // 优先使用传入的 token,其次使用实例的 token
        const finalToken = token || this.token;
        if (finalToken) {
          params.token = finalToken;
        }
    
        const response = await this.client.get('/api/interface/get', { params });
    
        if (response.data.errcode !== 0) {
          throw new Error(response.data.errmsg || '获取接口详情失败');
        }
    
        return response.data.data;
      } catch (error) {
        this.handleError(error, '获取接口详情失败');
      }
    }
  • InterfaceFormatter.formatInterfaceDetails static method: Helper that transforms raw YApi interface data into a structured format with request/response details.
    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 full burden but offers minimal behavioral context. It mentions retrieving detailed information but doesn't disclose authentication requirements (token is optional but not explained), rate limits, error conditions, or what format the information returns. The description doesn't contradict annotations since none exist, but provides inadequate behavioral transparency for a tool that likely interacts with an API system.

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 a single, efficient sentence that states the core purpose. It's appropriately concise without being overly brief. However, it could be slightly more front-loaded by explicitly mentioning it retrieves by ID to distinguish from the URL-based sibling.

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?

For a tool with 2 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain what 'detailed information' includes beyond listing some components, doesn't mention authentication context despite the token parameter, and provides no guidance on error handling or response format. The description should do more to compensate for the lack of structured metadata.

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?

Schema description coverage is 100%, so the schema already documents both parameters thoroughly. The description adds no additional parameter semantics beyond what's in the schema - it doesn't explain interface_id format, token usage scenarios, or provide examples. Baseline 3 is appropriate when schema does the heavy lifting.

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接口的详细信息' (get detailed information of a YApi interface) with specific components mentioned (request parameters, response parameters, request examples). It distinguishes from siblings like yapi_list_interfaces (list) and yapi_search_interface (search), but doesn't explicitly differentiate from yapi_get_interface_by_url which likely retrieves by URL instead of ID.

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 doesn't mention when to choose this over yapi_get_interface_by_url (likely similar functionality with different input) or yapi_search_interface (broader search capability). No context about prerequisites or typical use cases is provided.

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