DB MCP Server

Imports HR CSV data into an in-memory SQLite database for structured querying.

README.md

DB MCP (HR CSV → SQLite) — Open Source Reference

This folder contains a fully open-source Model Context Protocol (MCP) server implementation that:

  • Loads an HR “people” CSV file
  • Reads 3 lines of metadata at the top of the CSV (comment lines starting with #)
  • Imports the CSV into an in-memory SQLite database
  • Exposes read-only MCP tools over stdio (newline-delimited JSON-RPC 2.0)

No Claude Desktop setup is required. A small Python client is included for testing.

Files

  • db_mcp_server.py — MCP server (stdio)
  • db_mcp_client.py — simple MCP stdio client for testing
  • data/hr_people.csv — sample HR CSV with 3-line metadata header

Run the server

python db_mcp_server.py

Optionally pass a custom CSV path:

python db_mcp_server.py /path/to/your/hr_people.csv

Or set an environment variable:

HR_CSV_PATH=/path/to/your/hr_people.csv python db_mcp_server.py

Test with the included client (recommended)

python db_mcp_client.py

You should see:

  • initialize handshake
  • tools/list
  • a sample SQL query result
  • an interactive prompt to run more SELECT queries

Tools exposed

  • hr_metadata — returns the 3-line metadata header as a JSON object
  • hr_schema — returns the SQLite schema for table employees
  • hr_query — execute read-only SELECT/WITH SQL queries
  • hr_find_people — structured search without writing SQL

CSV metadata format (first 3 lines)

Example:

# dataset: HR People
# description: Synthetic employee roster for MCP demo (no real PII)
# primary_key: employee_id
employee_id,first_name,last_name,...

Metadata lines are parsed as key: value. If a line is not key: value, it is stored as meta_line_1, meta_line_2, etc.

Notes for sharing

  • Everything here is standard-library Python (SQLite + CSV).
  • The demo data is synthetic (no real PII).
  • The server writes only JSON-RPC to stdout. Logs go to stderr (safe for stdio MCP).

Samples

-Terminal 1

C:\Users\davidzhang\Downloads\ml\ml\db_mcp_1>python mcp_server.py data/hr_people.csv
[db_mcp_server] Ready. Loaded data/hr_people.csv. Tools: 4

-Terminal 2
 C:\Users\davidzhang\Downloads\ml\ml\db_mcp_1>python client.py --csv ./data/hr_people.csv
[db_mcp_server] Ready. Loaded ./data/hr_people.csv. Tools: 4
[db_mcp_server] Internal error:
Traceback (most recent call last):
  File "C:\Users\davidzhang\Downloads\ml\ml\db_mcp_1\db_mcp_server.py", line 537, in main
    server.handle(msg)
  File "C:\Users\davidzhang\Downloads\ml\ml\db_mcp_1\db_mcp_server.py", line 493, in handle
    self.handle_initialize(id_value, params)
  File "C:\Users\davidzhang\Downloads\ml\ml\db_mcp_1\db_mcp_server.py", line 438, in handle_initialize
Initialize response:
{
  "jsonrpc": "2.0",
  "error": {
    "code": -32603,
    "message": "Internal error"
  },
  "id": 1
}
    _send(resp)

Tools:
  File "C:\Users\davidzhang\Downloads\ml\ml\db_mcp_1\db_mcp_server.py", line 45, in _send
{
  "jsonrpc": "2.0",
  "id": 2,
  "result": {
    "tools": [
      {
        "name": "hr_metadata",
        "title": "HR dataset metadata",
        "description": "Return the 3-line metadata header read from the HR CSV file.",
        "inputSchema": {
          "type": "object",
          "additionalProperties": false
        },
        "outputSchema": {
          "type": "object"
        }
      },
      {
        "name": "hr_schema",
        "title": "HR table schema",
        "description": "Return SQLite schema information for the employees table.",
        "inputSchema": {
          "type": "object",
          "additionalProperties": false
        },
        "outputSchema": {
          "type": "object"
        }
      },
      {
        "name": "hr_query",
        "title": "Run a read-only SQL query",
        "description": "Execute a read-only SQL query (SELECT/WITH only) against the in-memory SQLite database.\nTable name: employees\nExample: SELECT department, COUNT(*) AS n FROM employees GROUP BY department",
        "inputSchema": {
          "type": "object",
          "properties": {
            "sql": {
              "type": "string",
              "description": "A SELECT/WITH SQL query to run."
            },
            "limit": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "description": "Optional row limit (wraps the query)."
            }
          },
          "required": [
            "sql"
          ],
          "additionalProperties": false
        },
        "outputSchema": {
          "type": "object",
          "properties": {
            "rowCount": {
              "type": "integer"
            },
            "rows": {
              "type": "array",
              "items": {
                "type": "object"
              }
            }
          },
          "required": [
            "rowCount",
            "rows"
          ]
        }
      },
      {
        "name": "hr_find

Tools 4

hr_metadataReturn the 3-line metadata header read from the HR CSV file.
hr_schemaReturn SQLite schema information for the employees table.
hr_queryExecute a read-only SQL query (SELECT/WITH only) against the in-memory SQLite database.
hr_find_peoplePerform a structured search on employee data without writing SQL.

Environment Variables

HR_CSV_PATHPath to the HR CSV file to be loaded into the database.

Try it

What is the metadata for the current HR dataset?
Show me the schema for the employees table.
Run a query to count how many employees are in each department.
Find all employees with the last name Smith.

Frequently Asked Questions

What are the key features of DB MCP?

Loads HR CSV files into an in-memory SQLite database. Parses 3-line metadata headers from CSV files. Exposes read-only SQL query capabilities. Provides structured search tools for employee data. Uses standard-library Python with no external dependencies.

What can I use DB MCP for?

Querying synthetic HR rosters for data analysis. Performing structured searches on employee records via natural language. Validating CSV data structures using SQL schemas. Integrating HR dataset metadata into AI-assisted workflows.

How do I install DB MCP?

Install DB MCP by running: python db_mcp_server.py

What MCP clients work with DB MCP?

DB MCP works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Turn this server into reusable context

Keep DB MCP docs, env vars, and workflow notes in Conare so your agent carries them across sessions.

Open Conare