Relational DB Seeder MCP Server

Relational DB Seeder MCP Server

Enables LLMs to inspect database schemas and seed relational databases with custom data while automatically resolving foreign key relationships.

Category
访问服务器

README

Relational DB Seeder MCP Server

An intelligent, schema-aware, fully asynchronous Model Context Protocol (MCP) server that enables LLMs (like Claude) to inspect database structures and seed relational databases with custom, semantic data while preserving foreign key integrity in a single payload.

This is a developer tool designed to bridge the gap between AI reasoning and database populating. Instead of requiring the LLM to make multiple slow, sequential tool calls to resolve auto-generated IDs, the server parses constraints, sorts tables topologically, and maps generated IDs to foreign keys automatically.


🚀 Key Features

  • Multi-Database Support: Out-of-the-box support for both SQLite (local files) and PostgreSQL databases, configured on startup via environment variables.
  • Automatic Relative Path Resolution: Any relative SQLite path (e.g. sqlite:///employee.db) is automatically resolved relative to the server's project root directory, keeping database files in a predictable location regardless of where the client runs.
  • Relational Graph Insertion: Seeds complex tables with relationships in one batch. LLMs can reference parent rows using labels like ref:users:alice_temp and the engine automatically resolves them to real database-generated primary keys.
  • Fully Asynchronous: High-performance database operations powered by aiosqlite and the modern psycopg (v3) async library.
  • Schema Auto-Discovery: Queries database catalogs (information_schema and SQLite pragma lists) to dump tables, columns, constraints, and relationships for the LLM to reason about.
  • Credential Masking: Built-in security that automatically hides database passwords and user credentials in server logs and returned status states.

🛠️ Architecture

db_seeder/
├── adapters/
│   ├── __init__.py
│   ├── base.py           # Base connection interface using abc.ABC
│   ├── sqlite.py         # SQLite async adapter using aiosqlite
│   └── postgres.py       # PostgreSQL async adapter using psycopg
├── core/
│   ├── __init__.py
│   ├── graph.py          # Topological sort & cycle detector
│   └── seeder.py         # Relational graph insertion engine
└── tests/                # Unit & integration tests

📦 Installation & Setup

Ensure you have uv or standard Python 3.14+ installed.

1. Clone & Install Dependencies

git clone https://github.com/yourusername/DB_Seeder.git
cd DB_Seeder
uv sync

2. Run the MCP Server Locally

You can run the server in development mode using fastmcp:

uv run fastmcp dev server.py

3. Add to Claude Desktop Configuration

To connect this server to your Claude Desktop application, edit your claude_desktop_config.json:

  • MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

Add the server connection (defining the DATABASE_URL for your target SQLite or Postgres database):

{
  "mcpServers": {
    "db-seeder": {
      "command": "uv",
      "args": [
        "--directory",
        "/absolute/path/to/DB_Seeder",
        "run",
        "server.py"
      ],
      "env": {
        "DATABASE_URL": "sqlite:///employee.db"
      }
    }
  }
}

🔧 Expose Tools

The server registers the following asynchronous MCP tools with the client:

Tool Parameters When to Use Description
get_database_status None At the start of a session or when checking DB configuration. Returns active database type, table list, and connection details (credentials masked).
get_schema None Before writing queries or generating mock data payloads. Dumps all columns, types, nullability, primary keys, and foreign keys.
insert_graph payload Preferred tool for inserting records and database seeding. Inserts a relational dataset, mapping and resolving parent keys.
execute_query query For SELECT checks, DDL schemas (CREATE, ALTER), or updates. Runs arbitrary SQL statements on the connected database.

📊 Relational Graph Seeding Example

When seeding, the LLM agent sends a payload where parent tables have a __temp_id and child tables refer to them using the format ref:parent_table:temp_id.

Payload sent by LLM:

{
  "departments": [
    {
      "__temp_id": "d1",
      "dept_name": "Engineering"
    },
    {
      "__temp_id": "d2",
      "dept_name": "Sales"
    }
  ],
  "employees": [
    {
      "name": "Alice Smith",
      "email": "alice@company.com",
      "number": "555-1234",
      "salary": 85000,
      "dept_id": "ref:departments:d1"
    },
    {
      "name": "Bob Johnson",
      "email": "bob@company.com",
      "number": "555-5678",
      "salary": 72000,
      "dept_id": "ref:departments:d2"
    }
  ]
}

Seeder Execution Steps:

  1. Detects that employees depends on departments via the foreign key constraint on dept_id.
  2. Sorts the insertion order: departments first, then employees.
  3. Inserts departments, capturing their database-generated primary keys (e.g. Engineering -> 1, Sales -> 2).
  4. Replaces "ref:departments:d1" with 1 and "ref:departments:d2" with 2 in the employees payload.
  5. Inserts employees, guaranteeing that no foreign key constraint violations occur.

🧪 Testing

The project has robust unit and integration tests written using pytest and pytest-asyncio. Run them with:

PYTHONPATH=. uv run pytest

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选