MCP 集成
在 Astreus 文档中了解 MCP 集成,获取用于构建智能体系统的设置指导、API 模式和实用示例。 了解构建可靠的 Astreus 智能体系统所需的设置模式、API 和实用示例。
使用 Model Context Protocol 将智能体与外部工具连接。
快速开始
克隆完整示例
最简单的开始方式是克隆完整的示例仓库:
git clone https://github.com/astreus-ai/examples
cd examples/mcp-integration
npm install或仅安装包
如果你更喜欢从零开始构建:
npm install @astreus-ai/astreus环境配置
# .env
OPENAI_API_KEY=sk-your-openai-api-key-here
DB_URL=sqlite://./astreus.dbMCP 服务器集成
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);运行示例
如果你克隆了仓库:
npm run dev如果你从零开始构建,请创建一个 index.ts 文件并写入上面的代码,然后运行:
npx tsx index.ts仓库
完整示例可在 GitHub 上获取:examples/mcp-integration
最后更新时间:2026年7月6日
本节内容
你的第一个智能体
在 Astreus 文档中了解 你的第一个智能体,获取用于构建智能体系统的设置指导、API 模式和实用示例。 了解构建可靠的 Astreus 智能体系统所需的设置模式、API 和实用示例。
带记忆的智能体
在 Astreus 文档中了解 带记忆的智能体,获取用于构建智能体系统的设置指导、API 模式和实用示例。 了解构建可靠的 Astreus 智能体系统所需的设置模式、API 和实用示例。
带知识库的智能体
在 Astreus 文档中了解 带知识库的智能体,获取用于构建智能体系统的设置指导、API 模式和实用示例。 了解构建可靠的 Astreus 智能体系统所需的设置模式、API 和实用示例。
带视觉能力的智能体
在 Astreus 文档中了解 带视觉能力的智能体,获取用于构建智能体系统的设置指导、API 模式和实用示例。 了解构建可靠的 Astreus 智能体系统所需的设置模式、API 和实用示例。