Skip to content

This is a LLM application that integrates with a MySQL database via an MCP Database Server. In this example, it is configured for a hospital use case, but you can adapt it for your own domain such as retail, education, finance, or any other database-driven chatbot by changing the system prompt, database schema.

Notifications You must be signed in to change notification settings

shilok09/langGraph-sql-assistant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Alt text

LangGraph SQL Assistant

CareDesk is an AI-powered hospital receptionist application that integrates with a MySQL database via an MCP Database Server. In this example, it is configured for a hospital use case, but you can adapt it for your own domain such as retail, education, finance, or any other database-driven chatbot — by changing the system prompt, database schema, and tools configuration.

  • Main entrypoint: agent.py
  • Dependencies: requirements.txt
  • System prompt: files in prompts/ (e.g., hospital_receptionist.txt) you can edit it for you
  • MCP DB server: Node.js project providing tools via stdio transport

Requirements

  • Python 3.10+
  • Node.js 18+
  • MySQL 8+ (or a compatible MySQL server)

Python dependencies

Install from requirements.txt:

pip install -r requirements.txt

Current pinned packages (see requirements.txt):

  • python-dotenv
  • pydantic
  • langchain, langchain-openai, langchain-core
  • langgraph
  • langchain-mcp-adapters
  • python-multipart
  • rich

Environment configuration

Create a .env file in the project root. The agent expects:

# GitHub Models (used in agent.py)
GITHUB_TOKEN=ghp_your_github_token_here 

# Optional: override DB defaults
DB_HOST=localhost
DB_NAME=hospital
DB_PORT=3306
DB_USER=root
DB_PASSWORD=your_mysql_password

Notes:

  • agent.py maps GITHUB_TOKEN to OPENAI_API_KEY and sets OPENAI_API_BASE=https://models.github.ai/inference to use GitHub Models.
  • If you prefer a different OpenAI-compatible provider, adjust those envs in agent.py accordingly.

Prompts

Place role/system prompts under prompts/. In this example, it is configured for a hospital use case using the hospital_receptionist.txt system prompt, but you can replace it with your own role prompt for any domain such as retail, education, finance, or other database-driven chatbots.

  • Default used: prompts/hospital_receptionist.txt
  • If missing, agent.py falls back to a built-in system prompt.

MCP Database Server (MySQL)

agent.py launches a local MCP server over stdio. The code expects the built server at:

<mrepo>/mcp-database-server/dist/src/index.js

If you don’t have it yet, download and build it as follows (then place/rename the folder to mcp-database-server in the project root):

  1. Clone the repository:
    git clone https://github.com/executeautomation/mcp-database-server.git
    cd database-server
  2. Install dependencies:
    npm install
  3. Build the project:
    npm run build

After building, ensure the folder name under this project root is exactly mcp-database-server so the path in agent.py resolves:

customerSupport/
├─ agent.py
├─ mcp-database-server/
│  └─ dist/src/index.js
└─ prompts/

If your cloned folder is named differently (e.g., database-server), either rename it to mcp-database-server or update the path in agent.py where mcp_server_path is set.

MySQL preparation

Ensure your MySQL instance is reachable and the credentials in .env are valid. The default database name is hospital. Seed your schema/data as appropriate for your use case.

Run the agent

From the project root:

python agent.py

You’ll see a welcome panel and a list of available MCP database tools on successful connection. Try queries like:

  • "List tables"
  • "Describe table patients"
  • "Show doctors"

Type exit to quit.

Troubleshooting

  • "Failed to get MCP tools":
    • Verify Node.js is installed and the server path exists at mcp-database-server/dist/src/index.js.
    • Make sure you ran npm install && npm run build inside the MCP server folder.
  • Authentication errors with model:
    • Ensure .env contains a valid GITHUB_TOKEN and your network allows access to https://models.github.ai/inference.
  • DB connection errors:
    • Confirm DB_HOST, DB_NAME, DB_PORT, DB_USER, DB_PASSWORD are correct and the database is reachable.

File references

  • Agent: agent.py
  • Requirements: requirements.txt
  • Prompts directory: prompts/ (e.g., prompts/hospital_receptionist.txt)

About

This is a LLM application that integrates with a MySQL database via an MCP Database Server. In this example, it is configured for a hospital use case, but you can adapt it for your own domain such as retail, education, finance, or any other database-driven chatbot by changing the system prompt, database schema.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages