一个基于Swift的跨平台模型上下文协议(MCP)服务器,为AI代理提供全面的文本处理和内容分析工具,同时严格遵守安全和隐私要求。
git clone https://github.com/bretbouchard/Local_Intelligence_MCP.git
cd Local_Intelligence_MCP
swift build -c release
# 构建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
| 工具 | 描述 | 示例用法 |
|---|---|---|
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助手配置:
{
"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多个测试方法,覆盖:
# 运行所有测试
swift test
# 运行特定测试类别
swift test --filter SecurityAuditTests
swift test --filter ConcurrencyTests
swift test --filter EndToEndTests
# 使用详细输出运行
swift test --verbose
# 运行特定测试
swift test --filter testSecurityAudit_MaliciousParameterInjection
此项目使用SwiftLint和SwiftFormat以保持一致的代码风格:
# 安装工具(如果尚未安装)
brew install swiftlint swiftformat
# 运行代码检查
swiftlint
# 格式化代码
swiftformat .
服务器包含22个全面的安全测试,覆盖:
总安全测试覆盖率:涵盖所有攻击向量的300多个安全场景
{
"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"
}
}
}
此项目遵循本地智能MCP宪章,定义了核心原则:
[许可证名称] - 详情见LICENSE文件。