Skip to main content
Glama

update_document

Update or regenerate specific document types like project briefs, product context, and system patterns within the Memory Bank MCP server to maintain accurate and structured project knowledge.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentNo
documentTypeYes
regenerateNo

Implementation Reference

  • The handler function executes the tool logic: checks initialization, constructs file path, creates file if missing, handles regenerate by appending date or saves provided content using saveDocument, returns success/error messages.
      async ({ documentType, content, regenerate }) => {
        try {
          // Check if Memory Bank directory is initialized
          if (!MEMORY_BANK_DIR) {
            throw new Error('Memory Bank not initialized. Please use initialize_memory_bank tool first.');
          }
    
          const filePath = path.join(MEMORY_BANK_DIR, `${documentType}.md`);
    
          // Check if file exists
          if (!await fs.pathExists(filePath)) {
            // Create file if it doesn't exist
            await fs.ensureFile(filePath);
            await fs.writeFile(filePath, `# ${documentType}\n\n`, 'utf-8');
          }
    
          if (regenerate) {
            // Read existing document
            const currentContent = await readDocument(filePath);
            
            // Always use en-US locale for date formatting to ensure English output
            const dateOptions = { year: 'numeric', month: 'long', day: 'numeric' };
            const englishDate = new Date().toLocaleDateString('en-US');
            
            // TODO: Generate new content with Gemini (example for now)
            const newContent = `${currentContent}\n\n## Update\nThis document was regenerated on ${englishDate}.`;
            
            // Save document
            await saveDocument(newContent, filePath);
          } else if (content) {
            // Save provided content
            await saveDocument(content, filePath);
          } else {
            throw new Error('Content must be provided or regenerate=true');
          }
    
          // Always use English for all response messages
          return {
            content: [{ 
              type: 'text', 
              text: `✅ "${documentType}.md" document successfully updated!` 
            }]
          };
        } catch (error) {
          console.error('Error updating document:', error);
          // Ensure error messages are also in English
          const errorMessage = error instanceof Error ? error.message : String(error);
          return {
            content: [{ type: 'text', text: `❌ Error: ${errorMessage}` }],
            isError: true
          };
        }
      }
    );
  • Zod input schema defining parameters for the update_document tool: documentType as enum of valid documents, optional content string, optional regenerate boolean (defaults to false).
    {
      documentType: z.enum(['projectbrief', 'productContext', 'systemPatterns', 'techContext', 'activeContext', 'progress']),
      content: z.string().optional(),
      regenerate: z.boolean().default(false)
    },
  • MCP server.tool registration of the 'update_document' tool with schema and handler function.
    server.tool(
      'update_document',
      {
        documentType: z.enum(['projectbrief', 'productContext', 'systemPatterns', 'techContext', 'activeContext', 'progress']),
        content: z.string().optional(),
        regenerate: z.boolean().default(false)
      },
      async ({ documentType, content, regenerate }) => {
        try {
          // Check if Memory Bank directory is initialized
          if (!MEMORY_BANK_DIR) {
            throw new Error('Memory Bank not initialized. Please use initialize_memory_bank tool first.');
          }
    
          const filePath = path.join(MEMORY_BANK_DIR, `${documentType}.md`);
    
          // Check if file exists
          if (!await fs.pathExists(filePath)) {
            // Create file if it doesn't exist
            await fs.ensureFile(filePath);
            await fs.writeFile(filePath, `# ${documentType}\n\n`, 'utf-8');
          }
    
          if (regenerate) {
            // Read existing document
            const currentContent = await readDocument(filePath);
            
            // Always use en-US locale for date formatting to ensure English output
            const dateOptions = { year: 'numeric', month: 'long', day: 'numeric' };
            const englishDate = new Date().toLocaleDateString('en-US');
            
            // TODO: Generate new content with Gemini (example for now)
            const newContent = `${currentContent}\n\n## Update\nThis document was regenerated on ${englishDate}.`;
            
            // Save document
            await saveDocument(newContent, filePath);
          } else if (content) {
            // Save provided content
            await saveDocument(content, filePath);
          } else {
            throw new Error('Content must be provided or regenerate=true');
          }
    
          // Always use English for all response messages
          return {
            content: [{ 
              type: 'text', 
              text: `✅ "${documentType}.md" document successfully updated!` 
            }]
          };
        } catch (error) {
          console.error('Error updating document:', error);
          // Ensure error messages are also in English
          const errorMessage = error instanceof Error ? error.message : String(error);
          return {
            content: [{ type: 'text', text: `❌ Error: ${errorMessage}` }],
            isError: true
          };
        }
      }
    );
  • Helper utility function called by the handler to persist document content to the filesystem, ensuring directory exists before writing.
    export async function saveDocument(content: string, filePath: string): Promise<void> {
      try {
        // Ensure directory exists
        await fs.ensureDir(path.dirname(filePath));
        
        // Write file
        await fs.writeFile(filePath, content, 'utf-8');
        
        console.log(`Document saved: ${filePath}`);
      } catch (error) {
        console.error('Error saving document:', error);
        throw new Error(`Failed to save document: ${error}`);
      }
    }
  • Helper utility function used in regenerate mode to read existing document content before updating.
    export async function readDocument(filePath: string): Promise<string> {
      try {
        // Check if file exists
        if (!await fs.pathExists(filePath)) {
          throw new Error(`Document not found: ${filePath}`);
        }
        
        // Read file
        const content = await fs.readFile(filePath, 'utf-8');
        
        return content;
      } catch (error) {
        console.error('Error reading document:', error);
        throw new Error(`Failed to read document: ${error}`);
      }
    }
Behavior1/5

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

Tool has no description.

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

Conciseness1/5

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

Tool has no description.

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

Completeness1/5

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

Tool has no description.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Tool has no description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose1/5

Does the description clearly state what the tool does and how it differs from similar tools?

Tool has no description.

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

Usage Guidelines1/5

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

Tool has no description.

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

Related 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/tuncer-byte/memory-bank-MCP'

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