Skip to content

Phase 3: GitHub MCP Client for Codeoba #54

@paulpv

Description

@paulpv

GitHub MCP Client for Codeoba

Background

Codeoba needs to integrate with GitHub's MCP (Model Context Protocol) server to enable voice-driven GitHub operations. MCP is a standardized client-server protocol where:

  • MCP Server (GitHub's): Hosted at https://api.githubcopilot.com/mcp/, implements tools for GitHub operations
  • MCP Client (Codeoba): Connects to server, discovers available tools, executes tool calls via JSON-RPC

Architecture Overview

Voice Input → OpenAI Realtime API → Tool Call Event → Codeoba MCP Client
                                                           ↓ (JSON-RPC over HTTP)
                                                  GitHub MCP Server (api.githubcopilot.com/mcp/)
                                                           ↓
                                                    GitHub API Operations
                                                           ↓
                                                        Result

Implementation Requirements

1. MCP Protocol Layer

File: core/src/commonMain/kotlin/.../data/mcp/McpProtocol.kt

Implement JSON-RPC 2.0 messages per MCP spec:

  • initialize - Establish connection with server capabilities
  • tools/list - Discover available tools from server
  • tools/call - Execute a tool with arguments
  • Handle responses with result/error structure

2. HTTP Transport Layer

File: core/src/commonMain/kotlin/.../data/mcp/McpTransport.kt

  • Use Ktor HTTP client for communication with https://api.githubcopilot.com/mcp/
  • Support OAuth or PAT-based authentication via Authorization header
  • Handle JSON-RPC request/response serialization
  • Implement error handling and retries

3. MCP Client Implementation

File: core/src/commonMain/kotlin/.../data/McpClientImpl.kt

class McpClientImpl(private val githubToken: String) : McpClient {
    // Connect to GitHub MCP server
    suspend fun connect()
    
    // Fetch and cache available tools from server
    suspend fun discoverTools(): List<ToolDefinition>
    
    // Execute tool call via server
    override suspend fun handleToolCall(name: String, argsJson: String): McpResult
}

4. Tool Discovery & Caching

  • On initialization, call tools/list to discover available GitHub tools
  • Cache tool definitions (name, description, input schema)
  • No hardcoded tool implementations - server handles all execution

5. Approval Flow Integration

  • Check if tool requires approval based on operation type
  • Use existing ApprovalManager for user consent
  • Pass approved calls to GitHub MCP server

6. Configuration

  • Load GitHub token from local.properties as DANGEROUS_GITHUB_TOKEN
  • Configure MCP server URL (default: https://api.githubcopilot.com/mcp/)
  • Support optional enterprise endpoints

Key Differences from Current Implementation

Remove:

  • All custom GitHub API REST client code (GitHubApiClientImpl.kt)
  • Manual tool handlers (handlers/GitHubToolHandlers.kt)
  • Custom tool registry with hardcoded handlers
  • Direct GitHub API v3 calls

Keep:

  • ApprovalManager for user consent
  • McpClient interface
  • Configuration via local.properties
  • Integration with CodeobaApp.handleToolCall()

Testing Strategy

  1. Mock MCP server responses for unit tests
  2. Test JSON-RPC message serialization
  3. Test tool discovery flow
  4. Test tool execution with approval
  5. Optional: Integration test with real GitHub MCP server (requires token)

References

Success Criteria

  • MCP client connects to GitHub's server
  • Dynamically discovers all available GitHub tools
  • Successfully executes tool calls through server
  • No custom GitHub REST API code
  • All operations go through MCP protocol

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions