Skip to main content
Glama

yapi_search_interface

Search for API interfaces in YApi projects by name or path to quickly find endpoint details and documentation.

Instructions

在YApi项目中搜索接口,支持按接口名称、路径搜索

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYesYApi项目ID
keywordYes搜索关键词
tokenNo访问令牌(可选)

Implementation Reference

  • The handler function for 'yapi_search_interface' tool. It calls yapiClient.searchInterface with provided arguments and returns the search results as JSON or an error message.
      async (args: { project_id: string; keyword: string; token?: string }) => {
        try {
          const results = await yapiClient.searchInterface(
            args.project_id,
            args.keyword,
            args.token
          );
    
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify(results, null, 2),
              },
            ],
          };
        } catch (error) {
          return {
            content: [
              {
                type: 'text',
                text: `错误: ${error instanceof Error ? error.message : String(error)}`,
              },
            ],
            isError: true,
          };
        }
      }
    );
  • Input schema definition for the 'yapi_search_interface' tool, including parameters project_id, keyword, and optional token.
    {
      description: '在YApi项目中搜索接口,支持按接口名称、路径搜索',
      inputSchema: {
        project_id: z.string().describe('YApi项目ID'),
        keyword: z.string().describe('搜索关键词'),
        token: z.string().optional().describe('访问令牌(可选)'),
      },
    },
  • src/index.ts:575-613 (registration)
    Registration of the 'yapi_search_interface' tool using server.registerTool, including schema and handler.
    server.registerTool(
      'yapi_search_interface',
      {
        description: '在YApi项目中搜索接口,支持按接口名称、路径搜索',
        inputSchema: {
          project_id: z.string().describe('YApi项目ID'),
          keyword: z.string().describe('搜索关键词'),
          token: z.string().optional().describe('访问令牌(可选)'),
        },
      },
      async (args: { project_id: string; keyword: string; token?: string }) => {
        try {
          const results = await yapiClient.searchInterface(
            args.project_id,
            args.keyword,
            args.token
          );
    
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify(results, null, 2),
              },
            ],
          };
        } catch (error) {
          return {
            content: [
              {
                type: 'text',
                text: `错误: ${error instanceof Error ? error.message : String(error)}`,
              },
            ],
            isError: true,
          };
        }
      }
    );
  • YApiClient.searchInterface helper method that makes the HTTP request to YApi's /api/interface/search endpoint to perform the interface search.
    async searchInterface(projectId: string, keyword: string, token?: string): Promise<any[]> {
      try {
        const params: any = {
          project_id: projectId,
          q: keyword,
        };
    
        // 优先使用传入的 token,其次使用实例的 token
        const finalToken = token || this.token;
        if (finalToken) {
          params.token = finalToken;
        }
    
        const response = await this.client.get('/api/interface/search', { 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