opencode-ast-mcp
Allows using local or hosted Ollama instances as an OpenAI-compatible endpoint for cloud planning and as part of the autonomous code-test-fix loop.
Allows using OpenAI's API as the cloud planning backend for generating software design documents and supporting the autonomous loop.
Provides isolated test execution and code sandboxing using rootless Podman containers, for running shell commands and autonomous code-test-fix loops.
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., "@opencode-ast-mcpget the skeleton of server.py"
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.
Opencode AST MCP Server
Turn any MCP-aware IDE (OpenCode, Claude Desktop, etc.) into an agentic coding system backed by tree-sitter, a local Qwen 18B, OpenRouter (Claude Haiku by default), and Podman.
Why this project
A drop-in MCP server that gives your coding agent 9 specialised tools — AST extraction without reading whole files, local code analysis via Qwen, cloud SDD planning via OpenRouter, and isolated test execution in Podman — so the agent spends its context window on code, not on boilerplate.
Related MCP server: ast-editor
Features
9 MCP tools in a single Python server (FastMCP + stdio)
tree-sitter AST extraction for Python, JavaScript, TypeScript, TSX
Local LLM analysis via LM Studio + Qwen 18B (no cloud for code review)
Cloud planning via any OpenAI-compatible endpoint (OpenRouter, OpenAI, ollama)
Podman sandbox for test execution with hardened mount validation
Autonomous code→test→fix loop with a 5-iteration circuit breaker
35 pytest tests, all runnable in the sandbox
Table of contents
Quick start
# 1. Clone & enter
git clone <repo-url> opencode-ast-mcp
cd opencode-ast-mcp
# 2. Create a virtualenv & install
python3.13 -m venv venv
./venv/bin/pip install -r requirements.txt
# 3. Configure secrets
cp .env.example .env
# Edit .env — set MINIMAX_API_KEY to your OpenRouter/OpenAI key
$EDITOR .env
# 4. Build the Podman sandbox image (one time)
podman compose -f sandbox/compose.yaml build
# 5. (Optional) Start LM Studio and load the Qwen model
lms server start
lms load qwen3.5-18b-a3b-reap-coding-heretic-v0-i1 --gpu max -c 16384 --yes
# 6. Register the MCP server in OpenCode
# Edit ~/.config/opencode/opencode.json and add:
# "opencode-ast": {
# "type": "local",
# "command": ["/absolute/path/to/opencode-ast-mcp/start.sh"]
# }Full setup walkthrough (with all 9 env vars and Podman machine init): docs/SETUP.md. Something broken? docs/TROUBLESHOOTING.md.
Tools at a glance
# | Tool | Backing service | Purpose |
1 |
| tree-sitter | Compact outline of a file's top-level structure |
2 |
| tree-sitter | Full source of a named function or class |
3 |
| tree-sitter | Structured JSON of a file's nodes |
4 |
| LM Studio (Qwen) | Security / data-flow analysis of a code chunk |
5 |
| LM Studio (Qwen) | Summarise a verbose error log to ≤2 sentences |
6 |
| Podman | Run a single shell command in a container |
7 |
| Podman + Qwen + OpenRouter | Code → test → fix loop with circuit breaker |
8 |
| OpenRouter (default) | Generate product/tech/plan docs for a feature |
9 |
| local FS | Read |
Full per-tool reference (params, returns, gotchas, decision tree): docs/TOOLS.md
How it works with OpenCode plan/build mode
OpenCode itself has a plan mode (read-only) and a build mode (full write access). The MCP tools map onto those modes as follows:
MCP tool | Side effects? | Plan mode | Build mode |
| None | ✅ | ✅ |
| LM Studio HTTP call | ✅ | ✅ |
| LM Studio HTTP call | ✅ | ✅ |
| Reads | ✅ | ✅ |
| One HTTPS call, no disk writes | ✅ | ✅ |
| Podman container + workspace mount | ❌ | ✅ |
| Sandbox + writes | ❌ | ✅ |
generate_sdd is the bridge between the two modes: it runs entirely in
plan mode (no file writes), produces the SDD artifacts the user reviews,
and the user then flips to build mode for execute_autonomous_loop_tool
to walk through plan.md step by step. See
docs/ARCHITECTURE.md for the full request
lifecycle and the four "Gotchas" (A: os.sync(), B: circuit breaker,
C: thermal cooldown, D: mount validation) that make the system safe.
Project status
All 9 tools validated end-to-end as of v0.1.0:
Tool | Status |
| ✅ working |
| ✅ working |
| ✅ working |
| ✅ working (requires LM Studio) |
| ✅ working (requires LM Studio) |
| ✅ working (35/35 pytest tests verified) |
| ✅ working for the test+report path |
| ✅ working (OpenRouter + Claude Haiku) |
| ✅ working |
Known gap: execute_autonomous_loop_tool runs the test, captures the
result, and asks the brain for a patch, but does not yet apply that
patch to the filesystem. Patches are written to .opencode/patches/
for audit. Tracking in
docs/TOOLS.md §7.
Project layout
opencode-ast-mcp/
├── server.py # FastMCP entry point — registers 9 tools
├── start.sh # Boot script: starts LM Studio, runs server.py
├── config.py # Centralised env-var configuration
├── ast_extractor.py # tree-sitter powered skeleton/JSON/extract
├── lm_client.py # LM Studio HTTP client (Qwen 18B)
├── m3_client.py # LLM brain client (OpenAI-compatible)
├── sandbox_runner.py # Podman container execution + safety checks
├── autonomous_loop.py # Code→test→fix loop with circuit breaker
├── dummy_auth.py # Test fixture for the AST extractor
├── requirements.txt # Python dependencies
├── LICENSE # MIT
├── .env.example # Template for .env
├── .github/
│ ├── workflows/test.yml # CI: 35 pytest in Podman on every push/PR
│ └── dependabot.yml # Dependabot for pip
├── sandbox/
│ ├── Containerfile # python:3.13-slim + pytest
│ └── compose.yaml # Podman compose for the sandbox
├── sdd/ # Project's own SDD (product/tech/plan.md)
├── prompts/
│ └── system_prompt.md # Brain orchestrator system prompt
├── tests/ # pytest suite (35 tests)
├── docs/ # ARCHITECTURE / TOOLS / SETUP / TROUBLESHOOTING
├── AGENTS.md # Guidance for AI coding agents
├── CHANGELOG.md # Release history
├── CONTRIBUTING.md # How to contribute
├── SECURITY.md # How to report security issues
└── venv/ # Local virtualenv (gitignored)Documentation
docs/ARCHITECTURE.md — component diagram, request lifecycle, Gotchas A–D
docs/TOOLS.md — full per-tool reference + decision tree
docs/SETUP.md — 9-step setup with provider-swap matrix
docs/TROUBLESHOOTING.md — 6 grouped failure modes with fixes
sdd/ — the project's own software design docs
AGENTS.md — guidance for AI agents (OpenCode-using and contributor)
prompts/system_prompt.md — the brain's own system prompt
Contributing
PRs welcome. The dev loop is:
./venv/bin/pip install -r requirements.txt
./venv/bin/python -m pytest tests/ -v # host, fast
# or
podman compose -f sandbox/compose.yaml run --rm opencode-sandbox \
bash -c "cd /workspace && pip install -q -r requirements.txt && python -m pytest tests/ -v"
# sandbox, matches CI
# Add a tool → see AGENTS.md "Adding a new MCP tool"
# Add a language → see AGENTS.md "Adding a new language to the AST extractor"Please read AGENTS.md before changing code — it documents the module boundaries, safety constraints, and plan-mode etiquette that all contributors (human or AI) are expected to follow.
See CONTRIBUTING.md for the full contributor checklist and SECURITY.md for private disclosure.
License
MIT — © 2026 Tim
Acknowledgments
tree-sitter — the AST parser that makes deterministic code analysis possible
LM Studio + Qwen 3.5 18B — local inference for per-function code review
Anthropic Claude via OpenRouter — cloud-side SDD planning
Podman — rootless container isolation
FastMCP — the Python MCP server SDK
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
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/maThiaslI152/opencode-ast-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server