How solejay/mcpswiftwrapper works
Project type and purpose
• This is a Swift Package Library (“MCPSwiftWrapper”) plus an example macOS chat client (“MCPClientChat”).
• The library wraps the [mcp-swift-sdk] to let Swift apps spin up MCP servers (via Node.js processes) and call “tools” exposed by those servers, then translate tool invocations to Anthropic or OpenAI API calls.
Main components
a. Example macOS App (“MCPClientChat”)
• SwiftUI UI layer (ChatView, ChatMessageView, ChatInputView)
• ChatManager & Models (ChatMessage, ChatManager)
• MCP Clients (GithubMCPClient, ClaudeCodeMCPClient, OpenAIChatNonStreamManager, AnthropicNonStreamManager)
b. MCPSwiftWrapper Library
• MCPClient class (core entry point)
• Extensions for each tool provider (MCPTool+AnthropicTool, MCPTool+OpenAITool)
• Transport layer: stdioProcess factory
c. External child processes
• Node.js-based MCP servers (e.g. “npx @modelcontextprotocol/server-github”)
• Communicate over STDIO (JSON RPC)
d. Remote Services
• GitHub API
• OpenAI API
• Anthropic API
Relationships & data flows
• User types message → UI (SwiftUI) → ChatManager invokes appropriate MCP client →
• MCPClient.start(transport: .stdioProcess(…)) spins up Node.js MCP server process →
• Swift calls client.openAITools()/anthropicTools() to discover tools → maps to SwiftOpenAI/SwiftAnthropic tool definitions →
• When model requests a tool, ChatManager marshals the tool invocation → MCPClient.openAICallTool()/anthropicCallTool() → sends JSON over STDIO → server process → calls external API (GitHub/OpenAI/Anthropic) → returns JSON → MCPClient → ChatManager → UI updates.
Architectural patterns & principles
• Layered separation: UI layer / application logic / wrapper library / child process / external services.
• Asynchronous concurrency: uses Swift async/await and AsyncStream.
• Protocol-oriented extensibility: library defines protocols for tool conversion; extensions implement each provider.