anhptimx/swift-mcp-server
If you are the rightful owner of swift-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
The Swift MCP Server is a professional implementation of the Model Context Protocol (MCP) in Swift, designed to provide advanced static analysis and architectural insights for Swift codebases.
Swift MCP Server
Production-ready Model Context Protocol (MCP) server for Swift projects. Enterprise-grade dual transport architecture with comprehensive analysis capabilities.
🎯 Vision
The definitive tool for Swift code quality, architecture guidance, and performance optimization.
Built for professional Swift developers who need reliable, fast, and intelligent project analysis that integrates seamlessly with their workflow.
✅ What's Working Today
🏗️ Rock-Solid Foundation
- 🔄 Dual Transport: HTTP server + STDIO for VS Code/Serena integration
- 🛠️ 15+ Analysis Tools: Symbol search, references, architecture analysis
- 🏢 Enterprise Ready: JSON config, structured logging, graceful shutdown
- ⚡ Swift 6 Compatible: Modern concurrency and production-ready architecture
- 📊 Real-time Analysis: Live compilation feedback and performance metrics
- 🎯 VS Code Integration: Direct STDIO support for MCP extensions
🚀 Developer Experience
- One-Command Setup:
./swift-mcp.sh- builds, configures, tests in < 30 seconds - Auto-IDE Configuration: VS Code works out of the box
- Comprehensive Testing: All functionality verified automatically
- Auto-Fix Common Issues:
./swift-mcp.shresolves 90% of problems - Zero Exit Code 64 Errors: Robust argument parsing with positional support
🔧 Production Features
- Cross-Platform: macOS and Linux support
- Professional CLI: ArgumentParser with comprehensive options
- Error Recovery: Graceful handling of edge cases
- Performance Optimized: Sub-second analysis for medium projects
- Memory Efficient: Minimal resource usage with cleanup
🚀 What's Coming Next
Phase 2: Intelligence Engine (Q1 2025)
// Swift 6 Compliance Analyzer
✅ Detect concurrency issues automatically
✅ Suggest actor isolation patterns
✅ Auto-fix common async/await mistakes
✅ Prevent data races before they happen
// Architecture Pattern Analysis
✅ Identify MVVM, VIPER, TCA patterns
✅ Detect massive view controllers
✅ Suggest separation of concerns
✅ Recommend dependency injection
// Performance Optimization
✅ Find main thread blocking operations
✅ Suggest efficient data structures
✅ Identify memory leak potential
✅ Recommend caching strategies
Quick Start
One-Command Setup
# All-in-one script - builds, configures, tests everything
./swift-mcp.sh
# Or run specific functions:
./swift-mcp.sh build # Build only
./swift-mcp.sh stdio # Run persistent STDIO mode
./swift-mcp.sh test # Test functionality
Manual Installation
# Build production binary
swift build --configuration release
# Verify installation
./.build/release/swift-mcp-server --help
🎛️ Transport Modes
VS Code Integration (Recommended)
### VS Code Integration (Recommended)
```bash
# Automatic VS Code configuration
./swift-mcp.sh vscode # Sets up VS Code config automatically
# Manual VS Code MCP configuration:
{
"mcp.servers": {
"swift-mcp-server": {
"command": "/path/to/swift-mcp-server/.build/release/swift-mcp-server",
"args": ["--transport", "stdio", "${workspaceFolder}"],
"env": {"SWIFT_MCP_MODE": "vscode"}
}
}
}
Persistent STDIO Mode
# Run server without shutdown (for multiple requests)
./swift-mcp.sh stdio
Enterprise HTTP API
# Production HTTP server
swift-mcp-server --config http-config.json --transport http --port 9000
📊 Available Analysis Tools
Core Analysis
list_symbols- Find all functions, classes, protocols, and variablesfind_references- Locate where symbols are used across the codebaseanalyze_architecture- Detect patterns, dependencies, and code organizationgenerate_documentation- Auto-create comprehensive documentationanalyze_project- Full project health and structure analysis
Advanced Features
- iOS Framework Analysis - Detect UIKit, SwiftUI, Core Data usage patterns
- Dependency Mapping - Visualize module relationships and coupling
- Performance Analysis - Identify optimization opportunities
- Modern Concurrency - Analyze async/await and actor usage
- Memory Safety - Detect potential retain cycles and memory issues
🔧 Configuration
Project Files
swift-mcp-server/
├── 📄 README.md # Main documentation (you are here)
├── CONFIG_GUIDE.md # Advanced configuration guide
├── 📦 Package.swift # Swift package definition
├── 🛠️ Management/
│ └── swift-mcp.sh # ⚡ All-in-one management script
├── ⚙️ Configuration/
│ ├── vscode-mcp-config.json # VS Code MCP extension settings
│ ├── stdio-config.json # STDIO transport configuration
│ └── http-config.json # HTTP server configuration
└── 💻 Sources/
├── SwiftMCPServer/ # Main application entry point
├── SwiftMCPCore/ # Core MCP protocol implementation
└── ModernConcurrency/ # Swift 6 concurrency utilities
🚨 Troubleshooting
Common Issues
Exit Code 64 (Fixed ✅)
# This is now resolved with positional argument support
# VS Code MCP extension passes workspace as positional argument
swift-mcp-server /path/to/workspace # Works perfectly
Permission Issues
./swift-mcp.sh # Fixes all issues automatically
SourceKit-LSP Not Found
./swift-mcp.sh health # Verifies SourceKit-LSP installation
VS Code Integration
./swift-mcp.sh vscode # Sets up VS Code MCP configuration
See for detailed troubleshooting.
📈 Project Status
✅ Phase 1: Foundation (100% Complete)
- Dual transport architecture (HTTP + STDIO)
- VS Code and Serena integration
- 15+ analysis tools working
- Cross-platform support (macOS + Linux)
- Zero exit code 64 errors
- Comprehensive health checking
- Production-ready error handling
🚀 Phase 2: Intelligence Engine (Planned Q1 2025)
- Swift 6 compliance analyzer
- Architecture pattern detection
- Performance optimization suggestions
- Advanced memory safety analysis
- Intelligent code completion
- Automated refactoring recommendations
Current Status: Production-ready foundation with strategic enhancement roadmap.
🤝 Contributing
See for development guidelines.
Quick Development Setup
git clone https://github.com/your-username/swift-mcp-server.git
cd swift-mcp-server
./swift-mcp.sh # Sets up everything for development
swift test # Run test suite
📄 Documentation
- - Advanced configuration
- - Troubleshooting guide
- - Serena app integration
Available Tools
find_symbols- Search Swift symbols with intelligent filteringfind_references- Find all references to symbolsget_definition- Navigate to symbol definitionsanalyze_project- Complete project analysis and metricsgenerate_documentation- Auto-generate project documentationanalyze_architecture- Architectural pattern detection
Configuration
Command Line Options
swift-mcp-server --help
# Key options:
--transport <mode> # http, stdio (default: http)
--workspace <path> # Swift project path
--config <file> # JSON configuration file
--port-min <min> # Auto port selection range
--port-max <max> # Auto port selection range
--log-level <level> # Logging verbosity
--json-logs # Structured JSON output
Enterprise Configuration
Create config.json for advanced deployment:
{
"mcpServer": {
"transport": {
"type": "http",
"host": "0.0.0.0",
"portRange": {"min": 9000, "max": 9010}
}
},
"performance": {
"maxConcurrentTasks": 10,
"taskTimeoutSeconds": 30.0
}
}
API Documentation
Available MCP Tools
Core Analysis
analyze_project- Complete project analysis with metricsfind_symbols- Advanced symbol search and filteringfind_references- Symbol reference trackingget_definition- Symbol definition lookup
Architecture Analysis
analyze_architecture- Pattern detection (MVC, MVVM, VIPER)analyze_pop_usage- Protocol-Oriented Programming assessmentgenerate_documentation- Automatic API documentation
Development Tools
format_document- Swift code formattingget_hover_info- Symbol information and documentation
HTTP API Examples
# List available tools
curl -X POST http://localhost:8080/mcp \
-H "Content-Type: application/json" \
-d '{"method": "tools/list", "params": {}}'
# Analyze project structure
curl -X POST http://localhost:8080/mcp \
-H "Content-Type: application/json" \
-d '{
"method": "tools/call",
"params": {
"name": "analyze_project",
"arguments": {"project_path": "/path/to/project"}
}
}'
Architecture
Project Structure
Sources/
├── SwiftMCPServer/ # Main application entry point
│ └── SwiftMCPApp.swift # CLI interface with dual transport
├── SwiftMCPCore/ # Core MCP server implementation
│ ├── MCPServer.swift # HTTP transport server
│ ├── StdioTransport.swift # STDIO transport for VS Code
│ ├── ServerConfiguration.swift # Enterprise configuration
│ └── SwiftLanguageServer.swift # Swift analysis engine
└── ModernConcurrency/ # Advanced concurrency features
├── FCITaskManager.swift # Task management and coordination
└── FCIModernThreadSafety.swift # Thread safety utilities
Transport Architecture
- HTTP Transport: RESTful API server with intelligent port management
- STDIO Transport: Direct JSON-RPC communication for VS Code integration
- Unified Core: Shared analysis engine serving both transport modes
Development
Requirements
- Swift 5.9+ (Swift 6 compatible)
- macOS 13.0+ or Linux Ubuntu 18.04+
- Xcode 15.0+ (includes SourceKit-LSP)
Building
# Debug build
swift build
# Release build with optimizations
swift build --configuration release
# Run tests
swift test
🏗️ Technical Architecture
Transport Layer
// Unified MCP Core serves multiple transport modes
SwiftMCPCore/
├── MCPServer.swift // HTTP JSON-RPC server
├── StdioTransport.swift // VS Code STDIO integration
├── MCPProtocolHandler.swift // Protocol compliance layer
└── ServerConfiguration.swift // Enterprise configuration
Analysis Engine
// Professional Swift project analysis
SwiftMCPCore/
├── SwiftLanguageServer.swift // SourceKit-LSP integration
├── SymbolSearchEngine.swift // Advanced symbol search
├── ProjectAnalyzer.swift // Architecture pattern detection
├── ArchitectureAnalyzer.swift // MVVM/VIPER/TCA analysis
└── iOSFrameworkAnalyzer.swift // UIKit/SwiftUI analysis
Modern Concurrency
// Swift 6 compatible concurrency patterns
ModernConcurrency/
├── FCITaskManager.swift // Async task coordination
├── FCIModernThreadSafety.swift // Actor-based safety
└── FCIModernContinuationManager.swift // Continuation handling
🔧 Advanced Configuration
Enterprise HTTP Server
{
"mcpServer": {
"transport": {
"type": "http",
"host": "0.0.0.0",
"portRange": {"min": 9000, "max": 9010}
},
"performance": {
"maxConcurrentTasks": 10,
"taskTimeoutSeconds": 30.0
},
"logging": {
"level": "info",
"format": "json",
"enableMetrics": true
}
}
}
VS Code STDIO Configuration
{
"mcp.servers": {
"swift-mcp-server": {
"command": "/path/to/.build/release/swift-mcp-server",
"args": ["--transport", "stdio", "${workspaceFolder}"],
"env": {
"SWIFT_MCP_MODE": "vscode",
"LOG_LEVEL": "info"
}
}
}
}
🧪 Development & Testing
Requirements
- Swift: 5.9+ (Swift 6 ready)
- Platform: macOS 13.0+ or Linux Ubuntu 18.04+
- Xcode: 15.0+ (includes SourceKit-LSP)
- Tools: ArgumentParser, Logging, Foundation
Quick Development
# Clone and setup development environment
git clone https://github.com/your-username/swift-mcp-server.git
cd swift-mcp-server
./swift-mcp.sh # Full development setup
# Development workflow
swift build # Debug build
swift test # Run test suite
./swift-mcp.sh test # Test server functionality
swift build # Debug build
swift test # Run test suite
swift build --configuration release # Production build
Testing
# Comprehensive testing
./swift-mcp.sh test # Full functionality tests
swift test # Unit tests
# Manual testing
./.build/release/swift-mcp-server --help
./.build/release/swift-mcp-server --workspace . --transport http
Check port availability
lsof -i :8080
Use auto port selection
swift-mcp-server --port-min 8080 --port-max 8090
Check which port was selected from logs
### Path Issues
#### Project Path Not Recognized
```bash
# Verify path exists and is accessible
ls -la /path/to/your/swift/project
# Check for Package.swift
find /path/to/project -name "Package.swift" -type f
# Use absolute paths
swift-mcp-server --workspace "$(pwd)/path/to/project"
# Check workspace permissions
chmod -R 755 /path/to/your/project
SourceKit-LSP Path Issues
# Verify SourceKit-LSP installation
which sourcekit-lsp
# Expected: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/sourcekit-lsp
# If not found, install Xcode Command Line Tools
xcode-select --install
# Set correct Xcode path
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
Dependencies Issues
Swift Package Dependencies
# Resolve package dependencies
swift package resolve
# Update dependencies
swift package update
# Clean and rebuild
swift package clean && swift build
VS Code MCP Extension Dependencies
# Install VS Code MCP extension
code --install-extension your-mcp-extension
# Check VS Code configuration
cat ~/.vscode/settings.json | grep mcp
# Restart VS Code after configuration changes
Serena Integration Dependencies
# Install UV package manager (required for Serena)
curl -LsSf https://astral.sh/uv/install.sh | sh
# Install Serena MCP
uvx --from git+https://github.com/oraios/serena serena start-mcp-server
# Verify Serena installation
serena --version
Common Configuration Fixes
Fix VS Code Configuration
{
"mcp.servers": {
"swift-mcp-server": {
"command": "/absolute/path/to/swift-mcp-server/.build/release/swift-mcp-server",
"args": [
"--transport", "stdio",
"--workspace", "${workspaceFolder}",
"--log-level", "info"
],
"env": {
"PATH": "/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Xcode.app/Contents/Developer/usr/bin"
},
"cwd": "${workspaceFolder}"
}
}
}
Fix Environment Variables
# Add to ~/.zshrc or ~/.bashrc
export PATH="/Applications/Xcode.app/Contents/Developer/usr/bin:$PATH"
export SOURCEKIT_LSP_PATH="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/sourcekit-lsp"
# Reload shell
source ~/.zshrc
Debug Configuration
# Test with maximum verbosity
swift-mcp-server \
--transport stdio \
--workspace "$(pwd)" \
--log-level trace \
--dev \
--json-logs
# Check server capabilities
curl -X POST http://localhost:8080/mcp \
-H "Content-Type: application/json" \
-d '{"method": "initialize", "params": {"protocolVersion": "2024-11-05"}}'
Health Check & Quick Fixes
We provide automated scripts to help with setup and troubleshooting:
Health Check
Run the comprehensive health check:
./swift-mcp.sh health
This automatically verifies:
- Swift installation and version
- SourceKit-LSP availability
- Xcode path configuration
- Server binary existence
- Package dependencies
- Transport modes functionality
Quick Fix Script
For automatic issue resolution:
# All-in-one management script
./swift-mcp.sh # Setup everything (default)
# Specific functions
./swift-mcp.sh build # Build server only
./swift-mcp.sh vscode # Setup VS Code config
./swift-mcp.sh test # Test functionality
./swift-mcp.sh stdio # Run persistent STDIO mode
./swift-mcp.sh health # Health check
The swift-mcp.sh script automatically:
- Builds the server
- Configures VS Code MCP integration
- Tests all functionality
- Provides persistent STDIO mode
- Runs comprehensive health checks
📄 License
This project is licensed under the MIT License - see the file for details.
🙏 Acknowledgments
- Swift Community: Built with Swift 6 and modern concurrency patterns
- SourceKit-LSP: Integrates with SourceKit-LSP for accurate Swift analysis
- MCP Ecosystem: Compatible with VS Code MCP extensions and Serena coding agents
- Open Source: Standing on the shoulders of giants in the Swift ecosystem
Ready to supercharge your Swift development workflow?
Start with ./quick-start.sh and experience enterprise-grade Swift project analysis in under 30 seconds! 🚀