filesystem-mcp.ts
1 /** 2 * MCP Filesystem Server Example 3 * 4 * Demonstrates using MCP to connect to a filesystem server. 5 * 6 * Prerequisites: 7 * npm install praisonai-ts 8 * export OPENAI_API_KEY=your-api-key 9 * 10 * Run: 11 * npx ts-node filesystem-mcp.ts 12 */ 13 14 import { Agent, createMCP } from '../../../src/praisonai-ts/src'; 15 16 async function main() { 17 console.log('=== MCP Filesystem Server Example ===\n'); 18 19 // Connect to MCP filesystem server 20 const mcp = await createMCP({ 21 transport: { 22 type: 'stdio', 23 command: 'npx', 24 args: ['-y', '@modelcontextprotocol/server-filesystem', '.'], 25 }, 26 }); 27 28 console.log('Connected to MCP filesystem server\n'); 29 30 // Get tools from MCP server 31 const tools = await mcp.tools(); 32 console.log('Available tools:', Object.keys(tools)); 33 34 // Create agent with MCP tools 35 const agent = new Agent({ 36 name: 'FileAgent', 37 instructions: 'You help manage files using the filesystem tools.', 38 tools: Object.values(tools), 39 }); 40 41 // Ask the agent to list files 42 const response = await agent.chat('List all TypeScript files in the current directory'); 43 console.log('\nResponse:', response); 44 45 // Cleanup 46 await mcp.close(); 47 } 48 49 main().catch(console.error);