Skip to main content
Glama

update_doc

Update documentation files by applying diff-based changes. Specify the project path, file name, and content to search and replace, ensuring accurate and efficient updates.

Instructions

Update a specific documentation file using diff-based changes

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
continueToNextNoWhether to continue to the next file after this update
docFileYesName of the documentation file to update
projectPathYesPath to the project root directory
replaceContentYesContent to replace the search content with
searchContentYesContent to search for in the file

Implementation Reference

  • Handler function for 'update_doc' tool. Extracts arguments, validates that the document was previously read, checks if search content exists, performs string replacement, writes updated content to file, updates global state, and returns success response with diff info.
    case "update_doc": {
      const { projectPath, docFile, searchContent, replaceContent, continueToNext = false } =
        request.params.arguments as {
          projectPath: string;
          docFile: string;
          searchContent: string;
          replaceContent: string;
          continueToNext?: boolean;
        };
    
      try {
        // Validate that the file was read first
        if (state.lastReadFile !== docFile || !state.lastReadContent) {
          throw new McpError(
            ErrorCode.InvalidRequest,
            `Must read ${docFile} before updating it`
          );
        }
    
        const filePath = `${projectPath}/.handoff_docs/${docFile}`;
    
        // Verify the search content exists in the file
        if (!state.lastReadContent.includes(searchContent)) {
          throw new McpError(
            ErrorCode.InvalidRequest,
            `Search content not found in ${docFile}`
          );
        }
    
        // Apply the diff
        const newContent = state.lastReadContent.replace(searchContent, replaceContent);
        await fs.writeFile(filePath, newContent);
    
        // Update state
        state.lastReadContent = newContent;
        if (!state.completedFiles.includes(docFile)) {
          state.completedFiles.push(docFile);
        }
        state.continueToNext = continueToNext;
    
        if (continueToNext) {
          const remainingDocs = DEFAULT_DOCS.filter(doc => !state.completedFiles.includes(doc));
          if (remainingDocs.length > 0) {
            state.currentFile = remainingDocs[0];
          } else {
            state.currentFile = null;
            state.inProgress = false;
          }
        }
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify({
                message: "Documentation updated successfully",
                file: docFile,
                completedFiles: state.completedFiles,
                nextFile: state.currentFile,
                diff: {
                  from: searchContent,
                  to: replaceContent
                }
              }, null, 2)
            }
          ]
        };
      } catch (error: unknown) {
        const errorMessage = error instanceof Error ? error.message : String(error);
        throw new McpError(
          ErrorCode.InternalError,
          `Error updating documentation: ${errorMessage}`
        );
      }
    }
  • src/index.ts:450-479 (registration)
    Registration of the 'update_doc' tool in the ListToolsRequestSchema handler, including name, description, and full input schema definition.
    {
      name: "update_doc",
      description: "Update a specific documentation file using diff-based changes",
      inputSchema: {
        type: "object",
        properties: {
          projectPath: {
            type: "string",
            description: "Path to the project root directory"
          },
          docFile: {
            type: "string",
            description: "Name of the documentation file to update"
          },
          searchContent: {
            type: "string",
            description: "Content to search for in the file"
          },
          replaceContent: {
            type: "string",
            description: "Content to replace the search content with"
          },
          continueToNext: {
            type: "boolean",
            description: "Whether to continue to the next file after this update"
          }
        },
        required: ["projectPath", "docFile", "searchContent", "replaceContent"]
      }
    },
  • Input schema definition for the 'update_doc' tool, specifying parameters like projectPath, docFile, searchContent, replaceContent, and optional continueToNext.
    inputSchema: {
      type: "object",
      properties: {
        projectPath: {
          type: "string",
          description: "Path to the project root directory"
        },
        docFile: {
          type: "string",
          description: "Name of the documentation file to update"
        },
        searchContent: {
          type: "string",
          description: "Content to search for in the file"
        },
        replaceContent: {
          type: "string",
          description: "Content to replace the search content with"
        },
        continueToNext: {
          type: "boolean",
          description: "Whether to continue to the next file after this update"
        }
      },
      required: ["projectPath", "docFile", "searchContent", "replaceContent"]
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. While 'Update' implies mutation, it doesn't specify whether this operation is destructive, requires specific permissions, or has side effects (e.g., file locking). The mention of 'diff-based changes' hints at a non-overwrite approach but lacks detail on error handling or rollback capabilities.

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 a single, efficient sentence that front-loads the core purpose without unnecessary words. Every element ('Update', 'specific documentation file', 'diff-based changes') contributes directly to understanding the tool's function, making it highly concise and well-structured.

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

Completeness2/5

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

For a mutation tool with 5 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain what 'diff-based changes' entail operationally, what happens on success/failure, or how it interacts with sibling tools. The agent lacks critical context 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?

Schema description coverage is 100%, so all parameters are documented in the schema itself. The description adds minimal value by implying 'diff-based' behavior, which loosely relates to 'searchContent' and 'replaceContent', but doesn't provide additional syntax, format, or usage details beyond what the schema already specifies.

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

Purpose4/5

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

The description clearly states the action ('Update') and resource ('a specific documentation file') with the method ('using diff-based changes'), making the purpose immediately understandable. However, it doesn't explicitly differentiate this from sibling tools like 'update_metadata' or 'customize_template', which prevents a perfect score.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives like 'update_metadata' or 'customize_template'. It also lacks information about prerequisites (e.g., file must exist) or constraints (e.g., only works with certain file types), leaving the agent with minimal context for decision-making.

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/ryanjoachim/mcp-rtfm'

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