A Model Context Protocol (MCP) client that connects to GitHub's MCP server and uses Google's Gemini LLM for intelligent interactions.
The Model Context Protocol (MCP) is an open standard that allows LLM applications to access data, prompts, and tools in a standardized way. Think of it as a universal adapter between AI models and external services.
Key Concepts:
- MCP Server: Exposes tools, resources, and prompts (e.g., GitHub's MCP server provides tools like
search_repositories,create_issue) - MCP Client: Connects to servers and makes their tools available to applications
- Transport: The communication layer (this project uses
stdiotransport)
Build a simple MCP client and connect it with a free LLM to interact with GitHub.
- MCP Architecture: Understanding how clients and servers communicate via transports
- Tool Calling: How LLMs use function declarations to decide when to call external tools
- Schema Sanitization: Gemini's API is strict about JSON Schema format—learned to strip unsupported fields
- Rate Limiting: Handling 429 errors with exponential backoff retry logic
- ESM in Node.js: Using
tsxfor proper ESM TypeScript module resolution
src/
├── index.ts # Entry point - orchestrates the client
├── config.ts # Zod-validated environment config
├── mcp-client.ts # MCPClient class for server communication
└── gemini-adapter.ts # Gemini LLM integration with retry logic
- Node.js 18+
- GitHub Personal Access Token
- Google Gemini API Key
-
Clone and install dependencies:
git clone <repo-url> cd github-mcp npm install
-
Create
.envfile:GITHUB_TOKEN=your_github_personal_access_token GEMINI_API_KEY=your_gemini_api_key
-
Get your tokens:
Default prompt:
npm run devCustom prompt:
npm run dev "List all my repositories with more than 10 stars"┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ User │────▶│ Gemini │────▶│ MCP Client
│ Prompt │ │ (LLM) │ │ │
└─────────────┘ └──────┬──────┘ └──────┬──────┘
│ │
│ Tool Calls │ Stdio Transport
▼ ▼
┌─────────────┐ ┌─────────────┐
│ Tool Results│◀────│ GitHub MCP │
│ │ │ Server │
└─────────────┘ └─────────────┘
- User provides a natural language prompt
- Gemini receives the prompt along with available GitHub tools
- Gemini decides which tools to call and with what arguments
- MCP Client executes the tools via the GitHub MCP server
- Results are sent back to Gemini for final response
- TypeScript - Type-safe JavaScript
- Zod - Runtime schema validation
- @modelcontextprotocol/sdk - Official MCP client SDK
- @google/generative-ai - Gemini API SDK
- tsx - Modern TypeScript runner for ESM