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
| Name | Required | Description | Default |
|---|---|---|---|
| continueToNext | No | Whether to continue to the next file after this update | |
| docFile | Yes | Name of the documentation file to update | |
| projectPath | Yes | Path to the project root directory | |
| replaceContent | Yes | Content to replace the search content with | |
| searchContent | Yes | Content to search for in the file |
Implementation Reference
- src/index.ts:954-1029 (handler)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"] } },
- src/index.ts:453-477 (schema)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"]