DB MCP (HR CSV to SQLite)

DB MCP (HR CSV to SQLite)

An open-source MCP server that imports HR CSV data into an in-memory SQLite database for structured querying and metadata retrieval. It enables users to perform read-only SQL queries and structured searches on employee data through natural language.

Category
访问服务器

README

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_people",
        "title": "Find employees (structured filters)",
        "description": "Find employees by common HR filters without writing SQL.",
        "inputSchema": {
          "type": "object",
          "properties": {
            "name_contains": {
              "type": "string",
              "description": "Substring match against first or last name (case-insensitive)."
            },
            "department": {
              "type": "string"
            },
            "title": {
              "type": "string"
            },
            "location": {
              "type": "string"
            },
            "min_salary": {
              "type": "number"
            },
            "max_salary": {
              "type": "number"
            },
            "hired_after": {
              "type": "string",
              "description": "YYYY-MM-DD"
            },
            "hired_before": {
              "type": "string",
              "description": "YYYY-MM-DD"
            },
            "limit": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 25
            }
          },
          "additionalProperties": false
        },
        "outputSchema": {
          "type": "object",
          "properties": {
            "rowCount": {
              "type": "integer"
            },
            "rows": {
              "type": "array",
              "items": {
                "type": "object"
              }
            },
            "appliedFilters": {
              "type": "object"
            }
          },
          "required": [
            "rowCount",
            "rows",
            "appliedFilters"
          ]
        }
      }
  }
}

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选