Skip to main content
Glama

get_server_context

Generate a server context file showing current state, memory, and capabilities for instant LLM awareness in architectural decision analysis.

Instructions

Generate a comprehensive context file showing the server's current state, memory, and capabilities. Creates .mcp-server-context.md that can be @ referenced in conversations for instant LLM awareness

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
writeToFileNoWhether to write the context to .mcp-server-context.md file
outputPathNoCustom output path for the context file
includeDetailedNoInclude detailed information
maxRecentItemsNoMaximum number of recent items to show

Implementation Reference

  • The main handler function that executes the get_server_context tool. It creates a ServerContextGenerator instance, generates the current server context using provided managers, optionally writes it to .mcp-server-context.md, and returns the appropriate MCP CallToolResult.
    export async function getServerContext(
      args: GetServerContextArgs,
      kgManager: KnowledgeGraphManager,
      memoryManager: MemoryEntityManager,
      conversationManager: ConversationMemoryManager
    ): Promise<CallToolResult> {
      const { writeToFile = true, outputPath, includeDetailed = true, maxRecentItems = 5 } = args;
    
      const generator = new ServerContextGenerator();
    
      try {
        // Generate context
        const contextContent = await generator.generateContext(
          kgManager,
          memoryManager,
          conversationManager,
          { includeDetailed, maxRecentItems }
        );
    
        // Optionally write to file
        if (writeToFile) {
          await generator.writeContextFile(kgManager, memoryManager, conversationManager, outputPath);
        }
    
        return {
          content: [
            {
              type: 'text',
              text: writeToFile
                ? `✅ Server context updated and written to \`.mcp-server-context.md\`\n\nYou can now \`@.mcp-server-context.md\` to reference this context in conversations.\n\n---\n\n${contextContent}`
                : contextContent,
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `❌ Failed to generate server context: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
          isError: true,
        };
      }
    }
  • MCP tool metadata including name, description, and inputSchema for registration and validation.
    export const getServerContextMetadata = {
      name: 'get_server_context',
      description:
        "Generate a comprehensive context file showing the server's current state, memory, and capabilities. Creates .mcp-server-context.md that can be @ referenced in conversations to give LLMs instant awareness of the server.",
      inputSchema: {
        type: 'object',
        properties: {
          writeToFile: {
            type: 'boolean',
            description: 'Whether to write the context to .mcp-server-context.md file',
            default: true,
          },
          outputPath: {
            type: 'string',
            description: 'Custom output path for the context file',
          },
          includeDetailed: {
            type: 'boolean',
            description: 'Include detailed information',
            default: true,
          },
          maxRecentItems: {
            type: 'number',
            description: 'Maximum number of recent items to show',
            default: 5,
          },
        },
      },
    };
  • TypeScript interface defining the input arguments for the handler function, matching the inputSchema.
    export interface GetServerContextArgs {
      /**
       * Whether to write the context to .mcp-server-context.md file
       * @default true
       */
      writeToFile?: boolean;
    
      /**
       * Custom output path for the context file
       */
      outputPath?: string;
    
      /**
       * Include detailed information
       * @default true
       */
      includeDetailed?: boolean;
    
      /**
       * Maximum number of recent items to show
       * @default 5
       */
      maxRecentItems?: number;
    }
  • Registration of the tool in the central TOOL_CATALOG used for dynamic discovery, ListTools responses via tool-dispatcher, and categorization.
    TOOL_CATALOG.set('get_server_context', {
      name: 'get_server_context',
      shortDescription: 'Get server context',
      fullDescription: 'Gets the current server context and configuration.',
      category: 'utility',
      complexity: 'simple',
      tokenCost: { min: 200, max: 500 },
      hasCEMCPDirective: true, // Phase 4.3: Simple tool - context retrieval
      relatedTools: ['check_ai_execution_status', 'manage_cache'],
      keywords: ['server', 'context', 'config', 'status'],
      requiresAI: false,
      inputSchema: {
        type: 'object',
        properties: {
          includeConfig: { type: 'boolean', default: false },
        },
      },
    });
  • Key helper method writeContextFile used by the handler to persist the generated context to disk and ensure gitignore entry.
    async writeContextFile(
      kgManager: KnowledgeGraphManager,
      memoryManager: MemoryEntityManager,
      conversationManager: ConversationMemoryManager,
      filePath?: string
    ): Promise<void> {
      const outputPath = filePath || path.join(this.config.projectPath, '.mcp-server-context.md');
      const content = await this.generateContext(kgManager, memoryManager, conversationManager);
    
      await fs.writeFile(outputPath, content, 'utf-8');
    
      // Ensure .mcp-server-context.md is in .gitignore (auto-generated files shouldn't be tracked)
      await this.ensureGitignoreEntry(this.config.projectPath, '.mcp-server-context.md');
    
      this.logger.info('Server context file updated', 'ServerContextGenerator', {
        path: outputPath,
        size: content.length,
      });
    }

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/tosin2013/mcp-adr-analysis-server'

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