Token导航 LogoToken导航TokenDH.com
MCP Server Ios logo
开发工具stdio官方级别未说明来源级核验

MCP Server Ios

MCP Server

MCP Xcode Server 是一个本地化 AI 编程助手,通过集成 Ollama LLM 和 LanceDB 向量数据库,为 Xcode 提供代码生成、解释、修复及上下文感知的编程辅助功能。

工具数

8

提示词数

0

GitHub Stars

0

资源数

0
AI编程助手本地LLMPython代码生成向量数据库

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

iQbalADR

提供方

iQbalADR

最后核验

2026/5/17 20:20

运行时

Python

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

python3 --version

详细介绍

MCP Xcode服务器与Ollama+矢量数据库

🧠 Xcode的本地AI编码助手

使用LanceDB将本地Ollama LLM连接到Xcode的具有持久内存的AI助手。

______________________________________________________________________

📋 目录

______________________________________________________________________

概述

此项目创建了一个 模型上下文协议(MCP)服务器 这座桥:

组件描述
奥拉玛用于代码生成的本地LLM(Qwen2.5-Coder-7B)
Xcode 26.X支持AI助手的苹果IDE
兰斯数据库持久内存矢量数据库(RAG)
重新排名交叉编码器用于精确的搜索结果排名

主要特点

  • 完全本地化 -无云依赖,完全隐私
  • 代码优化LLM -Qwen2.5-Coder-7B,专门接受过代码培训
  • 持久内存 -你的代码“笔记本”在会话中幸存下来
  • RAG+重新排名 -具有精确重新排名的上下文感知响应
  • 自动标签 -自动代码分类(用户界面、网络、测试等)
  • 调试模式 -用于故障排除的全面日志记录
  • 简易设置 -用于快速安装的自动化脚本

______________________________________________________________________

建筑

┌─────────────────────────────────────────────────────────────────┐
│                         Your Mac                                 │
├─────────────────────────────────────────────────────────────────┤
│                                                                  │
│   ┌─────────────────────┐                                       │
│   │    Xcode 26.x       │                                       │
│   │  ┌───────────────┐  │                                       │
│   │  │ AI Assistant  │  │                                       │
│   │  └───────┬───────┘  │                                       │
│   └──────────┼──────────┘                                       │
│              │ OpenAI-compatible API                              │
│              ▼                                                   │
│   ┌─────────────────────────────────────────────┐               │
│   │         MCP Xcode Server (Python)           │               │
│   │  ┌───────────────────────────────────────┐  │               │
│   │  │            MCP Protocol               │  │               │
│   │  ├───────────────────────────────────────┤  │               │
│   │  │              Tools                    │  │               │
│   │  │  • generate_code    • explain_code    │  │               │
│   │  │  • fix_code         • ask_with_context│  │               │
│   │  │  • add_to_memory    • search_memory   │  │               │
│   │  ├───────────────────────────────────────┤  │               │
│   │  │           RAG Pipeline                │  │               │
│   │  │  • Retrieval  • Augmentation          │  │               │
│   │  └───────────────────────────────────────┘  │               │
│   └──────────┬──────────────────┬───────────────┘               │
│              │                  │                                │
│              ▼                  ▼                                │
│   ┌──────────────────┐  ┌──────────────────┐                    │
│   │     Ollama       │  │     LanceDB      │                    │
│   │  (Local LLM)     │  │  (Vector DB)     │                    │
│   │                  │  │                  │                    │
│   │  Qwen2.5-Coder   │  │  Code Memory     │                    │
│   │  nomic-embed     │  │  + Auto Labels   │                    │
│   │  :v1.5           │  │  + Re-Ranker     │                    │
│   └──────────────────┘  └──────────────────┘                    │
│                                                                  │
└─────────────────────────────────────────────────────────────────┘

______________________________________________________________________

先决条件

1.Xcode 26.x或更高版本

# Check Xcode version
xcodebuild -version
备注:Xcode 26.3(2025)中引入了MCP支持。确保您拥有最新版本。

2.奥拉马

从以下位置安装 奥拉玛 或通过Homebrew:

brew install ollama

验证安装:

ollama --version

3.Python 3.10+

# Check Python version
python3 --version

# Install if needed
brew install python@3.12

______________________________________________________________________

快速开始

步骤1:克隆和设置

# Navigate to project directory
cd /path/to/xcode-mcp-server

# Run setup script
chmod +x scripts/setup.sh
./scripts/setup.sh

安装脚本将:

  • 创建Python虚拟环境
  • 安装所有依赖项
  • 确认Ollama正在运行
  • 创建自定义iOS型号或提取所需型号
  • 创建必要的目录

第二步:承接你的项目

# Ingest an Xcode project
python scripts/ingest_project.py /path/to/your/XcodeProject

步骤3:启动服务器

./scripts/start_server.sh

步骤4:连接到Xcode 26+

启动Xcode“本地托管”提供程序的HTTP服务器:

./scripts/start_http_server.sh

然后在Xcode中:

  1. 打开 Xcode→ 设置→ 智能
  2. 点击 “添加模型提供程序…”
  3. 选择 “本地托管”
  4. 设置端口: 1234
  5. 设置说明: MCP Xcode Server
  6. 点击 “添加”

就是这样!Xcode现在将使用您的本地Ollama模型和您摄入的代码库中的RAG上下文。

替代方案:MCP检查员测试

对于没有Xcode的测试:

npx @anthropic-ai/mcp-inspector ./venv/bin/python -m server.mcp_server

______________________________________________________________________

详细设置指南

安装Ollama

  1. 下载自 ollama.ai/下载
  2. 安装应用程序
  3. 启动Ollama服务:
ollama serve
  1. 拉动所需型号:
# Code generation model (choose one)
ollama pull codellama:13b      # Recommended for code
# OR
ollama pull llama3.2:latest    # General purpose
# OR
ollama pull deepseek-coder     # Alternative code model

# Embedding model (required for RAG)
ollama pull nomic-embed-text   # Best for embeddings
  1. 验证模型是否可用:
ollama list

项目设置

# 1. Navigate to project
cd xcode-mcp-server

# 2. Create virtual environment
python3 -m venv venv

# 3. Activate it
source venv/bin/activate

# 4. Install dependencies
pip install -r requirements.txt

# 5. Create directories
mkdir -p data/lancedb logs

Xcode配置

将Xcode 26+连接到服务器

  1. 启动HTTP服务器
   ./scripts/start_http_server.sh
  1. 打开Xcode设置

- 菜单: Xcode > Settings... 或按 ⌘,

  1. 导航到情报

- 点击 智能 侧边栏中的选项卡

  1. 添加模型提供程序

- 点击 “添加模型提供程序…” - 选择 “本地托管” - 设置端口: 1234 - 设置说明: MCP Xcode Server - 点击 “添加”

  1. 选择型号

- 点击进入您的新提供商 - ✅ 启用 ios-qwen-coder:latest (推荐--代码优化) - ✅ 可选启用 ios-swift-architect:latest (通用) - ❌ 不启用 nomic-embed-text (仅嵌入,无法聊天)

  1. 启用Xcode工具

- 同时启用 Xcode工具 智能设置中的(双筒望远镜图标) - 这使AI可以访问您的项目结构并构建诊断

验证连接

# Server health
curl http://localhost:1234/health

# Available models
curl http://localhost:1234/v1/models

# Vector DB stats
curl http://localhost:1234/mcp/stats

在Xcode中:按 ⌥⌘/ 打开AI助手并键入提示。查看终端的请求日志。

______________________________________________________________________

用法

吸收你的代码库

在有效使用AI助手之前,请先消化您的项目:

# Ingest a directory
python scripts/ingest_project.py /path/to/project

# Ingest with specific extensions only
python scripts/ingest_project.py /path/to/project --extensions swift m h

# Ingest with custom labels
python scripts/ingest_project.py /path/to/project --labels ios production

# Watch mode (auto-ingest on file changes)
python scripts/ingest_project.py /path/to/project --watch

# Clear existing memory and re-ingest
python scripts/ingest_project.py /path/to/project --clear

# Disable auto-labeling
python scripts/ingest_project.py /path/to/project --no-auto-labels

用于快速访问的Shell别名

将这些别名添加到您的 ~/.zshrc 从任何地方轻松获取项目:

# Add to ~/.zshrc
export MCP_SERVER_PATH="/Users/user65419/Documents/Development/AI/xcode-mcp-server"

# Ingest current directory
alias mcp-ingest='$MCP_SERVER_PATH/venv/bin/python $MCP_SERVER_PATH/scripts/ingest_project.py .'

# Ingest with watch mode
alias mcp-watch='$MCP_SERVER_PATH/venv/bin/python $MCP_SERVER_PATH/scripts/ingest_project.py . --watch'

# Search memory
alias mcp-search='$MCP_SERVER_PATH/venv/bin/python $MCP_SERVER_PATH/scripts/memory_search.py'

# Start MCP server
alias mcp-server='$MCP_SERVER_PATH/scripts/start_server.sh'

添加后,重新加载shell:

source ~/.zshrc

现在,您可以从任何Xcode项目目录运行这些命令:

cd ~/MyXcodeProject

# Ingest current project
mcp-ingest

# Watch for changes during development
mcp-watch

# Search your code memory
mcp-search --query "authentication"

搜索内存

使用交互式内存搜索工具:

# Interactive mode
python scripts/memory_search.py

# Direct search
python scripts/memory_search.py --query "authentication"

# Show statistics
python scripts/memory_search.py --stats

# Export memory backup
python scripts/memory_search.py --export backup.json

在Xcode中使用

连接后,正常使用Xcode中的AI助手。MCP服务器提供以下增强功能:

  1. 提出问题 -使用代码库获取上下文感知答案
  2. 生成代码 -基于现有模式创建代码
  3. 解释代码 -理解复杂的代码段
  4. 修复错误 -从项目上下文中获取错误修复
  5. 添加到内存 -保存重要片段以备将来参考

______________________________________________________________________

配置

编辑 config.yaml 要自定义服务器,请执行以下操作:

Ollama设置

ollama:
  base_url: "http://localhost:11434"
  chat_model: "ios-qwen-coder"          # Qwen2.5-Coder-7B (recommended)
  embedding_model: "nomic-embed-text:v1.5"
  temperature: 0.1                       # Lower = more deterministic
  max_tokens: 4096

AI堆栈

组件型号RAM
LLM Qwen2.5-Coder-7B (通过 ios-qwen-coder)~5.5 GB
嵌入件nomic-embed-text:v1.5~0.3 GB
重新排名ms-marco-MiniLM-L-6-v2 (自动加载)~0.1 GB
矢量数据库LanceDB(嵌入式)~0.5 GB

LanceDB设置

lancedb:
  db_path: "./data/lancedb"
  max_results: 10

调试设置

debug:
  enabled: true
  save_requests: true
  request_log: "./logs/requests.jsonl"
  verbose_mcp: true

日志记录

logging:
  level: "DEBUG"                       # DEBUG, INFO, WARNING, ERROR
  file: "./logs/mcp_server.log"
  console: true

______________________________________________________________________

工具参考

MCP服务器为Xcode提供了以下工具:

generate_code

使用RAG上下文从自然语言描述生成代码。

Input:
  - description: What to generate
  - language: Programming language (default: swift)

Example: "Create a function that fetches user data from an API"

explain_code

用简单的英语解释代码的作用。

Input:
  - code: The code to explain
  - language: Programming language

Example: Pass a complex Swift function for explanation

fix_code

根据错误消息修复损坏的代码。

Input:
  - code: The broken code
  - error: The error message
  - language: Programming language

Example: Pass code and compiler error for a fix

ask_with_context

从你的代码库中询问任何与RAG上下文相关的问题。

Input:
  - question: Your question

Example: "How does authentication work in this project?"

add_to_memory

将代码或注释添加到持久内存中。

Input:
  - content: Content to remember
  - type: "code", "docs", or "note"
  - file_path: Optional file reference
  - description: Optional description

search_memory

搜索你的代码存储器/笔记本。

Input:
  - query: Search query
  - type: "code", "docs", or "all"
  - limit: Maximum results

get_memory_stats

获取矢量数据库的统计信息。

clear_memory

清除内存集合(小心使用)。

Input:
  - collection: "code", "docs", or "history"

______________________________________________________________________

内存/笔记本功能

“笔记本”功能使用LanceDB来维护持久内存:

运作原理

  1. 代码存储器:存储项目中的代码片段
  2. 文档存储器:存储评论和文档
  3. 对话历史:存储过去的问答以获取上下文

内存流

┌─────────────┐     ┌───────────────┐     ┌─────────────┐
│ Your Code   │────▶│ Embeddings    │────▶│  LanceDB    │
│ Files       │     │ (Ollama)      │     │ Vector DB   │
└─────────────┘     └───────────────┘     └─────────────┘
                                                 │
                                                 │ Similarity
                                                 │ Search
                                                 ▼
┌─────────────┐     ┌───────────────┐     ┌─────────────┐
│ AI Response │◀────│ LLM + Context │◀────│ Relevant    │
│             │     │ (Ollama)      │     │ Chunks      │
└─────────────┘     └───────────────┘     └─────────────┘

最佳实践

  1. 承接您的项目 提问前
  2. 定期重新摄入 保持记忆新鲜
  3. 使用手表模式 在开发过程中
  4. 添加重要片段 手动快速参考

______________________________________________________________________

调试

启用调试模式

./scripts/start_server.sh --debug

查看日志

# Real-time log viewing
tail -f logs/mcp_server.log

# View request/response log
cat logs/requests.jsonl | jq .

调试请求日志格式

每一行 requests.jsonl 是一个JSON对象:

{
  "id": 1,
  "timestamp": "2025-02-08T10:30:00",
  "type": "request",
  "method": "tools/call/generate_code",
  "params": {"description": "..."}
}

测试Ollama连接

# Test Ollama health
curl http://localhost:11434/api/tags

# Test chat
curl http://localhost:11434/api/chat -d '{
  "model": "codellama:13b",
  "messages": [{"role": "user", "content": "Hello!"}],
  "stream": false
}'

测试向量存储

# In Python REPL
from server.vector_store import VectorStore, create_vector_store_with_ollama
import asyncio

async def test():
    store = await create_vector_store_with_ollama()
    stats = await store.get_stats()
    print(stats)

asyncio.run(test())

______________________________________________________________________

故障排除

Ollama不跑

错误: Ollama server is not running!

解决方案:

ollama serve

未找到型号

错误: Model 'codellama:13b' not found

解决方案:

ollama pull codellama:13b

Python导入错误

错误: ModuleNotFoundError: No module named 'mcp'

解决方案:

source venv/bin/activate
pip install -r requirements.txt

LanceDB权限错误

错误: Permission denied: ./data/lancedb

解决方案:

chmod -R 755 data/

Xcode未连接

  1. 确保HTTP服务器正在运行: ./scripts/start_http_server.sh
  2. 验证端口是否匹配:默认值为 1234
  3. 检查Xcode>设置>智能显示您的提供商
  4. 测试端点: curl http://localhost:1234/health

反应缓慢

  1. 使用较小的模型: ollama pull codellama:7b
  2. 减少 max_results 在config.yaml中
  3. 检查CPU/GPU使用情况 htop

内存使用率高

  1. 限制config.yaml中摄入的文件大小
  2. 清除历史记录: python scripts/memory_search.py 然后 clear history
  3. 减少RAG配置中的块大小

______________________________________________________________________

文件结构

xcode-mcp-server/
├── config.yaml              # Configuration file
├── requirements.txt         # Python dependencies
├── README.md               # This file
│
├── server/                 # Main server package
│   ├── __init__.py
│   ├── mcp_server.py       # MCP protocol server
│   ├── ollama_client.py    # Ollama LLM client
│   └── vector_store.py     # LanceDB wrapper
│
├── scripts/                # Helper scripts
│   ├── setup.sh            # Initial setup
│   ├── start_server.sh     # Start server
│   ├── create_models.sh    # Create custom Ollama models
│   ├── ingest_project.py   # Ingest code files
│   └── memory_search.py    # Search memory
│
├── models/                 # Custom Ollama Modelfiles
│   ├── Modelfile.ios-architect
│   ├── Modelfile.swiftui
│   └── Modelfile.reviewer
│
├── data/                   # Data storage
│   └── lancedb/            # Vector database
│
└── logs/                   # Log files
    ├── mcp_server.log
    └── requests.jsonl

______________________________________________________________________

贡献

欢迎投稿!拜托:

  1. 克隆该仓库
  2. 创建要素分支
  3. 提交拉取请求

______________________________________________________________________

许可证

MIT许可证-可以自由使用和修改。

______________________________________________________________________

致谢

目录标签

目录标签

AI编程助手本地LLMPython代码生成向量数据库本地部署Xcode集成

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

none

运行时(runtime,运行环境)

Python

工具数量(toolCount,工具数)

8

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdionone部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP