Add MCP support to command mode
Description
This PR adds a bunch a features in order to support MCP for command mode execution. The list of the features are:
- Add separate strategies for routing Anthropic requests and OpenAI compatible requests.
- If the model provider is anthropic, messages api is used. Else responses api is preferred and completions is used as fallback
- Minor updates to the command mode chat UI - moved around the buttons a little bit
- Added a mechanism to define the MCP config and edit it from the FluidVoice app
- Fixed some issues on tool calls are rendered on the chat
- Once action is completed mode, depending on whether the user active display screen has notch - a compact dynamic island notification is shown for success, else a system notification is sent for success
- Added Markdown syntax rendering in the command mode chat
Type of Change
- [ ] 🐞 Bug fix (non-breaking change which fixes an issue)
- [x] ✨ New feature (non-breaking change which adds functionality)
- [ ] 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] 📝 Documentation update
Related Issues
- Closes #275
Testing
- [x] Tested on Apple Silicon Mac
- [x] Tested on macOS [version]
- [x] Ran linter locally:
swiftlint --strict --config .swiftlint.yml Sources - [x] Ran formatter locally:
swiftformat --config .swiftformat Sources - [x] Built locally:
sh build_incremental.sh
Notes
- Due to the size of the change, would recommend pulling the code and testing once.
- Do a beta release first
One blocker before merge: chat completions fallback still receives Responses-style tool definitions.
In buildChatCompletionsBody, body["tools"] = config.tools forwards tools shaped like {"type":"function","name":...,"parameters":...}. If /v1/responses is rejected and we fall back to /v1/chat/completions, Chat Completions expects {"type":"function","function":{"name":...,"parameters":...}}, so command mode tool calls can 400 or be ignored exactly on fallback providers.
Fix should be small: add a normalizeToolsForChatCompletions(...) helper and use it in buildChatCompletionsBody, while keeping normalizeToolsForResponses(...) for Responses.
One more concrete blocker I found in MCP tool registration: uniqueToolName can loop forever when two tool names collide after the 64-character truncation.
base is already sanitized/truncated to 64 chars. On collision, candidate = sanitizeToolName("\(base)_\(counter)") appends a suffix, but sanitizeToolName truncates back to 64 chars, so the suffix is dropped and candidate remains identical to base forever.
Scenario: two MCP tools with names that differ only after the first 64 sanitized characters, or long server/tool combinations with the same prefix. That would hang MCP bootstrap/tool catalog rebuild.
Fix should be small: when adding a collision suffix, reserve suffix length before truncating the base, e.g. truncate to 64 - suffix.count then append _2, _3, etc.