DB MCP (HR CSV to SQLite) 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).

##How to run

Server (auto-builds index if missing)

python mcp_server.py

Test client

python client.py (interactive mode)

python client.py --search "diabetes treatment" --top-k 5

#add more documentation files:

Drop .txt or .md files into ./docs/

Rebuild:

python build_doc_index.py --docs_dir ./docs --out_map ./doc_map.json --out_db ./doc_i

#run sample

--terminal 1
 C:\Users\davidzhang\Downloads\ml\ml\doc_mcp_1>python mcp_server.py
[doc_mcp_server] Loaded 1 docs. FTS5=yes
[doc_mcp_server] Ready.

--terminal 2
 C:\Users\davidzhang\Downloads\ml\ml\doc_mcp_1>python client.py --search "diabetes treatment" --top-k 5
[doc_mcp_server] Loaded 1 docs. FTS5=yes
[doc_mcp_server] Ready.
{
  "jsonrpc": "2.0",
  "id": 2,
  "result": {
    "content": [
      {
        "type": "text",
        "text": "{\n  \"query\": \"diabetes treatment\",\n  \"top_k\": 5,\n  \"matches\": [\n    {\n      \"doc_id\": \"cdc-diabetes-treatment-guidelines\",\n      \"title\": \"CDC DIABETES COMPLICATION RISK MANAGEMENT GUIDELINES\",\n      \"chunk_id\": 3,\n      \"score\": 3.3014800093648174e-06,\n      \"snippet\": \"…Type 2 [diabetes] with circulatory complications\\n- I50.9: Heart failure (if present)\\n\\n### 3.2 Aggressive [Treatment]…\",\n      \"text\": \"itoring (CGM)\\n- Kidney function testing: Every 6 months\\n- Eye examination: Every 6-12 months\\n\\n### 2.5 Enhanced Interventions\\n- Referral to certified diabetes care and education specialist\\n- Quarterly nutritionist consultations\\n- Structured exercise program\\n- Cardiovascular risk assessment\\n- Sleep apnea screening if indicated\\n- Depression and diabetes distress screening\\n\\n### 2.6 Complication Screening\\nBiannual assessments:\\n- Comprehensive foot examination\\n- Monofilament testing for neuropathy\\n- Ankle-brachial index if claudication symptoms\\n- Retinal photography or dilated eye exam\\n\\n---\\n\\n## Section 3: HIGH RISK PATIENTS (60-80% Complication Probability)\\n\\n### 3.1 ICD-10-CM Coding\\nPrimary codes:\\n- E11.65: Type 2 diabetes with hyperglycemia\\n- E11.69: Type 2 diabetes with other specified complication\\n- E11.8: Type 2 diabetes with unspecified complications\\n\\nComplication-specific codes as identified:\\n- E11.21: Type 2 diabetes with diabetic nephropathy\\n- E11.311-319: Type 2 diabetes with diabetic retinopathy\\n- E11.40-49: Type 2 diabetes with diabetic neuropathy\\n- E11.51-59: Type 2 diabetes with circulatory complications\\n- I50.9: Heart failure (if present)\\n\\n### 3.2 Aggressive Treatment Goals\"\n    },\n    {\n      \"doc_id\": \"cdc-diabetes-treatment-guidelines\",\n      \"title\": \"CDC DIABETES COMPLICATION RISK MANAGEMENT GUIDELINES\",\n      \"chunk_id\": 15,\n      \"score\": 3.258944413339537e-06,\n      \"snippet\": \"ational [Diabetes] Statistics Report (2023)\\n- Endocrine Society Clinical Practice Guidelines\\n- AACE/ACE Comprehensive Type 2 [Diabetes]…\",\n      \"text\": \"ational Diabetes Statistics Report (2023)\\n- Endocri

Tools 4

hr_metadataReturns the 3-line metadata header from the CSV as a JSON object.
hr_schemaReturns the SQLite schema for the employees table.
hr_queryExecutes read-only SELECT or WITH SQL queries against the HR data.
hr_find_peoplePerforms a structured search for employee records without writing SQL.

Environment Variables

HR_CSV_PATHPath to the HR CSV file to be imported into the SQLite database.

Try it

What is the metadata associated with the current HR dataset?
Show me the database schema for the employee records.
Find all employees with the last name 'Smith' using the search tool.
Run a SQL query to count how many employees are in the database.
List the first 5 employees from the database using a SELECT query.

Frequently Asked Questions

What are the key features of DB MCP (HR CSV to SQLite)?

Loads HR CSV files into an in-memory SQLite database. Parses 3-line metadata headers from CSV files. Exposes read-only SQL query capabilities via MCP. Provides structured search tools for employee records. Uses standard-library Python for lightweight deployment.

What can I use DB MCP (HR CSV to SQLite) for?

Querying synthetic HR rosters for data analysis tasks. Integrating CSV-based employee data into LLM workflows. Performing structured lookups on HR datasets without manual file parsing. Testing SQL-based data retrieval patterns within an MCP environment.

How do I install DB MCP (HR CSV to SQLite)?

Install DB MCP (HR CSV to SQLite) by running: python db_mcp_server.py

What MCP clients work with DB MCP (HR CSV to SQLite)?

DB MCP (HR CSV to SQLite) 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 (HR CSV to SQLite) docs, env vars, and workflow notes in Conare so your agent carries them across sessions.

Open Conare