Skip to main content
Glama
transparentlyok

MCP Context Manager

get_relevant_context

Retrieve targeted code snippets by describing your needs in natural language to find relevant programming context efficiently.

Instructions

Get code context relevant to a natural language query. Returns minimal, targeted code snippets.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesNatural language description of what you need context for
maxTokensNoMaximum tokens to return (approximate). Default: 4000

Implementation Reference

  • Implementation of getRelevantContext method which performs the search and prepares the response.
    async getRelevantContext(query: string, maxTokens: number): Promise<string> {
      // Use advanced search engine
      const allSymbols = this.getAllSymbols();
      const files = this.indexer.getAllFiles();
    
      const searchOptions: SearchOptions = {
        maxResults: 50, // Get more candidates, then filter by tokens
        fuzzyThreshold: 0.7,
        includeCodeBodies: true,
        includeComments: true,
        boostExactMatches: true,
      };
    
      const matches = CodeSearchEngine.search(query, allSymbols, files, searchOptions);
    
      if (matches.length === 0) {
        // Provide helpful suggestions
        const queryTokens = CodeSearchEngine.tokenize(query);
        const suggestions = this.getSuggestions(queryTokens);
    
        return `No relevant context found for query: "${query}"\n\n${
          suggestions.length > 0
            ? `Did you mean one of these?\n${suggestions.map(s => `  - ${s}`).join('\n')}\n\n`
            : ''
        }Try:\n- Using more specific terms\n- Checking for typos (fuzzy search is active but needs some similarity)\n- Using search_code for regex pattern matching\n- Using find_symbol for exact symbol lookup`;
      }
    
      // Build response within token limit
      let result = `🔍 Found ${matches.length} relevant results for: "${query}"\n\n`;
      let estimatedTokens = this.estimateTokens(result);
      let included = 0;
    
      for (const match of matches) {
        const formattedMatch = this.formatSearchMatch(match, true);
        const matchTokens = this.estimateTokens(formattedMatch);
    
        if (estimatedTokens + matchTokens > maxTokens) {
          result += `\n... (${matches.length - included} more results available, but truncated to stay within ${maxTokens} token limit)`;
          break;
        }
  • src/index.ts:144-152 (registration)
    Registration of the get_relevant_context MCP tool.
    name: 'get_relevant_context',
    description: '⭐ PREFERRED SEARCH: Use this INSTEAD OF Grep for finding code by description. Natural language search with BM25 ranking. Saves 70-90% tokens vs reading files directly. Examples: "authentication middleware", "payment processing", "gacha spin mechanics". Returns only relevant code snippets with relevance scores.',
    inputSchema: {
      type: 'object',
      properties: {
        query: {
          type: 'string',
          description: 'Natural language description of what you need (e.g., "user authentication flow", "error handling logic")',
        },

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