Reimplement the 3 core MCP servers (filesystem, git, fetch) as a single Swift binary called mcpx
.
- Single binary deployment (no Node.js dependency)
- Native macOS performance
- Clean, modern syntax
- Excellent Foundation library for filesystem/networking
- First-class MCP Swift SDK available
mcpx
├── fs (filesystem operations)
├── git (git operations)
└── fetch (HTTP requests)
mcpx --allow-dir /path/to/project
# Exposes all three tool sets via MCP protocol
Tools to implement:
read_file
- Read file contents with UTF-8 encodingwrite_file
- Create/overwrite fileslist_directory
- List directory contents with [FILE]/[DIR] prefixescreate_directory
- Create directories recursivelymove_file
- Move/rename files and directoriessearch_files
- Recursive file search with pattern matchingget_file_info
- File metadata (size, dates, permissions)
Key APIs:
FileManager.default
for directory operationsString(contentsOf:)
andData.write(to:)
for file I/OFileManager.contentsOfDirectory(atPath:)
for listings
Tools to implement:
git_status
- Show working directory statusgit_add
- Stage filesgit_commit
- Create commitsgit_push
- Push to remotegit_pull
- Pull from remotegit_log
- Show commit historygit_diff
- Show file differencesgit_branch
- Branch operations
Implementation approach:
- Use
Process
to execute git commands - Parse stdout/stderr for structured responses
- Handle git credential management
Tools to implement:
http_get
- GET requests with headershttp_post
- POST requests with body/headershttp_put
- PUT requestshttp_delete
- DELETE requests
Key APIs:
URLSession
for HTTP requestsJSONSerialization
for JSON handling- Proper error handling for network failures
Sources/
├── SwiftMCP/
│ ├── main.swift # Entry point
│ ├── MCPServer.swift # MCP protocol handling
│ ├── FilesystemTools.swift
│ ├── GitTools.swift
│ └── FetchTools.swift
└── Package.swift
// Package.swift
dependencies: [
.package(url: "https://github.com/modelcontextprotocol/swift-sdk", from: "1.0.0")
]
- Path validation - Only allow operations within specified directories
- Git safety - Validate git commands to prevent injection
- HTTP limits - Reasonable timeouts and request size limits
- Error handling - Never expose internal system paths in errors
- Use the official Swift MCP SDK
- Implement
ListToolsRequestSchema
handler - Implement
CallToolRequestSchema
handler - Follow MCP tool schema patterns from Node.js versions
- Drop-in replacement - Same MCP tool interface as Node.js versions
- Single binary - No runtime dependencies
- Better performance - Faster than Node.js equivalents
- Clean error messages - User-friendly error handling
- Cross-platform - Works on macOS and Linux
- Start with filesystem - Core functionality, easiest to test
- Add fetch - HTTP operations, good for testing network handling
- Finish with git - Most complex due to subprocess management
- Test against existing MCP clients (Claude Desktop)
- Compare output format with Node.js versions
- Test edge cases: large files, network failures, git errors
- Verify security boundaries work correctly
- No async/await ceremony - Use Swift's structured concurrency
- Native error types - Proper Swift error handling vs JavaScript exceptions
- Type safety - Compile-time guarantees vs runtime schema validation
- Resource management - Automatic memory management vs manual cleanup