DAZ命令MCP服务器
*一种模型上下文协议(MCP)服务器,提供基于会话的命令执行和基于LLM的智能摘要。*
______________________________________________________________________
🚀 特性
- 🔧 会话管理:创建、打开和管理隔离的命令执行会话
- ⚡ 命令执行:运行带有超时控制和工作目录管理的shell命令
- 📁 文件操作:具有全面错误处理功能的读写文本文件
- 🤖 LLM总结:使用结构化LLM响应自动跟踪会话进度
- 📋 事件日志记录:完成会议期间所有业务的审计跟踪
- 🔒 线程安全:具有适当同步的稳健并发操作
📦 安装
先决条件
- Python 3.8+
fastmcp图书馆dazllmLLM集成库
快速设置
- 克隆此存储库:
git clone https://github.com/yourusername/daz-command-mcp.git
cd daz-command-mcp- 安装依赖项:
pip install -r requirements.txt- 配置LLM模型 在脚本中(默认值:
lm-studio:openai/gpt-oss-20b)
🎯 用法
启动服务器
python main.py可用工具
会话管理
daz_sessions_list()-列出所有会话并确定活动会话daz_session_create(name, description)-创建并激活新会话daz_session_open(session_id)-打开并激活现有会话daz_session_current()-获取当前活动会话的详细信息daz_session_close()-关闭当前会话daz_session_rename(old_name, new_name)-重命名现有会话daz_session_delete(session_name)-通过移动到deleted_sessions删除会话
命令和文件操作
所有命令和文件操作都需要活动会话和上下文参数:
daz_command_cd(directory, current_task, summary_of_what_we_just_did, summary_of_what_we_about_to_do)-更改工作目录daz_command_read(file_path, current_task, summary_of_what_we_just_did, summary_of_what_we_about_to_do)-读取文本文件daz_command_write(file_path, content, current_task, summary_of_what_we_just_did, summary_of_what_we_about_to_do)-编写文本文件daz_command_run(command, current_task, summary_of_what_we_just_did, summary_of_what_we_about_to_do, timeout=60)-执行shell命令
学习与指导
daz_add_learnings(learning_info)-为会议添加重要发现和背景daz_instructions_read()-阅读当前会话说明daz_instructions_add(instruction)-向会话添加新指令daz_instructions_replace(instructions)-用新列表替换所有说明daz_record_user_request(user_request)-在多步骤任务开始时记录用户请求
工作流示例
# Create a new session
daz_session_create("Setup Project", "Setting up a new Python project with dependencies")
# Navigate to project directory
daz_command_cd("/path/to/project",
"Setting up Python project",
"Created new session for project setup",
"Navigate to project root directory")
# Run commands
daz_command_run("pip install -r requirements.txt",
"Setting up Python project",
"Navigated to project directory",
"Install project dependencies")
# Read configuration
daz_command_read("config.json",
"Setting up Python project",
"Installed dependencies successfully",
"Review current configuration settings")
# Write new file
daz_command_write("setup.py", "...",
"Setting up Python project",
"Reviewed configuration file",
"Create package setup file")🏗️ 建筑
会话存储
会话以JSON文件的形式存储在 sessions/ 目录具有以下结构:
{
"id": "unique-session-id",
"name": "Session Name",
"description": "Detailed description",
"created_at": 1692123456.789,
"updated_at": 1692123456.789,
"summary": "LLM-generated summary",
"progress": "Current progress status",
"current_directory": "/current/working/dir",
"events_count": 42
}事件日志记录
每个操作都记录在 event_log.jsonl:
{
"timestamp": 1692123456.789,
"type": "run|read|write|cd|user_request|learning",
"current_task": "The task being worked on",
"summary_of_what_we_just_did": "What was just completed",
"summary_of_what_we_about_to_do": "What's planned next",
"inputs": {...},
"outputs": {...},
"duration": 0.123
}LLM集成
服务器使用异步LLM处理来维护会话摘要:
- 🔄 后台处理:摘要在单独的线程中运行
- 🛡️ 容错:LLM故障不会影响MCP操作
- 📋 结构化输出:使用Pydantic模型进行可靠的解析
- ⚙️ 可配置模型:易于在不同LLM提供商之间切换
⚙️ 配置
LLM模型
编辑 LLM_MODEL_NAME 恒常 src/models.py:
LLM_MODEL_NAME = "your-model-name"会话目录
会话存储在 ./sessions/ 默认情况下。这可以通过更改 SESSIONS_DIR 恒常 src/models.py.
🛠️ 错误处理
- 🔄 故障弱化:即使LLM摘要失败,操作也会继续
- 📝 综合录井:所有错误都记录到stderr
- ✅ 输入验证:强大的参数检查和净化
- 🔒 文件安全:原子文件操作可防止损坏
🔗 整合
此MCP服务器与Claude Desktop和其他MCP兼容客户端集成。将其添加到MCP配置中:
{
"mcpServers": {
"daz-command": {
"command": "python",
"args": ["/path/to/main.py"]
}
}
}📁 项目结构
daz-command-mcp/
├── README.md # This file
├── main.py # Entry point
├── requirements.txt # Dependencies
├── images/ # Documentation images
├── sessions/ # Session storage (auto-created)
└── src/ # Source code
├── __init__.py
├── command_executor.py # Command execution logic
├── history_manager.py # Session history management
├── mcp_tools.py # MCP tool definitions
├── models.py # Data models and constants
├── session_manager.py # Session lifecycle management
├── summary_generator.py # LLM summary generation
├── summary_worker.py # Background summarization worker
├── utils.py # Utility functions
└── tests/ # Unit tests
├── test_add_learnings.py
├── test_initialization_fix.py
├── test_llm_system_integration.py
├── test_new_parameter_system.py
└── test_summary_generation.py🧪 测试
运行综合测试套件:
# Run all tests
python -m pytest src/tests/
# Run specific test
python -m pytest src/tests/test_summary_generation.py -v
# Run with coverage
python -m pytest src/tests/ --cov=src🤝 贡献
- 分叉存储库
- 创建要素分支(
git checkout -b feature/amazing-feature) - 进行更改
- 如果适用,添加测试
- 提交您的更改(
git commit -m 'Add amazing feature') - 推到分支(
git push origin feature/amazing-feature) - 提交拉取请求
📜 许可证
\[在此处添加您的许可证\]
📦 依赖项
- fastmcp:MCP服务器框架
- 达兹勒姆:LLM集成库
💬 支持
有关问题和疑问,请在GitHub上打开问题或联系\[您的联系信息\]。
______________________________________________________________________
*内置于❤️ 模型上下文协议生态系统*
许可证
该项目已获得许可 CC BY NC 4.0 -可自由使用和修改,但未经许可不得用于商业用途。
