Skip to main content
Glama

yapi_list_interfaces

Retrieve API interface lists from YApi projects or categories to organize and access documentation efficiently within MCP-compatible editors.

Instructions

获取YApi项目或分类下的接口列表

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYesYApi项目ID
cat_idNo分类ID(可选)
tokenNo访问令牌(可选)

Implementation Reference

  • The handler function for the yapi_list_interfaces tool. It calls yapiClient.getInterfaceList with the provided arguments and returns the interfaces as JSON text, or an error message.
    async (args: { project_id: string; cat_id?: string; token?: string }) => {
      try {
        const interfaces = await yapiClient.getInterfaceList(
          args.project_id,
          args.cat_id,
          args.token
        );
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(interfaces, null, 2),
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `错误: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
          isError: true,
        };
      }
    }
  • Input schema definition for the yapi_list_interfaces tool using Zod, defining project_id as required string, cat_id and token as optional.
    {
      description: '获取YApi项目或分类下的接口列表',
      inputSchema: {
        project_id: z.string().describe('YApi项目ID'),
        cat_id: z.string().optional().describe('分类ID(可选)'),
        token: z.string().optional().describe('访问令牌(可选)'),
      },
    },
  • src/index.ts:534-572 (registration)
    Registration of the yapi_list_interfaces tool on the MCP server using server.registerTool, including name, schema, and inline handler.
    server.registerTool(
      'yapi_list_interfaces',
      {
        description: '获取YApi项目或分类下的接口列表',
        inputSchema: {
          project_id: z.string().describe('YApi项目ID'),
          cat_id: z.string().optional().describe('分类ID(可选)'),
          token: z.string().optional().describe('访问令牌(可选)'),
        },
      },
      async (args: { project_id: string; cat_id?: string; token?: string }) => {
        try {
          const interfaces = await yapiClient.getInterfaceList(
            args.project_id,
            args.cat_id,
            args.token
          );
    
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify(interfaces, null, 2),
              },
            ],
          };
        } catch (error) {
          return {
            content: [
              {
                type: 'text',
                text: `错误: ${error instanceof Error ? error.message : String(error)}`,
              },
            ],
            isError: true,
          };
        }
      }
    );
  • YApiClient.getInterfaceList method, the core helper function that fetches the interface list from YApi API via axios, handling project or category endpoints and authentication.
    async getInterfaceList(projectId: string, catId?: string, token?: string): Promise<any[]> {
      try {
        let endpoint: string;
        const params: any = {};
    
        if (catId) {
          endpoint = '/api/interface/list_cat';
          params.catid = catId;
        } else {
          endpoint = '/api/interface/list';
          params.project_id = projectId;
        }
    
        // 优先使用传入的 token,其次使用实例的 token
        const finalToken = token || this.token;
        if (finalToken) {
          params.token = finalToken;
        }
    
        const response = await this.client.get(endpoint, { params });
    
        if (response.data.errcode !== 0) {
          throw new Error(response.data.errmsg || '获取接口列表失败');
        }
    
        return response.data.data || [];
      } catch (error) {
        this.handleError(error, '获取接口列表失败');
      }
    }

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