MCP_BRIDGE_SOLUTION.mdβ’6.16 kB
# MCP Bridge Solution - Connecting AI Assistants to PyForge Git Operations
## π― Problem Solved
**Previously**: AI assistants had real bash access through `server-universal.js` but couldn't perform git operations due to architectural separation from PyForge IDE.
**Now**: AI assistants can perform git operations through PyForge's sandboxed environment via MCP bridge endpoints.
## π Solution Overview
The MCP Bridge creates REST API endpoints in PyForge backend that allow AI assistants to:
- Perform git operations in PyForge's workspace
- Use PyForge's GitHub configuration and PAT authentication
- Access PyForge's sandboxed bash environment
- Maintain security and isolation
## π‘ MCP Bridge Endpoints
### `/mcp-git` - Git Operations
**POST** request with git operations:
```bash
# Clone repository
curl -X POST http://localhost:3001/mcp-git \
-H "Content-Type: application/json" \
-d '{
"operation": "clone",
"repo": "https://github.com/user/repo.git",
"pat": "ghp_..."
}'
# Commit changes
curl -X POST http://localhost:3001/mcp-git \
-H "Content-Type: application/json" \
-d '{
"operation": "commit",
"message": "Commit message"
}'
# Get status
curl -X POST http://localhost:3001/mcp-git \
-H "Content-Type: application/json" \
-d '{"operation": "status"}'
# View log
curl -X POST http://localhost:3001/mcp-git \
-H "Content-Type: application/json" \
-d '{"operation": "log"}'
# List branches
curl -X POST http://localhost:3001/mcp-git \
-H "Content-Type: application/json" \
-d '{"operation": "branch"}'
# Checkout branch
curl -X POST http://localhost:3001/mcp-git \
-H "Content-Type: application/json" \
-d '{
"operation": "checkout",
"branch": "feature-branch"
}'
# Push changes
curl -X POST http://localhost:3001/mcp-git \
-H "Content-Type: application/json" \
-d '{"operation": "push"}'
# Pull changes
curl -X POST http://localhost:3001/mcp-git \
-H "Content-Type: application/json" \
-d '{"operation": "pull"}'
```
### `/mcp-github-config` - GitHub Configuration
**POST** request for PAT management:
```bash
# Get current configuration
curl -X POST http://localhost:3001/mcp-github-config \
-H "Content-Type: application/json" \
-d '{"action": "get"}'
# Set GitHub PAT
curl -X POST http://localhost:3001/mcp-github-config \
-H "Content-Type: application/json" \
-d '{
"action": "set",
"pat": "ghp_..."
}'
# Clear PAT
curl -X POST http://localhost:3001/mcp-github-config \
-H "Content-Type: application/json" \
-d '{"action": "clear"}'
```
## π Security Features
- **Sandboxed Execution**: All git operations run in PyForge's sandbox directory
- **Command Validation**: Only allowed git operations are permitted
- **PAT Protection**: PATs are validated and embedded securely
- **Rate Limiting**: Protected against abuse (20 requests/minute)
- **Error Handling**: Comprehensive error reporting and validation
## ποΈ Architecture
```
βββββββββββββββββββββββββββ βββββββββββββββββββββββββββ
β AI Assistant β β PyForge Backend β
β - Can use REST API βββββΆβ - /mcp-git β
β - No git context β β - /mcp-github-config β
β β β - Sandbox execution β
βββββββββββββββββββββββββββ β - PAT management β
β - Security controls β
βββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββ
β PyForge Workspace β
β - Git repositories β
β - Secure environment β
βββββββββββββββββββββββββββ
```
## π§ͺ Testing
Use the provided test script:
```bash
node test-mcp-bridge.cjs
```
This tests:
- GitHub configuration management
- All git operations
- Error handling
- Security validation
## π Benefits
1. **Unified Git Access**: AI assistants can now perform git operations
2. **Security**: Maintains PyForge's sandboxed environment
3. **Authentication**: Leverages PyForge's GitHub PAT management
4. **Integration**: Seamlessly bridges two systems
5. **Compatibility**: Works with existing MCP protocol
## π Implementation Details
### Backend Changes (`pyforge-ide/backend/server.js`)
- Added `/mcp-git` endpoint with 8 git operations
- Added `/mcp-github-config` endpoint for PAT management
- Implemented PAT embedding in git URLs
- Added comprehensive error handling and validation
- Maintained existing security controls
### Test Script (`test-mcp-bridge.cjs`)
- Complete test suite for all endpoints
- Simulates AI assistant usage patterns
- Validates both success and error cases
- Provides usage examples
## π§ Usage for AI Assistant
An AI assistant can now:
1. **Configure GitHub PAT**:
```
POST /mcp-github-config {"action": "set", "pat": "ghp_..."}
```
2. **Clone Repository**:
```
POST /mcp-git {"operation": "clone", "repo": "https://github.com/user/repo.git"}
```
3. **Make Changes**:
```
POST /mcp-git {"operation": "status"}
POST /mcp-git {"operation": "commit", "message": "My changes"}
POST /mcp-git {"operation": "push"}
```
## π Future Enhancements
- Add file-specific git operations (add, remove)
- Implement merge conflict resolution
- Add branch creation/deletion
- Integrate with GitHub API for enhanced operations
- Add webhook support for real-time updates
---
**Status**: β
**COMPLETE AND TESTED**
The MCP Bridge successfully resolves the architectural gap between AI assistants and PyForge IDE, enabling git operations while maintaining security and isolation.