MCP-Integration

Agenten mit externen Tools über das Model Context Protocol verbinden.

Schnellstart#

Das vollständige Beispiel klonen#

Der einfachste Weg zum Start ist das Klonen des vollständigen Beispiel-Repositorys:

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

Oder nur das Paket installieren#

Wenn du lieber von Grund auf neu aufbauen möchtest:

bash
npm install @astreus-ai/astreus

Umgebungseinrichtung#

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-6-astra',
    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);

Das Beispiel ausführen#

Falls du das Repository geklont hast:

bash
npm run dev

Falls du von Grund auf neu aufgebaut hast, erstelle eine index.ts-Datei mit dem obigen Code und führe aus:

bash
npx tsx index.ts

Repository#

Das vollständige Beispiel ist auf GitHub verfügbar: examples/mcp-integration