Skip to main content
Glama
run_tool.ts1.48 kB
import { Client } from '@modelcontextprotocol/sdk/client/index.js'; import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'; import path from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); async function runTool() { const toolName = process.argv[2]; const toolArgsRaw = process.argv[3]; if (!toolName) { console.error('Usage: npx tsx tests/run_tool.ts <tool_name> [json_args]'); process.exit(1); } const toolArgs = toolArgsRaw ? JSON.parse(toolArgsRaw) : {}; const serverPath = path.resolve(__dirname, '../dist/index.js'); const transport = new StdioClientTransport({ command: 'node', args: [serverPath], }); const client = new Client( { name: 'mcp-tester', version: '0.0.1' }, { capabilities: {} } ); await client.connect(transport); try { const result = await client.callTool({ name: toolName, arguments: toolArgs, }); if (result.content && Array.isArray(result.content)) { result.content.forEach((item: any) => { if (item.type === 'text') { console.log(item.text); } else { console.log(JSON.stringify(item)); } }); } else { console.log(JSON.stringify(result)); } } catch (error: any) { console.error(`Error: ${error.message}`); } await client.close(); } runTool().catch(console.error);

Latest Blog Posts

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/samicokar/mcp-mac'

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