mcp-gsheets 1.5.0 → 1.5.3

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 (3) hide show
  1. package/README.md +175 -48
  2. package/dist/index.js +34 -4
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -12,33 +12,122 @@
12
12
  ![Node](https://img.shields.io/badge/Node.js-18%2B-339933?logo=node.js&logoColor=white)
13
13
  ![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?logo=prettier&logoColor=white)
14
14
 
15
- A Model Context Protocol (MCP) server for Google Sheets API integration. Enables reading, writing, and managing Google Sheets documents directly from your MCP client (e.g., Claude Desktop).
15
+ A Model Context Protocol (MCP) server for Google Sheets API integration. Enables reading, writing, and managing Google Sheets documents directly from your MCP client (e.g., Claude Code, Claude Desktop, Cursor, etc.).
16
16
 
17
- ## 🚀 Quick Start
17
+ ## Key Features
18
18
 
19
- ### 1. Prerequisites
19
+ - **Complete Google Sheets Integration**: Read, write, and manage spreadsheets
20
+ - **Advanced Operations**: Batch operations, formatting, charts, and conditional formatting
21
+ - **Flexible Authentication**: Support for both file-based and JSON string credentials
22
+ - **Production Ready**: Built with TypeScript, comprehensive error handling, and full test coverage
20
23
 
21
- - Node.js v18 or higher
22
- - Google Cloud Project with Sheets API enabled
24
+ ## Requirements
25
+
26
+ - [Node.js](https://nodejs.org/) v18 or higher
27
+ - [Google Cloud Project](https://console.cloud.google.com) with Sheets API enabled
23
28
  - Service Account with JSON key file
29
+ - [npm](https://www.npmjs.com/)
30
+
31
+ ## Getting Started
32
+
33
+ ### Quick Install (Recommended)
34
+
35
+ Add the following config to your MCP client:
36
+
37
+ ```json
38
+ {
39
+ "mcpServers": {
40
+ "mcp-gsheets": {
41
+ "command": "npx",
42
+ "args": ["-y", "mcp-gsheets@latest"],
43
+ "env": {
44
+ "GOOGLE_PROJECT_ID": "your-project-id",
45
+ "GOOGLE_APPLICATION_CREDENTIALS": "/absolute/path/to/service-account-key.json"
46
+ }
47
+ }
48
+ }
49
+ }
50
+ ```
24
51
 
25
- ### 2. Installation
52
+ > [!NOTE]
53
+ > Using `mcp-gsheets@latest` ensures that your MCP client will always use the latest version of the MCP Google Sheets server.
54
+
55
+ ### MCP Client Configuration
56
+
57
+ <details>
58
+ <summary>Claude Code</summary>
59
+ Use the Claude Code CLI to add the MCP Google Sheets server (<a href="https://docs.anthropic.com/en/docs/claude-code/mcp">guide</a>):
26
60
 
27
61
  ```bash
28
- # Clone the repository
29
- git clone https://github.com/freema/mcp-gsheets.git
30
- # Or using SSH
31
- # git clone git@github.com:freema/mcp-gsheets.git
32
- cd mcp-gsheets
62
+ claude mcp add mcp-gsheets npx mcp-gsheets@latest
63
+ ```
33
64
 
34
- # Install dependencies
35
- npm install
65
+ After adding, edit your Claude Code config to add the required environment variables:
36
66
 
37
- # Build the project
38
- npm run build
67
+ ```json
68
+ {
69
+ "mcpServers": {
70
+ "mcp-gsheets": {
71
+ "command": "npx",
72
+ "args": ["mcp-gsheets@latest"],
73
+ "env": {
74
+ "GOOGLE_PROJECT_ID": "your-project-id",
75
+ "GOOGLE_APPLICATION_CREDENTIALS": "/absolute/path/to/service-account-key.json"
76
+ }
77
+ }
78
+ }
79
+ }
80
+ ```
81
+
82
+ </details>
83
+
84
+ <details>
85
+ <summary>Claude Desktop</summary>
86
+
87
+ Add to your Claude Desktop config:
88
+ - macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
89
+ - Windows: `%APPDATA%\Claude\claude_desktop_config.json`
90
+ - Linux: `~/.config/claude/claude_desktop_config.json`
91
+
92
+ ```json
93
+ {
94
+ "mcpServers": {
95
+ "mcp-gsheets": {
96
+ "command": "npx",
97
+ "args": ["-y", "mcp-gsheets@latest"],
98
+ "env": {
99
+ "GOOGLE_PROJECT_ID": "your-project-id",
100
+ "GOOGLE_APPLICATION_CREDENTIALS": "/absolute/path/to/service-account-key.json"
101
+ }
102
+ }
103
+ }
104
+ }
39
105
  ```
40
106
 
41
- ### 3. Google Cloud Setup
107
+ </details>
108
+
109
+ <details>
110
+ <summary>Cursor</summary>
111
+
112
+ Go to `Cursor Settings` → `MCP` → `New MCP Server`. Use the config provided above.
113
+
114
+ </details>
115
+
116
+ <details>
117
+ <summary>Cline</summary>
118
+
119
+ Follow https://docs.cline.bot/mcp/configuring-mcp-servers and use the config provided above.
120
+
121
+ </details>
122
+
123
+ <details>
124
+ <summary>Other MCP Clients</summary>
125
+
126
+ For other MCP clients, use the standard configuration format shown above. Ensure the `command` is set to `npx` and include the environment variables for Google Cloud authentication.
127
+
128
+ </details>
129
+
130
+ ### Google Cloud Setup
42
131
 
43
132
  1. Go to [Google Cloud Console](https://console.cloud.google.com)
44
133
  2. Create a new project or select existing
@@ -54,48 +143,92 @@ npm run build
54
143
  - Click Share and add the service account email (from JSON file)
55
144
  - Grant "Editor" permissions
56
145
 
57
- ### 4. Configure MCP Client
146
+ ### Alternative Authentication Methods
58
147
 
59
- #### Easy Setup (Recommended)
148
+ #### Option 1: JSON String Authentication
60
149
 
61
- Run the interactive setup script:
150
+ 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.
62
151
 
63
- ```bash
64
- npm run setup
152
+ ```json
153
+ {
154
+ "mcpServers": {
155
+ "mcp-gsheets": {
156
+ "command": "npx",
157
+ "args": ["-y", "mcp-gsheets@latest"],
158
+ "env": {
159
+ "GOOGLE_PROJECT_ID": "your-project-id",
160
+ "GOOGLE_SERVICE_ACCOUNT_KEY": "{\"type\":\"service_account\",\"project_id\":\"your-project\",\"private_key_id\":\"...\",\"private_key\":\"-----BEGIN PRIVATE KEY-----\\n...\\n-----END PRIVATE KEY-----\\n\",\"client_email\":\"...@....iam.gserviceaccount.com\",\"client_id\":\"...\",\"auth_uri\":\"https://accounts.google.com/o/oauth2/auth\",\"token_uri\":\"https://oauth2.googleapis.com/token\",\"auth_provider_x509_cert_url\":\"https://www.googleapis.com/oauth2/v1/certs\",\"client_x509_cert_url\":\"...\"}"
161
+ }
162
+ }
163
+ }
164
+ }
65
165
  ```
66
166
 
67
- This will:
68
- - Guide you through the configuration
69
- - Automatically detect your Node.js installation (including nvm)
70
- - Find your Claude Desktop config
71
- - Create the proper JSON configuration
72
- - Optionally create a .env file for development
167
+ **Note**: When using `GOOGLE_SERVICE_ACCOUNT_KEY`:
168
+ - The entire JSON must be on a single line
169
+ - All quotes must be escaped with backslashes
170
+ - Newlines in the private key must be represented as `\\n`
171
+ - If the JSON includes a `project_id`, you can omit `GOOGLE_PROJECT_ID`
73
172
 
74
- #### Manual Setup
173
+ #### Option 2: Private Key Authentication (Simplified)
75
174
 
76
- If you prefer manual configuration, add to your Claude Desktop config:
77
- - macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
78
- - Windows: `%APPDATA%\Claude\claude_desktop_config.json`
79
- - Linux: `~/.config/claude/claude_desktop_config.json`
175
+ 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:
80
176
 
81
177
  ```json
82
178
  {
83
179
  "mcpServers": {
84
180
  "mcp-gsheets": {
85
- "command": "node",
86
- "args": ["/absolute/path/to/mcp-gsheets/dist/index.js"],
181
+ "command": "npx",
182
+ "args": ["-y", "mcp-gsheets@latest"],
87
183
  "env": {
88
- "GOOGLE_PROJECT_ID": "your-project-id",
89
- "GOOGLE_APPLICATION_CREDENTIALS": "/absolute/path/to/service-account-key.json"
184
+ "GOOGLE_PRIVATE_KEY": "-----BEGIN PRIVATE KEY-----\\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCgR6bvMNOUHZ29\\n+YgbVHAXsT/s+L/jnXTCB193zikCzspSBSfxLu8VRDjkNq9WUoDxizTATzMFNvNf\\n...\\n-----END PRIVATE KEY-----\\n",
185
+ "GOOGLE_CLIENT_EMAIL": "spreadsheet@your-project.iam.gserviceaccount.com"
90
186
  }
91
187
  }
92
188
  }
93
189
  }
94
190
  ```
95
191
 
96
- #### Alternative: JSON String Authentication
192
+ **Note**: When using `GOOGLE_PRIVATE_KEY`:
193
+ - Newlines in the private key should be represented as `\\n`
194
+ - The private key must include the `-----BEGIN PRIVATE KEY-----` and `-----END PRIVATE KEY-----` markers
195
+ - The client email should be the service account email from your JSON file
196
+ - `GOOGLE_PROJECT_ID` is optional when using this method
97
197
 
98
- Instead of using a file path, 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.
198
+ ## Local Development Setup
199
+
200
+ If you want to develop or contribute to this project, you can clone and build it locally:
201
+
202
+ ```bash
203
+ # Clone the repository
204
+ git clone https://github.com/freema/mcp-gsheets.git
205
+ cd mcp-gsheets
206
+
207
+ # Install dependencies
208
+ npm install
209
+
210
+ # Build the project
211
+ npm run build
212
+ ```
213
+
214
+ ### Interactive Setup Script
215
+
216
+ Run the interactive setup script to configure your local MCP client:
217
+
218
+ ```bash
219
+ npm run setup
220
+ ```
221
+
222
+ This will:
223
+ - Guide you through the configuration
224
+ - Automatically detect your Node.js installation (including nvm)
225
+ - Find your Claude Desktop config
226
+ - Create the proper JSON configuration
227
+ - Optionally create a .env file for development
228
+
229
+ ### Manual Local Configuration
230
+
231
+ If you prefer manual configuration with a local build, add to your MCP client config:
99
232
 
100
233
  ```json
101
234
  {
@@ -105,21 +238,13 @@ Instead of using a file path, you can provide the service account credentials di
105
238
  "args": ["/absolute/path/to/mcp-gsheets/dist/index.js"],
106
239
  "env": {
107
240
  "GOOGLE_PROJECT_ID": "your-project-id",
108
- "GOOGLE_SERVICE_ACCOUNT_KEY": "{\"type\":\"service_account\",\"project_id\":\"your-project\",\"private_key_id\":\"...\",\"private_key\":\"-----BEGIN PRIVATE KEY-----\\n...\\n-----END PRIVATE KEY-----\\n\",\"client_email\":\"...@....iam.gserviceaccount.com\",\"client_id\":\"...\",\"auth_uri\":\"https://accounts.google.com/o/oauth2/auth\",\"token_uri\":\"https://oauth2.googleapis.com/token\",\"auth_provider_x509_cert_url\":\"https://www.googleapis.com/oauth2/v1/certs\",\"client_x509_cert_url\":\"...\"}"
241
+ "GOOGLE_APPLICATION_CREDENTIALS": "/absolute/path/to/service-account-key.json"
109
242
  }
110
243
  }
111
244
  }
112
245
  }
113
246
  ```
114
247
 
115
- **Note**: When using `GOOGLE_SERVICE_ACCOUNT_KEY`:
116
- - The entire JSON must be on a single line
117
- - All quotes must be escaped with backslashes
118
- - Newlines in the private key must be represented as `\\n`
119
- - If the JSON includes a `project_id`, you can omit `GOOGLE_PROJECT_ID`
120
-
121
- Restart Claude Desktop after adding the configuration.
122
-
123
248
  ## 📦 Build & Development
124
249
 
125
250
  ### Development Commands
@@ -258,7 +383,9 @@ npm run typecheck
258
383
  **"Authentication failed"**
259
384
  - If using file-based auth: Verify JSON key path is absolute and correct
260
385
  - If using JSON string auth: Ensure JSON is properly escaped and valid
261
- - Check GOOGLE_PROJECT_ID matches your project (or is included in JSON)
386
+ - If using private key auth: Check that the private key includes BEGIN/END markers and newlines are escaped as `\\n`
387
+ - Verify GOOGLE_CLIENT_EMAIL is a valid service account email
388
+ - Check GOOGLE_PROJECT_ID matches your project (or is included in JSON for full JSON auth)
262
389
  - Ensure Sheets API is enabled
263
390
 
264
391
  **"Permission denied"**
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
- if (!process.env.GOOGLE_APPLICATION_CREDENTIALS && !process.env.GOOGLE_SERVICE_ACCOUNT_KEY) {
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 either:\n- GOOGLE_APPLICATION_CREDENTIALS to the path of your service account key file, or\n- GOOGLE_SERVICE_ACCOUNT_KEY to the JSON string of your service account credentials."
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 (!process.env.GOOGLE_APPLICATION_CREDENTIALS && process.env.GOOGLE_SERVICE_ACCOUNT_KEY) {
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.0",
3
+ "version": "1.5.3",
4
4
  "description": "Model Context Protocol (MCP) server for Google Sheets API integration",
5
5
  "author": "freema",
6
6
  "license": "MIT",