@mutallip/google-workspace-mcp 0.0.0-stage → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +353 -2
- package/README.npm.md +28 -0
- package/auth/__init__.py +1 -0
- package/auth/auth_info_middleware.py +419 -0
- package/auth/client_secrets.py +76 -0
- package/auth/credential_store.py +598 -0
- package/auth/external_oauth_provider.py +369 -0
- package/auth/gateway_identity.py +164 -0
- package/auth/google_auth.py +1550 -0
- package/auth/google_oauth_provider.py +20 -0
- package/auth/mcp_session_middleware.py +95 -0
- package/auth/oauth21_session_store.py +1332 -0
- package/auth/oauth_callback_server.py +466 -0
- package/auth/oauth_config.py +693 -0
- package/auth/oauth_proxy_config.py +122 -0
- package/auth/oauth_responses.py +230 -0
- package/auth/oauth_types.py +92 -0
- package/auth/permissions.py +330 -0
- package/auth/port_resolver.py +153 -0
- package/auth/request_identity.py +89 -0
- package/auth/scopes.py +369 -0
- package/auth/service_decorator.py +1109 -0
- package/bin/google-workspace-mcp.cjs +123 -0
- package/core/__init__.py +1 -0
- package/core/api_enablement.py +108 -0
- package/core/attachment_storage.py +496 -0
- package/core/camel_case_middleware.py +98 -0
- package/core/cli.py +161 -0
- package/core/comments.py +609 -0
- package/core/config.py +57 -0
- package/core/context.py +43 -0
- package/core/file_limits.py +632 -0
- package/core/gcs_attachment_storage.py +253 -0
- package/core/http_utils.py +339 -0
- package/core/log_formatter.py +270 -0
- package/core/portable_schema_middleware.py +67 -0
- package/core/server.py +1192 -0
- package/core/startup_ui.py +239 -0
- package/core/storage.py +23 -0
- package/core/telemetry.py +194 -0
- package/core/tool_descriptions.py +19 -0
- package/core/tool_registry.py +311 -0
- package/core/tool_tier_loader.py +197 -0
- package/core/tool_tiers.yaml +179 -0
- package/core/toolset_header_middleware.py +67 -0
- package/core/utils.py +1537 -0
- package/core/valkey_storage.py +271 -0
- package/core/warning_filters.py +19 -0
- package/fastmcp_server.py +198 -0
- package/gappsscript/README.md +512 -0
- package/gappsscript/TESTING.md +254 -0
- package/gappsscript/__init__.py +0 -0
- package/gappsscript/apps_script_tools.py +1940 -0
- package/gcalendar/__init__.py +1 -0
- package/gcalendar/calendar_helpers.py +1323 -0
- package/gcalendar/calendar_tools.py +2252 -0
- package/gchat/__init__.py +7 -0
- package/gchat/chat_helpers.py +410 -0
- package/gchat/chat_tools.py +798 -0
- package/gcontacts/__init__.py +1 -0
- package/gcontacts/contacts_helpers.py +765 -0
- package/gcontacts/contacts_tools.py +1685 -0
- package/gdocs/__init__.py +0 -0
- package/gdocs/docs_anchors.py +163 -0
- package/gdocs/docs_comments.py +89 -0
- package/gdocs/docs_helpers.py +2201 -0
- package/gdocs/docs_links.py +87 -0
- package/gdocs/docs_markdown.py +828 -0
- package/gdocs/docs_markdown_writer.py +592 -0
- package/gdocs/docs_plain_text.py +463 -0
- package/gdocs/docs_structure.py +621 -0
- package/gdocs/docs_tables.py +425 -0
- package/gdocs/docs_tools.py +3300 -0
- package/gdocs/managers/__init__.py +18 -0
- package/gdocs/managers/batch_operation_manager.py +1694 -0
- package/gdocs/managers/header_footer_manager.py +526 -0
- package/gdocs/managers/table_operation_manager.py +488 -0
- package/gdocs/managers/validation_manager.py +1504 -0
- package/gdocs/operation_schemas.py +594 -0
- package/gdrive/__init__.py +0 -0
- package/gdrive/drive_helpers.py +1738 -0
- package/gdrive/drive_tools.py +3085 -0
- package/gforms/__init__.py +3 -0
- package/gforms/forms_tools.py +575 -0
- package/gmail/__init__.py +1 -0
- package/gmail/gmail_helpers.py +2107 -0
- package/gmail/gmail_tools.py +4895 -0
- package/gmail/gmail_web_mime.py +441 -0
- package/gsearch/__init__.py +0 -0
- package/gsearch/search_tools.py +253 -0
- package/gsheets/__init__.py +31 -0
- package/gsheets/sheets_helpers.py +2236 -0
- package/gsheets/sheets_tools.py +3280 -0
- package/gslides/__init__.py +0 -0
- package/gslides/slides_digest.py +390 -0
- package/gslides/slides_helpers.py +392 -0
- package/gslides/slides_markup.py +770 -0
- package/gslides/slides_tools.py +376 -0
- package/gtasks/__init__.py +5 -0
- package/gtasks/tasks_tools.py +936 -0
- package/main.py +1170 -0
- package/package.json +43 -4
- package/pyproject.toml +173 -0
- package/uv.lock +2504 -0
package/core/cli.py
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Persistent CLI wrapper for interacting with a running Workspace MCP server.
|
|
3
|
+
|
|
4
|
+
Reuses the project's existing FileTreeStore and FernetEncryptionWrapper to
|
|
5
|
+
cache OAuth tokens on disk so that ``fastmcp list/call`` does not re-trigger
|
|
6
|
+
the full browser-based OAuth flow on every invocation.
|
|
7
|
+
|
|
8
|
+
Usage::
|
|
9
|
+
|
|
10
|
+
uv run workspace-cli list
|
|
11
|
+
uv run workspace-cli call search_gmail_messages query="is:unread" max_results=5
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import argparse
|
|
15
|
+
import asyncio
|
|
16
|
+
import json
|
|
17
|
+
import logging
|
|
18
|
+
import os
|
|
19
|
+
import stat
|
|
20
|
+
import sys
|
|
21
|
+
from typing import Any
|
|
22
|
+
|
|
23
|
+
from cryptography.fernet import Fernet
|
|
24
|
+
from fastmcp import Client
|
|
25
|
+
from fastmcp.client.auth import OAuth
|
|
26
|
+
from key_value.aio.wrappers.encryption import FernetEncryptionWrapper
|
|
27
|
+
|
|
28
|
+
from core.storage import make_sanitized_file_store
|
|
29
|
+
|
|
30
|
+
logger = logging.getLogger(__name__)
|
|
31
|
+
|
|
32
|
+
DEFAULT_URL = "http://localhost:8000/mcp"
|
|
33
|
+
CLI_HOME = os.path.expanduser("~/.workspace-mcp")
|
|
34
|
+
TOKEN_DIR = os.path.join(CLI_HOME, "cli-tokens")
|
|
35
|
+
KEY_PATH = os.path.join(CLI_HOME, ".cli-encryption-key")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _get_token_storage() -> FernetEncryptionWrapper:
|
|
39
|
+
"""Return an encrypted, disk-backed token store.
|
|
40
|
+
|
|
41
|
+
On first run the directory tree and a random Fernet key are created.
|
|
42
|
+
The key file is restricted to owner-only access (0o600).
|
|
43
|
+
"""
|
|
44
|
+
os.makedirs(TOKEN_DIR, exist_ok=True)
|
|
45
|
+
|
|
46
|
+
try:
|
|
47
|
+
fd = os.open(KEY_PATH, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
|
|
48
|
+
except FileExistsError:
|
|
49
|
+
with open(KEY_PATH, "rb") as fh:
|
|
50
|
+
key = fh.read()
|
|
51
|
+
else:
|
|
52
|
+
key = Fernet.generate_key()
|
|
53
|
+
try:
|
|
54
|
+
os.write(fd, key)
|
|
55
|
+
finally:
|
|
56
|
+
os.close(fd)
|
|
57
|
+
os.chmod(KEY_PATH, stat.S_IRUSR | stat.S_IWUSR)
|
|
58
|
+
|
|
59
|
+
return FernetEncryptionWrapper(
|
|
60
|
+
key_value=make_sanitized_file_store(TOKEN_DIR),
|
|
61
|
+
fernet=Fernet(key),
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _build_oauth() -> OAuth:
|
|
66
|
+
"""Build an OAuth helper with persistent encrypted token storage."""
|
|
67
|
+
storage = _get_token_storage()
|
|
68
|
+
return OAuth(token_storage=storage)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _coerce_cli_value(value: str) -> Any:
|
|
72
|
+
"""Parse a CLI value as JSON, but keep the raw text whenever it is a string.
|
|
73
|
+
|
|
74
|
+
``max_results=5`` still becomes ``int(5)``, while a quoted value such as
|
|
75
|
+
``query='"grow therapy"'`` keeps its quotes instead of being unwrapped into
|
|
76
|
+
``grow therapy``, which would break Gmail phrase matching.
|
|
77
|
+
"""
|
|
78
|
+
try:
|
|
79
|
+
parsed = json.loads(value)
|
|
80
|
+
except json.JSONDecodeError:
|
|
81
|
+
return value
|
|
82
|
+
return value if isinstance(parsed, str) else parsed
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
async def _list_tools(url: str) -> None:
|
|
86
|
+
"""Connect, authenticate once, and print available tools."""
|
|
87
|
+
try:
|
|
88
|
+
auth = _build_oauth()
|
|
89
|
+
except Exception as e:
|
|
90
|
+
print(
|
|
91
|
+
f"Error: failed to initialize OAuth ({type(e).__name__})", file=sys.stderr
|
|
92
|
+
)
|
|
93
|
+
sys.exit(1)
|
|
94
|
+
try:
|
|
95
|
+
async with Client(url, auth=auth) as client:
|
|
96
|
+
tools = await client.list_tools()
|
|
97
|
+
except Exception as e:
|
|
98
|
+
print(f"Error: failed to list tools ({type(e).__name__})", file=sys.stderr)
|
|
99
|
+
sys.exit(1)
|
|
100
|
+
for tool in tools:
|
|
101
|
+
desc = (tool.description or "").split("\n")[0]
|
|
102
|
+
print(f" {tool.name:40s} {desc}")
|
|
103
|
+
print(f"\n{len(tools)} tools available")
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
async def _call_tool(url: str, tool_name: str, raw_args: list[str]) -> None:
|
|
107
|
+
"""Connect, authenticate once, call a single tool, and print the result."""
|
|
108
|
+
kwargs: dict[str, Any] = {}
|
|
109
|
+
for arg in raw_args:
|
|
110
|
+
if "=" not in arg:
|
|
111
|
+
print(f"Error: argument '{arg}' must be in key=value form", file=sys.stderr)
|
|
112
|
+
sys.exit(1)
|
|
113
|
+
k, v = arg.split("=", 1)
|
|
114
|
+
kwargs[k] = _coerce_cli_value(v)
|
|
115
|
+
|
|
116
|
+
async with Client(url, auth=_build_oauth()) as client:
|
|
117
|
+
result = await client.call_tool(tool_name, kwargs)
|
|
118
|
+
for block in result.content:
|
|
119
|
+
if hasattr(block, "text"):
|
|
120
|
+
try:
|
|
121
|
+
parsed = json.loads(block.text)
|
|
122
|
+
print(json.dumps(parsed, indent=2))
|
|
123
|
+
except (json.JSONDecodeError, TypeError):
|
|
124
|
+
print(block.text)
|
|
125
|
+
else:
|
|
126
|
+
print(block)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def main() -> None:
|
|
130
|
+
parser = argparse.ArgumentParser(
|
|
131
|
+
prog="workspace-cli",
|
|
132
|
+
description="CLI for Workspace MCP with persistent OAuth token caching",
|
|
133
|
+
)
|
|
134
|
+
parser.add_argument(
|
|
135
|
+
"--url",
|
|
136
|
+
default=os.getenv("WORKSPACE_MCP_URL", DEFAULT_URL),
|
|
137
|
+
help=f"MCP server URL (default: {DEFAULT_URL})",
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
sub = parser.add_subparsers(dest="command")
|
|
141
|
+
|
|
142
|
+
sub.add_parser("list", help="List available tools")
|
|
143
|
+
|
|
144
|
+
call_parser = sub.add_parser("call", help="Call a tool")
|
|
145
|
+
call_parser.add_argument("tool", help="Tool name")
|
|
146
|
+
call_parser.add_argument("args", nargs="*", help="key=value arguments")
|
|
147
|
+
|
|
148
|
+
args = parser.parse_args()
|
|
149
|
+
|
|
150
|
+
if not args.command:
|
|
151
|
+
parser.print_help()
|
|
152
|
+
sys.exit(1)
|
|
153
|
+
|
|
154
|
+
if args.command == "list":
|
|
155
|
+
asyncio.run(_list_tools(args.url))
|
|
156
|
+
elif args.command == "call":
|
|
157
|
+
asyncio.run(_call_tool(args.url, args.tool, args.args))
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
if __name__ == "__main__":
|
|
161
|
+
main()
|