Skip to main content
Glama
crazyrabbitLTC

Vibe-Coder MCP Server

save_document

Save structured documentation for coding features by specifying feature ID, document type, and file path to organize development workflow.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
featureIdYes
documentTypeYes
filePathNo

Implementation Reference

  • The main handler function for the 'save_document' tool. Validates inputs, checks feature and document existence, maps string to DocumentType enum, and delegates saving to documentStorage helpers based on whether custom filePath is provided.
    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
        };
      }
    }
  • Zod input schema for the save_document tool parameters: featureId (required), documentType (required, e.g. 'prd'), filePath (optional custom path).
    {
      featureId: z.string().min(1),
      documentType: z.string().min(1),
      filePath: z.string().min(1).optional()
  • Registration of the save_document tool on the MCP server using server.tool(name, inputSchema, handlerFn).
    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
          };
        }
      }
    );
  • Helper function that saves a document to its default file path (computed as documents/{featureId}/{type}.md), ensures directory exists, writes content, updates isSaved metadata.
    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;
    }
  • Helper function that saves a document to a custom file path after validating it (path traversal protection, .md extension, within rootDir), ensures dir, writes content, marks saved.
    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;
    }

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/crazyrabbitLTC/mcp-vibecoder'

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