How to Debug External MCP Problems (My Real Story)
Summary
Alright, fellow hardware wranglers, Jax Rivera here. Let's dive into the nitty-gritty of debugging AI coding agents, specifically focusing on those moments when things go sideways with MCPs (that's 'My Code Processors,' for the uninitiated). Forget debugging code; we're debugging the whole darn process.
The Lay of the Land
Picture this: Claude Code, bless its digital heart, is cranking away using the Laravel Boost package—a suite of tools designed to streamline Laravel development. Among these tools is one for fetching the database schema. But, as often happens in the world of tech, gremlins abound.
The Problem
The database schema tool was pulling info from all the databases on the local MySQL server, not just the one tied to the Laravel project. The result? A massive, unwieldy JSON file bloated with irrelevant data.
The Detective Work
So, how did I sniff out this digital miscreant? By turning Claude Code into a digital informant. I prompted it not only to perform a task but also to list the MCP tools used and their token consumption. Think of it as asking your sous chef to not only cook the dish but also tell you exactly which ingredients they grabbed and how much they used.
Jax's Two-Step Debugging Tango
- Ctrl+O Revelation: When you spot something fishy, hit
Ctrl+Oto expand the output. This unveils the inner workings of the MCP, showing you exactly what it's doing and returning. It’s like peeking behind the curtain to see the wizard pulling the levers. I expanded the output and was confronted by a JSON behemoth. - Token Analysis Takedown: After the task completes, Claude Code provides a token analysis. This is where the heavy hitter, the database schema tool, was unmasked, hogging a disproportionate number of tokens due to its data gluttony.
My Eureka Moment
Spotting tables in the JSON that didn't belong to the project was the dead giveaway. It was like finding a penguin in the Sahara—clearly out of place.
Pro Tips from Jax's Toolkit
- Expand on Suspicion: If something feels off,
Ctrl+Ois your new best friend. - Token Tracking: Keep an eye on token usage post-task to identify resource hogs.
Lessons Learned
By using Claude Code to monitor its own processes and diving into the expanded outputs, I pinpointed the rogue MCP tool. This wasn't just about fixing a bug; it was about understanding the inner workings of AI agents and learning to speak their language.
Debugging AI agents isn't just about fixing code; it's about understanding the flow, monitoring resource usage, and knowing when to dig deeper. Keep experimenting, keep questioning, and remember: the best code is the code you understand.