UNPKG

dbx-mcp-server

Version:

A Model Context Protocol server for Dropbox integration with AI-powered PDF analysis, multi-directory indexing, and parallel processing

457 lines (338 loc) โ€ข 14.9 kB
# dbx-mcp-server A Model Context Protocol (MCP) server that provides comprehensive Dropbox integration with **AI-powered PDF analysis capabilities**. Features high-performance parallel processing, multi-directory indexing, and OpenRouter structured outputs for reliable document analysis. **Important Disclaimer:** This project is not affiliated with, endorsed by, or sponsored by Dropbox. It is an independent integration that works with Dropbox's public API. ## ๐Ÿš€ Key Features - **๐Ÿ“ Complete Dropbox Integration** - Upload, download, search, and manage files - **๐Ÿค– AI-Powered PDF Analysis** - Analyze PDFs with OpenRouter structured outputs using Gemini 2.5 Flash - **๐Ÿ“Š Document Classification** - Automatically classify documents as contracts, invoices, proposals, or reports - **๐Ÿ” Intelligent Document Search** - Index and search documents by content and metadata - **โšก High-Performance Processing** - Parallel PDF analysis with configurable batch sizes (10-30 documents) - **๐Ÿ“‚ Multi-Directory Indexing** - Index multiple directories simultaneously with targeted scoping - **๐Ÿ’ผ Business Intelligence** - Track contract expirations, overdue invoices, and document analytics - **๐Ÿข Dropbox Business Support** - Full support for team accounts with user selection - **๐Ÿ” Enterprise Security** - OAuth 2.0 with PKCE, encrypted token storage, and audit logging ## Table of Contents - [Quick Start](#quick-start) - [Claude Code Installation](#claude-code-installation) - [Manual Installation](#manual-installation) - [Authentication](#authentication) - [Available Tools](#available-tools) - [PDF Analysis Features](#pdf-analysis-features) - [Configuration](#configuration) - [Usage Examples](#usage-examples) - [Testing](#testing) - [Development](#development) - [License](#license) ## Quick Start The fastest way to get started is using [Claude Code](https://claude.ai/code) with our npm package: ```bash # Install the MCP server with Claude Code claude mcp add dbx-mcp-server -- npx -y dbx-mcp-server ``` That's it! The server is now available in Claude Code. Continue to [Authentication](#authentication) to set up your Dropbox credentials. For manual installation or development, see [Manual Installation](#manual-installation). ## Claude Code Installation ### Prerequisites - [Claude Code](https://claude.ai/code) installed - Node.js 18+ installed - Dropbox App credentials (see [Authentication](#authentication)) ### Step 1: Add the MCP Server Choose the installation scope that best fits your needs: #### For Personal Use (User Scope) ```bash # Available across all your projects claude mcp add dbx-mcp-server -s user -- npx -y dbx-mcp-server ``` #### For Team Projects (Project Scope) ```bash # Shared with your team via version control claude mcp add dbx-mcp-server -s project -- npx -y dbx-mcp-server ``` #### For Current Project Only (Local Scope) ```bash # Default - only for current project directory claude mcp add dbx-mcp-server -- npx -y dbx-mcp-server ``` ### Step 2: Configure Environment Variables Add your Dropbox credentials as environment variables: ```bash # Add with environment variables claude mcp add dbx-mcp-server -s user \ -e DROPBOX_APP_KEY=your_app_key_here \ -e DROPBOX_APP_SECRET=your_app_secret_here \ -e DROPBOX_REDIRECT_URI=http://localhost:3000/callback \ -e TOKEN_ENCRYPTION_KEY=your_32_plus_character_encryption_key \ -e OPENROUTER_API_KEY=your_openrouter_api_key_here \ -- npx -y dbx-mcp-server ``` ### Step 3: Verify Installation Check that the server is properly configured: ```bash # List all MCP servers claude mcp list # Get specific server details claude mcp get dbx-mcp-server # Test server connectivity in Claude Code /mcp ``` ### Step 4: Authenticate with Dropbox In Claude Code, ask Claude to help you authenticate: > "Help me set up authentication with Dropbox using the setup tool" Claude will guide you through the OAuth process using the `dbx_setup` tool. ### Scope Management Claude Code offers three scopes for MCP server configuration: | Scope | Storage | Use Case | Command Flag | |-------|---------|----------|--------------| | **Local** | Project-specific settings | Personal dev, testing | (default) | | **Project** | `.mcp.json` in repo | Team collaboration | `-s project` | | **User** | Global user settings | Personal utilities | `-s user` | **Project scope** is recommended for team environments as it creates a `.mcp.json` file that can be version controlled. ### Troubleshooting **Server not starting?** ```bash # Check Node.js version node --version # Should be 18+ # Test server manually npx dbx-mcp-server ``` **Environment variables not loading?** ```bash # Verify your environment variables are set claude mcp get dbx-mcp-server ``` **Permission issues?** ```bash # Reset project choices if using project scope claude mcp reset-project-choices ``` ## Manual Installation For development or custom deployments: ### 1. Clone and Install ```bash git clone https://github.com/olivierdebeuf/dbx-mcp-server.git cd dbx-mcp-server npm install npm run build ``` ### 2. Setup Dropbox App Create app at [Dropbox App Console](https://www.dropbox.com/developers/apps): - Choose "Scoped access" API - Select required permissions: `files.metadata.read`, `files.content.read`, `files.content.write`, `sharing.write`, `account_info.read` - Add redirect URI: `http://localhost:3000/callback` - Note your App key and App secret ### 3. Get OpenRouter API Key Sign up at [OpenRouter](https://openrouter.ai) for AI analysis ### 4. Configure Environment ```bash # Create .env file with: DROPBOX_APP_KEY=your_app_key DROPBOX_APP_SECRET=your_app_secret DROPBOX_REDIRECT_URI=http://localhost:3000/callback TOKEN_ENCRYPTION_KEY=your_32_plus_character_encryption_key OPENROUTER_API_KEY=your_openrouter_api_key ``` ### 5. Run Setup & Test ```bash npm run setup # Complete OAuth authentication npm run inspector # Launch MCP inspector for testing ``` ### 6. Start Analyzing PDFs! ๐ŸŽ‰ ## Authentication The server uses OAuth 2.0 with PKCE for secure authentication with Dropbox. ### Environment Variables **Required:** - `DROPBOX_APP_KEY`: Your Dropbox app's key - `DROPBOX_APP_SECRET`: Your Dropbox app's secret - `DROPBOX_REDIRECT_URI`: OAuth redirect URI - `TOKEN_ENCRYPTION_KEY`: 32+ character key for token encryption - `OPENROUTER_API_KEY`: API key for AI analysis (get from openrouter.ai) **Optional:** - `DROPBOX_BUSINESS_USER_ID`: Team member ID for Dropbox Business accounts (auto-detected) - `TOKEN_REFRESH_THRESHOLD_MINUTES`: Minutes before expiration to refresh token (default: 5) - `MAX_TOKEN_REFRESH_RETRIES`: Maximum number of refresh attempts (default: 3) - `TOKEN_REFRESH_RETRY_DELAY_MS`: Delay between refresh attempts in ms (default: 1000) ## Available Tools ### File Operations - `list_files`: List files in a directory - `upload_file`: Upload a file - `download_file`: Download a file - `safe_delete_item`: Safely delete with recycle bin support - `create_folder`: Create a new folder - `copy_item`: Copy a file or folder - `move_item`: Move or rename a file/folder ### Metadata and Search - `get_file_metadata`: Get file/folder metadata - `search_file_db`: Search files and folders - `get_sharing_link`: Create sharing links - `get_file_content`: Get file contents ### Account Operations - `get_account_info`: Get account information ### ๐Ÿค– AI-Powered PDF Analysis Tools - `dropbox_analyze_pdf`: Analyze PDF files with custom AI prompts - `dropbox_index_file`: Index a single PDF for structured document management - `dropbox_index_folder`: Batch index all PDFs in a folder - `dropbox_search_indexed`: Search indexed documents by content and metadata - `dropbox_document_stats`: Get business intelligence and document analytics ## PDF Analysis Features ### ๐ŸŽฏ Document Classification The AI system automatically classifies PDFs into four main categories: 1. **๐Ÿ“„ Contracts** - Legal agreements, service contracts, employment contracts - Extracts: parties, dates, values, terms, governing law - Tracks: expiration dates, renewal clauses, notice periods 2. **๐Ÿงพ Invoices** - Bills, invoices, receipts, payment requests - Extracts: vendor details, amounts, due dates, line items - Tracks: overdue payments, payment status, tax information 3. **๐Ÿ“‹ Proposals** - Business proposals, project proposals, quotes - Extracts: client information, project details, timelines, deliverables - Tracks: proposal validity, project scope, pricing 4. **๐Ÿ“Š Reports** - Research reports, financial reports, analysis documents - Extracts: findings, recommendations, data insights, conclusions - Tracks: report types, time periods, key metrics ### ๐Ÿ” Advanced Search & Analytics - **Content-based search** across all indexed documents - **Metadata filtering** by document type, date ranges, confidence scores - **Business intelligence queries** for expired contracts, overdue invoices - **Document statistics** and collection analytics ### ๐Ÿข Enterprise Features - **Dropbox Business support** with automatic team member detection - **Batch processing** with configurable rate limiting - **SQLite database** for persistent document metadata storage - **Confidence scoring** for AI analysis quality assessment - **Audit logging** for compliance and tracking ### ๐Ÿšซ Smart Exclusion System Control exactly which files get indexed with flexible exclusion options: - **Global exclusions** via environment variables for organization-wide rules - **Per-operation exclusions** for specific indexing tasks - **Path-based exclusions** for exact folder matching - **Pattern-based exclusions** using glob patterns like `*/temp/*`, `*.backup/` - **Built-in defaults** exclude system folders (`.git`, `node_modules`, `.DS_Store`, etc.) **Configuration Options:** ```bash # Global exclusions (applied to all indexing operations) DROPBOX_INDEX_EXCLUDED_PATHS=/private,/temp,/backup ``` **Usage Examples:** ```typescript // Exclude specific paths and patterns await mcp.useTool("dbx-mcp-server", "dropbox_index_folder", { path: "/documents", excludePaths: ["/documents/confidential"], excludePatterns: ["*/archive/*", "*/old_*"], respectGlobalExclusions: true }); ``` ## Usage Examples ### Basic File Operations ```typescript // List files in root directory await mcp.useTool("dbx-mcp-server", "list_files", { path: "" }); // Upload a file await mcp.useTool("dbx-mcp-server", "upload_file", { path: "/test.txt", content: Buffer.from("Hello World").toString("base64"), }); // Search for files await mcp.useTool("dbx-mcp-server", "search_file_db", { query: "report", path: "/Documents", max_results: 10, }); ``` ### ๐Ÿค– AI-Powered PDF Analysis ```typescript // Analyze a PDF with custom prompt await mcp.useTool("dbx-mcp-server", "dropbox_analyze_pdf", { path: "/contracts/service_agreement.pdf", prompt: "Extract key contract terms, parties involved, and expiration date", useThinking: true // Enable advanced reasoning mode }); // Index a PDF for structured search await mcp.useTool("dbx-mcp-server", "dropbox_index_file", { path: "/invoices/invoice_2024_001.pdf" }); // Batch index entire folder await mcp.useTool("dbx-mcp-server", "dropbox_index_folder", { path: "/documents", recursive: true, batchSize: 5 // Process 5 files at a time }); // Index folder with exclusions await mcp.useTool("dbx-mcp-server", "dropbox_index_folder", { path: "/documents", excludePaths: ["/documents/private", "/documents/temp"], excludePatterns: ["*/backup/*", "*/.git/*", "*/draft/*"], respectGlobalExclusions: true }); // Search indexed documents await mcp.useTool("dbx-mcp-server", "dropbox_search_indexed", { query: "overdue payments", docType: "invoice", // Filter by document type limit: 10 }); // Get document analytics await mcp.useTool("dbx-mcp-server", "dropbox_document_stats", {}); ``` ### Real-World Use Cases ```typescript // Business Intelligence: Find expiring contracts await mcp.useTool("dbx-mcp-server", "dropbox_search_indexed", { query: "expiring", docType: "contract" }); // Financial Analysis: Track overdue invoices await mcp.useTool("dbx-mcp-server", "dropbox_search_indexed", { query: "overdue", docType: "invoice" }); // Document Management: Analyze proposal success rates await mcp.useTool("dbx-mcp-server", "dropbox_document_stats", {}); ``` ## Testing Run the test suite: ```bash npm test ``` Tests verify all operations including authentication, file operations, and error handling. ### Test Structure The test suite is organized into several modules: - **Dropbox Operations**: Tests for basic file operations (upload, download, list, etc.) - **Account Operations**: Tests for accessing account information - **Search and Delete**: Tests for search functionality and safe deletion with recycle bin support - **Resource System**: Tests for the MCP resource system integration ### Handling Test Data The tests use dynamically generated file and folder names based on timestamps to avoid conflicts. Test data is automatically cleaned up after test execution. ### Running Specific Tests To run a specific test file or test group: ```bash npm test -- tests/dropbox/search-delete.test.ts # Run specific test file npm test -- -t "should search for files" # Run tests matching description ``` ### Troubleshooting Tests If tests fail with timing or authentication issues: 1. Check that the mock implementations in `tests/setup.ts` match your test expectations 2. Ensure test helpers are correctly configured 3. For Jest scope errors, avoid referencing imported variables in mock factory functions ## Development Built with: - TypeScript - Model Context Protocol SDK - Dropbox SDK v10.34.0 - Dropbox API v2 ## License MIT License Copyright (c) 2025 MCP Server Contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.