UNPKG

mcp-orchestrator

Version:

MCP Orchestrator - Discover and install MCPs with automatic OAuth support. Uses Claude CLI for OAuth MCPs (Canva, Asana, etc). 34 trusted MCPs from Claude Partners.

72 lines (71 loc) โ€ข 2.89 kB
/** * Proof of Concept: Spawn an MCP server and connect to it * * This script demonstrates: * 1. Spawning a child process running an MCP server * 2. Creating an MCP Client connected to that process * 3. Listing available tools * 4. Calling a tool */ import { Client } from '@modelcontextprotocol/sdk/client/index.js'; import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'; async function testMCPConnection() { console.log('๐Ÿš€ Starting MCP Orchestrator POC...\n'); try { // Step 1: Create MCP Client with stdio transport // This will automatically spawn the process console.log('๐Ÿ”Œ Creating MCP Client and spawning filesystem server...'); const transport = new StdioClientTransport({ command: 'mcp-server-filesystem', args: [process.cwd()] // Use current directory as workspace }); const client = new Client({ name: 'mcp-orchestrator-poc', version: '0.1.0' }, { capabilities: {} }); console.log('๐Ÿค Connecting to MCP server...'); await client.connect(transport); console.log('โœ… Connected!\n'); // Step 3: List available tools console.log('๐Ÿ”ง Listing available tools...'); const toolsResult = await client.listTools(); console.log(`Found ${toolsResult.tools.length} tools:\n`); toolsResult.tools.forEach((tool, index) => { console.log(`${index + 1}. ${tool.name}`); console.log(` Description: ${tool.description}`); console.log(); }); // Step 4: Call a tool (list directory) if (toolsResult.tools.some(t => t.name === 'read_file' || t.name === 'list_directory')) { const toolToCall = toolsResult.tools.find(t => t.name === 'list_directory' || t.name === 'read_file'); if (toolToCall) { console.log(`๐Ÿ“ž Calling tool: ${toolToCall.name}...\n`); try { const result = await client.callTool({ name: toolToCall.name, arguments: toolToCall.name === 'read_file' ? { path: 'package.json' } : { path: '.' } }); console.log('๐Ÿ“Š Tool result:'); console.log(JSON.stringify(result, null, 2)); } catch (error) { console.error('Error calling tool:', error); } } } // Cleanup console.log('\n๐Ÿงน Cleaning up...'); await client.close(); console.log('โœ… POC completed successfully!'); process.exit(0); } catch (error) { console.error('โŒ Error during POC:', error); process.exit(1); } } testMCPConnection();