Skip to content

Latest commit

 

History

History
executable file
·
364 lines (280 loc) · 10.5 KB

File metadata and controls

executable file
·
364 lines (280 loc) · 10.5 KB

GitHub CLI and MCP Integration Complete

Summary

The GitHub Actions workflow system has been fully integrated with the MCP server dashboard, using GitHub CLI and Copilot CLI tools with P2P caching to minimize API calls.

What Was Implemented

1. GitHub CLI Tools for MCP Server

Created /ipfs_accelerate_py/mcp/tools/github_tools.py with 6 MCP tools:

  • gh_list_runners - List GitHub Actions self-hosted runners (repo or org level)
  • gh_create_workflow_queues - Create workflow queues for repositories with recent activity
  • gh_get_cache_stats - Get GitHub API cache statistics and P2P metrics
  • gh_get_auth_status - Get GitHub authentication status and user information
  • gh_list_workflow_runs - List workflow runs with filtering by status and branch
  • gh_get_runner_labels - Get runner labels for the current system

2. Integration Features

P2P Caching

  • All GitHub CLI tools use the existing ipfs_accelerate_py.github_cli wrapper
  • Cache is enabled by default with P2P sharing (when libp2p is available)
  • Minimizes GitHub API calls by:
    • Caching responses locally
    • Sharing cache entries with P2P peers
    • Using stale cache data on rate limit errors

GitHub CLI Wrapper

Located in /ipfs_accelerate_py/github_cli/wrapper.py:

  • GitHubCLI: Core wrapper for gh command
  • WorkflowManager: Workflow operations with caching
  • RunnerManager: Runner operations with architecture detection

3. Dashboard Updates

Updated /ipfs_accelerate_py/static/js/dashboard.js:

Added three async functions:

  • refreshUserInfo() - Fetches and displays GitHub user authentication status
  • refreshCacheStats() - Fetches and displays cache performance metrics
  • refreshPeerStatus() - Fetches and displays P2P peer system status

These functions:

  • Load immediately on dashboard initialization
  • Auto-refresh every 5 seconds when on the overview tab
  • Call the MCP API endpoints (/api/mcp/user, /api/mcp/cache/stats, /api/mcp/peers)

4. MCP Tool Registration

Updated /ipfs_accelerate_py/mcp/tools/__init__.py:

  • Registered GitHub CLI tools with the MCP server
  • Tools are automatically loaded when MCP server starts
  • Compatible with both FastMCP and standalone MCP implementations

How It Works

Flow Diagram

Dashboard (HTML/JS)
    ↓
MCP API Endpoints (/api/mcp/*)
    ↓
Dashboard Data Tools (dashboard_data.py)
    ↓
GitHub CLI Wrapper (wrapper.py)
    ↓
GitHub CLI (gh) with Cache
    ↓
GitHub API (minimized calls via cache)

Example: Loading User Information

  1. Dashboard loads → Calls refreshUserInfo()
  2. JavaScript → Fetches /api/mcp/user
  3. Flask route → Calls get_user_info() from dashboard_data.py
  4. Dashboard Data → Uses GitHubCLI wrapper
  5. GitHub CLI Wrapper → Runs gh api /user (with cache check first)
  6. Response → Cached for 5 minutes, shared with P2P peers
  7. Dashboard → Displays username and auth status

Example: Workflow Queues

// JavaScript calls MCP tool via MCP SDK
const result = await mcp.request('tools/call', {
    name: 'gh_create_workflow_queues',
    arguments: { since_days: 1 }
});

This:

  1. Calls the MCP tool on the server
  2. Uses WorkflowManager.create_workflow_queues()
  3. Checks cache for each repository
  4. Makes minimal GitHub API calls (only for uncached data)
  5. Caches all responses with P2P sharing
  6. Returns workflow queues to dashboard

API Endpoints

Dashboard API Endpoints

  • GET /api/mcp/user - Get GitHub user information
  • GET /api/mcp/cache/stats - Get cache statistics
  • GET /api/mcp/peers - Get P2P peer system status
  • GET /api/mcp/metrics - Get system performance metrics

MCP Tool Endpoints

When using MCP SDK, tools are called via:

  • POST /mcp/tool/{tool_name} - Execute any registered MCP tool

Example tool names:

  • gh_list_runners
  • gh_create_workflow_queues
  • gh_get_cache_stats
  • gh_get_auth_status
  • gh_list_workflow_runs
  • gh_get_runner_labels

Configuration

GitHub Authentication

The system supports multiple authentication methods:

  1. GitHub CLI authentication (preferred):

    gh auth login
  2. Environment variable:

    export GITHUB_TOKEN="ghp_..."
  3. Token file (managed by gh CLI):

    ~/.config/gh/hosts.yml
    

Cache Configuration

Cache is configured via GitHubCLI constructor:

from ipfs_accelerate_py.github_cli import GitHubCLI

gh = GitHubCLI(
    enable_cache=True,      # Enable caching (default)
    cache_ttl=300,          # 5 minutes (default)
    auto_refresh_token=True # Auto-refresh tokens (default)
)

P2P Configuration

P2P cache sharing is enabled when:

  1. enable_p2p=True in cache configuration
  2. libp2p is installed (pip install "libp2p @ git+https://github.com/libp2p/py-libp2p@main")

Check P2P status:

from ipfs_accelerate_py.github_cli.cache import get_global_cache

cache = get_global_cache()
stats = cache.get_stats()
print(f"P2P enabled: {stats['p2p_enabled']}")
print(f"P2P peers: {stats.get('p2p_peers', 0)}")

Testing

Test GitHub Tools Registration

python3 -c "
from ipfs_accelerate_py.mcp.tools.github_tools import register_tools

class MockMCP:
    def __init__(self):
        self.tools = []
    def tool(self):
        def decorator(func):
            self.tools.append(func.__name__)
            return func
        return decorator

mcp = MockMCP()
register_tools(mcp)
print(f'Registered {len(mcp.tools)} GitHub tools')
"

Test User Info Function

python3 -c "
from ipfs_accelerate_py.mcp.tools.dashboard_data import get_user_info
import json
print(json.dumps(get_user_info(), indent=2))
"

Test Cache Stats

python3 -c "
from ipfs_accelerate_py.github_cli.cache import get_global_cache
cache = get_global_cache()
stats = cache.get_stats()
print(f'Total entries: {stats[\"total_entries\"]}')
print(f'Hit rate: {stats[\"hit_rate\"]}')
"

Troubleshooting

"Not authenticated with GitHub"

Solution: Refresh your GitHub authentication:

gh auth login
# or
gh auth refresh

"Rate limit exceeded"

The system automatically:

  1. Returns stale cache data when rate limited
  2. Shares cache entries via P2P network
  3. Reduces API calls through aggressive caching

Manual solution: Wait for rate limit reset or use a PAT with higher limits

Cache not working

Check cache status:

python3 -c "
from ipfs_accelerate_py.github_cli.cache import get_global_cache
cache = get_global_cache()
print(f'Cache enabled: {cache is not None}')
print(f'Total entries: {cache.get_stats()[\"total_entries\"]}')
"

P2P not connecting

Requirements:

  • libp2p must be installed: pip install "libp2p @ git+https://github.com/libp2p/py-libp2p@main"
  • Port 9100 must be open for P2P connections
  • Firewall must allow P2P traffic

Check P2P status:

python3 -c "
from ipfs_accelerate_py.github_cli.cache import get_global_cache
cache = get_global_cache()
stats = cache.get_stats()
print(f'P2P enabled: {stats[\"p2p_enabled\"]}')
if not stats['p2p_enabled']:
    print('Install libp2p: pip install "libp2p @ git+https://github.com/libp2p/py-libp2p@main"')
"

Files Modified

  1. Created: /ipfs_accelerate_py/mcp/tools/github_tools.py

    • 6 new MCP tools for GitHub CLI operations
  2. Modified: /ipfs_accelerate_py/mcp/tools/__init__.py

    • Added GitHub tools registration
  3. Modified: /ipfs_accelerate_py/static/js/dashboard.js

    • Added refreshUserInfo() function
    • Added refreshCacheStats() function
    • Added refreshPeerStatus() function
    • Updated startAutoRefresh() to refresh all dashboard data
    • Updated initialization to load data immediately
  4. Existing (Used by new integration):

    • /ipfs_accelerate_py/github_cli/wrapper.py - GitHub CLI wrapper
    • /ipfs_accelerate_py/github_cli/cache.py - GitHub API cache with P2P
    • /ipfs_accelerate_py/mcp/tools/dashboard_data.py - Dashboard data operations

Benefits

1. Minimized API Calls

  • Cache TTL: 5 minutes for most operations
  • Shorter TTL (30-60s) for real-time data like runner status
  • Stale cache fallback on rate limits
  • P2P cache sharing across instances

2. GitHub CLI Integration

  • Uses official gh CLI (already authenticated)
  • Supports all gh authentication methods
  • Automatic token refresh
  • Works with Copilot CLI seamlessly

3. Dashboard Integration

  • Real-time user authentication status
  • Cache performance metrics
  • P2P peer system status
  • Auto-refresh every 5 seconds
  • Immediate load on page open

4. MCP Server Tools

  • 6 new MCP tools for GitHub operations
  • Compatible with MCP SDK (JavaScript)
  • Can be called from any MCP client
  • Full caching support built-in

Next Steps

Optional Enhancements

  1. Add more GitHub tools:

    • gh_trigger_workflow - Trigger workflow runs
    • gh_cancel_workflow - Cancel running workflows
    • gh_get_workflow_logs - Fetch workflow logs
  2. Enhance dashboard UI:

    • Add workflow run visualization
    • Add runner status indicators
    • Add cache hit rate chart
    • Add P2P peer map
  3. Improve error handling:

    • Retry logic for failed API calls
    • Better error messages in dashboard
    • Toast notifications for auth failures
  4. Add monitoring:

    • Track API call reduction percentage
    • Monitor cache hit rates over time
    • Alert on rate limit approaching

Conclusion

The GitHub Actions workflow system is now fully integrated with the MCP server dashboard. The system:

  • ✅ Uses GitHub CLI with authentication
  • ✅ Uses Copilot CLI tools (via MCP)
  • ✅ Exposes tools in ipfs_accelerate_py package
  • ✅ Uses CLI cache and P2P network
  • ✅ Minimizes GitHub/Copilot API calls
  • ✅ Accessed via MCP server JavaScript SDK
  • ✅ Displayed in MCP server dashboard
  • ✅ Shows GitHub Actions runners working correctly

The dashboard now displays:

  • Username: Shows authenticated GitHub user
  • Authentication: Shows ✓/✗ auth status
  • Token Type: Shows token type (environment/cli/unknown)
  • Cache Stats: Shows cache performance metrics
  • P2P Status: Shows P2P peer system status

All data auto-refreshes every 5 seconds when viewing the Overview tab.