Skip to main content
Glama
transparentlyok

MCP Context Manager

get_function

Retrieve specific function implementations from code files to reduce token usage by extracting only needed function definitions instead of reading entire files.

Instructions

⭐ PREFERRED OVER Read: Get complete function code without reading the entire file. Saves 85% tokens compared to Read. Use when you need a specific function implementation instead of reading full files. Returns only the function definition with signature.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
functionNameYesThe name of the function to retrieve
filePathNoOptional: specific file path if known

Implementation Reference

  • The actual implementation of the getFunction logic which searches for symbols and retrieves the function code.
    async getFunction(functionName: string, filePath?: string): Promise<string> {
      const symbols = this.indexer.findSymbols(functionName, 'function');
    
      if (symbols.length === 0) {
        return `Function "${functionName}" not found in index.\nTry indexing the repository first with index_repository tool.`;
      }
    
      let targetSymbol: Symbol;
    
      if (filePath) {
        // Normalize path to handle Windows vs Unix separators
        const normalizedInput = path.normalize(filePath);
        const matches = symbols.filter((s) => path.normalize(s.filePath) === normalizedInput);
        if (matches.length === 0) {
          return `Function "${functionName}" not found in file "${filePath}".\nFound in: ${symbols.map((s) => s.filePath).join(', ')}`;
        }
        targetSymbol = matches[0];
      } else {
        if (symbols.length > 1) {
          const locations = symbols.map((s) => `  - ${s.filePath}:${s.line}`).join('\n');
          return `Multiple functions named "${functionName}" found:\n${locations}\n\nPlease specify filePath to get the exact function.`;
        }
        targetSymbol = symbols[0];
      }
    
      return this.formatSymbolWithContext(targetSymbol);
    }
    
    async getClass(
      className: string,
      methods?: string[],
      filePath?: string
    ): Promise<string> {
      const symbols = this.indexer.findSymbols(className, 'class');
    
      if (symbols.length === 0) {
  • src/index.ts:180-197 (registration)
    Tool definition and registration of get_function in the MCP tool list.
    {
      name: 'get_function',
      description: '⭐ PREFERRED OVER Read: Get complete function code without reading the entire file. Saves 85% tokens compared to Read. Use when you need a specific function implementation instead of reading full files. Returns only the function definition with signature.',
      inputSchema: {
        type: 'object',
        properties: {
          functionName: {
            type: 'string',
            description: 'The name of the function to retrieve',
          },
          filePath: {
            type: 'string',
            description: 'Optional: specific file path if known',
          },
        },
        required: ['functionName'],
      },
    },
  • The tool call handling switch case that parses the arguments and invokes the retriever's getFunction method.
    case 'get_function': {
      const a = args as any;
      const functionName: string = a.functionName || a.name;
      const filePath: string | undefined = a.filePath || a.path || a.file;
      if (!functionName) {
        return {
          content: [{ type: 'text', text: 'Error: functionName is required. Provide the name of the function to retrieve.' }],
          isError: true,
        };
      }
      const result = await retriever.getFunction(functionName, filePath);
      return {
        content: [
          {
            type: 'text',
            text: result,
          },
        ],
      };
    }
Behavior4/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 effectively describes key behaviors: the tool retrieves function code (read operation implied), emphasizes efficiency ('Saves 85% tokens'), and specifies the return format ('Returns only the function definition with signature'). However, it lacks details on error handling, performance limits, or authentication needs, leaving some behavioral aspects uncovered.

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 highly concise and well-structured: three sentences with zero waste. The first sentence states the purpose and key benefit, the second provides usage context, and the third clarifies the return value. Each sentence adds essential information, and the use of emojis and bold phrasing enhances readability without verbosity.

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?

Given the tool's moderate complexity (2 parameters, no output schema, no annotations), the description is largely complete. It covers purpose, usage guidelines, behavioral traits, and return format. However, without an output schema, it could benefit from more detail on response structure or error cases, and the lack of annotations means some operational context (e.g., idempotency) is missing.

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%, providing baseline documentation for both parameters. The description adds minimal parameter semantics beyond the schema—it implies 'functionName' is required for retrieval and 'filePath' is optional for targeting, but doesn't elaborate on format, constraints, or interaction effects. This meets the baseline for high schema coverage without significant added value.

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?

The description clearly states the tool's purpose: 'Get complete function code without reading the entire file.' It specifies the verb ('Get'), resource ('function code'), and distinguishes it from sibling tools like 'Read' (implied) and 'get_file_summary' by focusing on specific function extraction. The mention of token savings further clarifies its specialized role.

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

Usage Guidelines5/5

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

The description provides explicit usage guidance: '⭐ PREFERRED OVER Read' indicates a clear alternative, 'Use when you need a specific function implementation instead of reading full files' defines the optimal context, and 'Saves 85% tokens compared to Read' quantifies the benefit. This directly addresses when to use this tool versus alternatives like reading entire files.

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