本地智能管理控制平台(MCP)
一个基于Swift的跨平台模型上下文协议(MCP)服务器,为人工智能代理提供全面的文本处理和内容分析工具,同时严格遵守安全和隐私要求。
✨ 特点/功能
- 🔧 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 releaseDocker 安装
# Build Docker image
docker build -t local-intelligence-mcp .
# Run the container
docker run -p 3000:3000 local-intelligence-mcp
# Or use 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 }
}
}环境变量
服务器也可以通过环境变量进行配置:
# Override default port
export MCP_SERVER_PORT=8050
# Override host
export MCP_SERVER_HOST=0.0.0.0
# Override max clients
export MCP_MAX_CLIENTS=20
# Enable features
export MCP_ENABLE_SHORTCUTS=true
export MCP_ENABLE_VOICE_CONTROL=true
export MCP_ENABLE_SYSTEM_INFO=true
# Set log level
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 protocol implementation
├── Tools/ # MCP tool implementations
├── Services/ # Apple API integrations
├── Security/ # Privacy and security features
├── Models/ # Data models
└── Utils/ # Common utilities🧪 测试
这个项目包含一个全面的测试套件,其中 400多种测试方法 覆盖:
测试类别
- 单元测试使用200多种方法进行单个组件测试
- 集成测试采用20多种方法进行端到端工作流程测试
- 性能测试使用10+种方法进行并发负载测试
- 安全测试使用22+种方法进行攻击面分析
运行测试
# Run all tests
swift test
# Run specific test categories
swift test --filter SecurityAuditTests
swift test --filter ConcurrencyTests
swift test --filter EndToEndTests
# Run with verbose output
swift test --verbose
# Run specific test
swift test --filter testSecurityAudit_MaliciousParameterInjection测试覆盖率
- 安全测试针对OWASP Top 10的全面验证
- 性能测试进行高达100个并发请求的负载测试
- 集成测试完整的用户故事工作流程
- 模型测试所有数据模型均包含边缘情况验证
代码风格
这个项目使用 SwiftLint 和 SwiftFormat 来保持代码风格的一致性:
# Install tools (if not already installed)
brew install swiftlint swiftformat
# Run linting
swiftlint
# Format code
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": "Execute Apple Shortcuts",
"inputSchema": {
"type": "object",
"properties": {
"shortcutName": {"type": "string"},
"input": {"type": "object"},
"timeout": {"type": "number", "default": 30}
},
"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": "Shortcut executed successfully"
}
],
"isError": false
}
}错误响应
{
"jsonrpc": "2.0",
"id": "request-id",
"error": {
"code": -32602,
"message": "Invalid params",
"data": {
"details": "shortcutName is required"
}
}
}🏗️ 建筑学
Swift 6 并发模型
- 基于角色的设计线程安全的并发操作
- 严格并发编译时数据竞争预防
- 异步/等待(Async/Await)现代异步编程模式
- 任务组为复杂操作设计的结构化并发
安全架构
- 零信任安全所有输入均已验证并清理
- 分层防御每一层都有多重安全控制措施
- 故障安全默认设置默认配置安全
- 审计轨迹/审计追踪安全事件的完整日志记录
性能特性
- 并发请求处理100+ 个并发请求
- 内存效率优化了内存使用模式
- 低延迟大多数操作的响应时间低于100毫秒
- 资源管理自动清理和资源池化
宪法
这个项目遵循了 《地方智能MCP(多智能体协作平台/管理控制协议等,具体含义需根据上下文确定)章程》 这定义了核心原则:
- MCP协议合规性 - 严格遵守MCP标准
- 安全与隐私优先 - 用户数据保护为优先
- Swift原生实现 - 原生苹果平台开发
- 基于工具的架构 - 模块化、可独立测试的设计
- 离线优先设计 - 核心功能支持离线使用
文档
做出贡献
- 为仓库创建分支(或:克隆仓库)
- 创建一个特性分支
- 遵循宪法和代码风格指南
- 为新功能添加测试
- 确保所有测试通过
- 提交一个拉取请求
许可证
\[许可证名称\] - 详情请参见LICENSE文件。
