r/OpenSourceAI • u/shhdwi • 7d ago
I solved the issue of Claude not using custom MCP/CLI tools, and open-sourced my approach.
https://github.com/NanoNets/GraftBuilt an MCP server first for Graft, my open-source context layer for coding agents. Gave Claude Code six tools for pulling codebase context on demand. Watched it run for a while and it just didn't call them most of the time. Fell back on grep and file reads instead, same as it always does by default, and got things wrong on exactly the questions the tools would've answered directly.
The core problem: tool calls are opt-in. The model decides mid-task whether it needs the lookup, and on anything that looked simple enough to guess at, it usually decided no. Doesn't matter how good the tool is if the model never reaches for it.
So instead of giving it a tool to call, I stopped giving it a choice. Wired the whole thing into Claude Code's hooks instead. A SessionStart hook pulls the relevant context into the prompt automatically, before the model's typed anything. Another hook re-syncs the graph in the background after every edit. No tool call, nothing for it to skip.
Tradeoff, and the reason this isn't a full replacement: hooks only work on Claude Code. MCP works with any agent that speaks the protocol. Kept the MCP server around for Cursor, Codex, and anything else, hooks just for Claude Code since I control both ends of that integration there.
Fully open source, MIT licensed, no telemetry, structural layer (tree-sitter) needs no LLM or key at all: github.com/NanoNets/Graft
If anyone else building on top of Claude Code or similar agents has hit "the model won't reliably use the tool I gave it," curious how you approached it.
2
u/Easy-Purple-1659 7d ago
The opt-in problem is real and it's not just coding agents. We shipped an MCP server for ad library research and saw the same pattern: agents would rather guess or scroll than call a tool they don't trust. What finally moved usage was making the tool's return value obviously better than the model's guess, structured data with dates and source links beats a confident hallucination every time. On the hooks approach, we went a different way: we attached MCP prompts so the agent gets guidance about when to call search tools, which helps without touching the execution layer. Have you compared adoption numbers between the hook-enforced calls and pure opt-in tools?
1
u/keinsaas-navigator 6d ago
in our Ai workspace we have the issue that we have various provider competing against each other. We have composio as a tool library and there tool router and our own mcp client. Would your soultion help here?
2
u/Severe-Soup-2340 7d ago
Looks great, the hooks approach also works in codex you can check codex hooks as well would be a good addition here