save_document
Store generated documentation in a specified file path, linking it to a feature ID and document type for structured coding workflows on the Vibe-Coder MCP Server.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| documentType | Yes | ||
| featureId | Yes | ||
| filePath | No |
Implementation Reference
- src/mcp-server.ts:685-740 (handler)Primary handler and registration for the 'save_document' MCP tool. Includes inline Zod input schema, validation logic, prerequisite checks, and delegation to document storage save methods.server.tool( "save_document", { featureId: z.string().min(1), documentType: z.string().min(1), filePath: z.string().min(1).optional() }, async ({ featureId, documentType, filePath }) => { try { // Check if the feature exists const feature = getFeature(featureId); if (!feature) { throw new Error(`Feature ${featureId} not found`); } // Map the string to DocumentType enum let docType: DocumentType; if (documentType === 'prd') { docType = DocumentType.PRD; } else if (documentType === 'implementation-plan') { docType = DocumentType.IMPLEMENTATION_PLAN; } else { throw new Error(`Invalid document type: ${documentType}. Expected 'prd' or 'implementation-plan'`); } // Check if the document exists if (!documentStorage.hasDocument(feature.id, docType)) { throw new Error(`Document of type ${documentType} not found for feature ${feature.id}`); } let savedPath: string; // If a custom path was provided, use it; otherwise, save to the default path if (filePath) { savedPath = await documentStorage.saveDocumentToCustomPath(feature.id, docType, filePath); } else { savedPath = await documentStorage.saveDocumentToFile(feature.id, docType); } return { content: [{ type: "text", text: `Document saved successfully to: ${savedPath}` }] }; } catch (error) { return { content: [{ type: "text", text: `Error saving document: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } );
- src/document-storage.ts:250-267 (helper)Helper method saveDocumentToFile invoked by the tool handler to persist the document to its default file path.public async saveDocumentToFile(featureId: string, type: DocumentType): Promise<string> { const document = this.getDocument(featureId, type); if (!document) { throw new Error(`Document not found: ${featureId}:${type}`); } const filePath = document.metadata.filePath!; const dirPath = path.dirname(filePath); await this.ensureDir(dirPath); await fs.writeFile(filePath, document.content, 'utf-8'); // Update metadata document.metadata.isSaved = true; return filePath; }
- src/document-storage.ts:276-298 (helper)Helper method saveDocumentToCustomPath invoked by the tool handler when a custom filePath is provided.public async saveDocumentToCustomPath( featureId: string, type: DocumentType, customPath: string ): Promise<string> { const document = this.getDocument(featureId, type); if (!document) { throw new Error(`Document not found: ${featureId}:${type}`); } const validatedPath = this.validateCustomPath(customPath); const dirPath = path.dirname(validatedPath); await this.ensureDir(dirPath); await fs.writeFile(validatedPath, document.content, 'utf-8'); // Don't update metadata.filePath as we want to keep the default path // Just mark it as saved document.metadata.isSaved = true; return validatedPath; }