Skip to main content
Glama
MarveleE
by MarveleE

rap2_search_interfaces_by_keyword

Search API interfaces in RAP2 repositories using keywords to find relevant documentation and endpoints quickly.

Instructions

按关键字搜索接口(可选限定仓库)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keywordYes搜索关键字
repositoryIdNo仓库 ID(可选,传入字符串)

Implementation Reference

  • Core tool handler: Constructs query parameters for keyword (required) and optional repositoryId, performs HTTP GET to RAP2 /interface/search endpoint via _fetch, extracts and returns data array or propagates error.
    async searchInterfacesByKeyword(keyword, repositoryId) {
      const params = new URLSearchParams({ keyword: String(keyword || '') });
      if (repositoryId) params.set('repositoryId', String(repositoryId));
      const res = await this._fetch(`/interface/search?${params.toString()}`);
      const body = res?.data || {};
      if (body.errMsg) return { error: body.errMsg };
      return body.data || [];
    }
  • MCP CallToolRequest handler dispatch for this tool: Extracts and normalizes arguments using custom validators, creates Rap2Client instance, invokes core search method, logs, handles errors by throwing, returns JSON-formatted result as text content.
    if (name === 'rap2_search_interfaces_by_keyword') {
      const { keyword, repositoryId } = (req.params.arguments || {});
    
      const normalizedKeyword = validateAndNormalizeKeyword(keyword);
      const normalizedRepoId = validateAndNormalizeId('repositoryId', repositoryId, true); // 允许为空
    
      const client = createClient();
      const result = await client.searchInterfacesByKeyword(normalizedKeyword, normalizedRepoId);
    
      if (result?.error) {
        const errorMsg = String(result.error);
        logger.error({ tool: name, keyword: normalizedKeyword, repositoryId: normalizedRepoId, error: errorMsg }, 'tool failed');
        throw new Error(`搜索接口失败: ${errorMsg}`);
      }
    
      logger.info({ tool: name, keyword: normalizedKeyword, repositoryId: normalizedRepoId, resultCount: Array.isArray(result) ? result.length : 0 }, 'tool success');
      return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
  • Input schema defining the tool parameters: required 'keyword' string for search term, optional 'repositoryId' string to limit to a repository.
    inputSchema: {
      type: 'object',
      properties: {
        keyword: { type: 'string', description: '搜索关键字' },
        repositoryId: { type: 'string', description: '仓库 ID(可选,传入字符串)' },
      },
      required: ['keyword'],
    },
  • Tool definition object registered in the static tools list array, used for server capabilities.tools.list and listTools response.
    {
      name: 'rap2_search_interfaces_by_keyword',
      description: '按关键字搜索接口(可选限定仓库)',
      inputSchema: {
        type: 'object',
        properties: {
          keyword: { type: 'string', description: '搜索关键字' },
          repositoryId: { type: 'string', description: '仓库 ID(可选,传入字符串)' },
        },
        required: ['keyword'],
      },
    },
  • Helper function specifically for normalizing and validating the 'keyword' input parameter in the tool handler.
    function validateAndNormalizeKeyword(keyword) {
      if (!keyword) {
        throw new Error('参数错误: keyword 不能为空');
      }
    
      if (typeof keyword === 'string' && !keyword.trim()) {
        throw new Error('参数错误: keyword 不能是空字符串');
      }
    
      return typeof keyword === 'string' ? keyword.trim() : String(keyword);
    }

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/MarveleE/rap2-mcp'

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