sqlseed 0.1.18__tar.gz → 0.1.19__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. {sqlseed-0.1.18 → sqlseed-0.1.19}/CHANGELOG.md +18 -0
  2. {sqlseed-0.1.18 → sqlseed-0.1.19}/CHANGELOG.zh-CN.md +18 -0
  3. {sqlseed-0.1.18 → sqlseed-0.1.19}/PKG-INFO +7 -4
  4. {sqlseed-0.1.18 → sqlseed-0.1.19}/pyproject.toml +5 -3
  5. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/core/mapper.py +20 -0
  6. sqlseed-0.1.18/plugins/mcp-server-sqlseed/README.md +0 -77
  7. sqlseed-0.1.18/plugins/mcp-server-sqlseed/README.zh-CN.md +0 -77
  8. sqlseed-0.1.18/plugins/mcp-server-sqlseed/pyproject.toml +0 -47
  9. sqlseed-0.1.18/plugins/mcp-server-sqlseed/src/mcp_server_sqlseed/__init__.py +0 -7
  10. sqlseed-0.1.18/plugins/mcp-server-sqlseed/src/mcp_server_sqlseed/__main__.py +0 -6
  11. sqlseed-0.1.18/plugins/mcp-server-sqlseed/src/mcp_server_sqlseed/config.py +0 -9
  12. sqlseed-0.1.18/plugins/mcp-server-sqlseed/src/mcp_server_sqlseed/server.py +0 -190
  13. sqlseed-0.1.18/plugins/mcp-server-sqlseed/uv.lock +0 -1165
  14. sqlseed-0.1.18/plugins/sqlseed-ai/README.md +0 -109
  15. sqlseed-0.1.18/plugins/sqlseed-ai/README.zh-CN.md +0 -109
  16. sqlseed-0.1.18/plugins/sqlseed-ai/pyproject.toml +0 -44
  17. sqlseed-0.1.18/plugins/sqlseed-ai/src/sqlseed_ai/__init__.py +0 -77
  18. sqlseed-0.1.18/plugins/sqlseed-ai/src/sqlseed_ai/_client.py +0 -24
  19. sqlseed-0.1.18/plugins/sqlseed-ai/src/sqlseed_ai/_json_utils.py +0 -38
  20. sqlseed-0.1.18/plugins/sqlseed-ai/src/sqlseed_ai/_model_selector.py +0 -111
  21. sqlseed-0.1.18/plugins/sqlseed-ai/src/sqlseed_ai/analyzer.py +0 -353
  22. sqlseed-0.1.18/plugins/sqlseed-ai/src/sqlseed_ai/config.py +0 -55
  23. sqlseed-0.1.18/plugins/sqlseed-ai/src/sqlseed_ai/errors.py +0 -151
  24. sqlseed-0.1.18/plugins/sqlseed-ai/src/sqlseed_ai/examples.py +0 -183
  25. sqlseed-0.1.18/plugins/sqlseed-ai/src/sqlseed_ai/provider.py +0 -63
  26. sqlseed-0.1.18/plugins/sqlseed-ai/src/sqlseed_ai/refiner.py +0 -292
  27. sqlseed-0.1.18/plugins/sqlseed-ai/uv.lock +0 -677
  28. sqlseed-0.1.18/src/sqlseed/plugins/__init__.py +0 -12
  29. sqlseed-0.1.18/src/sqlseed/plugins/hookspecs.py +0 -119
  30. sqlseed-0.1.18/src/sqlseed/plugins/manager.py +0 -37
  31. {sqlseed-0.1.18 → sqlseed-0.1.19}/.gitignore +0 -0
  32. {sqlseed-0.1.18 → sqlseed-0.1.19}/LICENSE +0 -0
  33. {sqlseed-0.1.18 → sqlseed-0.1.19}/README.md +0 -0
  34. {sqlseed-0.1.18 → sqlseed-0.1.19}/README.zh-CN.md +0 -0
  35. {sqlseed-0.1.18 → sqlseed-0.1.19}/examples/build_demo_db.py +0 -0
  36. {sqlseed-0.1.18 → sqlseed-0.1.19}/examples/notebooks/01-quickstart.ipynb +0 -0
  37. {sqlseed-0.1.18 → sqlseed-0.1.19}/examples/notebooks/02-column-mapping.ipynb +0 -0
  38. {sqlseed-0.1.18 → sqlseed-0.1.19}/examples/notebooks/03-generators.ipynb +0 -0
  39. {sqlseed-0.1.18 → sqlseed-0.1.19}/examples/notebooks/04-database-advanced.ipynb +0 -0
  40. {sqlseed-0.1.18 → sqlseed-0.1.19}/examples/notebooks/05-dag-and-constraints.ipynb +0 -0
  41. {sqlseed-0.1.18 → sqlseed-0.1.19}/examples/notebooks/06-config-deep-dive.ipynb +0 -0
  42. {sqlseed-0.1.18 → sqlseed-0.1.19}/examples/notebooks/07-ai-plugin.ipynb +0 -0
  43. {sqlseed-0.1.18 → sqlseed-0.1.19}/examples/notebooks/08-mcp-server.ipynb +0 -0
  44. {sqlseed-0.1.18 → sqlseed-0.1.19}/examples/notebooks/09-plugin-hooks.ipynb +0 -0
  45. {sqlseed-0.1.18 → sqlseed-0.1.19}/examples/notebooks/10-cli-reference.ipynb +0 -0
  46. {sqlseed-0.1.18 → sqlseed-0.1.19}/examples/notebooks/11-utilities.ipynb +0 -0
  47. {sqlseed-0.1.18 → sqlseed-0.1.19}/examples/notebooks/12-testing-patterns.ipynb +0 -0
  48. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/__init__.py +0 -0
  49. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/_utils/__init__.py +0 -0
  50. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/_utils/logger.py +0 -0
  51. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/_utils/metrics.py +0 -0
  52. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/_utils/paths.py +0 -0
  53. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/_utils/progress.py +0 -0
  54. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/_utils/schema_helpers.py +0 -0
  55. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/_utils/sql_safe.py +0 -0
  56. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/_version.py +0 -0
  57. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/cli/__init__.py +0 -0
  58. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/cli/main.py +0 -0
  59. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/config/__init__.py +0 -0
  60. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/config/loader.py +0 -0
  61. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/config/models.py +0 -0
  62. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/config/snapshot.py +0 -0
  63. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/core/__init__.py +0 -0
  64. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/core/column_dag.py +0 -0
  65. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/core/constraints.py +0 -0
  66. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/core/enrichment.py +0 -0
  67. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/core/expression.py +0 -0
  68. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/core/orchestrator.py +0 -0
  69. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/core/plugin_mediator.py +0 -0
  70. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/core/relation.py +0 -0
  71. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/core/result.py +0 -0
  72. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/core/schema.py +0 -0
  73. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/core/transform.py +0 -0
  74. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/core/unique_adjuster.py +0 -0
  75. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/database/__init__.py +0 -0
  76. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/database/_base_adapter.py +0 -0
  77. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/database/_compat.py +0 -0
  78. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/database/_helpers.py +0 -0
  79. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/database/_protocol.py +0 -0
  80. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/database/optimizer.py +0 -0
  81. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/database/raw_sqlite_adapter.py +0 -0
  82. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/database/sqlite_utils_adapter.py +0 -0
  83. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/generators/__init__.py +0 -0
  84. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/generators/_dispatch.py +0 -0
  85. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/generators/_json_helpers.py +0 -0
  86. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/generators/_protocol.py +0 -0
  87. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/generators/_string_helpers.py +0 -0
  88. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/generators/base_provider.py +0 -0
  89. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/generators/faker_provider.py +0 -0
  90. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/generators/mimesis_provider.py +0 -0
  91. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/generators/registry.py +0 -0
  92. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/generators/stream.py +0 -0
  93. {sqlseed-0.1.18 → sqlseed-0.1.19}/src/sqlseed/py.typed +0 -0
  94. {sqlseed-0.1.18 → sqlseed-0.1.19}/uv.lock +0 -0
@@ -7,6 +7,24 @@ All notable changes to this project will be documented in this file.
7
7
  Format based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
8
8
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
9
9
 
10
+ ## [v0.1.19]
11
+
12
+ ### Added
13
+
14
+ - Column mapper `_to_snake_case()` normalization: camelCase/PascalCase/Hungarian column names (`sOrderNo`, `sItemNo`, `userName`, `isActive`) now auto-resolve via snake-case fallback after direct matching
15
+ - Sensitive identifier pattern rule: `user_no`, `card_no`, `card_number`, `identity_no` (and Hungarian variants `sUserNo`, `sCardNo`) map to masked string output instead of `foreign_key_or_integer`, preventing real values from leaking through FK resolution
16
+ - `tests/test_mapper_camelcase.py` — 23 test cases covering camelCase mapping, sensitive field desensitization, and `_to_snake_case()` helper
17
+
18
+ ### Changed
19
+
20
+ - `pyproject.toml`: moved `sqlite-utils` from required to optional dependency (matches `HAS_SQLITE_UTILS` fallback logic)
21
+ - `pyproject.toml`: renamed `notebook` optional dep group to `tqdm` for clarity
22
+ - `pyproject.toml`: restored `plugins/` to sdist exclude; added sdist exclude configs to plugin `pyproject.toml` files
23
+
24
+ ### Fixed
25
+
26
+ - `test_fill_with_snapshot` now sets `SQLSEED_CACHE_DIR` to `tmp_path` via `monkeypatch.setenv`, fixing `PermissionError` when default cache directory is not writable
27
+
10
28
  ## [v0.1.17]
11
29
 
12
30
  ### Added
@@ -7,6 +7,24 @@
7
7
  格式基于 [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
8
8
  本项目遵循[语义化版本](https://semver.org/spec/v2.0.0.html)。
9
9
 
10
+ ## [v0.1.19]
11
+
12
+ ### 新增
13
+
14
+ - 列映射器 `_to_snake_case()` 规范化:camelCase/PascalCase/Hungarian 列名(`sOrderNo`、`sItemNo`、`userName`、`isActive`)在直接匹配失败后自动通过 snake_case 回退解析
15
+ - 敏感标识符模式规则:`user_no`、`card_no`、`card_number`、`identity_no`(及 Hungarian 变体 `sUserNo`、`sCardNo`)映射为脱敏字符串,防止真实值通过 FK 解析或 SharedPool 泄露
16
+ - `tests/test_mapper_camelcase.py` — 23 个测试用例,覆盖 camelCase 映射、敏感字段脱敏和 `_to_snake_case()` 辅助函数
17
+
18
+ ### 变更
19
+
20
+ - `pyproject.toml`:`sqlite-utils` 从必需依赖移至可选依赖(与 `HAS_SQLITE_UTILS` 回退逻辑一致)
21
+ - `pyproject.toml`:可选依赖组 `notebook` 重命名为 `tqdm`
22
+ - `pyproject.toml`:恢复 `plugins/` 到 sdist 排除列表;插件 `pyproject.toml` 新增 sdist 排除配置
23
+
24
+ ### 修复
25
+
26
+ - `test_fill_with_snapshot` 通过 `monkeypatch.setenv` 将 `SQLSEED_CACHE_DIR` 设置为 `tmp_path`,修复默认缓存目录无写入权限时的 `PermissionError`
27
+
10
28
  ## [v0.1.17]
11
29
 
12
30
  ### 新增
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlseed
3
- Version: 0.1.18
3
+ Version: 0.1.19
4
4
  Summary: Declarative SQLite test data generation toolkit
5
5
  Project-URL: Homepage, https://github.com/sunbos/sqlseed
6
6
  Project-URL: Documentation, https://github.com/sunbos/sqlseed#readme
@@ -28,12 +28,12 @@ Requires-Dist: pyyaml>=6.0
28
28
  Requires-Dist: rich>=13.0
29
29
  Requires-Dist: rstr>=3.2
30
30
  Requires-Dist: simpleeval>=1.0
31
- Requires-Dist: sqlite-utils>=3.36
32
31
  Requires-Dist: structlog>=24.0
33
32
  Requires-Dist: typing-extensions>=4.4
34
33
  Provides-Extra: all
35
34
  Requires-Dist: faker>=30.0; extra == 'all'
36
35
  Requires-Dist: mimesis>=18.0; extra == 'all'
36
+ Requires-Dist: sqlite-utils>=3.36; extra == 'all'
37
37
  Requires-Dist: tqdm>=4.66; extra == 'all'
38
38
  Provides-Extra: dev
39
39
  Requires-Dist: mypy>=1.10; extra == 'dev'
@@ -43,6 +43,7 @@ Requires-Dist: pytest-benchmark>=4.0; extra == 'dev'
43
43
  Requires-Dist: pytest-cov>=5.0; extra == 'dev'
44
44
  Requires-Dist: pytest>=8.0; extra == 'dev'
45
45
  Requires-Dist: ruff>=0.5; extra == 'dev'
46
+ Requires-Dist: sqlite-utils>=3.36; extra == 'dev'
46
47
  Requires-Dist: tqdm>=4.66; extra == 'dev'
47
48
  Provides-Extra: docs
48
49
  Requires-Dist: mkdocs-material>=9.0; extra == 'docs'
@@ -51,8 +52,10 @@ Provides-Extra: faker
51
52
  Requires-Dist: faker>=30.0; extra == 'faker'
52
53
  Provides-Extra: mimesis
53
54
  Requires-Dist: mimesis>=18.0; extra == 'mimesis'
54
- Provides-Extra: notebook
55
- Requires-Dist: tqdm>=4.66; extra == 'notebook'
55
+ Provides-Extra: sqlite-utils
56
+ Requires-Dist: sqlite-utils>=3.36; extra == 'sqlite-utils'
57
+ Provides-Extra: tqdm
58
+ Requires-Dist: tqdm>=4.66; extra == 'tqdm'
56
59
  Description-Content-Type: text/markdown
57
60
 
58
61
  <div align="center">
@@ -27,7 +27,6 @@ classifiers = [
27
27
  ]
28
28
 
29
29
  dependencies = [
30
- "sqlite-utils>=3.36",
31
30
  "pydantic>=2.0",
32
31
  "pluggy>=1.3",
33
32
  "structlog>=24.0",
@@ -46,11 +45,13 @@ Repository = "https://github.com/sunbos/sqlseed"
46
45
  Issues = "https://github.com/sunbos/sqlseed/issues"
47
46
 
48
47
  [project.optional-dependencies]
48
+ sqlite-utils = ["sqlite-utils>=3.36"]
49
49
  faker = ["faker>=30.0"]
50
50
  mimesis = ["mimesis>=18.0"]
51
- notebook = ["tqdm>=4.66"]
52
- all = ["faker>=30.0", "mimesis>=18.0", "tqdm>=4.66"]
51
+ tqdm = ["tqdm>=4.66"]
52
+ all = ["sqlite-utils>=3.36", "faker>=30.0", "mimesis>=18.0", "tqdm>=4.66"]
53
53
  dev = [
54
+ "sqlite-utils>=3.36",
54
55
  "pytest>=8.0",
55
56
  "pytest-cov>=5.0",
56
57
  "pytest-asyncio>=0.24",
@@ -83,6 +84,7 @@ packages = ["src/sqlseed"]
83
84
  exclude = [
84
85
  "docs/",
85
86
  "tests/",
87
+ "plugins/",
86
88
  ".github/",
87
89
  ".trae/",
88
90
  ".gemini/",
@@ -130,6 +130,11 @@ class ColumnMapper:
130
130
  PATTERN_MATCH_RULES: ClassVar[list[tuple[str, str, dict[str, Any]]]] = [
131
131
  (r"^id$", "autoincrement", {}),
132
132
  (r".*_id$", "foreign_key_or_integer", {}),
133
+ (
134
+ r".*(?:user|card|identity)(?:_no|_number|_nbr)$",
135
+ "string",
136
+ {"min_length": 8, "max_length": 20, "charset": "alphanumeric"},
137
+ ),
133
138
  (r".*_no$|.*_nbr$", "foreign_key_or_integer", {}),
134
139
  (r".*_ids$", "json", {}),
135
140
  (r".*_at$", "datetime", {}),
@@ -255,6 +260,12 @@ class ColumnMapper:
255
260
  return GeneratorSpec(generator_name="skip")
256
261
  return None
257
262
 
263
+ _CAMELCASE_RE: ClassVar[re.Pattern[str]] = re.compile(r"(?<=[a-z0-9])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])")
264
+
265
+ @classmethod
266
+ def _to_snake_case(cls, name: str) -> str:
267
+ return cls._CAMELCASE_RE.sub("_", name).lower()
268
+
258
269
  def map_column(
259
270
  self,
260
271
  column_info: ColumnInfo,
@@ -287,6 +298,15 @@ class ColumnMapper:
287
298
  if pattern_match:
288
299
  return pattern_match
289
300
 
301
+ snake_name = self._to_snake_case(column_info.name)
302
+ if snake_name != column_name:
303
+ snake_exact = self._match_exact(snake_name)
304
+ if snake_exact:
305
+ return snake_exact
306
+ snake_pattern = self._match_pattern(snake_name)
307
+ if snake_pattern:
308
+ return snake_pattern
309
+
290
310
  fallback_spec = self._map_from_default_or_nullable(column_info, column_type, enrich, force_type_infer)
291
311
  if fallback_spec:
292
312
  return fallback_spec
@@ -1,77 +0,0 @@
1
- # mcp-server-sqlseed
2
-
3
- **[English](README.md)** | [中文](README.zh-CN.md)
4
-
5
- [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) server for [sqlseed](https://github.com/sunbos/sqlseed) — enabling AI assistants to inspect schemas, generate configs, and fill SQLite databases.
6
-
7
- ## Installation
8
-
9
- ```bash
10
- # Basic
11
- pip install mcp-server-sqlseed
12
-
13
- # With AI support (includes sqlseed-ai)
14
- pip install mcp-server-sqlseed[ai]
15
- ```
16
-
17
- ## Configuration
18
-
19
- ### Claude Desktop
20
-
21
- Add to `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or equivalent:
22
-
23
- ```json
24
- {
25
- "mcpServers": {
26
- "sqlseed": {
27
- "command": "mcp-server-sqlseed"
28
- }
29
- }
30
- }
31
- ```
32
-
33
- ### Cursor / Other MCP Clients
34
-
35
- Use command: `mcp-server-sqlseed`
36
-
37
- ## MCP Tools
38
-
39
- | Tool | Description |
40
- |:-----|:------------|
41
- | `sqlseed_inspect_schema` | Inspect database schema: columns, foreign keys, indexes, sample data, schema_hash. Accepts optional `table_name` (all tables if omitted). |
42
- | `sqlseed_generate_yaml` | AI-driven YAML config generation with self-correction. Requires `sqlseed-ai` plugin and API key. Supports `api_key`/`base_url`/`model` parameter overrides. |
43
- | `sqlseed_execute_fill` | Execute data generation. Accepts optional `yaml_config` string, `count`, and `enrich` flag. Max YAML config size: 256KB. |
44
-
45
- ### MCP Resource
46
-
47
- | Resource | Description |
48
- |:---------|:------------|
49
- | `sqlseed://schema/{db_path}/{table_name}` | Read-only JSON schema for a specific table |
50
-
51
- ## Example Usage
52
-
53
- After configuring your MCP client, you can prompt:
54
-
55
- > "Inspect the schema of `app.db`, generate a YAML config for the `users` table, then fill 1000 rows."
56
-
57
- The AI assistant will call:
58
- 1. `sqlseed_inspect_schema` → get table structure
59
- 2. `sqlseed_generate_yaml` → generate YAML config (if sqlseed-ai is installed)
60
- 3. `sqlseed_execute_fill` → fill data
61
-
62
- ## AI Integration
63
-
64
- When `sqlseed-ai` is installed and an API key is configured (`SQLSEED_AI_API_KEY` or `OPENAI_API_KEY`), the `sqlseed_generate_yaml` tool uses LLM-driven analysis with self-correction. Without the AI plugin, the tool returns a fallback message.
65
-
66
- ## Requirements
67
-
68
- - Python >= 3.10
69
- - `sqlseed >= 0.1.0`
70
- - `mcp >= 1.0`
71
-
72
- Optional:
73
- - `sqlseed-ai` (for `sqlseed_generate_yaml` tool)
74
-
75
- ## License
76
-
77
- AGPL-3.0-or-later
@@ -1,77 +0,0 @@
1
- # mcp-server-sqlseed
2
-
3
- [English](README.md) | **[中文](README.zh-CN.md)**
4
-
5
- [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) 服务器,用于 [sqlseed](https://github.com/sunbos/sqlseed) — 让 AI 助手直接检查 Schema、生成配置和填充 SQLite 数据库。
6
-
7
- ## 安装
8
-
9
- ```bash
10
- # 基础安装
11
- pip install mcp-server-sqlseed
12
-
13
- # 含 AI 支持(包含 sqlseed-ai)
14
- pip install mcp-server-sqlseed[ai]
15
- ```
16
-
17
- ## 配置
18
-
19
- ### Claude Desktop
20
-
21
- 添加到 `~/Library/Application Support/Claude/claude_desktop_config.json`(macOS):
22
-
23
- ```json
24
- {
25
- "mcpServers": {
26
- "sqlseed": {
27
- "command": "mcp-server-sqlseed"
28
- }
29
- }
30
- }
31
- ```
32
-
33
- ### Cursor / 其他 MCP 客户端
34
-
35
- 使用命令:`mcp-server-sqlseed`
36
-
37
- ## MCP Tools
38
-
39
- | Tool | 说明 |
40
- |:-----|:-----|
41
- | `sqlseed_inspect_schema` | 检查数据库 Schema:列、外键、索引、样本数据、schema_hash。可选 `table_name`(省略则返回所有表)。 |
42
- | `sqlseed_generate_yaml` | AI 驱动的 YAML 配置生成,含自纠正。需要 `sqlseed-ai` 插件和 API Key。支持 `api_key`/`base_url`/`model` 参数覆盖。 |
43
- | `sqlseed_execute_fill` | 执行数据生成。可选 `yaml_config` 字符串、`count` 和 `enrich` 标志。YAML 配置最大 256KB。 |
44
-
45
- ### MCP Resource
46
-
47
- | Resource | 说明 |
48
- |:---------|:-----|
49
- | `sqlseed://schema/{db_path}/{table_name}` | 指定表的只读 JSON Schema |
50
-
51
- ## 使用示例
52
-
53
- 配置 MCP 客户端后,可以这样提示:
54
-
55
- > "检查 `app.db` 的 Schema,为 `users` 表生成 YAML 配置,然后填充 1000 行数据。"
56
-
57
- AI 助手会依次调用:
58
- 1. `sqlseed_inspect_schema` → 获取表结构
59
- 2. `sqlseed_generate_yaml` → 生成 YAML 配置(需安装 sqlseed-ai)
60
- 3. `sqlseed_execute_fill` → 填充数据
61
-
62
- ## AI 集成
63
-
64
- 当安装了 `sqlseed-ai` 并配置了 API Key(`SQLSEED_AI_API_KEY` 或 `OPENAI_API_KEY`)时,`sqlseed_generate_yaml` 工具使用 LLM 驱动的分析和自纠正。未安装 AI 插件时,该工具返回回退消息。
65
-
66
- ## 依赖
67
-
68
- - Python >= 3.10
69
- - `sqlseed >= 0.1.0`
70
- - `mcp >= 1.0`
71
-
72
- 可选:
73
- - `sqlseed-ai`(用于 `sqlseed_generate_yaml` 工具)
74
-
75
- ## 许可证
76
-
77
- AGPL-3.0-or-later
@@ -1,47 +0,0 @@
1
- [build-system]
2
- requires = ["hatchling", "hatch-vcs"]
3
- build-backend = "hatchling.build"
4
-
5
- [project]
6
- name = "mcp-server-sqlseed"
7
- dynamic = ["version"]
8
- requires-python = ">=3.10"
9
- description = "MCP server for sqlseed - AI-powered SQLite test data generation"
10
- readme = "README.md"
11
- license = "AGPL-3.0-or-later"
12
- authors = [
13
- {name = "SunBo", email = "1443584939@qq.com"},
14
- ]
15
- classifiers = [
16
- "Development Status :: 3 - Alpha",
17
- "License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",
18
- "Programming Language :: Python :: 3",
19
- "Programming Language :: Python :: 3.10",
20
- "Programming Language :: Python :: 3.11",
21
- "Programming Language :: Python :: 3.12",
22
- "Programming Language :: Python :: 3.13",
23
- ]
24
- dependencies = [
25
- "sqlseed>=0.1.0,<2",
26
- "mcp>=1.0,<2",
27
- ]
28
-
29
- [project.urls]
30
- Homepage = "https://github.com/sunbos/sqlseed"
31
- Repository = "https://github.com/sunbos/sqlseed/tree/main/plugins/mcp-server-sqlseed"
32
-
33
- [project.optional-dependencies]
34
- ai = ["sqlseed-ai"]
35
-
36
- [project.scripts]
37
- mcp-server-sqlseed = "mcp_server_sqlseed:main"
38
-
39
- [tool.hatch.version]
40
- source = "vcs"
41
- fallback-version = "0.0.0"
42
-
43
- [tool.hatch.version.raw-options]
44
- root = "../.."
45
-
46
- [tool.hatch.build.targets.wheel]
47
- packages = ["src/mcp_server_sqlseed"]
@@ -1,7 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from mcp_server_sqlseed.server import mcp
4
-
5
-
6
- def main() -> None:
7
- mcp.run()
@@ -1,6 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from mcp_server_sqlseed import main
4
-
5
- if __name__ == "__main__":
6
- main()
@@ -1,9 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from pydantic import BaseModel
4
-
5
-
6
- class MCPServerConfig(BaseModel):
7
- db_path: str | None = None
8
- host: str = "localhost"
9
- port: int = 8000
@@ -1,190 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import hashlib
4
- import json
5
- from pathlib import Path
6
- from typing import Any
7
-
8
- import yaml
9
- from mcp.server.fastmcp import FastMCP
10
-
11
- from sqlseed.config.models import GeneratorConfig
12
- from sqlseed.core.orchestrator import DataOrchestrator
13
-
14
- try:
15
- from sqlseed_ai.analyzer import SchemaAnalyzer
16
- from sqlseed_ai.config import AIConfig
17
- from sqlseed_ai.refiner import AiConfigRefiner, AISuggestionFailedError
18
-
19
- _AI_AVAILABLE = True
20
- except ImportError:
21
- _AI_AVAILABLE = False
22
-
23
- mcp = FastMCP("sqlseed")
24
-
25
- _MAX_YAML_CONFIG_SIZE = 256 * 1024
26
-
27
-
28
- def _validate_db_path(db_path: str) -> str:
29
- resolved = Path(db_path).resolve()
30
- valid_exts = (".db", ".sqlite", ".sqlite3")
31
- if not str(resolved).endswith(valid_exts):
32
- raise ValueError(f"Invalid database path: {db_path}. Must be a .db, .sqlite, or .sqlite3 file.")
33
- if not resolved.exists():
34
- raise ValueError(f"Database file not found: {db_path}")
35
- return str(resolved)
36
-
37
-
38
- def _validate_table_name(table_name: str, allowed_tables: list[str]) -> str:
39
- if table_name not in allowed_tables:
40
- raise ValueError(f"Table '{table_name}' does not exist in the database. Available: {allowed_tables}")
41
- return table_name
42
-
43
-
44
- def _serialize_schema_context(ctx: dict[str, Any]) -> dict[str, Any]:
45
- return {
46
- "table_name": ctx["table_name"],
47
- "columns": [
48
- {
49
- "name": c.name,
50
- "type": c.type,
51
- "nullable": c.nullable,
52
- "default": c.default,
53
- "is_primary_key": c.is_primary_key,
54
- "is_autoincrement": c.is_autoincrement,
55
- }
56
- for c in ctx["columns"]
57
- ],
58
- "foreign_keys": [
59
- {"column": fk.column, "ref_table": fk.ref_table, "ref_column": fk.ref_column} for fk in ctx["foreign_keys"]
60
- ],
61
- "indexes": ctx["indexes"],
62
- "sample_data": ctx["sample_data"],
63
- "all_table_names": ctx["all_table_names"],
64
- }
65
-
66
-
67
- def _compute_schema_hash(schema_ctx: dict[str, Any]) -> str:
68
- hash_input = json.dumps(
69
- {
70
- "columns": [{"name": c.name, "type": c.type, "nullable": c.nullable} for c in schema_ctx["columns"]],
71
- "foreign_keys": [{"column": fk.column, "ref_table": fk.ref_table} for fk in schema_ctx["foreign_keys"]],
72
- },
73
- sort_keys=True,
74
- )
75
- return hashlib.sha256(hash_input.encode()).hexdigest()[:16]
76
-
77
-
78
- @mcp.resource("sqlseed://schema/{db_path}/{table_name}")
79
- def get_schema_resource(db_path: str, table_name: str) -> str:
80
- db_path = _validate_db_path(db_path)
81
- with DataOrchestrator(db_path) as orch:
82
- _validate_table_name(table_name, orch.get_table_names())
83
- ctx = orch.get_schema_context(table_name)
84
- serializable_ctx = _serialize_schema_context(ctx)
85
- return json.dumps(serializable_ctx, ensure_ascii=False, indent=2)
86
-
87
-
88
- @mcp.tool()
89
- def sqlseed_inspect_schema(db_path: str, table_name: str | None = None) -> dict[str, Any]:
90
- """Inspect database schema. Returns column info, foreign keys, indexes,
91
- sample data, and schema_hash for specified table or all tables."""
92
- db_path = _validate_db_path(db_path)
93
- with DataOrchestrator(db_path) as orch:
94
- if table_name:
95
- _validate_table_name(table_name, orch.get_table_names())
96
- tables = [table_name] if table_name else orch.get_table_names()
97
- result: dict[str, Any] = {}
98
- for tbl in tables:
99
- ctx = orch.get_schema_context(tbl)
100
- result[tbl] = _serialize_schema_context(ctx)
101
- result[tbl]["schema_hash"] = _compute_schema_hash(ctx)
102
- return result
103
-
104
-
105
- @mcp.tool()
106
- def sqlseed_generate_yaml(
107
- db_path: str,
108
- table_name: str,
109
- max_retries: int = 3,
110
- api_key: str | None = None,
111
- base_url: str | None = None,
112
- model: str | None = None,
113
- ) -> str:
114
- """Generate YAML config for a table using AI analysis with self-correction.
115
- Returns YAML string for human review. Requires sqlseed-ai plugin and API key."""
116
- if not _AI_AVAILABLE:
117
- return "# No AI suggestions available. Ensure sqlseed-ai plugin is installed and API key is configured."
118
-
119
- db_path = _validate_db_path(db_path)
120
- with DataOrchestrator(db_path) as orch:
121
- _validate_table_name(table_name, orch.get_table_names())
122
-
123
- ai_config = AIConfig.from_env().apply_overrides(api_key=api_key, base_url=base_url, model=model)
124
-
125
- ai_config.resolve_model()
126
-
127
- analyzer = SchemaAnalyzer(config=ai_config)
128
- refiner = AiConfigRefiner(analyzer, db_path)
129
-
130
- try:
131
- result = refiner.generate_and_refine(
132
- table_name=table_name,
133
- max_retries=max_retries,
134
- )
135
- except AISuggestionFailedError as e:
136
- return f"# AI suggestion failed: {e}"
137
- except (ValueError, RuntimeError, OSError) as e:
138
- return f"# Error: {e}"
139
-
140
- if result:
141
- output = {"db_path": db_path, "provider": "mimesis", "locale": "en_US", "tables": [result]}
142
- return str(yaml.dump(output, allow_unicode=True, sort_keys=False, default_flow_style=False))
143
- return "# No AI suggestions available. Ensure sqlseed-ai plugin is installed and API key is configured."
144
-
145
-
146
- @mcp.tool()
147
- def sqlseed_execute_fill(
148
- db_path: str,
149
- table_name: str,
150
- count: int = 1000,
151
- yaml_config: str | None = None,
152
- enrich: bool = False,
153
- ) -> dict[str, Any]:
154
- """Execute data generation for a table. Optionally provide YAML config string for column rules."""
155
- db_path = _validate_db_path(db_path)
156
-
157
- if yaml_config is not None and len(yaml_config) > _MAX_YAML_CONFIG_SIZE:
158
- raise ValueError(f"yaml_config exceeds maximum allowed size of {_MAX_YAML_CONFIG_SIZE} bytes")
159
-
160
- with DataOrchestrator(db_path) as orch:
161
- _validate_table_name(table_name, orch.get_table_names())
162
- column_configs = None
163
- clear_before = False
164
- seed = None
165
-
166
- if yaml_config:
167
- data = yaml.safe_load(yaml_config)
168
- config = GeneratorConfig(**data)
169
- for t in config.tables:
170
- if t.name == table_name:
171
- column_configs = t.columns
172
- clear_before = t.clear_before
173
- seed = t.seed
174
- break
175
-
176
- result = orch.fill_table(
177
- table_name=table_name,
178
- count=count,
179
- column_configs=column_configs,
180
- clear_before=clear_before,
181
- seed=seed,
182
- enrich=enrich,
183
- )
184
-
185
- return {
186
- "table_name": result.table_name,
187
- "count": result.count,
188
- "elapsed": result.elapsed,
189
- "errors": result.errors,
190
- }