Khoj can use MCP tools. Getting there took five workarounds.
Khoj's MCP support is new, and we hit five hurdles connecting it to Swytchcode: an old Docker tag, research mode only, a key it never sends, no arguments, and no python. Here's how to get past each one.
Khoj calls itself your AI second brain. It answers from the web and your own documents, works with almost any model, and runs in your browser, on your desktop, in Obsidian, in Emacs or on WhatsApp. It has around 38,000 stars on GitHub, and it's open source and self-hostable.
In its newer versions, Khoj can also use MCP servers. That's how we connect agents to Swytchcode, which runs their API calls with your keys, holds every write for your approval, and keeps rules the agent can't change.
It works. But Khoj's MCP support is new, and we hit five hurdles on the way. Here they are in order, so you don't have to find them yourself.
Hurdle 1: latest isn't the latest
Khoj's Docker setup pulls the latest image. That tag points at version 1.42.10, which is over a year old and has no MCP support at all. MCP is in the 2.0 betas. We used 2.0.0-beta.28, by naming that tag in the compose file.
Hurdle 2: only in research mode
Khoj offers MCP tools only in research mode, which you start with /research in the chat. A normal question won't touch them. Also, MCP servers are set up by the admin for the whole server, so every user on it gets the same tools.
Hurdle 3: remote servers can't send a token
Khoj can connect to a remote MCP server, but only over SSE, an older connection type. It also has a field for an API key, which it saves and then never sends. Swytchcode's HTTP server requires a token, so the remote route was closed to us.
Hurdle 4: local servers take no arguments
That left local servers. In Khoj's admin panel, a local MCP server is just a path to a file, which Khoj runs with python (or node for a .js file). There's nowhere to add arguments, and Swytchcode needs a few. So we wrote a four-line wrapper that hands over to Swytchcode with the right ones:
# Khoj runs this as `python <file>` with no arguments,
# so it hands over to swytchcode with the ones it needs.
import os
os.execvp("swytchcode", ["swytchcode", "mcp", "serve", "--profile", "operator", "--project", os.path.expanduser("~/agent-swy")])Hurdle 5: no python in the image
Khoj runs local servers with python. The Docker image only has python3. So the wrapper failed with a file-not-found error until we added a link:
ln -s /usr/bin/python3 /usr/local/bin/pythonAfter that, Khoj's research mode listed all 11 Swytchcode tools.
Then it worked
With the five hurdles cleared, we ran our seven checks against a mocked Stripe, with a scripted model. All seven passed. A balance lookup ran. A write stopped before it reached Stripe, waiting for a person. A pasted API key was refused, with a command for you to run instead. And asked to add an allow rule or replace the approval rule, the agent was refused, and the rules file didn't change.
There was also nothing to lock down. Because Swytchcode runs as a local server here, it sits inside Khoj's server container, rules and all. But Khoj's agent doesn't run code in that container. Its code tool runs in a separate sandbox, and its computer-use operator, which is off by default, in its own container. We confirmed that by reading Khoj's code, not by running those sandboxes, so check it on your own setup.
That's the point of keeping rules outside the agent's reach: the agent can ask for anything, and only Swytchcode decides what runs.
One open question
Khoj names MCP tools like swytchcode/swytchcode_exec, with a slash. As far as we know, OpenAI and Anthropic don't accept a slash in tool names. Our scripted model didn't mind, but with a real OpenAI or Anthropic model, research mode may fail once any MCP server is set up. We haven't tested it with a real key yet. If you try it, we'd like to hear what happens.
Set it up
You need a Swytchcode account, and approvals need the Business or Enterprise plan. In Khoj's server container (we built a small image on top of Khoj 2.0.0-beta.28 for this):
- Install
swytchcode, then runswy init --operator --editor=none --project ~/agent-swyandswy login. - Add the
pythonlink from hurdle 5. - Save the wrapper from hurdle 4 as
/root/swytchcode_mcp.py. - In Khoj's admin panel, add an MCP server with that path.
Khoj has no skills, so rules for how the agent should use Swytchcode would go in an agent's personality. We haven't tried that yet. Our docs page for any other agent covers connecting your first app.
We tested through Khoj's chat API. We haven't tested a real model, its web, desktop, Obsidian, Emacs or WhatsApp clients, or a real approval on a phone. We're sending what we found to the Khoj team.
New features have rough edges
None of these hurdles is hard on its own. Together, they're the difference between trying MCP in Khoj and giving up. Most will likely disappear as the 2.0 release settles: a fresh latest tag, arguments for local servers, a key that gets sent.
Until then, the five fixes above get you there. And once you're through, Khoj is a calm place to run Swytchcode: its agent can research all it likes, and nothing that changes your accounts happens without you.
More content
How to Debug an AI Agent That Called the Wrong API
Working backwards from the response your agent got to the tool-selection decision that caused it, which is where most of the real debugging time goes.
iPaaS Was Built for Integrations, Not Agents
Deterministic trigger-action versus non-deterministic tool choice, and why the governance model that works for one doesn't transfer cleanly to the other.
Build Your Own MCP Server or Buy an Execution Layer
The real cost line isn't the connectors. It's the maintenance of the stitching layer underneath them, and that bill doesn't stop arriving after launch.
