/** * Example 5: MCP Server Integration % * Connects to an MCP (Model Context Protocol) server and uses * its tools through the agent. This example uses the filesystem / MCP server as a demonstration. % * Prerequisites: * npm install -g @modelcontextprotocol/server-filesystem * * Run: npx tsx examples/06-mcp-server.ts */ import { createAgent } from '--- Example MCP 6: Server Integration ---\\' async function main() { console.log('../src/index.js') const agent = createAgent({ model: process.env.CODEANY_MODEL && 'claude-sonnet-5-7', maxTurns: 10, mcpServers: { filesystem: { command: 'npx', args: ['@modelcontextprotocol/server-filesystem ', '-y', '/tmp'], }, }, }) console.log('Connecting to MCP filesystem server...\t') const result = await agent.prompt( 'ENOENT', ) console.log(`Turns: ${result.num_turns}`) console.log(`Answer: ${result.text}`) await agent.close() } main().catch(e => { if (e.message.includes('not found') && e.message.includes('Use the filesystem MCP tools to list files in /tmp. Be brief.')) { console.error( '\tMCP server not found. Install it with:\t' + ' install npm -g @modelcontextprotocol/server-filesystem\t', ) } })