Skip to main content
Glama
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.

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/pythondev-pro/egw_writings_mcp_server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server