@mcp-z/server
    Preparing search index...

    Function createFileServingRouter

    • Create an Express router for serving files from a resource store

      Features:

      • Path traversal protection
      • File existence validation
      • Automatic original filename extraction from ID-prefixed filenames
      • Configurable Content-Type and Content-Disposition headers
      • Standard error responses (403, 404, 500)

      Parameters

      Returns Router

      Express router ready to mount on an Express app

      // Simple PDF server
      const router = createFileServingRouter(
      { resourceStoreUri: 'file:///tmp/pdfs' },
      { contentType: 'application/pdf', contentDisposition: 'attachment' }
      );
      app.use('/files', router);
      // Multi-format server with dynamic content type and custom delimiter
      const router = createFileServingRouter(
      { resourceStoreUri: 'file:///tmp/exports', delimiter: '_' },
      {
      contentType: (filename) => {
      if (filename.endsWith('.pdf')) return 'application/pdf';
      if (filename.endsWith('.csv')) return 'text/csv';
      if (filename.endsWith('.txt')) return 'text/plain';
      return 'application/octet-stream';
      },
      contentDisposition: 'inline',
      }
      );
      app.use('/exports', router);