Debugging MCP with SQLite: Lessons from Building an AI Agent Server

By Shreesh Sanyal
In my journey to explore agentic workflows using the Model Context Protocol (MCP), I ran into an issue that seemed trivial at first—but it ended up teaching me a lot about building resilient AI systems.
The Problem: "Table Does Not Exist"
I was trying to query an existing SQL table through an MCP server set up in Node.js, using the official MCP TypeScript SDK. Despite the table being correctly defined and populated, I was getting the error:
"Table does not exist"
I had copied the SDK example code almost exactly. So why wasn’t it working?
The Real Issue: Misuse of Documentation Code
After some thorough debugging, I realized the problem wasn’t SQLite or MCP itself—it was the assumption that documentation code works out of the box for every use case.
The SDK provides great starting points, but production-ready integration needs custom functions, especially when dealing with:
Table schema differences
SQLite connection lifecycles
Query context handling inside the MCP server logic
The Solution: Custom Function Wrappers
By writing custom wrappers around the query logic, and ensuring my MCP server managed connections and queries with context awareness, I not only resolved the error—but also expanded the server’s functionality. Now it can:
✅ Fetch records from SQL
✅ Insert new records into the database
✅ Handle dynamic inputs with better reliability
Why This Matters for AI Agents
This small fix illustrates a bigger point: when building agentic systems, context and adaptability matter more than static templates.
The Model Context Protocol (MCP) and Agent-to-Agent (A2A) communication are key building blocks for decentralized, intelligent agents. But these systems need flexibility, not just plug-and-play code. Real-world data, workflows, and logic always differ from examples.
Use Case: Blog Publishing via Agents
One of my experiments involves using my own MCP server to create blog posts—like this one—directly from code or X threads. It's a small but powerful example of how agents can automate creative and technical tasks together.
Takeaways
Don’t blindly rely on SDK examples—adapt them to your context.
Agents need contextual awareness, especially with data operations.
MCP + SQL + Node.js is a lightweight but powerful stack for AI workflows.
Building agentic systems is as much about debugging and learning as it is about automation.
Follow me on X(@CyberSleuth24) for real-time updates on AI, agent workflows, and protocol-driven systems.
Subscribe to my newsletter
Read articles from Shreesh Sanyal directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Shreesh Sanyal
Shreesh Sanyal
Building seamless full-stack web experiences with MongoDB, Express, React & Node.js. Passionate about crafting intelligent, autonomous agents that make tech more intuitive and human-centered. On a mission to bridge the gap between web development and cutting-edge AI. Let's build the future—one line of code at a time. 💻 #JavaScript #React #NodeJS #Golang #AI #AutonomousAgents #WebDev #OpenSource