polycode
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@polycodeStart a new opencode session and implement a binary search."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
A production-grade MCP (Model Context Protocol) server exposing 13 tools that let Claude Code (or any MCP client) control three AI coding agents — opencode, Gemini CLI, and Qwen Code — with full session continuity, auth checking, and structured error handling.
How It Works
Claude Code (or Gemini CLI / Qwen Code)
│ calls tools (MCP stdio)
▼
polycode server (this package — auto-started by the MCP client)
│
├── spawns opencode serve → talks to any of 182 models via opencode
├── invokes gemini CLI → Gemini API with session continuity
└── invokes qwen CLI → Qwen API with session continuityThe MCP client (Claude Code, Gemini CLI, Qwen Code) auto-starts this server when the session begins. You never start it manually.
Related MCP server: MCP Coding Agents
Requirements
Python 3.11+
python --versionopencode CLI — for the
opencode_*toolsnpm install -g opencode-ai opencode --version # should print 1.x.xGemini CLI — for the
gemini_*tools (optional)npm install -g @google/gemini-cli gemini --version # should print 0.36.x or higherQwen Code CLI — for the
qwen_*tools (optional)npm install -g @qwen-code/qwen-code qwen --version # should print 0.14.x or higherA model provider for opencode — for the default
ollama/qwen3.5:cloud, Ollama must be running locally. See Changing the Model for alternatives.
Installation
pip install polycodeVerify the CLI is accessible:
polycode --helpWindows note: If
polycodeis not found after install, find the full path withwhere polycodein PowerShell and use it in the MCP config below.
MCP Client Setup
All three supported MCP clients use the same config format — only the config file path differs.
macOS / Linux:
{
"mcpServers": {
"polycode": {
"command": "polycode",
"env": {
"OPENCODE_DEFAULT_MODEL": "ollama/qwen3.5:cloud"
}
}
}
}Windows — use the full path to the binary. Find it by running where polycode in PowerShell, then paste the result as the command value:
{
"mcpServers": {
"polycode": {
"command": "C:\\Users\\YourName\\AppData\\Local\\Programs\\Python\\Python313\\Scripts\\polycode.exe",
"env": {
"OPENCODE_DEFAULT_MODEL": "ollama/qwen3.5:cloud"
}
}
}
}MCP Client | Config file |
Claude Code |
|
Gemini CLI |
|
Qwen Code |
|
Restart your MCP client after saving. All 13 tools appear automatically.
Tools Reference
opencode tools (8)
These tools control opencode — a multi-provider AI coding agent. Sessions are stateful — messages within a session share full context across any of the 180+ supported models.
opencode_start_session
Start a new opencode session. Must be called before opencode_send_message.
Parameter | Type | Required | Description |
| string | No | Absolute path to the project. Defaults to current working directory. |
| string | No | Model in |
Returns:
{
"session_id": "ses_2a29...",
"model": "ollama/qwen3.5:cloud",
"project_dir": "/path/to/project"
}opencode_send_message
Send a prompt to an active session. Blocks until opencode finishes responding.
Parameter | Type | Required | Description |
| string | Yes | From |
| string | Yes | Your prompt. |
| int | No | Default: |
Returns:
{
"response": "Here is the updated function...",
"session_id": "ses_2a29...",
"message_index": 1,
"partial": false
}opencode_get_history
Retrieve the full message history for a session (tracked in-process).
Parameter | Type | Required |
| string | Yes |
Returns:
{
"session_id": "ses_2a29...",
"messages": [
{"role": "user", "content": "...", "timestamp": "2026-04-05T19:00:00Z"},
{"role": "assistant", "content": "...", "timestamp": "2026-04-05T19:00:05Z"}
]
}opencode_list_sessions
List all active opencode sessions.
Returns:
{
"sessions": [
{
"session_id": "ses_2a29...",
"model": "ollama/qwen3.5:cloud",
"project_dir": "/path/to/project",
"message_count": 4,
"created_at": "2026-04-05T19:00:00Z"
}
]
}opencode_end_session
Close a session and free its resources.
Parameter | Type | Required |
| string | Yes |
Returns: {"session_id": "ses_2a29...", "closed": true}
opencode_list_models
List all models available in opencode across all authenticated providers, grouped by provider. Only providers you are authenticated/connected to will show models.
Returns:
{
"models": ["ollama/qwen3.5:cloud", "openai/gpt-4o", "google/gemini-2.5-flash", "..."],
"by_provider": {
"ollama": ["ollama/qwen3.5:cloud", "..."],
"openai": ["openai/gpt-4o", "..."],
"google": ["google/gemini-2.5-flash", "..."]
},
"total": 182,
"default_model": "ollama/qwen3.5:cloud"
}opencode_set_model
Change the default model for new sessions (takes effect immediately for all subsequent opencode_start_session calls).
Parameter | Type | Required | Example |
| string | Yes |
|
Returns: {"previous_model": "ollama/...", "new_model": "openai/gpt-4o"}
opencode_shutdown
Gracefully stop the opencode server and close all active sessions.
Returns: {"stopped": true, "sessions_closed": 2}
Gemini CLI tools (4)
These tools invoke the gemini CLI directly. Sessions are persisted to disk by the CLI — pass session_id to continue a conversation across calls.
Requires: gemini CLI installed and authenticated (OAuth or GEMINI_API_KEY).
gemini_check_auth
Check whether the Gemini CLI is authenticated before making prompt calls.
Parameter | Type | Required | Default |
| int | No |
|
Returns:
{
"authenticated": true,
"method": "api_key_or_oauth",
"detail": "OK — model: gemini-2.5-flash-lite",
"suggestion": ""
}If authenticated is false, suggestion tells you how to fix it.
gemini_prompt
Send a prompt to Gemini CLI. Returns the response and a session_id that can be passed back to continue the conversation.
Parameter | Type | Required | Description |
| string | Yes | The prompt to send. |
| string | No | Resume a previous session. Leave empty to start a new one. |
| string | No | E.g. |
| int | No | Default: |
| string | No | Working directory. Defaults to current directory. |
Returns:
{
"response": "The word you asked me to remember is BLUEBIRD.",
"model": "gemini-2.5-flash-lite",
"session_id": "69cfc177-319c-484c-9..."
}Multi-turn example:
# Turn 1 — new session
gemini_prompt(prompt="Remember the word BLUEBIRD")
→ { session_id: "69cfc177-..." }
# Turn 2 — continue session
gemini_prompt(prompt="What word did I ask you to remember?", session_id="69cfc177-...")
→ { response: "BLUEBIRD" }gemini_list_sessions
List saved Gemini CLI sessions for the current project.
Parameter | Type | Required | Description |
| string | No | Defaults to current directory. |
| int | No | Default: |
Returns:
{
"sessions": [
{"raw": "0: [2026-04-05] Remember the word BLUEBIRD"},
{"raw": "1: [2026-04-05] Explain the polycode architecture"}
]
}Qwen Code CLI tools (3)
These tools invoke the qwen CLI directly. Sessions are persisted to disk by the CLI — pass session_id to continue a conversation across calls.
Requires: qwen CLI installed and authenticated (qwen auth qwen-oauth or qwen auth coding-plan).
qwen_check_auth
Check whether the Qwen Code CLI is authenticated before making prompt calls.
Parameter | Type | Required | Default |
| int | No |
|
Returns:
{
"authenticated": true,
"method": "qwen-oauth",
"detail": "=== Authentication Status ===\n✓ Authentication Method: Qwen OAuth\n Type: Free tier",
"suggestion": ""
}If authenticated is false, suggestion tells you the exact command to run.
qwen_prompt
Send a prompt to Qwen Code CLI. Returns the response and a session_id that can be passed back to continue the conversation.
Parameter | Type | Required | Description |
| string | Yes | The prompt to send. |
| string | No | Resume a previous session. Leave empty to start a new one. |
| string | No | E.g. |
| int | No | Default: |
| string | No | Working directory. Defaults to current directory. |
Returns:
{
"response": "The word you asked me to remember was REDPANDA.",
"model": "coder-model",
"session_id": "ead03e7a-afff-4ccd-a..."
}Multi-turn example:
# Turn 1 — new session
qwen_prompt(prompt="Remember the word REDPANDA")
→ { session_id: "ead03e7a-..." }
# Turn 2 — continue session
qwen_prompt(prompt="What word did I ask you to remember?", session_id="ead03e7a-...")
→ { response: "REDPANDA" }Changing the opencode Model
The model format is provider/model-name. Set it via env var:
"env": {
"OPENCODE_DEFAULT_MODEL": "openai/gpt-4o"
}Or call opencode_set_model at runtime. Call opencode_list_models to see all 182 available models across your connected providers.
Common models:
Provider | Model string |
Ollama (local) |
|
OpenAI |
|
Anthropic |
|
| |
GitHub Copilot |
|
Configuration
Variable | Default | Description |
|
| Default model for new opencode sessions |
|
| Port for the opencode server |
|
| Seconds to wait for opencode to start |
|
| Seconds before a generation times out |
|
| Log level: |
| (unset) | Optional HTTP Basic Auth password for the opencode server |
Error Handling
Every tool always returns a structured response — never a raw exception:
{
"error": "OpencodeBinaryNotFoundError",
"message": "gemini CLI not found on PATH. Install: npm install -g @google/gemini-cli",
"detail": {},
"recoverable": false,
"suggestion": "Install opencode via: npm install -g opencode-ai"
}Field | Description |
| Exception class name |
| What went wrong |
| Structured context (stderr, attempted values, etc.) |
| Whether retrying makes sense |
| Exact next step to fix it |
Common errors:
Error | Cause | Fix |
| CLI not on PATH | Install the CLI listed in |
| opencode failed to start | Increase |
| Generation took too long | Increase |
| Session ID not found | Call |
| Bad input or auth error | Read the |
| Unexpected CLI output shape | Update the CLI to the latest version |
Troubleshooting
"polycode not found" on Windows
Use the full path in your MCP config. Find it with:
where polycodeopencode server times out on startup
Cloud models do a network handshake on first use. Increase the timeout:
"env": { "OPENCODE_STARTUP_TIMEOUT": "30" }Tools appear but calls hang
On Windows, subprocesses can inherit a blocked stdin from the MCP stdio pipe. This package sets stdin=DEVNULL on all subprocesses — ensure you are on polycode >= 0.1.0.
gemini_prompt or qwen_prompt returns an auth error
Run the auth check first:
gemini_check_auth→ readssuggestionfield for the fixqwen_check_auth→ readssuggestionfield for the fix
Then authenticate interactively (gemini or qwen auth qwen-oauth) and retry.
Running Tests
git clone https://github.com/h19overflow/polycode
cd polycode
pip install -e ".[dev]"
# Unit tests — no CLIs required
pytest tests/ --ignore=tests/test_integration.py -v
# Integration tests — requires opencode + ollama
pytest tests/test_integration.py -m integration -vContributing
Fork the repo
pip install -e ".[dev]"Write tests first (TDD)
pytest tests/ --ignore=tests/test_integration.pymust passpyright .must show 0 errorsOpen a PR
License
MIT — see LICENSE
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/h19overflow/polycode'
If you have feedback or need assistance with the MCP directory API, please join our Discord server