sync_with_github_mcp.pyā¢3.8 kB
#!/usr/bin/env python3
"""
Use MCP tools to sync with GitHub repository.
"""
import asyncio
import sys
from pathlib import Path
# Add the src directory to the path
sys.path.insert(0, str(Path(__file__).parent / "src"))
from radicle_mcp.server import run_rad_command
async def use_mcp_for_github_sync():
"""Use MCP tools to handle GitHub sync."""
print("š Using MCP to sync with GitHub repository fovi-llc/radicle-mcp")
# First, let's check our current Radicle status
print("\n1. š Checking current Radicle status...")
status_result = await run_rad_command(["rad", "inspect"])
print(f"Current RID: {status_result['stdout']}")
# Check current remotes
print("\n2. š Checking current remotes...")
remote_result = await run_rad_command(["rad", "remote"])
print(f"Current remotes:\n{remote_result['stdout']}")
# Use git through our MCP wrapper to add GitHub remote
print("\n3. š Adding GitHub remote...")
git_remote_result = await run_rad_command([
"git", "remote", "add", "github",
"https://github.com/fovi-llc/radicle-mcp.git"
])
if git_remote_result['success']:
print("ā
GitHub remote added successfully")
else:
print(f"ā ļø GitHub remote add result: {git_remote_result['stderr']}")
# Fetch from GitHub to get the LICENSE file
print("\n4. š„ Fetching from GitHub...")
fetch_result = await run_rad_command(["git", "fetch", "github"])
if fetch_result['success']:
print("ā
Successfully fetched from GitHub")
print(f"Fetch output: {fetch_result['stdout']}")
else:
print(f"ā Fetch failed: {fetch_result['stderr']}")
# Check what we got
print("\n5. š Checking GitHub branches...")
branch_result = await run_rad_command(["git", "branch", "-r"])
print(f"Remote branches: {branch_result['stdout']}")
# Merge or rebase with GitHub main if it exists
print("\n6. š Merging GitHub changes...")
merge_result = await run_rad_command([
"git", "merge", "github/main", "--allow-unrelated-histories"
])
if merge_result['success']:
print("ā
Successfully merged GitHub changes")
else:
print(f"ā ļø Merge result: {merge_result['stderr']}")
# Try to continue anyway
# Stage all our new files
print("\n7. š Staging local changes...")
add_result = await run_rad_command(["git", "add", "."])
if add_result['success']:
print("ā
All files staged")
else:
print(f"ā Failed to stage files: {add_result['stderr']}")
# Commit our changes
print("\n8. š¾ Committing changes...")
commit_result = await run_rad_command([
"git", "commit", "-m",
"Add Radicle + GitHub MCP server integration\n\n- Complete Python MCP server for Radicle CLI\n- GitHub MCP server integration\n- VS Code and Claude Desktop configuration\n- Setup and test scripts"
])
if commit_result['success']:
print("ā
Changes committed successfully")
print(f"Commit result: {commit_result['stdout']}")
else:
print(f"ā ļø Commit result: {commit_result['stderr']}")
# Push to GitHub
print("\n9. š Pushing to GitHub...")
push_result = await run_rad_command(["git", "push", "github", "main"])
if push_result['success']:
print("ā
Successfully pushed to GitHub!")
print(f"Push result: {push_result['stdout']}")
else:
print(f"ā Push failed: {push_result['stderr']}")
print("\nš MCP-powered GitHub sync complete!")
print("Your local changes are now synced with https://github.com/fovi-llc/radicle-mcp")
if __name__ == "__main__":
asyncio.run(use_mcp_for_github_sync())