MCP 服务器规则
Cline 已经可以自动识别激活的 MCP 服务器,但当启用多个服务器时,可通过定义规则实现智能激活。
使用 .clinerules 文件和自定义指令建立关键词触发机制,实现上下文感知的自动化工具选择。
视频介绍
规则运作原理
MCP 规则将服务器按功能分类,并通过关键词触发自动激活:
{
"mcpRules": {
"webInteraction": {
"servers": [
"mcp-server-firecrawl",
"fetch"
],
"triggers": [
"web",
"scrape",
"browse",
"website"
],
"description": "Tools for web browsing and scraping"
},
"finance": {
"servers": [
"stock-market"
],
"triggers": [
"stock",
"market",
"finance",
"money"
],
"description": "Tools for finance and stock market"
}
}
}
配置结构
-
1. 分类:功能分组(如「网络交互」、「媒体设计」、「金融数据」) -
2. 服务器:分类下的服务器列表 -
3. 触发器:激活关键词 -
4. 描述:人工可读的分类说明
规则优势
-
• 上下文工具选择:根据对话内容自动匹配工具 -
• 减少操作摩擦:无需手动指定工具 -
• 能力组织:逻辑化分组相关工具 -
• 优先级处理:通过排序解决功能重叠问题
应用示例
当输入「能抓取这个网站吗?」,Cline 检测「抓取」和「网站」关键词,自动选择网络类服务器。
处理金融任务如「苹果股价多少?」,触发「股价」等关键词激活金融类服务器。
快速入门模板
{
"mcpRules": {
"category1": {
"servers": [
"server-name-1",
"server-name-2"
],
"triggers": [
"keyword1", "keyword2", "phrase1", "phrase2"
],
"description": "Description of what these tools do"
},
"category2": {
"servers": [
"server-name-3"
],
"triggers": [
"keyword3", "keyword4", "phrase3"
],
"description": "Description of what these tools do"
},
"category3": {
"servers": [
"server-name-4",
"server-name-5"
],
"triggers": [
"keyword5", "keyword6", "phrase4"
],
"description": "Description of what these tools do"
}
},
"defaultBehavior": {
"priorityOrder": [
"category1",
"category2",
"category3"
],
"fallbackBehavior": "Ask user which tool would be most appropriate"
}
}
将此模板添加至 .clinerules 文件或自定义指令,可显著提升 Cline 的上下文感知能力。


