# SQLite MCP to interact with your DB

### <https://github.com/modelcontextprotocol/servers/blob/main/src/sqlite/README.md>

### Query SQL with natural language

#### SQLite MCP server

1. Setup Demo DB with sqlite

* install VSCode/Cursosr extension [SQLite Viewer](https://marketplace.visualstudio.com/items?itemName=qwtel.sqlite-viewer)
* generate data

  * create file name `mcp_demo.db`
  * using python code to setup data

  ```python
      import sqlite3

      # Connect to SQLite database (or create it if it doesn't exist)
      conn = sqlite3.connect('mcp_demo.db')

      # Create a cursor object
      cursor = conn.cursor()

      # Create a table
      cursor.execute('''
      CREATE TABLE IF NOT EXISTS mcp_data (
          id INTEGER PRIMARY KEY AUTOINCREMENT,
          sensor_name TEXT NOT NULL,
          sensor_value REAL NOT NULL,
          timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
      )
      ''')

      # Insert sample data
      cursor.execute("INSERT INTO mcp_data (sensor_name, sensor_value) VALUES ('Temperature', 25.5)")
      cursor.execute("INSERT INTO mcp_data (sensor_name, sensor_value) VALUES ('Humidity', 60.0)")

      # Commit changes and close the connection
      conn.commit()
      conn.close()

      print("Database created and sample data inserted.")
  ```

  * setup MCP server with Cursor like:

  ```json
   "sqlite": {
    "command": "uv",
    "args": [
      "run",
      "mcp-server-sqlite",
      "--db-path",
      "/path/automation-test-ai/mcp_demo.db"
    ]

  ```

#### MCP-Database-server

* #### Code: <https://github.com/executeautomation/mcp-database-server>

{% embed url="<https://youtu.be/IRo2vtGAbbs?si=G4a-_b7VNT-_ftOp>" %}
