delegate-to-gemini
v1.1.0
Published
An MCP server that delegates large conversation contexts from Claude to Gemini
Readme
DelegateToGemini MCP Server
An MCP (Model Context Protocol) server that delegates large conversation contexts from Claude to Gemini when approaching token limits.
Overview
This project provides a solution for managing context windows in AI conversations by:
- Detecting when Claude's context window is nearly full
- Sending the large context to Gemini (which has 1-2M token capacity)
- Having Gemini process and summarize the context
- Returning the condensed information to Claude
- Continuing the conversation without the "context too long" error
Features
- Context Size Checking: Detects when the context is approaching Claude's token limit
- Context Delegation: Sends large contexts to Gemini for processing
- Customizable Summarization: Supports parameters for controlling how Gemini summarizes the context
- JSON Response Format: Returns structured data for easy integration
- Clipboard Helper: Automatically detects large contexts on your clipboard
Installation
# Clone the repository
git clone https://github.com/yourusername/delegate-to-gemini.git
cd delegate-to-gemini
# Install dependencies
pnpm install
# Build the project
pnpm build
# Set up the clipboard helper
pnpm run setup-helperConfiguration
Set your Gemini API key as an environment variable:
export GEMINI_API_KEY="your-api-key-here"Usage
Running the Server
pnpm startThe server runs as an MCP server that communicates via stdin/stdout.
Using the Clipboard Helper for Cursor
The clipboard helper makes delegation more automatic by proactively monitoring for context issues:
Start the clipboard helper:
pnpm run helperThe helper will automatically detect:
- "Your conversation is too long" error messages
- Warning phrases about context limits
- Conversations exceeding token thresholds
- Long Claude conversations
When detected, it will:
- Automatically process the content on your clipboard
- Summarize it with Gemini
- Put the summarized context back on your clipboard
- Display a desktop notification when ready
Just paste the summarized context into a new conversation and continue
Pro tip: Copy your conversation (Ctrl+A, Ctrl+C) whenever you feel it's getting long, even before hitting the limit. The helper will proactively summarize it if needed.
Note: The helper temporarily modifies the source code to include your context, rebuilds the project, and then runs the MCP server. This approach was chosen due to limitations in parameter passing with the MCP SDK.
Available Tools
The MCP server provides the following tools:
1. check_context_size
Checks if the conversation context is approaching Claude's token limit.
Response Example:
{
"isApproachingLimit": true,
"estimatedTokens": 95000,
"maxTokens": 100000,
"percentUsed": 95
}2. delegate_to_gemini
Delegates the conversation context to Gemini for processing and summarization.
Response Example:
{
"summarizedContent": "This is the summarized content...",
"topicsCovered": ["Topic 1", "Topic 2"],
"keyPoints": ["Key point 1", "Key point 2"],
"tokensReduced": "Original: ~95,000 tokens → Summarized: ~10,000 tokens",
"originalTokens": 95000,
"summarizedTokens": 10000
}3. delegate_context
Delegates a specific context to Gemini with parameters (sample implementation).
Integration
To integrate with Claude or other AI systems, you'll need to:
- Set up an MCP client to communicate with this server
- Monitor the context size using
check_context_size - When approaching the limit, call
delegate_to_geminito get a summarized context - Use the summarized context to continue the conversation
Development
# Run in development mode with auto-reload
pnpm devLicense
MIT
Using DelegateToGemini in Cursor
When you see the "Your conversation is too long" warning in Cursor, follow these steps:
Copy your conversation:
- Press
Ctrl+A(orCmd+Aon Mac) to select all text - Press
Ctrl+C(orCmd+Con Mac) to copy it to clipboard
- Press
Tell Claude to use the tool (choose one method):
- Type in the chat input:
<ctrl+/> delegate-to-gemini - Ask naturally: "Please use the delegate-to-gemini tool to summarize this conversation"
- Use the quick invoke shortcut: Run
pnpm invokein your terminal, then paste in Cursor
- Type in the chat input:
Review the summarized result:
- Claude will invoke the MCP tool
- The tool reads your clipboard content
- Gemini summarizes it
- Claude shows you the result
Quick Invoke Helper
To make invocation even easier, use the included quick invoke script:
# Run the invoke helper
pnpm invokeThis script:
- Copies the exact invocation syntax to your clipboard
- Preserves your previous clipboard content (restores after 10 seconds)
- Just paste in Cursor to invoke the tool
Troubleshooting
If the tool isn't working:
Check MCP server configuration in Cursor:
- Go to Settings > Features > MCP Servers
- Add or edit the server with:
- Name:
DelegateToGemini - Command:
node /path/to/DelegateToGemini/dist/main.js
- Name:
- Make sure the server is enabled
Restart Cursor if you've just added the server
Project Structure
// ... existing content ...
