mcp-gsheets 1.5.2 → 1.5.4
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/README.md +36 -2
- package/dist/index.js +34 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -137,13 +137,16 @@ For other MCP clients, use the standard configuration format shown above. Ensure
|
|
|
137
137
|
4. Create Service Account:
|
|
138
138
|
- Go to "APIs & Services" → "Credentials"
|
|
139
139
|
- Click "Create Credentials" → "Service Account"
|
|
140
|
+
- In the service accounts list, click the three dots in the `Actions` column → `Manage keys` → `Add key` → `Create new key` → select JSON format
|
|
140
141
|
- Download the JSON key file
|
|
141
142
|
5. Share your spreadsheets:
|
|
142
143
|
- Open your Google Sheet
|
|
143
144
|
- Click Share and add the service account email (from JSON file)
|
|
144
145
|
- Grant "Editor" permissions
|
|
145
146
|
|
|
146
|
-
### Alternative
|
|
147
|
+
### Alternative Authentication Methods
|
|
148
|
+
|
|
149
|
+
#### Option 1: JSON String Authentication
|
|
147
150
|
|
|
148
151
|
Instead of using a file path for credentials, you can provide the service account credentials directly as a JSON string. This is useful for containerized environments, CI/CD pipelines, or when you want to avoid managing credential files.
|
|
149
152
|
|
|
@@ -168,6 +171,31 @@ Instead of using a file path for credentials, you can provide the service accoun
|
|
|
168
171
|
- Newlines in the private key must be represented as `\\n`
|
|
169
172
|
- If the JSON includes a `project_id`, you can omit `GOOGLE_PROJECT_ID`
|
|
170
173
|
|
|
174
|
+
#### Option 2: Private Key Authentication (Simplified)
|
|
175
|
+
|
|
176
|
+
For the most user-friendly approach, you can provide just the private key and email directly. This is the simplest method and requires only two fields from your service account JSON:
|
|
177
|
+
|
|
178
|
+
```json
|
|
179
|
+
{
|
|
180
|
+
"mcpServers": {
|
|
181
|
+
"mcp-gsheets": {
|
|
182
|
+
"command": "npx",
|
|
183
|
+
"args": ["-y", "mcp-gsheets@latest"],
|
|
184
|
+
"env": {
|
|
185
|
+
"GOOGLE_PRIVATE_KEY": "-----BEGIN PRIVATE KEY-----\\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCgR6bvMNOUHZ29\\n+YgbVHAXsT/s+L/jnXTCB193zikCzspSBSfxLu8VRDjkNq9WUoDxizTATzMFNvNf\\n...\\n-----END PRIVATE KEY-----\\n",
|
|
186
|
+
"GOOGLE_CLIENT_EMAIL": "spreadsheet@your-project.iam.gserviceaccount.com"
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
**Note**: When using `GOOGLE_PRIVATE_KEY`:
|
|
194
|
+
- Newlines in the private key should be represented as `\\n`
|
|
195
|
+
- The private key must include the `-----BEGIN PRIVATE KEY-----` and `-----END PRIVATE KEY-----` markers
|
|
196
|
+
- The client email should be the service account email from your JSON file
|
|
197
|
+
- `GOOGLE_PROJECT_ID` is optional when using this method
|
|
198
|
+
|
|
171
199
|
## Local Development Setup
|
|
172
200
|
|
|
173
201
|
If you want to develop or contribute to this project, you can clone and build it locally:
|
|
@@ -356,7 +384,9 @@ npm run typecheck
|
|
|
356
384
|
**"Authentication failed"**
|
|
357
385
|
- If using file-based auth: Verify JSON key path is absolute and correct
|
|
358
386
|
- If using JSON string auth: Ensure JSON is properly escaped and valid
|
|
359
|
-
- Check
|
|
387
|
+
- If using private key auth: Check that the private key includes BEGIN/END markers and newlines are escaped as `\\n`
|
|
388
|
+
- Verify GOOGLE_CLIENT_EMAIL is a valid service account email
|
|
389
|
+
- Check GOOGLE_PROJECT_ID matches your project (or is included in JSON for full JSON auth)
|
|
360
390
|
- Ensure Sheets API is enabled
|
|
361
391
|
|
|
362
392
|
**"Permission denied"**
|
|
@@ -445,6 +475,10 @@ See [CHANGELOG.md](CHANGELOG.md) for a list of changes in each version.
|
|
|
445
475
|
5. Push to the branch (`git push origin feature/amazing-feature`)
|
|
446
476
|
6. Open a Pull Request
|
|
447
477
|
|
|
478
|
+
## 👤 Author
|
|
479
|
+
|
|
480
|
+
**Tomáš Grásl** - [tomasgrasl.cz](https://www.tomasgrasl.cz/)
|
|
481
|
+
|
|
448
482
|
## 📄 License
|
|
449
483
|
|
|
450
484
|
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
package/dist/index.js
CHANGED
|
@@ -12336,6 +12336,13 @@ async function getAuthClient() {
|
|
|
12336
12336
|
"Failed to parse GOOGLE_SERVICE_ACCOUNT_KEY: Invalid JSON format. Please ensure the environment variable contains valid JSON."
|
|
12337
12337
|
);
|
|
12338
12338
|
}
|
|
12339
|
+
} else if (process.env.GOOGLE_PRIVATE_KEY && process.env.GOOGLE_CLIENT_EMAIL) {
|
|
12340
|
+
const credentials = {
|
|
12341
|
+
type: "service_account",
|
|
12342
|
+
private_key: process.env.GOOGLE_PRIVATE_KEY.replace(/\\n/g, "\n"),
|
|
12343
|
+
client_email: process.env.GOOGLE_CLIENT_EMAIL
|
|
12344
|
+
};
|
|
12345
|
+
options.credentials = credentials;
|
|
12339
12346
|
}
|
|
12340
12347
|
authClient = new GoogleAuth(options);
|
|
12341
12348
|
}
|
|
@@ -12353,12 +12360,35 @@ async function getAuthenticatedClient() {
|
|
|
12353
12360
|
return sheetsClient;
|
|
12354
12361
|
}
|
|
12355
12362
|
function validateAuth() {
|
|
12356
|
-
|
|
12363
|
+
const hasFileAuth = !!process.env.GOOGLE_APPLICATION_CREDENTIALS;
|
|
12364
|
+
const hasJsonAuth = !!process.env.GOOGLE_SERVICE_ACCOUNT_KEY;
|
|
12365
|
+
const hasPrivateKeyAuth = !!process.env.GOOGLE_PRIVATE_KEY && !!process.env.GOOGLE_CLIENT_EMAIL;
|
|
12366
|
+
if (!hasFileAuth && !hasJsonAuth && !hasPrivateKeyAuth) {
|
|
12357
12367
|
throw new Error(
|
|
12358
|
-
"No authentication method provided. Please set
|
|
12368
|
+
"No authentication method provided. Please set one of:\n- GOOGLE_APPLICATION_CREDENTIALS to the path of your service account key file\n- GOOGLE_SERVICE_ACCOUNT_KEY to the JSON string of your service account credentials\n- GOOGLE_PRIVATE_KEY and GOOGLE_CLIENT_EMAIL for direct private key authentication"
|
|
12359
12369
|
);
|
|
12360
12370
|
}
|
|
12361
|
-
if (!
|
|
12371
|
+
if (!hasFileAuth && !hasJsonAuth && hasPrivateKeyAuth) {
|
|
12372
|
+
if (!process.env.GOOGLE_PRIVATE_KEY) {
|
|
12373
|
+
throw new Error("GOOGLE_PRIVATE_KEY is required when using private key authentication");
|
|
12374
|
+
}
|
|
12375
|
+
if (!process.env.GOOGLE_CLIENT_EMAIL) {
|
|
12376
|
+
throw new Error("GOOGLE_CLIENT_EMAIL is required when using private key authentication");
|
|
12377
|
+
}
|
|
12378
|
+
const privateKey = process.env.GOOGLE_PRIVATE_KEY.replace(/\\n/g, "\n");
|
|
12379
|
+
if (!privateKey.includes("BEGIN PRIVATE KEY") || !privateKey.includes("END PRIVATE KEY")) {
|
|
12380
|
+
throw new Error(
|
|
12381
|
+
"GOOGLE_PRIVATE_KEY appears to be invalid. It should start with -----BEGIN PRIVATE KEY----- and end with -----END PRIVATE KEY-----"
|
|
12382
|
+
);
|
|
12383
|
+
}
|
|
12384
|
+
const emailRegex2 = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
12385
|
+
if (!emailRegex2.test(process.env.GOOGLE_CLIENT_EMAIL)) {
|
|
12386
|
+
throw new Error(
|
|
12387
|
+
"GOOGLE_CLIENT_EMAIL appears to be invalid. It should be a valid email address (e.g., your-service-account@your-project.iam.gserviceaccount.com)"
|
|
12388
|
+
);
|
|
12389
|
+
}
|
|
12390
|
+
}
|
|
12391
|
+
if (!hasFileAuth && hasJsonAuth) {
|
|
12362
12392
|
try {
|
|
12363
12393
|
const credentials = JSON.parse(process.env.GOOGLE_SERVICE_ACCOUNT_KEY);
|
|
12364
12394
|
if (!credentials.type || credentials.type !== "service_account") {
|
|
@@ -12382,7 +12412,7 @@ function validateAuth() {
|
|
|
12382
12412
|
throw error;
|
|
12383
12413
|
}
|
|
12384
12414
|
}
|
|
12385
|
-
if (!process.env.GOOGLE_PROJECT_ID) {
|
|
12415
|
+
if (!process.env.GOOGLE_PROJECT_ID && !hasPrivateKeyAuth) {
|
|
12386
12416
|
throw new Error(
|
|
12387
12417
|
"GOOGLE_PROJECT_ID environment variable is not set. Please set it to your Google Cloud project ID, or ensure it is included in your service account credentials."
|
|
12388
12418
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-gsheets",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.4",
|
|
4
4
|
"description": "Model Context Protocol (MCP) server for Google Sheets API integration",
|
|
5
5
|
"author": "freema",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@modelcontextprotocol/sdk": "^1.17.1",
|
|
50
|
-
"googleapis": "^
|
|
50
|
+
"googleapis": "^164.1.0",
|
|
51
51
|
"zod": "^3.22.4"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|