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"]

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