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")',
        },
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions returning 'minimal, targeted code snippets' but doesn't specify what 'relevant' means, how relevance is determined, whether it accesses cached data, or any performance characteristics like rate limits or permissions needed. This leaves significant gaps for a tool that presumably queries codebases.

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

Conciseness4/5

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

The description is a single, efficient sentence that front-loads the core purpose. It avoids unnecessary words, though it could be slightly more structured by separating purpose from behavioral traits. Every part earns its place, but it's borderline minimal.

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

Completeness2/5

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

Given the complexity of code context retrieval, no annotations, and no output schema, the description is incomplete. It doesn't explain what 'relevant' entails, how snippets are selected or formatted, error conditions, or dependencies on other tools like 'index_repository.' For a tool with 2 parameters and likely non-trivial behavior, this is inadequate.

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?

Schema description coverage is 100%, so the schema already documents both parameters fully. The description adds no additional meaning beyond what the schema provides—it doesn't clarify how 'query' should be formulated or what 'maxTokens' impacts in practice. Baseline 3 is appropriate as the schema does the heavy lifting.

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: 'Get code context relevant to a natural language query' with the specific action 'Returns minimal, targeted code snippets.' It distinguishes from siblings like 'search_code' by focusing on contextual relevance rather than broad searching, though it doesn't explicitly name alternatives.

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 implies usage for natural language queries about code context, but provides no explicit guidance on when to use this tool versus siblings like 'find_similar' or 'search_code.' It lacks any mention of prerequisites, exclusions, or specific scenarios where this tool is preferred.

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