Skip to main content
Glama
transparentlyok

MCP Context Manager

find_similar

Discover related code implementations and similar patterns by searching for symbols with comparable functionality across multiple programming languages.

Instructions

Find code similar to a given symbol. Useful for discovering related implementations, similar patterns, or alternative approaches.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolNameYesThe name of the symbol to find similar code for
limitNoMaximum number of similar symbols to return. Default: 5

Implementation Reference

  • The handler method in `retriever.ts` that orchestrates finding the target symbol and calling the search engine.
    async findSimilarSymbols(symbolName: string, limit: number = 5): Promise<string> {
      // Find the target symbol first
      const symbols = this.indexer.findSymbols(symbolName);
    
      if (symbols.length === 0) {
        return `Symbol "${symbolName}" not found.\nTry using find_symbol to locate it first.`;
      }
    
      const targetSymbol = symbols[0];
      const allSymbols = this.getAllSymbols();
    
      // Use search engine to find similar code
      const similar = CodeSearchEngine.findSimilarSymbols(targetSymbol, allSymbols, limit);
  • The core algorithm for calculating symbol similarity using Jaccard index.
    static findSimilarSymbols(targetSymbol: Symbol, allSymbols: Symbol[], limit: number = 5): SearchMatch[] {
      const matches: SearchMatch[] = [];
      const targetTokens = this.tokenize(targetSymbol.name + ' ' + targetSymbol.code);
    
      for (const symbol of allSymbols) {
        if (symbol === targetSymbol) continue;
    
        const symbolTokens = this.tokenize(symbol.name + ' ' + symbol.code);
    
        // Calculate Jaccard similarity (intersection over union)
        const intersection = targetTokens.filter(t => symbolTokens.includes(t)).length;
        const union = new Set([...targetTokens, ...symbolTokens]).size;
        const similarity = union > 0 ? intersection / union : 0;
    
        if (similarity > 0.1) { // At least 10% similar
          matches.push({
            symbol,
            score: similarity * 100,
            matchReason: [`${(similarity * 100).toFixed(1)}% similar code`],
            highlights: [symbol.name],
          });
        }
      }
    
      matches.sort((a, b) => b.score - a.score);
      return matches.slice(0, limit);
  • src/index.ts:565-584 (registration)
    The tool registration and request handler switch case in `src/index.ts`.
    case 'find_similar': {
      const a = args as any;
      const symbolName: string = a.symbolName || a.symbol || a.name;
      const limit: number = a.limit || a.max || a.maxResults || 5;
      if (!symbolName) {
        return {
          content: [{ type: 'text', text: 'Error: symbolName is required.' }],
          isError: true,
        };
      }
      const result = await retriever.findSimilarSymbols(symbolName, limit);
      return {
        content: [
          {
            type: 'text',
            text: result,
          },
        ],
      };
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the tool is 'useful for discovering' purposes, but it doesn't disclose key behavioral traits like whether it's read-only or destructive, authentication needs, rate limits, or how similarity is determined (e.g., based on code structure or semantics). This leaves significant gaps for an AI agent to understand the tool's behavior.

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?

The description is appropriately sized and front-loaded, consisting of two concise sentences. The first sentence states the purpose clearly, and the second adds useful context without redundancy. Every sentence earns its place, making it efficient and well-structured.

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

Completeness3/5

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

Given the tool has no annotations and no output schema, the description is somewhat complete but lacks details on behavioral traits and return values. It covers the purpose and usage context adequately for a simple tool, but for a code analysis tool with potential complexity, it should do more to explain how results are returned or what 'similar' means, making it minimally viable.

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

Parameters3/5

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

The input schema has 100% description coverage, with clear descriptions for both parameters ('symbolName' and 'limit'). The description adds no additional meaning beyond what the schema provides, such as explaining what a 'symbol' entails or how 'similar' is defined. Since the schema does the heavy lifting, the baseline score of 3 is appropriate.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Find code similar to a given symbol.' It specifies the verb ('Find') and resource ('code similar to a given symbol'), making the function understandable. However, it doesn't explicitly differentiate from sibling tools like 'find_symbol' or 'search_code', which might have overlapping purposes, preventing a perfect score.

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

Usage Guidelines3/5

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

The description provides implied usage guidelines by stating it's 'Useful for discovering related implementations, similar patterns, or alternative approaches.' This gives context on when to use it, but it doesn't explicitly mention when not to use it or name alternatives among sibling tools, such as how it differs from 'find_symbol' or 'search_code'.

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/transparentlyok/mcp-context-manager'

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