使用说明
MCP Dummy DB Integration POC
This project demonstrates how to use the Model Context Protocol (MCP) to act as a connector between an LLM/Client and a database.
Overview
The system consists of three main components:
- Database: A dummy SQLite database (
dummy.db) containingemployees,projects, andissues. - MCP Server (
mcp_server.py): Exposes tools to query the database securely. It uses themcpPython SDK to define tools likequery_databaseandlist_tables. - MCP Client (
client.py): Simulates an Agent/LLM that connects to the server via standard input/output (stdio) and calls tools to retrieve data.
Prerequisites
- Python 3.10+
mcppackage
Setup
-
Install Dependencies:
pip install -r requirements.txt -
Initialize Database: Run the setup script to create
dummy.dband populate it with sample data.python setup_db.py
Running the Demo
Run the client script to simulate the data retrieval flow:
python client.py
Expected Output
The client will:
- Connect to the MCP server.
- List available tools.
- List tables in the database.
- Execute a SELECT query to fetch employees in the 'AI' department.
- Demonstrate error handling for invalid or forbidden queries.
Agentic Workflow Demo
The project includes an agent_workflow.py script that demonstrates a simulated Agentic flow:
python agent_workflow.py
How it works:
- User Intent: The script accepts natural language queries (e.g., "Show me all employees in the AI department").
- Mock LLM: A simple logic block simulates an LLM converting the intent into SQL.
- Tool Selection: The agent decides whether to use
query_databaseorlist_tables. - Execution: The agent calls the MCP server to fetch data.
- Response: The agent formats and displays the results.
Architecture Flow
Client (Request) -> MCP Protocol (JSON-RPC) -> MCP Server -> SQLite DB
- Security: The server restricts queries to
SELECTonly, preventing modification or deletion of data. - Abstraction: The client doesn't need to know the database location or credentials, only the tool definition.