MCP統合

Model Context Protocolを使って、エージェントを外部ツールに接続します。

クイックスタート#

完全なサンプルをクローンする#

最も簡単な始め方は、完全なサンプルリポジトリをクローンすることです。

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

またはパッケージのみをインストール#

ゼロから構築したい場合は次のようにします。

bash
npm install @astreus-ai/astreus

環境設定#

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

MCPサーバー統合#

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);

サンプルの実行#

リポジトリをクローンした場合は次を実行します。

bash
npm run dev

ゼロから構築した場合は、上記のコードを含むindex.tsファイルを作成し、次を実行します。

bash
npx tsx index.ts

リポジトリ#

完全なサンプルはGitHubで公開されています: examples/mcp-integration