MCP-本地版-带Nvidia API-大型语言模型
用于系统编排的FastMCP服务器:创建/读取文件(TXT、CSV、XLSX、DOCX、JSON)、管理文件夹、运行shell命令、启动应用程序、列出进程,并带有安全保护的文件夹压缩功能;此外,还配备了一个NVIDIA LLM客户端,内置智能查询分类器,可将自然语言映射为工具调用,具备容错回退、参数提取和文件预览功能。
增强型FastMCP系统文档
概述
增强型FastMCP系统是一个全面的、基于人工智能的文件与系统编排平台,它结合了NVIDIA语言模型的强大功能与FastMCP坚固的服务器-客户端架构。该系统为复杂的文件操作、系统管理和数据处理任务提供了自然语言接口,并具备智能查询分类功能。
系统架构
核心组件
- 增强型FastMCP服务器 (
complete_server.py)
- 全面的系统编排能力 - 通用文件创建与管理 - 系统操作与流程管理 - 可配置的安全和访问控制
- 带有查询分类器的超鲁棒NVIDIA客户端 (
complete_client.py)
- 智能查询分类自动将查询分类为知识型、行动型或混合型 - 使用NVIDIA AI模型进行自然语言处理 - 采用三重回退解析的高级意图分类 - 多策略命令解析,具备容错错误处理能力
- 配置系统
- 服务器配置(server_config.json) - 客户端配置(client_config.json) - 环境变量支持 - 运行时参数调整
关键特性
🧠 智能查询分类系统
查询类别
- 知识查询由大型语言模型(LLM)直接回答的信息请求
- 示例:“什么是机器学习?”、“解释Python编程”
- 操作查询通过MCP工具执行的系统操作
- 示例:“创建文件 report.txt”,“运行 dir 命令”,“启动记事本”
- 混合查询知识与行动响应相结合
- 示例:“解释机器学习并创建demo.py”,“什么是文件压缩并压缩我的文件夹”
分类工作流程
# Enhanced client flow with classification
User Query → Query Classifier → Route Decision
↓
Knowledge ← [LLM Response] → Action → [MCP Execution]
↓
Hybrid → [Both LLM + MCP]分类方法
- 主要的,重要的基于大型语言模型(LLM)的分类与提示工程
- 次要的基于模式的回退分类
- 三级(或高等教育阶段)关键词评分并设定置信度阈值
🔧 通用文件操作
文件创建支持
- 文本文件:
.txt,.md,.log,.ini,.cfg,.conf - 编程文件:
.py,.js,.html,.css,.json,.xml,.yaml,.sql - 办公文档:
.xlsx,.xls,.docx,.doc,.rtf - 数据文件:
.csv,.tsv - 脚本:
.bat,.sh,.ps1
高级文件管理
# Examples of supported operations
create_file(path, content="", file_type="auto", working_directory=None)
create_folder(path, working_directory=None)
read_file(path, working_directory=None)
list_directory(path=".", working_directory=None)
copy_file(source, destination, working_directory=None)
move_file(source, destination, working_directory=None)
delete_file(path, working_directory=None)
search_files(pattern, directory=".", recursive=True)🖥️ 系统操作
Shell 命令执行
- 跨平台shell命令支持(Windows CMD、PowerShell、Linux Bash)
- 可配置的超时设置
- 输出捕获与格式化
- 工作目录上下文
流程管理
- 列出运行中的进程并进行过滤
- 过程监控与统计
- 系统资源信息
- 应用程序启动能力
档案操作
- 创建ZIP文件并保留文件夹结构
- 使用适当权限进行档案提取
- 批量压缩操作
- 完整性验证
增强型自然语言接口
查询分类特征
# New client components
_setup_query_classifier() # LLM-based query routing
_setup_knowledge_llm() # Dedicated knowledge responses
classify_query() # Primary classification method
knowledge_workflow() # LLM-only workflow
action_workflow() # MCP-only workflow
hybrid_workflow() # Combined workflow
process_query() # Main routing entry pointNVIDIA AI 集成
- 支持的模型Meta Llama 3.1、Mistral、CodeLlama 等
- 高级解析意图分类并附带置信度评分
- 情境感知工作目录和会话状态管理
- 备用策略多种解析方法以提高鲁棒性
增强的分类模式
{
"query_classification": {
"knowledge": {
"keywords": ["what", "how", "why", "explain", "tell me", "define"],
"confidence_threshold": 3
},
"action": {
"keywords": ["create", "make", "run", "execute", "launch", "show"],
"confidence_threshold": 3
},
"hybrid": {
"patterns": ["explain X and create Y", "tell me about X and make Y"],
"confidence_threshold": 5
}
}
}🔒 安全与配置
访问控制
- 系统级访问控制,支持可配置限制
- 路径验证和清理
- 受限目录保护
- 文件大小限制
增强配置
{
"server": {
"max_file_size": 104857600,
"system_wide_access": true,
"restricted_paths": ["C:\Windows\System32", "/bin", "/sbin"]
},
"nvidia": {
"model": "meta/llama-3.1-8b-instruct",
"temperature": 0.1,
"max_completion_tokens": 1000
},
"classification": {
"enable_query_classification": true,
"fallback_to_action": true,
"min_confidence_threshold": 3
}
}使用示例
增强的自然语言指令
知识查询(仅限大型语言模型响应)
User: "What is machine learning and how does it work?"
Classification: Knowledge
Response: Comprehensive LLM explanation about ML concepts, algorithms, applications
User: "Explain the difference between Python and JavaScript"
Classification: Knowledge
Response: Detailed comparison of both programming languages操作查询(仅限MCP执行)
User: "Create a text file called notes.txt with some project ideas"
Classification: Action
Response: File created via MCP server with specified content
User: "Show me all files in the Documents folder"
Classification: Action
Response: Directory listing via MCP list_directory tool混合查询(结合LLM + MCP)
User: "Explain Python programming and create hello.py"
Classification: Hybrid
Response:
🧠 Knowledge Response: [Detailed Python explanation]
⚡ Action Result: [hello.py file created successfully]
User: "Tell me about data analysis and create sample.csv"
Classification: Hybrid
Response:
🧠 Knowledge Response: [Data analysis concepts and methods]
⚡ Action Result: [sample.csv created with headers]增强的客户端架构变更
新的查询处理流程
之前(仅动作客户端)
User Query → Action Parser → MCP Tool → Result之后(分类增强客户端)
User Query → Query Classifier → Branch Decision
↓
Knowledge: LLM Response → Direct Answer
Action: MCP Tools → Tool Execution Result
Hybrid: Both Workflows → Combined Response新的客户端组件
1. 查询分类系统
async def classify_query(self, user_input: str) -> str:
"""Classify query into knowledge, action, or hybrid"""
# LLM-based classification with fallback
def _fallback_classification(self, user_input: str) -> str:
"""Pattern-based classification backup"""
# Keyword scoring and confidence thresholds2. 工作流路由
async def knowledge_workflow(self, user_input: str) -> str:
"""Handle pure knowledge queries with LLM"""
async def action_workflow(self, user_input: str) -> str:
"""Handle action queries with MCP tools"""
async def hybrid_workflow(self, user_input: str) -> str:
"""Handle queries needing both knowledge and actions"""3. 增强的配置
def _setup_query_classifier(self):
"""Setup LLM-based query classification"""
def _setup_knowledge_llm(self):
"""Setup dedicated knowledge response system"""分类准确率指标
置信度评分
- 高度自信 (评分5+):直接路由
- 中等信心 (得分3-4):带有验证的路由
- 低置信度 (得分\=1.0.0
[Previous dependencies remain the same]
#### 增强的客户端依赖关系
NVIDIA AI Integration (Enhanced)
langchain-nvidia-ai-endpoints>=0.1.0 langchain-core>=0.2.0
FastMCP Client
fastmcp>=1.0.0
New: Enhanced natural language processing
Additional utilities for classification
asyncio re (for pattern matching) typing (for enhanced type hints)
### 性能特性
- **分类时间**每查询200毫秒以内
- **知识响应**1-3秒(取决于大型语言模型)
- **动作执行**简单操作\<500毫秒
- **混合运营**两个工作流的合并定时
- **备用激活**模式匹配时间小于50毫秒
### 增强的错误处理
#### 四级错误恢复
1. **主要的,重要的**NVIDIA AI查询分类
1. **次要的**NVIDIA AI动作解析
1. **“Tertiary”在中文中通常翻译为“第三级”或“高等教育阶段”,具体含义取决于上下文。在教育领域,它常用来指代中学之后的教育阶段,即大学或学院的教育**基于模式的意图分类
1. **第四纪**基于规则的命令解析,辅以用户澄清
## 高级配置
### 分类调优
Adjust classification sensitivity
"classification_config": { "knowledge_keywords": ["what", "how", "why", "explain", "define", "tell me"], "action_keywords": ["create", "make", "run", "execute", "launch", "show"], "hybrid_patterns": ["explain.*and.*create", "tell.*about.*and.*make"], "confidence_thresholds": { "knowledge": 3, "action": 3, "hybrid": 5 } }
### 工作流定制化
Custom workflow behaviors
"workflow_config": { "knowledge_workflow": { "max_response_length": 1000, "include_examples": true, "format_markdown": true }, "action_workflow": { "confirm_destructive_actions": true, "show_execution_steps": true }, "hybrid_workflow": { "knowledge_first": true, "combine_responses": true } }
## 版本历史
- **版本1.0**初始发布,包含基本的FastMCP集成
- **v1.1**增加了NVIDIA AI自然语言处理功能
- **版本1.2**增强的配置系统和错误处理机制
- **v1.3(版本1.3)**高级意图分类与多策略解析
- **v1.4**全面的文件类型支持和系统操作
- **版本1.5**: **新功能 - 智能查询分类系统**
- 为知识/动作/混合路由添加了查询分类器
- 实现了结合大型语言模型(LLM)响应的专用知识工作流程
- 增强型混合工作流程,结合大型语言模型(LLM)的知识和机器控制程序(MCP)的操作
- 增加了分类置信度评分和回退机制
______________________________________________________________________
*本文档涵盖的是增强型FastMCP系统,该系统具备智能查询分类功能——这是一个强大的、由人工智能驱动的平台,通过智能查询路由,将自然语言理解与系统稳健操作无缝结合。*