Metadata-Version: 2.5
Name: barie-google-drive-mcp
Version: 0.1.6
Summary: Google Drive MCP Server for managing files and folders via the Model Context Protocol
Author-email: Barie <support@barie.ai>
License: MIT
Keywords: google-api,google-drive,mcp,model-context-protocol
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.10
Requires-Dist: google-api-python-client>=2.130.0
Requires-Dist: google-auth-httplib2>=0.2.0
Requires-Dist: google-auth-oauthlib>=1.2.0
Requires-Dist: google-auth>=2.29.0
Requires-Dist: httplib2>=0.19.0
Requires-Dist: mcp<2.0.0,>=0.9.0
Requires-Dist: pydantic>=2.0.0
Description-Content-Type: text/markdown

# Google Drive MCP Server

An MCP server for managing files and folders in Google Drive, integrating seamlessly with AI assistants using the Model Context Protocol.

## Features

- **List Files/Folders**: Search and list files with advanced query support.
- **Get Metadata**: Retrieve detailed information about specific files or folders.
- **Manage Folders**: Create new folders and organize content.
- **Organize Content**: Move, copy, and delete (or trash) files.
- **Trash Management**: List trashed items and restore by file ID or name.
- **Export**: Export Google Docs, Sheets, and Slides to formats like PDF or DOCX.
- **Download / Upload**: Download files or whole folders into a local workspace, edit them, and upload them back (update in place or create new).

## Installation

### Prerequisites

- Python 3.9 or higher.
- A Google Cloud Project with the Drive API enabled.
- OAuth2 credentials (Client ID and Client Secret).
- OAuth scope: `["https://www.googleapis.com/auth/drive"]`.

### Local Setup

1. Install dependencies:
   ```bash
   pip install -e .
   ```

2. Run the server:
   ```bash
   python main.py --access-token <TOKEN> --refresh-token <REFRESH_TOKEN> --client-id <CLIENT_ID> --client-secret <CLIENT_SECRET>
   ```

## Configuration

Add the following to your MCP host configuration (e.g., `mcp-config.json`):

```json
{
  "mcpServers": {
    "barie-google-drive-mcp": {
      "command": "uvx",
      "args": [
        "barie-google-drive-mcp",
        "--access-token",
        "YOUR_ACCESS_TOKEN",
        "--refresh-token",
        "YOUR_REFRESH_TOKEN",
        "--client-id",
        "YOUR_CLIENT_ID",
        "--client-secret",
        "YOUR_CLIENT_SECRET"
      ]
    }
  }
}
```

## Tools

- `list_files`: Search and list files.
- `get_file_metadata`: Get file details.
- `create_folder`: Create a new folder.
- `delete_file`: Delete or trash a file.
- `move_file`: Move a file to a new folder.
- `copy_file`: Copy a file.
- `export_file`: Export Google Workspace files and return base64 content with metadata.
- `list_trashed_files`: List files/folders currently in trash.
- `restore_file`: Restore trashed files/folders by `fileId` or `name`.
- `download_file`: Download a file or folder into the workspace and return the local path(s).
- `upload_file`: Upload a workspace file or folder; with `fileId` it updates the existing Drive file in place.

## Download / Upload

Files are transferred between Drive and a local workspace directory; file content is never
returned in the tool result, only the local path.

| Option | Default | Description |
|---|---|---|
| `--workspace-dir` | `/home/workspace` | All local paths must be inside this directory |
| `--max-file-size-mb` | `20` | Max size of one file |
| `--max-total-size-mb` | `100` | Max total size of a folder transfer |
| `--max-files` | `20` | Max number of files in a folder transfer |

Typical agent flow:

1. `download_file {"fileId": "abc123"}` → `{"localPath": "/home/workspace/budget.xlsx", "modifiedTime": "..."}`
2. The agent edits `/home/workspace/budget.xlsx`.
3. `upload_file {"path": "/home/workspace/budget.xlsx", "fileId": "abc123", "expected_modified_time": "..."}`

Behavior:
- Google Docs/Sheets/Slides/Drawings are exported on download (docx/xlsx/pptx/png by default, or
  `export_format`). An edited docx/xlsx/pptx can update the original Google file in place.
- `upload_file` with `fileId` keeps the file ID, link and sharing; the previous content stays in
  Drive version history. Without `fileId` a new file is created in `parentId` (or My Drive).
- Folders: a folder ID downloads the whole tree. Uploading a directory with a folder `fileId`
  updates changed same-name files (unchanged ones are skipped), creates new ones, and never deletes anything.
- `expected_modified_time` makes the update fail if the Drive file changed since it was downloaded.

## Restore Tool Behavior

`restore_file` supports two modes:

1. Restore by ID:
```json
{ "fileId": "FILE_ID" }
```

2. Restore by name:
```json
{
  "name": "report",
  "exactMatch": false,
  "restoreAllMatches": false
}
```

Notes:
- Provide either `fileId` or `name`.
- When restoring by name and multiple files match, only the first is restored unless `restoreAllMatches` is `true`.

## License

MIT
