8000 feat: replace google drive tool bundle with Google Drive MCP server by tybalex · Pull Request #708 · obot-platform/tools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: replace google drive tool bundle with Google Drive MCP server #708

New issue

Have a question about this project? 8000 Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 de 8000 letions google/drive/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.13
48 changes: 48 additions & 0 deletions google/drive/README.md
8000
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Obot Google Drive MCP Server
- Obot Google Drive mcp server, converted from the google-drive tool bundle.
- supports streamable HTTP
- tools of this mcp server expect `cred_token`(access_token of google oauth) as part of the tool input.

## Installation & Running

### Option 1: Using uvx (Recommended)
install from local directory:
```bash
uvx --from . obot-google-drive-mcp
```
or stdio server:
```bash
uvx --from . obot-google-drive-mcp-stdio
```

### Option 2: Using uv (Development)
Install dependencies:
```bash
uv pip install
```

Run the server:
```bash
uv run server.py
```

## Testing

### Unit-test with pytest
```
uv run python -m pytest
```

### Integration Testing

#### Get Your Access Token
This MCP server assumes Obot will take care of the Oauth2.0 flow and supply an access token. To test locally or without Obot, you need to get an access token by yourself. I use [postman workspace](https://blog.postman.com/how-to-access-google-apis-using-oauth-in-postman/) to create and manage my tokens.

#### Local Example Client
```
export GOOGLE_OAUTH_TOKEN=xxx
```
and then
```
uv run example_client.py
```
26 changes: 7 additions & 19 deletions google/drive/apis/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
from fastmcp.exceptions import ToolError
import os
import logging

Expand Down Expand Up @@ -32,39 +33,26 @@ def setup_logger(name, tool_name: str = "Google Drive Tool"):
logger = setup_logger(__name__)


def str_to_bool(value):
"""Convert a string to a boolean."""
return str(value).lower() in ("true", "1", "yes")
def get_client(cred_token: str, service_name: str = "drive", version: str = "v3"):


def get_client(service_name: str = "drive", version: str = "v3"):
token = os.getenv("GOOGLE_OAUTH_TOKEN")
if token is None:
raise ValueError("GOOGLE_OAUTH_TOKEN environment variable is not set")

creds = Credentials(token=token)
creds = Credentials(token=cred_token)
try:
service = build(serviceName=service_name, version=version, credentials=creds)
return service
except HttpError as err:
print(err)
exit(1)


def get_obot_user_timezone():
return os.getenv("OBOT_USER_TIMEZONE", "UTC").strip()
raise ToolError(f"HttpError retrieving google {service_name} client: {err}")


def get_user_timezone(service):
"""Fetches the authenticated user's time zone from User's Google Calendar settings."""
try:
settings = service.settings().get(setting="timezone").execute()
return settings.get(
"value", get_obot_user_timezone()
) # Default to Obot's user timezone if not found
"value", "UTC"
) # Default to UTC if not found
except HttpError as err:
if err.status_code == 403:
raise Exception(f"HttpError retrieving user timezone: {err}")
raise ToolError(f"HttpError retrieving user timezone: {err}")
logger.error(f"HttpError retrieving user timezone: {err}")
return "UTC"
except Exception as e:
Expand Down
6 changes: 2 additions & 4 deletions google/drive/apis/shared_drives.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Optional, List
from googleapiclient.discovery import Resource
from googleapiclient.errors import HttpError
from fastmcp.exceptions import ToolError


def _generate_ids(service: Resource, count: int = 1, space: str = "drive") -> List[str]:
Expand Down Expand Up @@ -54,10 +55,7 @@ def list_drives(service: Resource) -> List[dict]:
return drives
except HttpError as error:
error_details = error.error_details[0] if error.error_details else {}
print(
f"An error occurred. Error code: {error.resp.status}, Error message: {error_details}"
)
return []
raise ToolError(f"Error listing drives: {error_details}")


def get_drive(service: Resource, drive_id: str) -> Optional[dict]:
Expand Down
4 changes: 2 additions & 2 deletions google/drive/apis/workspace_file.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os
import gptscript
# import gptscript
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove if not needed.

from pathlib import Path
from apis.helper import setup_logger
from gptscript.datasets import DatasetElement
# from gptscript.datasets import DatasetElement
import asyncio

logger = setup_logger(__name__)
Expand Down
20 changes: 0 additions & 20 deletions google/drive/commands/__init__.py

This file was deleted.

19 changes: 0 additions & 19 deletions google/drive/commands/copy_file.py

This file was deleted.

49 changes: 0 additions & 49 deletions google/drive/commands/create_file.py

This file was deleted.

17 changes: 0 additions & 17 deletions google/drive/commands/create_folder.py

This file was deleted.

62 changes: 0 additions & 62 deletions google/drive/commands/create_permission.py

This file was deleted.

13 changes: 0 additions & 13 deletions google/drive/commands/create_shared_drive.py

This file was deleted.

18 changes: 0 additions & 18 deletions google/drive/commands/delete_file.py

This file was deleted.

22 changes: 0 additions & 22 deletions google/drive/commands/delete_permission.py

This file was deleted.

15 changes: 0 additions & 15 deletions google/drive/commands/delete_shared_drive.py

This file was deleted.

Loading
Loading
0