Skip to main content
Glama
by mohalmah
test-mcp-processes.jsโ€ข3.6 kB
#!/usr/bin/env node /** * Test script to call MCP server tools and observe enhanced logging */ import { Server } from "@modelcontextprotocol/sdk/server/index.js"; import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; import { discoverTools } from './lib/tools.js'; import { logger } from './lib/logger.js'; async function testMCPTool() { console.log('๐Ÿงช Testing MCP Server Tool Execution with Enhanced Logging\n'); try { // Discover and load tools logger.info('TEST', 'Starting MCP tool test'); const tools = await discoverTools(); // Find the script processes list tool const processListTool = tools.find(tool => tool.definition?.function?.name === 'script_processes_list' ); if (!processListTool) { console.error('โŒ script_processes_list tool not found'); return; } console.log('๐Ÿ” Found script_processes_list tool'); console.log(`๐Ÿ“ Description: ${processListTool.definition.function.description}`); console.log(`๐Ÿ”ง Required parameters: ${processListTool.definition.function.parameters.required.join(', ')}`); // Test 1: Call with missing required parameter (should trigger detailed error logging) console.log('\n๐Ÿงช Test 1: Calling tool with missing required parameter...'); try { await processListTool.function({}); } catch (error) { console.log('โœ… Expected error caught (missing scriptId)'); } // Test 2: Call with invalid scriptId (should trigger API error logging) console.log('\n๐Ÿงช Test 2: Calling tool with invalid scriptId...'); const testScriptId = 'invalid_script_id_12345'; try { const result = await processListTool.function({ scriptId: testScriptId, pageSize: 10 }); console.log('๐Ÿ“Š Tool execution result:'); console.log(JSON.stringify(result, null, 2)); } catch (error) { console.log('โœ… Expected error caught (invalid scriptId)'); console.log(` Error: ${error.message}`); } // Test 3: Call with a potentially valid scriptId format (will likely fail with auth or not found) console.log('\n๐Ÿงช Test 3: Calling tool with valid format scriptId...'); const validFormatScriptId = '1BxKdN9XvlHF8rF9mF8Km4K7Y6nC8XvV9WtE5QdA2B'; try { const result = await processListTool.function({ scriptId: validFormatScriptId, pageSize: 5, fields: 'processes(processType,functionName,startTime,duration,status)' }); console.log('๐Ÿ“Š Tool execution result:'); console.log(JSON.stringify(result, null, 2)); } catch (error) { console.log('โœ… Expected error caught (script not found or auth issue)'); console.log(` Error: ${error.message}`); } console.log('\nโœจ MCP Tool Test Completed!'); console.log('\n๐Ÿ“‹ What the enhanced logging showed:'); console.log(' โœ“ Tool discovery and loading'); console.log(' โœ“ Tool execution requests with parameters'); console.log(' โœ“ OAuth authentication attempts'); console.log(' โœ“ API calls to Google Apps Script API'); console.log(' โœ“ Response times and error details'); console.log(' โœ“ Detailed error context and stack traces'); } catch (error) { logger.error('TEST', 'Test failed with unexpected error', { error: { message: error.message, stack: error.stack } }); console.error('โŒ Test failed:', error.message); } } // Run the test testMCPTool().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/mohalmah/google-appscript-mcp-server'

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