MCP Database Assistant
Connects a local LLM (Ollama) to a SQLite database via the Model Context Protocol, enabling natural language queries and controlled read/write database operations through MCP tools.
README
MCP-Database-Assistant
The goal of this project is to build a simple realistic Database AI assistant following Model-Context-Protocol (MCP) standard that can understand natural-language questions using LLM like Ollama, communicates with database tools through an MCP client-server architecture, selects the correct database operation, and performs safe read/write actions on an external SQLite database.
Project Structure:
mcp_db_assistant/
├── streamlit_app.py # Simple browser UI for dropdown/custom questions, write approval, and final answer
├── host_app.py # Host app: Ollama LLM + MCP client orchestration
├── mcp_server.py # MCP server: exposes read/write DB tools
├── init_db.py # Creates and resets SQLite database
├── retail.db # Sample SQLite database
├── requirements.txt
├── .env
Tech stack used: Python, Ollama, qwen2.5:7b, MCP SDK, FastMCP, SQL, Streamlit
Workflow:
User asks a natural-language question
↓
Host discovers relevant MCP tools from the MCP server
↓
Host sends question + MCP tool schemas to Ollama qwen2.5:7b
↓
Ollama LLM decides which exposed tool to call and what arguments to pass
↓
Host executes the respective registered tool through MCP Client SDK
↓
MCP Client talks to MCP Server using MCP JSON-RPC over stdio
↓
MCP Server reads/writes SQLite database
↓
Executed tool result goes back to Host
↓
Host sends result back to Ollama
↓
Ollama explains the result to the end user
Important communication distinction
Host ↔ Ollama LLM
Uses Ollama Python SDK / Ollama API
Host ↔ MCP Client SDK
Uses normal Python method calls, such as session.call_tool(...)
MCP Client ↔ MCP Server
Uses MCP protocol, JSON-RPC over stdio
MCP Server ↔ SQLite Database
Uses normal python, sqlite3 database code
Tools registered in the MCP server
The MCP server has below registered tools which are the controlled database operations.
For reading operations:
- list_tables
- describe_table
- get_sales_summary
- get_revenue_by_region
- get_sales_by_channel
- get_daily_sales_trend
- check_inventory
- get_product_details
- search_products
- get_low_stock_products
- get_supplier_reorder_report
- get_top_products_by_revenue
- get_customer_profile
- get_customer_orders
- get_order_details
- get_segment_performance
- run_readonly_sql
For writing operations: The Host asks for human confirmation before executing write tools.
- create_customer
- update_customer_segment
- create_product
- update_product_price
- update_reorder_level
- restock_inventory
- adjust_inventory
- create_sales_order
- cancel_order
For tracking/auditing operations:
- get_inventory_movements
- get_audit_log
Handling Out-of-scope questions
Out-of-context handling is mainly done through the Host’s system prompt. If a custom question is not related to this retail database assistant, the LLM should not call MCP tools for unrelated topics. It should answer with a short message explaining that the demo only supports retail database operations and analytics, such as customers, products, inventory, sales/orders, suppliers, and audit logs.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.