Skip to main content
Glama

Google Sheets MCP Server

by stephenyu
GPL 3.0
test-xlsx.jsโ€ข3.69 kB
#!/usr/bin/env node import { GoogleSheetsService } from '../server/sheets.js'; import { writeFileSync, readFileSync } from 'fs'; import { join } from 'path'; // Test sheet ID (Google's sample spreadsheet) const TEST_SHEET_ID = '1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms'; const TEST_SHEET_URL = 'https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/edit'; async function testXlsxFunctionality() { console.log('๐Ÿงช Testing XLSX Download Functionality\n'); // Load credentials from JSON file const credentialsPath = process.env.GOOGLE_CREDENTIALS_JSON_FILE; if (!credentialsPath) { console.log('โŒ Missing GOOGLE_CREDENTIALS_JSON_FILE environment variable.'); console.log('Please set it to the path of your service account JSON file.'); return; } try { console.log('๐Ÿ“„ Loading credentials from JSON file...'); const credentialsContent = readFileSync(credentialsPath, 'utf8'); const credentials = JSON.parse(credentialsContent); const TEST_CONFIG = { serviceAccountEmail: credentials.client_email, privateKey: credentials.private_key, projectId: credentials.project_id, }; if (!TEST_CONFIG.serviceAccountEmail || !TEST_CONFIG.privateKey || !TEST_CONFIG.projectId) { console.log('โŒ Invalid credentials JSON file. Missing required fields: client_email, private_key, or project_id.'); return; } // Initialize the service console.log('๐Ÿ”ง Initializing Google Sheets service...'); const sheetsService = new GoogleSheetsService(TEST_CONFIG); await sheetsService.initialize(); console.log('โœ… Service initialized successfully\n'); // Test 1: Get spreadsheet by ID console.log('๐Ÿ“‹ Test 1: Getting spreadsheet by ID...'); const xlsxBufferById = await sheetsService.getSpreadsheetById(TEST_SHEET_ID); console.log(`โœ… Successfully downloaded XLSX by ID (${xlsxBufferById.length} bytes)`); // Save the file const outputPathById = join(process.cwd(), 'test-output-by-id.xlsx'); writeFileSync(outputPathById, xlsxBufferById); console.log(`๐Ÿ’พ Saved to: ${outputPathById}\n`); // Test 2: Get spreadsheet by URL console.log('๐Ÿ”— Test 2: Getting spreadsheet by URL...'); const xlsxBufferByUrl = await sheetsService.getSpreadsheetByUrl(TEST_SHEET_URL); console.log(`โœ… Successfully downloaded XLSX by URL (${xlsxBufferByUrl.length} bytes)`); // Save the file const outputPathByUrl = join(process.cwd(), 'test-output-by-url.xlsx'); writeFileSync(outputPathByUrl, xlsxBufferByUrl); console.log(`๐Ÿ’พ Saved to: ${outputPathByUrl}\n`); // Test 3: URL parsing console.log('๐Ÿ” Test 3: Testing URL parsing...'); const extractedId = sheetsService.extractSheetIdFromUrl(TEST_SHEET_URL); console.log(`โœ… Extracted ID: ${extractedId}`); console.log(`โœ… ID matches: ${extractedId === TEST_SHEET_ID ? 'Yes' : 'No'}\n`); // Test 4: Compare file sizes console.log('๐Ÿ“Š Test 4: Comparing file sizes...'); if (xlsxBufferById.length === xlsxBufferByUrl.length) { console.log('โœ… Both methods produced files of the same size'); } else { console.log('โš ๏ธ Files have different sizes (this might be expected due to timing)'); } console.log('\n๐ŸŽ‰ All tests completed successfully!'); console.log('\n๐Ÿ“ Generated files:'); console.log(` - ${outputPathById}`); console.log(` - ${outputPathByUrl}`); } catch (error) { console.error('โŒ Test failed:', error.message); console.error('Stack trace:', error.stack); process.exit(1); } } // Run the test testXlsxFunctionality().catch(console.error);

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/stephenyu/mcp-googlesheet'

If you have feedback or need assistance with the MCP directory API, please join our Discord server