Skip to content

Conversation

@maatheusgois-dd
Copy link

@maatheusgois-dd maatheusgois-dd commented May 30, 2025

Reimplement the @KayodeOgundimu-DoorDashSWE work. See more: https://github.com/KayodeOgundimu-DoorDashSWE/sweetpad

Screenshot 2025-05-30 at 14 48 07 Screenshot 2025-05-30 at 14 53 04

📋 Summary

This PR introduces comprehensive support for the Model Context Protocol (MCP) in SweetPad, enabling AI assistants like Claude Desktop to interact directly with iOS development workflows through standardized tools and real-time communication.

✨ What's New

🔧 Core MCP Server

  • HTTP/SSE Transport: Real-time bidirectional communication on port 61337
  • Standard Compliance: Built with official @modelcontextprotocol/sdk
  • Auto-start/stop: Seamless lifecycle management with VS Code extension

🛠️ Available Tools

execute_vscode_command

Execute any VS Code command and wait for task completion with automatic timeout handling.

Supported Commands Include:

  • sweetpad.build.build - Build iOS projects
  • sweetpad.build.run - Run on simulators/devices
  • sweetpad.build.test - Execute test suites
  • sweetpad.build.clean - Clean build artifacts
  • sweetpad.format.run - Format Swift code
  • sweetpad.simulators.start - Launch iOS Simulator
  • sweetpad.destinations.select - Choose build targets
  • And all other SweetPad commands...

📊 Monitoring & Observability

  • Prometheus Metrics: Tool execution counts, latencies, error rates
  • Structured Logging: Comprehensive operation tracking
  • Health Endpoints: Server status and diagnostics

📚 Complete Documentation

  • Client configuration guides (Claude Desktop, other MCP clients)
  • API reference with examples
  • Troubleshooting section
  • Developer guide for extending functionality

🏗️ Technical Implementation

Architecture

AI Assistant (Claude) ←→ MCP Client ←→ HTTP/SSE ←→ SweetPad MCP Server ←→ VS Code Commands

Key Components

  • src/mcp_server.ts: Main server implementation with Express.js
  • src/tools/executeCommand.ts: Command execution with timeout handling
  • src/metrics.ts: Prometheus metrics collection
  • src/types.ts: TypeScript definitions for type safety

Endpoints

Endpoint Method Purpose
/sse GET Establish SSE connection
/messages POST Handle MCP protocol messages
/metrics GET Prometheus metrics

🎯 Usage Examples

Client Configuration (Claude Desktop)

{
  "mcpServers": {
    "sweetpad-mcp": {
      "url": "http://localhost:61337/SSE"
    }
  }
}

AI Assistant Workflow

  1. "Build my iOS project" → Executes sweetpad.build.build
  2. "Run tests on simulator" → Executes sweetpad.build.test
  3. "Format Swift code" → Executes sweetpad.format.run
  4. "Start iOS Simulator" → Executes sweetpad.simulators.start

🔧 What Changed

New Files

  • src/mcp_server.ts - MCP server implementation
  • src/tools/executeCommand.ts - Command execution tool
  • src/metrics.ts - Metrics collection
  • src/types.ts - Type definitions
  • src/format/provider.ts - Format provider (missing dependency fix)
  • docs/wiki/mcp-integration.md - Complete documentation

Modified Files

  • src/extension.ts - Server initialization and lifecycle
  • src/common/commands.ts - Task completion signaling
  • package.json - MCP SDK dependencies
  • Build/testing commands - Enhanced progress tracking

🧪 Testing

Manual Testing Completed

  • ✅ Server starts/stops with extension lifecycle
  • ✅ SSE connections establish successfully
  • ✅ Command execution with proper timeout handling
  • ✅ Task completion signals fire correctly
  • ✅ Metrics collection and endpoint functionality
  • ✅ Claude Desktop integration working
  • ✅ Error handling and recovery

Example Test Flow

# 1. Start SweetPad extension
# 2. Connect Claude Desktop with config
# 3. Ask: "Build my iOS project"
# 4. Verify: Build executes and completes
# 5. Check: Metrics updated at /metrics

🚨 Breaking Changes

  • None - This is a purely additive feature
  • All existing functionality remains unchanged
  • No impact on users who don't use MCP

📖 Documentation

Added Documentation

  • Complete MCP Guide: docs/wiki/mcp-integration.md
  • Client Setup Instructions: Multiple MCP client examples
  • API Reference: All available tools and parameters
  • Troubleshooting: Common issues and solutions
  • Development Guide: Adding custom tools

Key Documentation Sections

  • Architecture overview
  • Client configuration (Claude Desktop, others)
  • Security considerations
  • Monitoring and metrics
  • Development and extension guide

🎉 Benefits for Users

For Individual Developers

  • AI-Powered Workflows: "Build and test my changes" in natural language
  • Hands-free Development: Let AI handle routine tasks
  • Intelligent Debugging: AI can analyze build output and suggest fixes

For Teams

  • Consistent Workflows: Standardized AI interactions across team
  • Onboarding: New developers can use AI to learn SweetPad commands
  • Documentation: AI can help explain and demonstrate features

For Power Users

  • Custom Workflows: Combine multiple commands in AI conversations
  • Automation: Complex multi-step processes via AI instruction
  • Integration: Connect with other MCP-enabled tools

🔒 Security Considerations

  • localhost-only: Server only accepts local connections
  • No authentication: Suitable for local development environment
  • Command scope: Limited to existing VS Code commands
  • Timeout protection: 10-minute maximum execution time

🚀 Future Possibilities

This foundation enables:

  • Project Analysis Tools: AI can read and analyze project structure
  • Code Generation: AI can create and modify Swift files
  • Advanced Debugging: AI-assisted debugging workflows
  • Custom Tools: Team-specific MCP tools for specialized workflows

📊 Performance Impact

  • Minimal overhead: Server only runs when extension is active
  • Efficient transport: SSE provides real-time communication with low latency
  • Resource usage: < 10MB additional memory footprint

🔍 Testing Instructions

  1. Install SweetPad with this branch
  2. Configure Claude Desktop with provided config
  3. Open iOS project in VS Code
  4. Ask Claude: "Build my project using SweetPad"
  5. Verify: Build executes and Claude receives completion status

📝 Related Issues

Addresses community requests for:

  • AI assistant integration
  • Remote command execution
  • Workflow automation
  • Better developer experience

…on with HTTP/SSE transport, execute_vscode_command tool, Prometheus metrics, VS Code command execution, task completion signals, and complete documentation
@maatheusgois-dd maatheusgois-dd changed the title feat: Add comprehensive MCP (Model Context Protocol) server integrati… 🚀 Add Model Context Protocol (MCP) Server Integration May 30, 2025
@hyzyla
Copy link
Collaborator

hyzyla commented Jun 1, 2025

I'll check this one after your previous pull request. In case there are some comments, do you prefer me to update the pull request, or do you prefer to update it yourself? I prefer the first option, but sometimes people prefer to resolve comments by themself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants