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,
      };

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