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 testingdata/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:
initializehandshaketools/list- a sample SQL query result
- an interactive prompt to run more
SELECTqueries
Tools exposed
hr_metadata— returns the 3-line metadata header as a JSON objecthr_schema— returns the SQLite schema for tableemployeeshr_query— execute read-onlySELECT/WITHSQL querieshr_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.