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,
      });
    }
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 states the tool creates a file (.mcp-server-context.md) and that it's for generating context, but does not disclose critical traits such as whether this is a read-only operation, potential side effects (e.g., file system writes), performance impacts, or error handling. This leaves significant gaps in understanding the tool's behavior.

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 appropriately sized with two sentences that are front-loaded with the main purpose. The second sentence adds value by explaining the file's utility in conversations, though it could be slightly more concise by integrating this benefit into the first sentence without losing clarity.

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

Completeness3/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 (4 parameters, no output schema, no annotations), the description is somewhat complete but has gaps. It explains the purpose and output file usage, but without annotations or output schema, it fails to cover behavioral aspects like side effects or return values, making it adequate but not fully comprehensive for safe and effective use.

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?

The input schema has 100% description coverage, so the schema already documents all four parameters thoroughly. The description does not add any meaning beyond what the schema provides, such as explaining interactions between parameters or usage examples. Thus, it meets the baseline of 3 where the schema does the heavy lifting.

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 with specific verbs ('Generate a comprehensive context file') and resources ('server's current state, memory, and capabilities'), distinguishing it from sibling tools like get_memory_stats or get_architectural_context by focusing on a comprehensive server context file generation.

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 context by mentioning the output file can be '@ referenced in conversations for instant LLM awareness,' suggesting it's for providing server context to AI agents. However, it lacks explicit guidance on when to use this tool versus alternatives like get_memory_stats or analyze_environment, and does not specify prerequisites or exclusions.

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

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