# delegate-ai-mcp MCP servers that let Claude Code delegate light, low-stakes work to local AI CLI backends, instead of spending its own budget on it. Currently one backend: qwen-code. ## How it works - `src/qwen-delegate.ts` — core logic: spawns `qwen -p ""`, captures stdout, handles timeouts and errors. Exported separately from the MCP wiring so it's unit-testable without a live MCP connection or a live qwen endpoint. - `src/qwen-delegate-server.ts` — thin MCP stdio server exposing one tool, `qwen_delegate`. qwen-code runs natively on Windows here (no WSL), backed by a local OpenAI-compatible model proxy configured in `~/.qwen/settings.json`. See `research/qwen-mcp-delegation.md` for how that was confirmed. Replies can take several minutes on a cold local model, so the tool uses a generous (10 min) timeout rather than trying to enforce "light work" in code — that's a judgment call left to whoever's calling the tool. Each backend is its own MCP server process with its own `claude mcp add` registration — there's no single multi-tool server. Adding a second backend means adding its own `src/-delegate.ts` + `src/-delegate-server.ts` pair and registering it separately (see Status below — the shared subprocess helper this implies isn't extracted yet). No build step: everything runs as plain `.ts` source via Node's native TypeScript type-stripping. No `tsconfig.json`, no `dist/`, no lint/format tooling — deliberate choices, not oversights (see the wayfinder map linked below). ## Prerequisites - Node.js 24+ (native TypeScript type-stripping) - `qwen` on `PATH` and working (`qwen -p "test"` should return a reply) ## Setup ```bash npm install npm test ``` ## Register with Claude Code Global (available in every project): ```bash claude mcp add --scope user qwen-delegate -- node /absolute/path/to/src/qwen-delegate-server.ts ``` Verify it connected: ```bash claude mcp list ``` ## Usage Once registered, Claude Code can call the `qwen_delegate` tool directly. The routing convention — *when* to delegate — lives in `~/.claude/CLAUDE.md` under "Delegating light work to qwen": simple lookups, quick research, boilerplate text, small single-file edits. Claude decides per-request; there's no enforced dispatcher. ## Testing ```bash npm test ``` Runs `test/qwen-delegate.test.ts` on Node's built-in test runner (`node --test`) — no test framework dependency. The subprocess spawn is mocked, so tests run in milliseconds and don't require a live `qwen` install. ## Status Project conventions are being worked through a [wayfinder map](https://git.arthurerlich.de/haylan/delegate-ai-mcp/issues/1) on this repo's issue tracker (see `docs/agents/issue-tracker.md` for how issues/tickets work here). Decided so far: no build process, ever; separate MCP server process + registration per backend, with a shared `src/lib/spawn-cli.ts` helper once a second backend exists (not extracted yet — still just `qwen-delegate.ts`); no lint/format tooling for now. Still open: a publish-shaped `package.json`.