MCP Integration

Connect agents with external tools using Model Context Protocol.

Quick Start#

Clone the Complete Example#

The easiest way to get started is to clone the complete example repository:

bash
git clone https://github.com/astreus-ai/examples
cd examples/mcp-integration
npm install

Or Install Package Only#

If you prefer to build from scratch:

bash
npm install @astreus-ai/astreus

Environment Setup#

bash
# .env
OPENAI_API_KEY=sk-your-openai-api-key-here
DB_URL=sqlite://./astreus.db

MCP Server Integration#

typescript
import { config } from 'dotenv';
import { Agent, Graph } from '@astreus-ai/astreus';

config();

async function main() {
  const mainAgent = await Agent.create({
    name: 'FileAnalysisAgent',
    model: 'gpt-4o',
    systemPrompt: 'You are a file analysis agent that processes files using graph-based workflows and MCP tools.'
  });

  const mcpConfig = {
    name: 'filesystem',
    command: "npx", 
    args: ["@modelcontextprotocol/server-filesystem", process.cwd()]
  };

  await mainAgent.addMCPServers([mcpConfig]);
  await new Promise(resolve => setTimeout(resolve, 3000));
  
  const analysisGraph = new Graph({
    name: 'File Summary Workflow',
    maxConcurrency: 1
  }, mainAgent);

  const readTask = analysisGraph.addTaskNode({
    name: 'File Reading',
    prompt: 'Read the content of "./info.txt" file and analyze it.',
    priority: 1
  });

  const summaryTask = analysisGraph.addTaskNode({
    name: 'Summary Creation', 
    prompt: 'Based on the analyzed file content from the previous task, create a concise summary and save it as "./summary.txt" file.',
    dependencies: [readTask],
    priority: 2
  });

  const result = await analysisGraph.run({ 
    stream: true,
    onChunk: (chunk) => {
      console.log(chunk);
    }
  });
}

main().catch(console.error);

Running the Example#

If you cloned the repository:

bash
npm run dev

If you built from scratch, create an index.ts file with the code above and run:

bash
npx tsx index.ts

Repository#

The complete example is available on GitHub: examples/mcp-integration