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:
git clone https://github.com/astreus-ai/examples
cd examples/mcp-integration
npm installOr Install Package Only#
If you prefer to build from scratch:
npm install @astreus-ai/astreusEnvironment Setup#
# .env
OPENAI_API_KEY=sk-your-openai-api-key-here
DB_URL=sqlite://./astreus.dbMCP Server Integration#
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:
npm run devIf you built from scratch, create an index.ts file with the code above and run:
npx tsx index.tsRepository#
The complete example is available on GitHub: examples/mcp-integration