google-services-mcp 0.1.0-beta.25
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 +302 -0
- package/dist/auth/config.d.ts +43 -0
- package/dist/auth/config.d.ts.map +1 -0
- package/dist/auth/config.js +108 -0
- package/dist/auth/config.js.map +1 -0
- package/dist/auth/manager.d.ts +50 -0
- package/dist/auth/manager.d.ts.map +1 -0
- package/dist/auth/manager.js +140 -0
- package/dist/auth/manager.js.map +1 -0
- package/dist/auth/oauth.d.ts +49 -0
- package/dist/auth/oauth.d.ts.map +1 -0
- package/dist/auth/oauth.js +211 -0
- package/dist/auth/oauth.js.map +1 -0
- package/dist/auth/store.d.ts +18 -0
- package/dist/auth/store.d.ts.map +1 -0
- package/dist/auth/store.js +45 -0
- package/dist/auth/store.js.map +1 -0
- package/dist/cli.d.ts +7 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +128 -0
- package/dist/cli.js.map +1 -0
- package/dist/main.d.ts +3 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +21 -0
- package/dist/main.js.map +1 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +28 -0
- package/dist/server.js.map +1 -0
- package/dist/services/calendar.d.ts +77 -0
- package/dist/services/calendar.d.ts.map +1 -0
- package/dist/services/calendar.js +141 -0
- package/dist/services/calendar.js.map +1 -0
- package/dist/services/contacts-tasks.d.ts +61 -0
- package/dist/services/contacts-tasks.d.ts.map +1 -0
- package/dist/services/contacts-tasks.js +103 -0
- package/dist/services/contacts-tasks.js.map +1 -0
- package/dist/services/docs.d.ts +30 -0
- package/dist/services/docs.d.ts.map +1 -0
- package/dist/services/docs.js +60 -0
- package/dist/services/docs.js.map +1 -0
- package/dist/services/drive.d.ts +51 -0
- package/dist/services/drive.d.ts.map +1 -0
- package/dist/services/drive.js +80 -0
- package/dist/services/drive.js.map +1 -0
- package/dist/services/forms.d.ts +28 -0
- package/dist/services/forms.d.ts.map +1 -0
- package/dist/services/forms.js +54 -0
- package/dist/services/forms.js.map +1 -0
- package/dist/services/gmail.d.ts +64 -0
- package/dist/services/gmail.d.ts.map +1 -0
- package/dist/services/gmail.js +144 -0
- package/dist/services/gmail.js.map +1 -0
- package/dist/services/sheets.d.ts +44 -0
- package/dist/services/sheets.d.ts.map +1 -0
- package/dist/services/sheets.js +53 -0
- package/dist/services/sheets.js.map +1 -0
- package/dist/services/slides.d.ts +28 -0
- package/dist/services/slides.d.ts.map +1 -0
- package/dist/services/slides.js +54 -0
- package/dist/services/slides.js.map +1 -0
- package/dist/services/youtube.d.ts +40 -0
- package/dist/services/youtube.d.ts.map +1 -0
- package/dist/services/youtube.js +91 -0
- package/dist/services/youtube.js.map +1 -0
- package/dist/tools/index.d.ts +3 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +659 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/util/result.d.ts +29 -0
- package/dist/util/result.d.ts.map +1 -0
- package/dist/util/result.js +21 -0
- package/dist/util/result.js.map +1 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nabheet S. Sandhu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
# google-services-mcp
|
|
2
|
+
|
|
3
|
+
MCP (Model Context Protocol) server that gives AI agents direct access to your
|
|
4
|
+
Google services — **Gmail, Calendar, Google Meet, Drive, Contacts, Tasks,
|
|
5
|
+
Sheets, Docs, Slides, YouTube, and Forms** — with multi-account OAuth support.
|
|
6
|
+
|
|
7
|
+
Add one account, wire the server into any MCP-compatible AI client, and your
|
|
8
|
+
agent can read and send email, manage your calendar, find files in Drive,
|
|
9
|
+
create documents and spreadsheets, and more — using your real Google data.
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Gmail** — send, list, read, modify, and reply to messages
|
|
14
|
+
- **Calendar** — list calendars, create/read/update/delete events, create Google Meet links
|
|
15
|
+
- **Drive** — list, read, upload, update, delete, and share files
|
|
16
|
+
- **Contacts** — list, search, and create contacts
|
|
17
|
+
- **Tasks** — list task lists, create/complete/delete tasks
|
|
18
|
+
- **Sheets** — create spreadsheets, read/write/append cell ranges, batch update
|
|
19
|
+
- **Docs** — create documents, read text, insert/replace text, batch update
|
|
20
|
+
- **Slides** — create presentations, add/delete slides, find-and-replace text
|
|
21
|
+
- **YouTube** — search videos, manage uploads/playlists/subscriptions
|
|
22
|
+
- **Forms** — create forms, add questions, read responses
|
|
23
|
+
- **Multi-account** — connect several Google accounts, set a default, or pass an `account` argument to any tool
|
|
24
|
+
- **OAuth 2.0** — one-time browser authorization; tokens are stored locally and refreshed automatically
|
|
25
|
+
|
|
26
|
+
> **60 tools** across 11 services, all prefixed `google_`. Full reference:
|
|
27
|
+
> [docs/TOOLS.md](docs/TOOLS.md).
|
|
28
|
+
|
|
29
|
+
## Requirements
|
|
30
|
+
|
|
31
|
+
- Node.js **24+** (CI runs Node 24; local dev on 26)
|
|
32
|
+
- A Google Cloud project with the required APIs enabled and an OAuth 2.0
|
|
33
|
+
**Desktop app** client (one-time setup, ~10 minutes — see below)
|
|
34
|
+
|
|
35
|
+
## Install
|
|
36
|
+
|
|
37
|
+
No install needed — run straight from npm via `npx`:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npx -y google-services-mcp --version
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`npx` downloads the package on first run and caches it. Every command in
|
|
44
|
+
this README (`add`, `list`, `status`, ...) works the same way:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npx -y google-services-mcp add personal
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
> **Pin a version for reproducibility** — check the current release with
|
|
51
|
+
> `npm view google-services-mcp version`, then run an exact version:
|
|
52
|
+
>
|
|
53
|
+
> ```bash
|
|
54
|
+
> npx -y google-services-mcp@<version> add personal
|
|
55
|
+
> ```
|
|
56
|
+
>
|
|
57
|
+
> MCP clients auto-launch this server, so pinning avoids surprise breakage
|
|
58
|
+
> when a new release ships.
|
|
59
|
+
|
|
60
|
+
### Alternative: global install
|
|
61
|
+
|
|
62
|
+
Prefer a persistent `google-services-mcp` command (and faster MCP client
|
|
63
|
+
startup)?
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
npm install -g google-services-mcp
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Then replace `npx -y google-services-mcp` with `google-services-mcp`
|
|
70
|
+
everywhere below.
|
|
71
|
+
|
|
72
|
+
### Release channels
|
|
73
|
+
|
|
74
|
+
- `latest` — stable releases, published automatically on every merge to `main`
|
|
75
|
+
- `beta` — staging builds, published manually from `main`
|
|
76
|
+
(e.g. `0.x.x-beta.0`)
|
|
77
|
+
|
|
78
|
+
Try the staging channel without touching your stable install:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
npx -y google-services-mcp@beta --version
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
All publishes are signed with npm **provenance** (trusted publishing via
|
|
85
|
+
GitHub Actions OIDC) — no npm token is stored in CI.
|
|
86
|
+
|
|
87
|
+
## Quick start
|
|
88
|
+
|
|
89
|
+
1. **Add a Google account** — opens your browser for one-time authorization:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
npx -y google-services-mcp add personal
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
2. **Register the server** with your MCP client (see
|
|
96
|
+
[MCP client configuration](#mcp-client-configuration) for Claude Desktop,
|
|
97
|
+
opencode, and generic configs).
|
|
98
|
+
|
|
99
|
+
3. **Start using it** — ask your agent to "check my email" or "add an event to
|
|
100
|
+
my calendar". Or add more accounts any time: `npx -y google-services-mcp add work`.
|
|
101
|
+
|
|
102
|
+
## MCP client configuration
|
|
103
|
+
|
|
104
|
+
The server speaks MCP over stdio. Point your client at the
|
|
105
|
+
`google-services-mcp` package via `npx` and pass your OAuth credentials via
|
|
106
|
+
environment variables. (If you installed globally, use `google-services-mcp`
|
|
107
|
+
as the command instead.)
|
|
108
|
+
|
|
109
|
+
### opencode
|
|
110
|
+
|
|
111
|
+
In `opencode.json` (or your global config):
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
{
|
|
115
|
+
"mcp": {
|
|
116
|
+
"google-services-mcp": {
|
|
117
|
+
"type": "local",
|
|
118
|
+
"command": ["npx", "-y", "google-services-mcp"],
|
|
119
|
+
"enabled": true,
|
|
120
|
+
"environment": {
|
|
121
|
+
"GOOGLE_MCP_CLIENT_ID": "your-client-id",
|
|
122
|
+
"GOOGLE_MCP_CLIENT_SECRET": "your-client-secret"
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Claude Desktop / Cursor / other MCP clients
|
|
130
|
+
|
|
131
|
+
In the client's MCP settings file (e.g. `claude_desktop_config.json`):
|
|
132
|
+
|
|
133
|
+
```json
|
|
134
|
+
{
|
|
135
|
+
"mcpServers": {
|
|
136
|
+
"google-services-mcp": {
|
|
137
|
+
"command": "npx",
|
|
138
|
+
"args": ["-y", "google-services-mcp"],
|
|
139
|
+
"env": {
|
|
140
|
+
"GOOGLE_MCP_CLIENT_ID": "your-client-id",
|
|
141
|
+
"GOOGLE_MCP_CLIENT_SECRET": "your-client-secret"
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Google Cloud setup (one-time)
|
|
149
|
+
|
|
150
|
+
Each installation uses its own OAuth client — credentials are per-user and
|
|
151
|
+
never shared.
|
|
152
|
+
|
|
153
|
+
### 1. Create a project
|
|
154
|
+
|
|
155
|
+
Open the [Google Cloud Console](https://console.cloud.google.com/), choose
|
|
156
|
+
**Select a project → New Project**, and name it (e.g. `google-services-mcp`).
|
|
157
|
+
|
|
158
|
+
### 2. Configure the OAuth consent screen
|
|
159
|
+
|
|
160
|
+
**APIs & Services → OAuth consent screen**:
|
|
161
|
+
|
|
162
|
+
1. User type: **External** (required for regular Google accounts).
|
|
163
|
+
2. App name: anything you like (e.g. `Google Service MCP`); support email = yours.
|
|
164
|
+
3. Under **Audience → Test users**, click **Add users** and enter **every Google
|
|
165
|
+
account that will use this server**. While the app is in Testing mode,
|
|
166
|
+
accounts not on this list get `access blocked` on the consent screen.
|
|
167
|
+
|
|
168
|
+
### 3. Enable the required APIs
|
|
169
|
+
|
|
170
|
+
**APIs & Services → Library**, search and **Enable** each:
|
|
171
|
+
|
|
172
|
+
`Gmail API` · `Google Calendar API` · `Google Drive API` · `People API` ·
|
|
173
|
+
`Google Tasks API` · `Google Sheets API` · `Google Docs API` ·
|
|
174
|
+
`Google Slides API` · `YouTube Data API v3` · `Google Forms API`
|
|
175
|
+
|
|
176
|
+
> **Automated:** with the `gcloud` CLI installed and authenticated
|
|
177
|
+
> (`gcloud auth login`), enable all 10 APIs at once — idempotent, safe to
|
|
178
|
+
> re-run:
|
|
179
|
+
>
|
|
180
|
+
> ```bash
|
|
181
|
+
> bash scripts/enable-apis.sh --project your-project-id
|
|
182
|
+
> ```
|
|
183
|
+
|
|
184
|
+
### 4. Create OAuth client credentials
|
|
185
|
+
|
|
186
|
+
**APIs & Services → Credentials → Create Credentials → OAuth client ID**:
|
|
187
|
+
|
|
188
|
+
1. Application type: **Desktop app**.
|
|
189
|
+
2. Authorized redirect URIs: `http://localhost:8787`.
|
|
190
|
+
3. Copy the **Client ID** and **Client Secret**.
|
|
191
|
+
|
|
192
|
+
### 5. Provide the credentials
|
|
193
|
+
|
|
194
|
+
Set these environment variables (or put them in your MCP client config as
|
|
195
|
+
above):
|
|
196
|
+
|
|
197
|
+
```
|
|
198
|
+
GOOGLE_MCP_CLIENT_ID=<your-oauth-client-id>
|
|
199
|
+
GOOGLE_MCP_CLIENT_SECRET=<your-oauth-client-secret>
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Optional:
|
|
203
|
+
|
|
204
|
+
```
|
|
205
|
+
GOOGLE_MCP_DIR=~/.google-services-mcp # where config and tokens live (default ~/.google-services-mcp)
|
|
206
|
+
GOOGLE_MCP_REDIRECT_PORT=8787 # local loopback port for OAuth (default 8787)
|
|
207
|
+
# Full redirect URI override. Takes precedence over REDIRECT_PORT and must
|
|
208
|
+
# exactly match a URI registered for this OAuth client in the Cloud Console.
|
|
209
|
+
# GOOGLE_MCP_REDIRECT_URI=http://127.0.0.1:8787/oauth2callback
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### 6. Connect your first account
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
npx -y google-services-mcp add personal
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
A browser opens to the Google consent screen. After you approve, the account is
|
|
219
|
+
stored in `~/.google-services-mcp/accounts/` and ready to use. Repeat with a
|
|
220
|
+
different name (e.g. `work`) to connect more accounts.
|
|
221
|
+
|
|
222
|
+
## CLI reference
|
|
223
|
+
|
|
224
|
+
```
|
|
225
|
+
npx -y google-services-mcp # run the MCP server over stdio
|
|
226
|
+
npx -y google-services-mcp add <name> # add a Google account (opens browser)
|
|
227
|
+
npx -y google-services-mcp list # list connected accounts
|
|
228
|
+
npx -y google-services-mcp remove <name> # remove an account
|
|
229
|
+
npx -y google-services-mcp set-default <name> # set the default account
|
|
230
|
+
npx -y google-services-mcp status # show config and token health
|
|
231
|
+
npx -y google-services-mcp --help # show help
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## For AI agents
|
|
235
|
+
|
|
236
|
+
- All tools are prefixed `google_`, e.g. `google_gmail_list`,
|
|
237
|
+
`google_calendar_list_events`, `google_drive_list_files`.
|
|
238
|
+
- The `account` argument selects which connected account a tool uses;
|
|
239
|
+
omit it to use the default account.
|
|
240
|
+
- Agents can connect new accounts themselves via the **`account_add`** tool —
|
|
241
|
+
it opens the browser consent flow without needing the CLI.
|
|
242
|
+
- See [docs/TOOLS.md](docs/TOOLS.md) for the full tool reference.
|
|
243
|
+
|
|
244
|
+
## Security
|
|
245
|
+
|
|
246
|
+
- OAuth tokens are stored in `~/.google-services-mcp/accounts/<account-name>.json`
|
|
247
|
+
with restrictive file permissions. Keep them private — never commit them.
|
|
248
|
+
- The server never logs tokens or credentials.
|
|
249
|
+
- Scopes requested: Gmail modify, Calendar, Drive, Contacts, Tasks, Sheets,
|
|
250
|
+
Docs, Slides, YouTube, Forms, plus `userinfo.email` for account display.
|
|
251
|
+
- If a client secret is ever exposed, rotate it in the Google Cloud Console
|
|
252
|
+
(Credentials → your OAuth client → rotate secret).
|
|
253
|
+
|
|
254
|
+
## Troubleshooting
|
|
255
|
+
|
|
256
|
+
| Symptom | Cause / fix |
|
|
257
|
+
|---|---|
|
|
258
|
+
| `access blocked` on consent | Account not in **Test users** (setup step 2.3) — add it and retry |
|
|
259
|
+
| `redirect_uri_mismatch` | Redirect URI must be exactly `http://localhost:8787` — no trailing slash — and match what your OAuth client allows |
|
|
260
|
+
| Tokens stop working after ~7 days | App is in **Testing** mode — re-run `add`, or **Publish app** on the consent screen |
|
|
261
|
+
| `npx: command not found` in the MCP client | GUI clients (Claude Desktop, Cursor) may not inherit your shell PATH — use the absolute path to `npx` (e.g. `/usr/local/bin/npx`) or install globally |
|
|
262
|
+
| `Google hasn't verified this app` | Normal for unverified apps — click **Advanced → Continue** for personal use |
|
|
263
|
+
|
|
264
|
+
## Local development
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
git clone https://github.com/nabheet/google-services-mcp.git
|
|
268
|
+
cd google-services-mcp
|
|
269
|
+
npm install
|
|
270
|
+
npm run build # compile to dist/
|
|
271
|
+
npm test # vitest, TDD suites
|
|
272
|
+
npm run typecheck # tsc --noEmit
|
|
273
|
+
npm run dev # run from source with tsx
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
See [AGENTS.md](AGENTS.md) for architecture and conventions.
|
|
277
|
+
|
|
278
|
+
## Releases (maintainers)
|
|
279
|
+
|
|
280
|
+
All publishing happens from GitHub Actions — no local npm login needed:
|
|
281
|
+
|
|
282
|
+
1. **Stable** — every merge to `main` auto-publishes the next patch version
|
|
283
|
+
to `latest` with provenance, then creates a `vX.Y.Z` tag and GitHub
|
|
284
|
+
release. No manual steps. The next version is derived from the last
|
|
285
|
+
published `latest` on npm, so repeated merges never collide; an
|
|
286
|
+
intentional minor/major bump in `package.json` is honored.
|
|
287
|
+
2. **Staging** — manual beta builds from `main`: **Actions → CI
|
|
288
|
+
→ Run workflow**. Publishes a `beta` build (`0.1.1-beta.X`) under the
|
|
289
|
+
`beta` dist-tag with provenance.
|
|
290
|
+
|
|
291
|
+
Prerelease tags `v*-beta*` publish to `beta` with a prerelease GitHub release
|
|
292
|
+
(patch/minor builds for milestone testing). Publishing uses npm **trusted
|
|
293
|
+
publishing** (OIDC): configure it once per package at
|
|
294
|
+
`npmjs.com/package/google-services-mcp/access` with the GitHub repository
|
|
295
|
+
`nabheet/google-services-mcp` and workflow name `ci.yml`.
|
|
296
|
+
npm allows **one trusted publisher per package** and validates the calling
|
|
297
|
+
workflow's filename — all channels run from the same `ci.yml` file.
|
|
298
|
+
No `NPM_TOKEN` secret is required.
|
|
299
|
+
|
|
300
|
+
## License
|
|
301
|
+
|
|
302
|
+
MIT
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for the OAuth client and server defaults.
|
|
3
|
+
*
|
|
4
|
+
* Credentials come from (in order of precedence):
|
|
5
|
+
* 1. Environment variables GOOGLE_MCP_CLIENT_ID / GOOGLE_MCP_CLIENT_SECRET
|
|
6
|
+
* 2. The config file at <dir>/config.json
|
|
7
|
+
*
|
|
8
|
+
* The data directory defaults to ~/.google-services-mcp and can be overridden with
|
|
9
|
+
* GOOGLE_MCP_DIR.
|
|
10
|
+
*/
|
|
11
|
+
export declare const DEFAULT_REDIRECT_PORT = 8787;
|
|
12
|
+
/** Scopes requested when adding an account. Covers all services this server exposes. */
|
|
13
|
+
export declare const DEFAULT_SCOPES: string[];
|
|
14
|
+
export interface Config {
|
|
15
|
+
clientId: string;
|
|
16
|
+
clientSecret: string;
|
|
17
|
+
/** Loopback port used during the OAuth redirect. Default 8787. Ignored when redirectUri is set. */
|
|
18
|
+
redirectPort?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Full redirect URI registered with Google, e.g. "http://127.0.0.1:8787/oauth2callback".
|
|
21
|
+
* Takes precedence over redirectPort and must exactly match what is registered for
|
|
22
|
+
* this OAuth client in the Google Cloud Console.
|
|
23
|
+
*/
|
|
24
|
+
redirectUri?: string;
|
|
25
|
+
/** Account used when tools are called without an explicit `account`. */
|
|
26
|
+
defaultAccount?: string;
|
|
27
|
+
/** Override the scope list requested at authorization time. */
|
|
28
|
+
scopes?: string[];
|
|
29
|
+
}
|
|
30
|
+
export declare function getDataDir(): string;
|
|
31
|
+
export declare function getConfigPath(): string;
|
|
32
|
+
export declare function getAccountsDir(): string;
|
|
33
|
+
export declare function getAccountPath(name: string): string;
|
|
34
|
+
export declare function sanitizeName(name: string): string;
|
|
35
|
+
export declare function isValidName(name: string): boolean;
|
|
36
|
+
export declare function ensureDirs(): Promise<void>;
|
|
37
|
+
export declare function loadConfig(): Promise<Config>;
|
|
38
|
+
export declare function saveConfig(config: Config): Promise<void>;
|
|
39
|
+
export declare function saveClientCredentials(clientId: string, clientSecret: string): Promise<void>;
|
|
40
|
+
export declare function hasCredentials(config: Config): boolean;
|
|
41
|
+
/** Location of this package's root (for README links etc.). */
|
|
42
|
+
export declare function getPackageRoot(): string;
|
|
43
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/auth/config.ts"],"names":[],"mappings":"AAKA;;;;;;;;;GASG;AAEH,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAE1C,wFAAwF;AACxF,eAAO,MAAM,cAAc,EAAE,MAAM,EAuBlC,CAAC;AAEF,MAAM,WAAW,MAAM;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,mGAAmG;IACnG,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wEAAwE;IACxE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,+DAA+D;IAC/D,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAMjD;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEjD;AAED,wBAAsB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAEhD;AAED,wBAAsB,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAwBlD;AAED,wBAAsB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ9D;AAED,wBAAsB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAKjG;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED,+DAA+D;AAC/D,wBAAgB,cAAc,IAAI,MAAM,CAEvC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import fs from "node:fs/promises";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for the OAuth client and server defaults.
|
|
7
|
+
*
|
|
8
|
+
* Credentials come from (in order of precedence):
|
|
9
|
+
* 1. Environment variables GOOGLE_MCP_CLIENT_ID / GOOGLE_MCP_CLIENT_SECRET
|
|
10
|
+
* 2. The config file at <dir>/config.json
|
|
11
|
+
*
|
|
12
|
+
* The data directory defaults to ~/.google-services-mcp and can be overridden with
|
|
13
|
+
* GOOGLE_MCP_DIR.
|
|
14
|
+
*/
|
|
15
|
+
export const DEFAULT_REDIRECT_PORT = 8787;
|
|
16
|
+
/** Scopes requested when adding an account. Covers all services this server exposes. */
|
|
17
|
+
export const DEFAULT_SCOPES = [
|
|
18
|
+
// Gmail: read, send, and modify (labels/trash) — not permanent delete
|
|
19
|
+
"https://www.googleapis.com/auth/gmail.modify",
|
|
20
|
+
// Calendar + Google Meet (conferenceData on events)
|
|
21
|
+
"https://www.googleapis.com/auth/calendar",
|
|
22
|
+
// Drive: full access to the user's Drive
|
|
23
|
+
"https://www.googleapis.com/auth/drive",
|
|
24
|
+
// Contacts (read/write)
|
|
25
|
+
"https://www.googleapis.com/auth/contacts",
|
|
26
|
+
// Tasks
|
|
27
|
+
"https://www.googleapis.com/auth/tasks",
|
|
28
|
+
// Sheets: read/write spreadsheets
|
|
29
|
+
"https://www.googleapis.com/auth/spreadsheets",
|
|
30
|
+
// Docs: read/write documents
|
|
31
|
+
"https://www.googleapis.com/auth/documents",
|
|
32
|
+
// Slides: read/write presentations
|
|
33
|
+
"https://www.googleapis.com/auth/presentations",
|
|
34
|
+
// YouTube: read/write the user's channel data and playlists
|
|
35
|
+
"https://www.googleapis.com/auth/youtube",
|
|
36
|
+
// Forms: read/write forms and responses
|
|
37
|
+
"https://www.googleapis.com/auth/forms",
|
|
38
|
+
// Identity: lets fetchUserInfo return the signed-in email for account display
|
|
39
|
+
"https://www.googleapis.com/auth/userinfo.email",
|
|
40
|
+
];
|
|
41
|
+
export function getDataDir() {
|
|
42
|
+
return process.env.GOOGLE_MCP_DIR || path.join(os.homedir(), ".google-services-mcp");
|
|
43
|
+
}
|
|
44
|
+
export function getConfigPath() {
|
|
45
|
+
return path.join(getDataDir(), "config.json");
|
|
46
|
+
}
|
|
47
|
+
export function getAccountsDir() {
|
|
48
|
+
return path.join(getDataDir(), "accounts");
|
|
49
|
+
}
|
|
50
|
+
export function getAccountPath(name) {
|
|
51
|
+
return path.join(getAccountsDir(), `${sanitizeName(name)}.json`);
|
|
52
|
+
}
|
|
53
|
+
export function sanitizeName(name) {
|
|
54
|
+
const cleaned = name.replace(/[^a-zA-Z0-9_-]/g, "_").toLowerCase();
|
|
55
|
+
if (!/[a-zA-Z0-9]/.test(cleaned)) {
|
|
56
|
+
throw new Error("Account name must contain at least one alphanumeric character.");
|
|
57
|
+
}
|
|
58
|
+
return cleaned;
|
|
59
|
+
}
|
|
60
|
+
export function isValidName(name) {
|
|
61
|
+
return /^[a-zA-Z0-9_-]+$/.test(name);
|
|
62
|
+
}
|
|
63
|
+
export async function ensureDirs() {
|
|
64
|
+
await fs.mkdir(getAccountsDir(), { recursive: true });
|
|
65
|
+
}
|
|
66
|
+
export async function loadConfig() {
|
|
67
|
+
await ensureDirs();
|
|
68
|
+
let file = {};
|
|
69
|
+
try {
|
|
70
|
+
const raw = await fs.readFile(getConfigPath(), "utf8");
|
|
71
|
+
file = JSON.parse(raw);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// No config file yet — env vars may still provide credentials.
|
|
75
|
+
}
|
|
76
|
+
const envId = process.env.GOOGLE_MCP_CLIENT_ID;
|
|
77
|
+
const envSecret = process.env.GOOGLE_MCP_CLIENT_SECRET;
|
|
78
|
+
const envPort = process.env.GOOGLE_MCP_REDIRECT_PORT;
|
|
79
|
+
const envUri = process.env.GOOGLE_MCP_REDIRECT_URI;
|
|
80
|
+
const config = {
|
|
81
|
+
clientId: envId || file.clientId || "",
|
|
82
|
+
clientSecret: envSecret || file.clientSecret || "",
|
|
83
|
+
redirectPort: envPort ? Number(envPort) : file.redirectPort || DEFAULT_REDIRECT_PORT,
|
|
84
|
+
redirectUri: envUri || file.redirectUri || undefined,
|
|
85
|
+
defaultAccount: file.defaultAccount,
|
|
86
|
+
scopes: file.scopes || DEFAULT_SCOPES,
|
|
87
|
+
};
|
|
88
|
+
return config;
|
|
89
|
+
}
|
|
90
|
+
export async function saveConfig(config) {
|
|
91
|
+
await ensureDirs();
|
|
92
|
+
const { clientId, clientSecret, redirectPort, redirectUri, defaultAccount, scopes } = config;
|
|
93
|
+
await fs.writeFile(getConfigPath(), JSON.stringify({ clientId, clientSecret, redirectPort, redirectUri, defaultAccount, scopes }, null, 2), "utf8");
|
|
94
|
+
}
|
|
95
|
+
export async function saveClientCredentials(clientId, clientSecret) {
|
|
96
|
+
const config = await loadConfig();
|
|
97
|
+
config.clientId = clientId || config.clientId;
|
|
98
|
+
config.clientSecret = clientSecret || config.clientSecret;
|
|
99
|
+
await saveConfig(config);
|
|
100
|
+
}
|
|
101
|
+
export function hasCredentials(config) {
|
|
102
|
+
return Boolean(config.clientId && config.clientSecret);
|
|
103
|
+
}
|
|
104
|
+
/** Location of this package's root (for README links etc.). */
|
|
105
|
+
export function getPackageRoot() {
|
|
106
|
+
return path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/auth/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;;;;;;;;;GASG;AAEH,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAE1C,wFAAwF;AACxF,MAAM,CAAC,MAAM,cAAc,GAAa;IACtC,sEAAsE;IACtE,8CAA8C;IAC9C,oDAAoD;IACpD,0CAA0C;IAC1C,yCAAyC;IACzC,uCAAuC;IACvC,wBAAwB;IACxB,0CAA0C;IAC1C,QAAQ;IACR,uCAAuC;IACvC,kCAAkC;IAClC,8CAA8C;IAC9C,6BAA6B;IAC7B,2CAA2C;IAC3C,mCAAmC;IACnC,+CAA+C;IAC/C,4DAA4D;IAC5D,yCAAyC;IACzC,wCAAwC;IACxC,uCAAuC;IACvC,8EAA8E;IAC9E,gDAAgD;CACjD,CAAC;AAmBF,MAAM,UAAU,UAAU;IACxB,OAAO,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,s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MAAM,GAAG,MAAM,UAAU,EAAE,CAAC;IAClC,MAAM,CAAC,QAAQ,GAAG,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC;IAC9C,MAAM,CAAC,YAAY,GAAG,YAAY,IAAI,MAAM,CAAC,YAAY,CAAC;IAC1D,MAAM,UAAU,CAAC,MAAM,CAAC,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,OAAO,OAAO,CAAC,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,YAAY,CAAC,CAAC;AACzD,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,cAAc;IAC5B,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Auth } from "googleapis";
|
|
2
|
+
import { type Config } from "./config.js";
|
|
3
|
+
import { type StoredAccount } from "./store.js";
|
|
4
|
+
export interface AddAccountOptions {
|
|
5
|
+
/** Set to false to skip opening the browser (headless). */
|
|
6
|
+
openBrowser?: boolean;
|
|
7
|
+
/** Milliseconds to wait for the OAuth callback before failing. Default 5 minutes. */
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface AccountStatus {
|
|
11
|
+
name: string;
|
|
12
|
+
email?: string;
|
|
13
|
+
expiresAt?: number;
|
|
14
|
+
tokenHealthy: boolean;
|
|
15
|
+
scopes: string[];
|
|
16
|
+
}
|
|
17
|
+
export interface ServerStatus {
|
|
18
|
+
credentialsConfigured: boolean;
|
|
19
|
+
dataDir: string;
|
|
20
|
+
defaultAccount?: string;
|
|
21
|
+
accounts: AccountStatus[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Coordinates credentials, per-account token storage, the interactive OAuth
|
|
25
|
+
* flow, and refresh. All service modules resolve auth through here.
|
|
26
|
+
*/
|
|
27
|
+
declare class AuthManager {
|
|
28
|
+
getConfig(): Promise<Config>;
|
|
29
|
+
listAccounts(): Promise<StoredAccount[]>;
|
|
30
|
+
/**
|
|
31
|
+
* Resolve an account to use for a tool call.
|
|
32
|
+
* Priority: explicit name -> configured default -> sole account.
|
|
33
|
+
*/
|
|
34
|
+
resolveAccount(name?: string): Promise<StoredAccount>;
|
|
35
|
+
/** Get an authenticated googleapis OAuth2 client, refreshing first if needed. */
|
|
36
|
+
getClient(name?: string): Promise<Auth.OAuth2Client>;
|
|
37
|
+
/**
|
|
38
|
+
* Run the interactive OAuth flow to add a new account: opens the consent
|
|
39
|
+
* screen, waits for the loopback callback, exchanges the code, and persists
|
|
40
|
+
* the account alongside the signed-in email.
|
|
41
|
+
*/
|
|
42
|
+
addAccount(name: string, options?: AddAccountOptions): Promise<StoredAccount>;
|
|
43
|
+
removeAccount(name: string): Promise<boolean>;
|
|
44
|
+
setDefaultAccount(name: string): Promise<void>;
|
|
45
|
+
saveCredentials(clientId: string, clientSecret: string): Promise<void>;
|
|
46
|
+
getStatus(): Promise<ServerStatus>;
|
|
47
|
+
}
|
|
48
|
+
export declare const authManager: AuthManager;
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/auth/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,IAAI,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAML,KAAK,MAAM,EACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EAA4D,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAY1G,MAAM,WAAW,iBAAiB;IAChC,2DAA2D;IAC3D,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,qFAAqF;IACrF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE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