Skip to main content
Glama
bsdnn
by bsdnn

searchSymbols

Find symbols in codebase using fuzzy search. Supports partial names, Chinese keywords like '登录' and '支付', and CamelCase prefixes.

Instructions

Fuzzy search for symbols. Supports partial names, Chinese keywords ("登录", "支付"), and CamelCase prefixes.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query

Implementation Reference

  • Handler for the searchSymbols tool. Delegates to codeAnalyzer.smartFindSymbols() and formats the results.
    private async handleSearchSymbols(query: string): Promise<{ content: TextContent[] }> {
      if (!this.codeAnalyzer) {
        return { content: [{ type: 'text', text: 'Analyzer not initialized' }] };
      }
      const fileName = (f: string) => f.split(/[\/\\]/).pop() || f;
      const results = this.codeAnalyzer.smartFindSymbols(query, 20);
      if (results.length === 0) {
        return { content: [{ type: 'text', text: `找不到匹配 "${query}" 的符号` }] };
      }
      let text = `# 🔍 搜索 "${query}" — 找到 ${results.length} 个匹配\n\n`;
      for (const sym of results) {
        const emoji = sym.type === 'class' ? '📦' : '🔧';
        text += `- ${emoji} \`${sym.name}\` (${sym.type}) — ${fileName(sym.location.file)}:${sym.location.range.start.line}\n`;
      }
      return { content: [{ type: 'text', text }] };
    }
  • Core fuzzy search logic for symbols: supports exact match, keyword mapping (Chinese/English), and substring/prefix scoring.
    smartFindSymbols(query: string, limit: number = 10): Symbol[] {
      if (!query) return [];
    
      const lowerQ = query.toLowerCase();
      const all = Array.from(this.symbolTable.values()).filter(
        (s) => s.type === 'function' || s.type === 'class'
      );
    
      // 1. 精确匹配(不区分大小写)
      const exact = all.filter((s) => s.name.toLowerCase() === lowerQ);
      if (exact.length > 0) return exact.slice(0, limit);
    
      // 2. 关键字映射
      const keywordMap = this.configManager.getKeywords();
      const expandedTerms: string[] = [lowerQ];
      for (const [keyword, aliases] of Object.entries(keywordMap)) {
        if (keyword.toLowerCase() === lowerQ || aliases.some((a) => a.toLowerCase() === lowerQ)) {
          expandedTerms.push(...aliases.map((a) => a.toLowerCase()));
        }
      }
      // 内置中英文关键字映射
      const builtin: Record<string, string[]> = {
        '登录': ['login', 'signin', 'authenticate', 'auth'],
        '登入': ['login', 'signin', 'authenticate', 'auth'],
        '注册': ['register', 'signup', 'create'],
        '支付': ['pay', 'payment', 'charge', 'checkout'],
        '订单': ['order', 'create-order'],
        '删除': ['delete', 'remove', 'destroy'],
        '查询': ['find', 'query', 'search', 'get'],
        '保存': ['save', 'create', 'persist'],
      };
      if (builtin[query]) {
        expandedTerms.push(...builtin[query]);
      }
    
      // 3. 子串/前缀匹配,按"匹配质量"打分
      //    注意:只允许"符号名包含查询词",不允许反向(避免 "handleLogin" 匹配到 "And")
      //    且要求查询词至少 3 个字符才做子串匹配
      const scored = all.map((s) => {
        const lname = s.name.toLowerCase();
        let score = 0;
        for (const term of expandedTerms) {
          if (term.length < 2) continue;
          if (lname === term) score += 100;
          else if (lname.startsWith(term)) score += 50;
          else if (term.length >= 3 && lname.includes(term)) score += 20;
        }
        return { sym: s, score };
      });
    
      return scored
        .filter((x) => x.score > 0)
        .sort((a, b) => b.score - a.score)
        .slice(0, limit)
        .map((x) => x.sym);
    }
  • src/index.ts:117-130 (registration)
    Tool registration with name, description, and input schema.
    {
      name: 'searchSymbols',
      description: 'Fuzzy search for symbols. Supports partial names, Chinese keywords ("登录", "支付"), and CamelCase prefixes.',
      inputSchema: {
        type: 'object' as const,
        properties: {
          query: {
            type: 'string',
            description: 'Search query',
          },
        },
        required: ['query'],
      },
    },
  • src/index.ts:175-176 (registration)
    Tool call routing: dispatches 'searchSymbols' requests to the handler.
    case 'searchSymbols':
      return this.handleSearchSymbols(args.query);
  • Symbol type definition — the return type used by searchSymbols results.
    export interface Symbol {
      id: string;
      name: string;
      type: SymbolType;
      location: Location;
      scope?: string;
      parent?: string;
      signatures?: FunctionSignature[];
      docstring?: string;
      // Java 专用元数据
      fqcn?: string;           // 全限定类名,例如 com.easymusic.service.PayOrderService
      fieldType?: string;      // 字段类型(解析自 docstring)
      extendsClass?: string;   // class 继承的父类(simple name)
      implementsInterfaces?: string[]; // class 实现的接口(simple name)
    }
    
    /** 每个文件级别的元数据,用于跨文件解析 */
    export interface FileMetadata {
      filePath: string;
      language: LanguageType;
      packageName?: string;           // Java package
      imports: Array<{                // 文件的导入列表
        fqcn: string;                 // 完整路径,如 com.foo.Bar 或 ./services/user
        simpleName: string;           // 短名,如 Bar 或 user
      }>;
    }
    
    export interface FunctionSignature {
      name: string;
      params: Parameter[];
      returnType?: string;
    }
    
    export interface Parameter {
      name: string;
      type?: string;
      defaultValue?: string;
    }
    
    export interface CallNode {
      id: string;
      symbol: Symbol;
      calls: Set<string>;
      calledBy: Set<string>;
      callType: CallType;
      confidence: Confidence;
      isCritical: boolean;
      criticalPointType?: CriticalPointType;
    }
    
    export interface ImportStatement {
      source: string;
      imported: string[];
      local?: string;
      isReExport: boolean;
      location: Location;
    }
    
    export interface DataFlowEdge {
      from: string;
      to: string;
      variable: string;
      type: 'parameter' | 'return' | 'assignment' | 'property';
    }
    
    export interface FlowPath {
      nodes: Symbol[];
      edges: DataFlowEdge[];
      confidence: Confidence;
    }
    
    export interface BusinessFlowResult {
      entryPoint: Symbol;
      callChain: Symbol[];
      dataFlows: FlowPath[];
      criticalPoints: Symbol[];
      links: {
        vscode?: string[];
        github?: string[];
      };
    }
    
    export interface ProjectConfig {
      version: string;
      project: {
        name: string;
        description?: string;
        languages: LanguageType[];
        rootPath: string;
      };
      sourceConfig: {
        include: string[];
        exclude: string[];
      };
      analysisConfig: {
        maxCallDepth: number;
        crossFileAnalysis: boolean;
        includeIndirectCalls: boolean;
        dataFlowDepth: number;
        dynamicCallHandling: 'annotate' | 'ignore' | 'warn';
      };
      linkConfig: {
        vscode: {
          enabled: boolean;
          absolutePaths: boolean;
        };
        github: {
          enabled: boolean;
          repository?: string;
          defaultBranch?: string;
          useCommitSHA?: boolean;
        };
      };
      aliases: Record<string, string>;
      keywords: Record<string, string[]>;
      outputConfig: {
        format: 'json' | 'mermaid' | 'graphviz';
        includeDataFlow: boolean;
        cacheDir: string;
        cacheTTL: number;
      };
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, so description carries the burden. It discloses the fuzzy matching behavior and support for Chinese and CamelCase, which goes beyond the schema. It does not mention read-only or side effects, but search tools are inherently non-destructive.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single sentence front-loads the core purpose ('Fuzzy search for symbols') and then concisely lists supported features. No wasted words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With one simple parameter and no output schema, the description adequately covers the tool's behavior. It might have mentioned result formatting or limits, but for a basic search it is sufficiently complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The only parameter 'query' has minimal schema description ('Search query'). The tool description adds significant value by specifying supported input forms (partial names, Chinese keywords, CamelCase prefixes), which aids correct invocation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Clearly states 'fuzzy search for symbols' and specifies supported patterns like partial names, Chinese keywords, and CamelCase prefixes, which distinguishes it from sibling tools like findCallers or traceBusinessFlow.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Implies usage for fuzzy searching symbols with specific features, but does not explicitly state when not to use it or provide alternatives. However, the context is clear enough for typical search scenarios.

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/bsdnn/mcp-code-flow-analyzer'

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