返回市场
本地智能MCP

本地智能MCP

作者:bretbouchard2 星标更新:2025-10-22

项目介绍

本地智能MCP

一个基于Swift的跨平台模型上下文协议(MCP)服务器,为AI代理提供全面的文本处理和内容分析工具,同时严格遵守安全和隐私要求。

✨ 特性

  • 🔧 MCP协议合规性:完全实现模型上下文协议规范
  • 📝 文本处理工具:21种专业工具用于文本分析、总结和内容处理
  • 🔍 内容分析:高级PII检测、意图分析和内容分类
  • 🛡️ 隐私保护:内置PII删除功能,保留音频术语
  • 🔒 企业级安全:全面的安全测试和防护措施
  • 🚀 高性能:并发请求处理与内存优化
  • 🐳 跨平台:在macOS、Linux和其他平台上构建和运行
  • 📱 离线能力:核心功能无需网络连接即可工作
  • ⚡ 流式支持:高效处理大型文档的流式处理

要求

  • Swift:6.0或更高版本
  • 平台:macOS 12.0+,Linux(Ubuntu 20.04+)
  • 内存:最小512MB,推荐1GB
  • 存储:安装需要100MB

安装

从源代码构建

git clone https://github.com/bretbouchard/Local_Intelligence_MCP.git
cd Local_Intelligence_MCP
swift build -c release

Docker安装

# 构建Docker镜像
docker build -t local-intelligence-mcp .

# 运行容器
docker run -p 3000:3000 local-intelligence-mcp

# 或使用docker-compose
docker-compose up -d

运行

swift run LocalIntelligenceMCP

配置

~/.config/local-intelligence-mcp-server/config.json创建配置文件:

{
  "server": {
    "host": "localhost",
    "port": 8050,
    "maxClients": 10
  },
  "security": {
    "requireAuthentication": false,
    "allowedClients": ["localhost"]
  },
  "features": {
    "shortcuts": { "enabled": true },
    "voiceControl": { "enabled": true },
    "systemInfo": { "enabled": true }
  }
}

环境变量

服务器也可以通过环境变量进行配置:

# 覆盖默认端口
export MCP_SERVER_PORT=8050

# 覆盖主机
export MCP_SERVER_HOST=0.0.0.0

# 覆盖最大客户端数
export MCP_MAX_CLIENTS=20

# 启用功能
export MCP_ENABLE_SHORTCUTS=true
export MCP_ENABLE_VOICE_CONTROL=true
export MCP_ENABLE_SYSTEM_INFO=true

# 设置日志级别
export MCP_LOG_LEVEL=info

🛠️ 可用的MCP工具

文本处理工具

工具描述示例用法
text_normalize清理和标准化文本输入{"text": " messy text ", "removeFillers": true}
text_chunking将大文本分割成可管理的部分{"text": "long document...", "maxChunkSize": 1000}
text_rewrite增强和重组内容{"text": "original text", "style": "professional"}
pii_redaction检测并删除敏感信息{"text": "Contact: john@example.com", "policy": "conservative"}

内容分析工具

工具描述示例用法
content_purpose_detector分析内容意图和目的{"text": "meeting notes...", "context": {"domain": "business"}}
query_analysis提取查询中的关键词和意图{"query": "find sales reports from last quarter"}
intent_recognition在文本中识别用户意图{"text": "Please schedule a meeting for tomorrow"}

摘要生成工具

工具描述示例用法
summarization生成文本摘要{"text": "long article...", "style": "executive", "maxLength": 200}
focused_summarization创建有针对性的摘要{"text": "document...", "focus": ["key_decisions", "action_items"]}
enhanced_summarization先进的带有分析的摘要生成{"text": "complex document...", "analysisDepth": "deep"}

提取工具

工具描述示例用法
tag_generation提取相关关键词和标签{"text": "article about AI and machine learning", "maxTags": 10}
schema_extraction从文本创建结构化数据{"text": "contact info...", "schemaType": "person"}
feedback_analysis分析用户反馈和情感{"feedback": "Product is great but needs improvement"}

目录工具

工具描述示例用法
catalog_summarization分析目录内容{"catalog": [{"title": "Item 1", "description": "..."}]}
session_notes处理会议记录{"transcript": "Meeting discussion...", "sessionType": "meeting"}
similarity_ranking查找相似内容{"query": "machine learning basics", "documents": [...]}

系统工具

工具描述示例用法
health_check服务器健康和状态监控{}
system_info获取系统信息{"categories": ["device", "performance"]}
capabilities_list列出可用工具和功能{}

🔐 安全特性

  • 输入验证:对所有输入进行全面验证和清理
  • 权限执行:基于角色的访问控制,具有细粒度权限
  • 攻击防护:防止注入、时间延迟和内存攻击
  • 速率限制:防止暴力破解和字典攻击
  • 审计日志:完整的安全事件日志和监控
  • 会话管理:具有劫持保护的安全会话处理

与AI助手的使用

添加到您的AI助手配置:

{
  "mcpServers": {
    "local-intelligence-mcp": {
      "type": "stdio",
      "command": "swift",
      "args": [
        "run",
        "--package-path",
        "/your/path/local_intelligence_mcp",
        "LocalIntelligenceMCP",
        "start-command",
        "--mcp-mode"
      ]
    }
  }
}

或者使用环境变量:

{
  "mcpServers": {
    "local-intelligence-mcp": {
      "command": "local-intelligence-mcp-server",
      "env": {
        "MCP_SERVER_PORT": "8050"
      }
    }
  }
}

开发

项目结构

Sources/LocalIntelligenceMCP/
├── Core/                # MCP协议实现
├── Tools/               # MCP工具实现
├── Services/            # Apple API集成
├── Security/            # 隐私和安全特性
├── Models/              # 数据模型
└── Utils/               # 常用工具

🧪 测试

该项目包含一个全面的测试套件,包括400多个测试方法,覆盖:

测试类别

  • 单元测试:单个组件测试,200多个方法
  • 集成测试:端到端工作流程测试,20多个方法
  • 性能测试:并发负载测试,10多个方法
  • 安全测试:攻击面分析,22多个方法

运行测试

# 运行所有测试
swift test

# 运行特定测试类别
swift test --filter SecurityAuditTests
swift test --filter ConcurrencyTests
swift test --filter EndToEndTests

# 使用详细输出运行
swift test --verbose

# 运行特定测试
swift test --filter testSecurityAudit_MaliciousParameterInjection

测试覆盖率

  • 安全性测试:针对OWASP Top 10的全面验证
  • 性能测试:高达100个并发请求的负载测试
  • 集成测试:完整的用户故事工作流程
  • 模型测试:所有数据模型,包括边缘情况验证

代码风格

此项目使用SwiftLint和SwiftFormat以保持一致的代码风格:

# 安装工具(如果尚未安装)
brew install swiftlint swiftformat

# 运行代码检查
swiftlint

# 格式化代码
swiftformat .

🔒 安全性和隐私

🛡️ 安全特性

  • 全面输入验证:防止注入攻击
  • 基于角色的访问控制:细粒度权限执行
  • 攻击面保护:防御时间延迟、内存和并发攻击
  • 速率限制:防止暴力破解和字典攻击
  • 会话安全:防止劫持和特权提升
  • 审计日志:完整的安全事件监控和日志

🛡️ 隐私特性

  • 不持久存储敏感用户数据
  • 集成Apple Keychain以安全存储凭证
  • 使用严格的并发Swift 6实现
  • 防止信息泄露
  • 敏感操作的零知识架构

🧪 安全测试

服务器包含22个全面的安全测试,覆盖:

  • 输入验证和清理测试
  • 认证和授权测试
  • 攻击面分析和渗透测试
  • 字典攻击防护验证
  • 时间延迟攻击漏洞检测
  • 内存耗尽防护测试
  • 并发滥用抵抗力验证
  • 竞态条件漏洞检测
  • 信息泄露分析
  • 协议滥用预防

总安全测试覆盖率:涵盖所有攻击向量的300多个安全场景

📚 API文档

MCP协议端点

服务器信息

{
  "jsonrpc": "2.0",
  "method": "initialize",
  "params": {
    "protocolVersion": "2024-11-05",
    "capabilities": {
      "tools": {
        "listChanged": true
      }
    }
  }
}

工具列表

{
  "jsonrpc": "2.0",
  "method": "tools/list",
  "result": {
    "tools": [
      {
        "name": "shortcuts_execute",
        "description": "执行Apple快捷方式",
        "inputSchema": {
          "type": "object",
          "properties": {
            "shortcutName": {"type": "string"},
            "input": {"type": "object"},
            "timeout": {"type": "number", "default": 10}
          },
          "required": ["shortcutName"]
        }
      }
    ]
  }
}

工具使用示例

执行快捷方式

{
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "name": "shortcuts_execute",
    "arguments": {
      "shortcutName": "Send Email",
      "input": {
        "to": "user@example.com",
        "subject": "Meeting Reminder",
        "body": "Don't forget our meeting at 2 PM"
      },
      "timeout": 60
    }
  }
}

获取系统信息

{
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "name": "system_info",
    "arguments": {
      "categories": ["device", "performance", "network"],
      "includeSensitive": false
    }
  }
}

语音控制命令

{
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "name": "voice_control",
    "arguments": {
      "command": "Open Safari and go to apple.com",
      "timeout": 30,
      "accessibility": true
    }
  }
}

响应格式

成功响应

{
  "jsonrpc": "2.0",
  "id": "request-id",
  "result": {
    "content": [
      {
        "type": "text",
        "text": "快捷方式执行成功"
      }
    ],
    "isError": false
  }
}

错误响应

{
  "jsonrpc": "2.0",
  "id": "request-id",
  "error": {
    "code": -32602,
    "message": "无效参数",
    "data": {
      "details": "需要shortcutName"
    }
  }
}

🏗️ 架构

Swift 6并发模型

  • 基于Actor的设计:线程安全的并发操作
  • 严格的并发:编译时数据竞争预防
  • 异步/等待:现代异步编程模式
  • 任务组:复杂操作的结构化并发

安全架构

  • 零信任安全:所有输入验证和清理
  • 多层防御:每层的多重安全控制
  • 安全默认设置:默认配置安全
  • 审计跟踪:完整的安全事件日志

性能特征

  • 并发请求处理:100+同时请求
  • 内存效率:优化的内存使用模式
  • 低延迟:大多数操作的响应时间低于100毫秒
  • 资源管理:自动清理和资源池

宪章

此项目遵循本地智能MCP宪章,定义了核心原则:

  1. MCP协议合规性 - 严格遵守MCP标准
  2. 安全与隐私优先 - 用户数据保护优先
  3. Swift原生实现 - 原生Apple平台开发
  4. 工具化架构 - 模块化、独立可测试设计
  5. 离线优先设计 - 核心功能离线工作

文档

贡献

  1. 分叉仓库
  2. 创建功能分支
  3. 遵循宪章和代码风格指南
  4. 为新功能添加测试
  5. 确保所有测试通过
  6. 提交拉取请求

许可

[许可证名称] - 详情见LICENSE文件。

支持

<p align="center"> <a href="https://ko-fi.com/bretbouchard" target="_blank"> <img src="https://cdn.ko-fi.com/cdn/kofi3.png?v=3" alt="支持我" height="45" style="margin-right:10px;"> </a> <a href="https://buymeacoffee.com/bretbouchard" target="_blank"> <img src="https://gips0.baidu.com/it/u=4028654372,1962960725&fm=3081&app=3081&f=PNG?w=170&h=37" alt="买我一杯咖啡" height="45"> </a> </p>