@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.
Files changed (105) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +353 -2
  3. package/README.npm.md +28 -0
  4. package/auth/__init__.py +1 -0
  5. package/auth/auth_info_middleware.py +419 -0
  6. package/auth/client_secrets.py +76 -0
  7. package/auth/credential_store.py +598 -0
  8. package/auth/external_oauth_provider.py +369 -0
  9. package/auth/gateway_identity.py +164 -0
  10. package/auth/google_auth.py +1550 -0
  11. package/auth/google_oauth_provider.py +20 -0
  12. package/auth/mcp_session_middleware.py +95 -0
  13. package/auth/oauth21_session_store.py +1332 -0
  14. package/auth/oauth_callback_server.py +466 -0
  15. package/auth/oauth_config.py +693 -0
  16. package/auth/oauth_proxy_config.py +122 -0
  17. package/auth/oauth_responses.py +230 -0
  18. package/auth/oauth_types.py +92 -0
  19. package/auth/permissions.py +330 -0
  20. package/auth/port_resolver.py +153 -0
  21. package/auth/request_identity.py +89 -0
  22. package/auth/scopes.py +369 -0
  23. package/auth/service_decorator.py +1109 -0
  24. package/bin/google-workspace-mcp.cjs +123 -0
  25. package/core/__init__.py +1 -0
  26. package/core/api_enablement.py +108 -0
  27. package/core/attachment_storage.py +496 -0
  28. package/core/camel_case_middleware.py +98 -0
  29. package/core/cli.py +161 -0
  30. package/core/comments.py +609 -0
  31. package/core/config.py +57 -0
  32. package/core/context.py +43 -0
  33. package/core/file_limits.py +632 -0
  34. package/core/gcs_attachment_storage.py +253 -0
  35. package/core/http_utils.py +339 -0
  36. package/core/log_formatter.py +270 -0
  37. package/core/portable_schema_middleware.py +67 -0
  38. package/core/server.py +1192 -0
  39. package/core/startup_ui.py +239 -0
  40. package/core/storage.py +23 -0
  41. package/core/telemetry.py +194 -0
  42. package/core/tool_descriptions.py +19 -0
  43. package/core/tool_registry.py +311 -0
  44. package/core/tool_tier_loader.py +197 -0
  45. package/core/tool_tiers.yaml +179 -0
  46. package/core/toolset_header_middleware.py +67 -0
  47. package/core/utils.py +1537 -0
  48. package/core/valkey_storage.py +271 -0
  49. package/core/warning_filters.py +19 -0
  50. package/fastmcp_server.py +198 -0
  51. package/gappsscript/README.md +512 -0
  52. package/gappsscript/TESTING.md +254 -0
  53. package/gappsscript/__init__.py +0 -0
  54. package/gappsscript/apps_script_tools.py +1940 -0
  55. package/gcalendar/__init__.py +1 -0
  56. package/gcalendar/calendar_helpers.py +1323 -0
  57. package/gcalendar/calendar_tools.py +2252 -0
  58. package/gchat/__init__.py +7 -0
  59. package/gchat/chat_helpers.py +410 -0
  60. package/gchat/chat_tools.py +798 -0
  61. package/gcontacts/__init__.py +1 -0
  62. package/gcontacts/contacts_helpers.py +765 -0
  63. package/gcontacts/contacts_tools.py +1685 -0
  64. package/gdocs/__init__.py +0 -0
  65. package/gdocs/docs_anchors.py +163 -0
  66. package/gdocs/docs_comments.py +89 -0
  67. package/gdocs/docs_helpers.py +2201 -0
  68. package/gdocs/docs_links.py +87 -0
  69. package/gdocs/docs_markdown.py +828 -0
  70. package/gdocs/docs_markdown_writer.py +592 -0
  71. package/gdocs/docs_plain_text.py +463 -0
  72. package/gdocs/docs_structure.py +621 -0
  73. package/gdocs/docs_tables.py +425 -0
  74. package/gdocs/docs_tools.py +3300 -0
  75. package/gdocs/managers/__init__.py +18 -0
  76. package/gdocs/managers/batch_operation_manager.py +1694 -0
  77. package/gdocs/managers/header_footer_manager.py +526 -0
  78. package/gdocs/managers/table_operation_manager.py +488 -0
  79. package/gdocs/managers/validation_manager.py +1504 -0
  80. package/gdocs/operation_schemas.py +594 -0
  81. package/gdrive/__init__.py +0 -0
  82. package/gdrive/drive_helpers.py +1738 -0
  83. package/gdrive/drive_tools.py +3085 -0
  84. package/gforms/__init__.py +3 -0
  85. package/gforms/forms_tools.py +575 -0
  86. package/gmail/__init__.py +1 -0
  87. package/gmail/gmail_helpers.py +2107 -0
  88. package/gmail/gmail_tools.py +4895 -0
  89. package/gmail/gmail_web_mime.py +441 -0
  90. package/gsearch/__init__.py +0 -0
  91. package/gsearch/search_tools.py +253 -0
  92. package/gsheets/__init__.py +31 -0
  93. package/gsheets/sheets_helpers.py +2236 -0
  94. package/gsheets/sheets_tools.py +3280 -0
  95. package/gslides/__init__.py +0 -0
  96. package/gslides/slides_digest.py +390 -0
  97. package/gslides/slides_helpers.py +392 -0
  98. package/gslides/slides_markup.py +770 -0
  99. package/gslides/slides_tools.py +376 -0
  100. package/gtasks/__init__.py +5 -0
  101. package/gtasks/tasks_tools.py +936 -0
  102. package/main.py +1170 -0
  103. package/package.json +43 -4
  104. package/pyproject.toml +173 -0
  105. package/uv.lock +2504 -0
@@ -0,0 +1,254 @@
1
+ # Apps Script MCP Testing Guide
2
+
3
+ This document provides instructions for running unit tests and end-to-end (E2E) tests for the Apps Script MCP feature.
4
+
5
+ ## Test Structure
6
+
7
+ ```
8
+ tests/gappsscript/
9
+ __init__.py
10
+ test_apps_script_tools.py # Unit tests with mocked API
11
+ manual_test.py # E2E tests against real API
12
+ ```
13
+
14
+ ## Unit Tests
15
+
16
+ Unit tests use mocked API responses and do not require Google credentials.
17
+
18
+ ### Running Unit Tests
19
+
20
+ ```bash
21
+ # Run all Apps Script unit tests
22
+ uv run pytest tests/gappsscript/test_apps_script_tools.py -v
23
+
24
+ # Run specific test
25
+ uv run pytest tests/gappsscript/test_apps_script_tools.py::test_list_script_projects -v
26
+
27
+ # Run with coverage
28
+ uv run pytest tests/gappsscript/test_apps_script_tools.py --cov=gappsscript
29
+ ```
30
+
31
+ ### Test Coverage
32
+
33
+ Unit tests cover the `_impl` functions behind each tool plus the action-dispatch
34
+ wrappers:
35
+ - get_script_project: list (Drive API), get project, get file
36
+ - manage_script_project: create, delete
37
+ - manage_script_content: update
38
+ - run_script_function
39
+ - list_script_deployments
40
+ - manage_deployment: create, update, delete
41
+ - get_script_version: list, get
42
+ - manage_script_version: create
43
+ - get_script_activity: processes, metrics
44
+ - manage_script_trigger: list, delete
45
+
46
+ ## E2E Tests
47
+
48
+ E2E tests interact with the real Google Apps Script API. They require valid OAuth credentials and will create real resources in your Google account.
49
+
50
+ ### Prerequisites
51
+
52
+ 1. **Google Cloud Project** with Apps Script API and Drive API enabled
53
+ 2. **OAuth credentials** (Desktop application type)
54
+ 3. **Test user** added to OAuth consent screen
55
+
56
+ ### Setup
57
+
58
+ **Option 1: Default paths (recommended for CI)**
59
+
60
+ Place credentials in the project root:
61
+ ```bash
62
+ # Place your OAuth client credentials here
63
+ cp /path/to/your/client_secret.json ./client_secret.json
64
+ ```
65
+
66
+ **Option 2: Custom paths via environment variables**
67
+
68
+ ```bash
69
+ export GOOGLE_CLIENT_SECRET_PATH=/path/to/client_secret.json
70
+ export GOOGLE_TOKEN_PATH=/path/to/token.pickle
71
+ ```
72
+
73
+ ### Running E2E Tests
74
+
75
+ ```bash
76
+ # Interactive mode (prompts for confirmation)
77
+ uv run python tests/gappsscript/manual_test.py
78
+
79
+ # Non-interactive mode (for CI)
80
+ uv run python tests/gappsscript/manual_test.py --yes
81
+ ```
82
+
83
+ ### E2E Test Flow
84
+
85
+ The test script performs the following operations:
86
+
87
+ 1. **List Projects** - Lists existing Apps Script projects via Drive API
88
+ 2. **Create Project** - Creates a new test project
89
+ 3. **Get Project** - Retrieves project details
90
+ 4. **Update Content** - Adds code to the project
91
+ 5. **Run Function** - Attempts to execute a function (see note below)
92
+ 6. **Create Deployment** - Creates a versioned deployment
93
+ 7. **List Deployments** - Lists all deployments
94
+ 8. **List Processes** - Lists recent script executions
95
+
96
+ ### Cleanup
97
+
98
+ The test script does not automatically delete created projects. After running tests:
99
+
100
+ 1. Go to [Google Apps Script](https://script.google.com/)
101
+ 2. Find projects named "MCP Test Project"
102
+ 3. Delete them manually via the menu (three dots) > Remove
103
+
104
+ ## Headless Linux Testing
105
+
106
+ For headless environments (servers, CI/CD, WSL without GUI):
107
+
108
+ ### OAuth Authentication Flow
109
+
110
+ The test script uses a headless-compatible OAuth flow:
111
+
112
+ 1. Script prints an authorization URL
113
+ 2. Open the URL in any browser (can be on a different machine)
114
+ 3. Complete Google sign-in and authorization
115
+ 4. Browser redirects to `http://localhost/?code=...` (page will not load)
116
+ 5. Copy the full URL from the browser address bar
117
+ 6. Paste it into the terminal when prompted
118
+
119
+ ### Example Session
120
+
121
+ ```
122
+ $ python tests/gappsscript/manual_test.py --yes
123
+
124
+ ============================================================
125
+ HEADLESS AUTH
126
+ ============================================================
127
+
128
+ 1. Open this URL in any browser:
129
+
130
+ https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=...
131
+
132
+ 2. Sign in and authorize the app
133
+ 3. You'll be redirected to http://localhost (won't load)
134
+ 4. Copy the FULL URL from browser address bar
135
+ (looks like: http://localhost/?code=4/0A...&scope=...)
136
+ 5. Paste it below:
137
+
138
+ Paste full redirect URL: http://localhost/?code=4/0AQSTgQ...&scope=...
139
+
140
+ Building API services...
141
+
142
+ === Test: List Projects ===
143
+ Found 3 Apps Script projects:
144
+ ...
145
+ ```
146
+
147
+ ### Credential Storage
148
+
149
+ OAuth tokens are stored as pickle files:
150
+ - Default: `./test_token.pickle` in project root
151
+ - Custom: Set via `GOOGLE_TOKEN_PATH` environment variable
152
+
153
+ Tokens are reused on subsequent runs until they expire or are revoked.
154
+
155
+ ## Known Limitations and Caveats
156
+
157
+ ### run_script_function Test Failure
158
+
159
+ The "Run Function" test will fail with a 404 error unless you manually configure the script as an API Executable. This is a Google platform requirement, not a bug.
160
+
161
+ To make run_script_function work:
162
+
163
+ 1. Open the created test script in Apps Script editor
164
+ 2. Go to Project Settings > Change GCP project
165
+ 3. Enter your GCP project number
166
+ 4. Deploy as "API Executable"
167
+
168
+ For E2E testing purposes, it is acceptable for this test to fail. All other tests should pass.
169
+
170
+ ### Drive API Requirement
171
+
172
+ The `get_script_project` list action uses the Google Drive API (not the Apps Script API) because the Apps Script API does not provide a projects.list endpoint. Ensure the Drive API is enabled in your GCP project.
173
+
174
+ ### Scope Requirements
175
+
176
+ The E2E tests require these scopes:
177
+ - `script.projects` and `script.projects.readonly`
178
+ - `script.deployments` and `script.deployments.readonly`
179
+ - `script.processes`
180
+ - `drive.readonly`
181
+
182
+ If you encounter "insufficient scopes" errors, delete the stored token file and re-authenticate.
183
+
184
+ ### Rate Limits
185
+
186
+ Google enforces rate limits on the Apps Script API. If running tests repeatedly, you may encounter quota errors. Wait a few minutes before retrying.
187
+
188
+ ## CI/CD Integration
189
+
190
+ For automated testing in CI/CD pipelines:
191
+
192
+ ### Unit Tests Only (Recommended)
193
+
194
+ ```yaml
195
+ # GitHub Actions example
196
+ - name: Run unit tests
197
+ run: uv run pytest tests/gappsscript/test_apps_script_tools.py -v
198
+ ```
199
+
200
+ ### E2E Tests in CI
201
+
202
+ E2E tests require OAuth credentials. Options:
203
+
204
+ 1. **Skip E2E in CI** - Run only unit tests in CI, run E2E locally
205
+ 2. **Service Account** - Not supported (Apps Script API requires user OAuth)
206
+ 3. **Pre-authenticated Token** - Store encrypted token in CI secrets
207
+
208
+ To use a pre-authenticated token:
209
+ ```bash
210
+ # Generate token locally
211
+ python tests/gappsscript/manual_test.py
212
+
213
+ # Store test_token.pickle contents as base64 in CI secret
214
+ base64 test_token.pickle > token.b64
215
+
216
+ # In CI, restore and set path
217
+ echo $TOKEN_SECRET | base64 -d > test_token.pickle
218
+ export GOOGLE_TOKEN_PATH=./test_token.pickle
219
+ python tests/gappsscript/manual_test.py --yes
220
+ ```
221
+
222
+ Note: Tokens expire and must be refreshed periodically.
223
+
224
+ ## Troubleshooting
225
+
226
+ ### "Apps Script API has not been used in project"
227
+
228
+ Enable the Apps Script API in your GCP project:
229
+ https://console.cloud.google.com/flows/enableapi?apiid=script.googleapis.com
230
+
231
+ ### "Access Not Configured. Drive API has not been used"
232
+
233
+ Enable the Drive API in your GCP project:
234
+ https://console.cloud.google.com/flows/enableapi?apiid=drive.googleapis.com
235
+
236
+ ### "Request had insufficient authentication scopes"
237
+
238
+ Delete the token file and re-authenticate:
239
+ ```bash
240
+ rm test_token.pickle
241
+ python tests/gappsscript/manual_test.py
242
+ ```
243
+
244
+ ### "User is not authorized to access this resource"
245
+
246
+ Ensure your email is added as a test user in the OAuth consent screen configuration.
247
+
248
+ ### "Requested entity was not found" (404 on run)
249
+
250
+ The script needs to be deployed as "API Executable". See the run_script_function section above.
251
+
252
+ ### OAuth redirect fails on headless machine
253
+
254
+ The redirect to `http://localhost` is expected to fail. Copy the URL from the browser address bar (including the error page URL) and paste it into the terminal.
File without changes