Skip to main content
Glama
transparentlyok

MCP Context Manager

get_class

Retrieve class definitions and specific methods without reading entire files to reduce token usage by 80%+ in code navigation.

Instructions

⭐ PREFERRED OVER Read: Get class definition without reading the entire file. Optionally filter specific methods. Saves 80%+ tokens vs reading full files. Use this when you need class structure or specific class methods.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
classNameYesThe name of the class to retrieve
methodsNoOptional: specific method names to include. If omitted, returns all methods.
filePathNoOptional: specific file path if known

Implementation Reference

  • The actual implementation of the getClass logic that searches the index and retrieves class definitions.
    async getClass(
      className: string,
      methods?: string[],
      filePath?: string
    ): Promise<string> {
      const symbols = this.indexer.findSymbols(className, 'class');
    
      if (symbols.length === 0) {
        return `Class "${className}" not found in index.`;
      }
    
      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 `Class "${className}" 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 classes named "${className}" found:\n${locations}\n\nPlease specify filePath to get the exact class.`;
        }
        targetSymbol = symbols[0];
      }
    
      // If specific methods requested, extract only those
      if (methods && methods.length > 0) {
        return this.extractClassMethods(targetSymbol, methods);
      }
    
      return this.formatSymbolWithContext(targetSymbol);
    }
    
    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,
  • src/index.ts:198-220 (registration)
    Registration of the 'get_class' tool definition including schema.
    {
      name: 'get_class',
      description: '⭐ PREFERRED OVER Read: Get class definition without reading the entire file. Optionally filter specific methods. Saves 80%+ tokens vs reading full files. Use this when you need class structure or specific class methods.',
      inputSchema: {
        type: 'object',
        properties: {
          className: {
            type: 'string',
            description: 'The name of the class to retrieve',
          },
          methods: {
            type: 'array',
            items: { type: 'string' },
            description: 'Optional: specific method names to include. If omitted, returns all methods.',
          },
          filePath: {
            type: 'string',
            description: 'Optional: specific file path if known',
          },
        },
        required: ['className'],
      },
    },
  • Tool handler switch case that calls retriever.getClass.
    case 'get_class': {
      const a = args as any;
      const className: string = a.className || a.name;
      const methods: string[] | undefined = a.methods;
      const filePath: string | undefined = a.filePath || a.path || a.file;
      if (!className) {
        return {
          content: [{ type: 'text', text: 'Error: className is required. Provide the name of the class to retrieve.' }],
          isError: true,
        };
      }
      const result = await retriever.getClass(className, methods, filePath);
      return {
        content: [
          {
            type: 'text',
            text: result,
          },
        ],
      };
    }
    
    case 'get_relevant_context': {

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