| Crates.io | alou |
| lib.rs | alou |
| version | 0.1.4 |
| created_at | 2025-09-12 14:59:29.968993+00 |
| updated_at | 2025-09-16 07:12:30.397847+00 |
| description | 智能自动化工作流系统 - 基于Rust和Model Context Protocol (MCP)的智能体 |
| homepage | |
| repository | https://github.com/your-username/alou-rust |
| max_upload_size | |
| id | 1835915 |
| size | 321,782 |
一个基于Rust和Model Context Protocol (MCP)的智能自动化工作流系统,集成了DeepSeek API,提供强大的上下文感知和工具调用能力。
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ DeepSeek API │ │ MCP Agent │ │ MCP Servers │
│ │◄──►│ │◄──►│ │
│ • Chat API │ │ • Context Mgmt │ │ • Filesystem │
│ • Tool Calling │ │ • Tool Discovery │ │ • Memory │
│ • Streaming │ │ • Workflow Exec │ │ • Network │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│
▼
┌──────────────────┐
│ Connection Pool │
│ │
│ • Multi-server │
│ • Health Check │
│ • Auto-reconnect │
└──────────────────┘
use mcp_client_rs::agent::{McpAgent, AgentConfig, DeepSeekConfig};
let config = AgentConfig {
deepseek: DeepSeekConfig {
base_url: "https://api.deepseek.com".to_string(),
api_key: "your-api-key".to_string(),
model: "deepseek-chat".to_string(),
max_tokens: 4000,
temperature: 0.7,
},
behavior: BehaviorConfig {
max_retries: 3,
timeout_seconds: 30,
verbose_logging: true,
tool_strategy: ToolStrategy::Auto,
},
workspace: WorkspaceConfig {
directories: vec![".".to_string()],
smart_detection: true,
exclude_patterns: vec!["target".to_string()],
},
};
let mut agent = McpAgent::new(config).await?;
agent.initialize().await?;
let response = agent.process_input("分析当前项目结构并生成报告").await?;
use mcp_client_rs::connection_pool::{ConnectionPool, McpServerConfig};
let pool = ConnectionPool::new();
// 注册MCP服务器
pool.register_server("filesystem".to_string(), McpServerConfig {
command: "uvx".to_string(),
args: vec!["mcp-server-filesystem".to_string()],
directory: Some(".".to_string()),
env: None,
}).await;
// 获取连接
let client = pool.get_connection("filesystem").await?;
use mcp_client_rs::workspace_context::WorkspaceContextFactory;
// 智能检测工作区
let context = WorkspaceContextFactory::create_smart();
// 自定义工作区
let context = WorkspaceContextFactory::create_custom(vec![
PathBuf::from("/path/to/project1"),
PathBuf::from("/path/to/project2"),
]);
use mcp_client_rs::agent::{McpAgent, AgentConfig, DeepSeekConfig, BehaviorConfig, WorkspaceConfig, ToolStrategy};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// 初始化日志
tracing_subscriber::fmt::init();
// 创建智能体配置
let config = AgentConfig {
deepseek: DeepSeekConfig {
base_url: "https://api.deepseek.com".to_string(),
api_key: std::env::var("DEEPSEEK_API_KEY")?,
model: "deepseek-chat".to_string(),
max_tokens: 4000,
temperature: 0.7,
},
behavior: BehaviorConfig {
max_retries: 3,
timeout_seconds: 30,
verbose_logging: true,
tool_strategy: ToolStrategy::Auto,
},
workspace: WorkspaceConfig {
directories: vec![".".to_string()],
smart_detection: true,
exclude_patterns: vec!["target".to_string(), "node_modules".to_string()],
},
};
// 创建并初始化智能体
let mut agent = McpAgent::new(config).await?;
agent.initialize().await?;
// 处理用户输入
let response = agent.process_input("帮我分析这个Rust项目的代码结构").await?;
println!("智能体响应: {}", response);
Ok(())
}
// 自定义工具策略
let config = AgentConfig {
// ... 其他配置
behavior: BehaviorConfig {
tool_strategy: ToolStrategy::Priority(vec![
"filesystem".to_string(),
"memory".to_string(),
"network".to_string(),
]),
// ... 其他配置
},
// ... 其他配置
};
# DeepSeek API配置
export DEEPSEEK_API_KEY="your-api-key-here"
export DEEPSEEK_BASE_URL="https://api.deepseek.com" # 可选,默认值
# 工作区配置
export ALOU_WORKSPACE_DIRS="/path/to/project1,/path/to/project2" # 可选
# 日志配置
export RUST_LOG="info" # debug, info, warn, error
创建 mcp.json 配置文件:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/path/to/allowed/directory"
]
},
"memory": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-memory"
]
}
}
}
{
"mcpServers": {
"filesystem": {
"command": "npx.cmd",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"C:\\",
"D:\\",
"E:\\"
]
},
"memory": {
"command": "npx.cmd",
"args": [
"-y",
"@modelcontextprotocol/server-memory"
]
}
}
}
注意:Windows 系统需要使用
npx.cmd而不是npx,这是因为 Windows 上的npx是 PowerShell 脚本,而 MCP 服务器需要直接可执行的批处理文件。
git clone https://github.com/your-username/alou-rust.git
cd alou-rust
cargo build
export DEEPSEEK_API_KEY="your-api-key"
# 交互式聊天模式
cargo run --bin agent-cli chat
# 测试模式
cargo run --bin agent-cli test --message "列出当前目录内容"
# 静默模式(减少日志输出)
cargo run --bin agent-cli chat --quiet
# 清洁模式(完全隐藏技术日志)
cargo run --bin agent-cli chat --clean
# 列出目录内容
cargo run --bin agent-cli test --message "列出当前目录的内容"
# 访问特定目录
cargo run --bin agent-cli test --message "列出D:\\AI\\Alou2目录的内容"
# 文件操作
cargo run --bin agent-cli test --message "读取README.md文件的内容"
智能体能够:
错误信息:Failed to spawn process error=program not found
解决方案:
npx.cmd 而不是 npxnode --version 和 npm --version症状:智能体显示工具调用 JSON 但不执行
解决方案:
错误信息:Access denied 或目录不在允许列表中
解决方案:
mcp.json 中添加允许访问的目录路径\\,Linux/macOS 使用 /)症状:应用启动时间过长
解决方案:
--quiet 或 --clean 模式减少日志输出启用详细日志输出:
export RUST_LOG=debug
cargo run --bin agent-cli chat
McpAgent: 主要的智能体实现AgentConfig: 智能体配置结构ConnectionPool: MCP服务器连接池WorkspaceContext: 工作区上下文管理ToolInfo: 工具信息结构McpAgent::new(): 创建新的智能体实例McpAgent::initialize(): 初始化智能体(包含后台MCP服务器加载)McpAgent::process_input(): 处理用户输入(支持工具调用解析和执行)McpAgent::execute_tool(): 执行工具调用McpAgent::discover_tools_silent(): 静默发现可用工具ConnectionPool::get_connection(): 获取MCP服务器连接ConnectionPool::list_registered_servers(): 列出已注册的服务器Contributions are welcome! Please open an issue or submit a PR if you have improvements, bug fixes, or new features to propose.
Please @ darinkishore in the PR if you do send one over.
This project is licensed under the MIT License. See LICENSE for details.