mcp-server-sqlseed 0.1.20__tar.gz → 0.2.0__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.
- {mcp_server_sqlseed-0.1.20 → mcp_server_sqlseed-0.2.0}/PKG-INFO +2 -1
- {mcp_server_sqlseed-0.1.20 → mcp_server_sqlseed-0.2.0}/README.md +1 -0
- {mcp_server_sqlseed-0.1.20 → mcp_server_sqlseed-0.2.0}/README.zh-CN.md +5 -0
- {mcp_server_sqlseed-0.1.20 → mcp_server_sqlseed-0.2.0}/src/mcp_server_sqlseed/server.py +161 -2
- {mcp_server_sqlseed-0.1.20 → mcp_server_sqlseed-0.2.0}/.gitignore +0 -0
- {mcp_server_sqlseed-0.1.20 → mcp_server_sqlseed-0.2.0}/pyproject.toml +0 -0
- {mcp_server_sqlseed-0.1.20 → mcp_server_sqlseed-0.2.0}/src/mcp_server_sqlseed/__init__.py +0 -0
- {mcp_server_sqlseed-0.1.20 → mcp_server_sqlseed-0.2.0}/src/mcp_server_sqlseed/__main__.py +0 -0
- {mcp_server_sqlseed-0.1.20 → mcp_server_sqlseed-0.2.0}/src/mcp_server_sqlseed/config.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mcp-server-sqlseed
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: MCP server for sqlseed - AI-powered SQLite test data generation
|
|
5
5
|
Project-URL: Homepage, https://github.com/sunbos/sqlseed
|
|
6
6
|
Project-URL: Repository, https://github.com/sunbos/sqlseed/tree/main/plugins/mcp-server-sqlseed
|
|
@@ -93,6 +93,7 @@ When `sqlseed-ai` is installed and an API key is configured (`SQLSEED_AI_API_KEY
|
|
|
93
93
|
|
|
94
94
|
Optional:
|
|
95
95
|
- `sqlseed-ai` (for `sqlseed_generate_yaml` tool)
|
|
96
|
+
- `google-generativeai` (for Gemma 4 tools: `sqlseed_gemma4_analyze`, `sqlseed_gemma4_agent_fill`)
|
|
96
97
|
|
|
97
98
|
## License
|
|
98
99
|
|
|
@@ -71,6 +71,7 @@ When `sqlseed-ai` is installed and an API key is configured (`SQLSEED_AI_API_KEY
|
|
|
71
71
|
|
|
72
72
|
Optional:
|
|
73
73
|
- `sqlseed-ai` (for `sqlseed_generate_yaml` tool)
|
|
74
|
+
- `google-generativeai` (for Gemma 4 tools: `sqlseed_gemma4_analyze`, `sqlseed_gemma4_agent_fill`)
|
|
74
75
|
|
|
75
76
|
## License
|
|
76
77
|
|
|
@@ -63,6 +63,10 @@ AI 助手会依次调用:
|
|
|
63
63
|
|
|
64
64
|
当安装了 `sqlseed-ai` 并配置了 API Key(`SQLSEED_AI_API_KEY` 或 `OPENAI_API_KEY`)时,`sqlseed_generate_yaml` 工具使用 LLM 驱动的分析和自纠正。未安装 AI 插件时,该工具返回回退消息。
|
|
65
65
|
|
|
66
|
+
### Gemma 4 集成
|
|
67
|
+
|
|
68
|
+
`sqlseed_gemma4_analyze` 和 `sqlseed_gemma4_agent_fill` 工具通过 `GEMMA_TOOLS` 接口利用 **Gemma 4 Native Function Calling**。当安装了 `google-generativeai` 并配置了 Google API Key(`GOOGLE_API_KEY`)时,这些工具使用 Gemma 4 的内置函数调用直接分析 Schema 并编排端到端填充工作流。使用 `sqlseed_list_gemma_models` 可查看可用的模型变体和后端。
|
|
69
|
+
|
|
66
70
|
## 依赖
|
|
67
71
|
|
|
68
72
|
- Python >= 3.10
|
|
@@ -71,6 +75,7 @@ AI 助手会依次调用:
|
|
|
71
75
|
|
|
72
76
|
可选:
|
|
73
77
|
- `sqlseed-ai`(用于 `sqlseed_generate_yaml` 工具)
|
|
78
|
+
- `google-generativeai`(用于 Gemma 4 工具:`sqlseed_gemma4_analyze`、`sqlseed_gemma4_agent_fill`)
|
|
74
79
|
|
|
75
80
|
## 许可证
|
|
76
81
|
|
|
@@ -8,12 +8,12 @@ from typing import Any
|
|
|
8
8
|
import yaml
|
|
9
9
|
from mcp.server.fastmcp import FastMCP
|
|
10
10
|
|
|
11
|
-
from sqlseed.config.models import GeneratorConfig
|
|
11
|
+
from sqlseed.config.models import ColumnConfig, GeneratorConfig
|
|
12
12
|
from sqlseed.core.orchestrator import DataOrchestrator
|
|
13
13
|
|
|
14
14
|
try:
|
|
15
15
|
from sqlseed_ai.analyzer import SchemaAnalyzer
|
|
16
|
-
from sqlseed_ai.config import AIConfig
|
|
16
|
+
from sqlseed_ai.config import AIBackend, AIConfig, GemmaModel
|
|
17
17
|
from sqlseed_ai.refiner import AiConfigRefiner, AISuggestionFailedError
|
|
18
18
|
|
|
19
19
|
_AI_AVAILABLE = True
|
|
@@ -25,6 +25,33 @@ mcp = FastMCP("sqlseed")
|
|
|
25
25
|
_MAX_YAML_CONFIG_SIZE = 256 * 1024
|
|
26
26
|
|
|
27
27
|
|
|
28
|
+
def _build_ai_config(
|
|
29
|
+
db_path: str,
|
|
30
|
+
model: str | None,
|
|
31
|
+
backend: str | None,
|
|
32
|
+
) -> tuple[AIConfig, dict[str, Any] | None]:
|
|
33
|
+
"""Build an AIConfig with Gemma 4 defaults, validating db_path and backend.
|
|
34
|
+
|
|
35
|
+
Returns (config, None) on success, or (config, error_dict) on failure.
|
|
36
|
+
"""
|
|
37
|
+
if not _AI_AVAILABLE:
|
|
38
|
+
return AIConfig(), {"error": "sqlseed-ai plugin not installed. Install with: pip install sqlseed-ai"}
|
|
39
|
+
|
|
40
|
+
db_path = _validate_db_path(db_path)
|
|
41
|
+
|
|
42
|
+
ai_config = AIConfig.from_env()
|
|
43
|
+
if model:
|
|
44
|
+
ai_config.model = model
|
|
45
|
+
if backend:
|
|
46
|
+
try:
|
|
47
|
+
ai_config.backend = AIBackend(backend)
|
|
48
|
+
except ValueError:
|
|
49
|
+
return ai_config, {"error": f"Invalid backend: {backend}. Use: google_ai_studio, ollama, openai_compat"}
|
|
50
|
+
ai_config.resolve_model()
|
|
51
|
+
|
|
52
|
+
return ai_config, None
|
|
53
|
+
|
|
54
|
+
|
|
28
55
|
def _validate_db_path(db_path: str) -> str:
|
|
29
56
|
resolved = Path(db_path).resolve()
|
|
30
57
|
valid_exts = (".db", ".sqlite", ".sqlite3")
|
|
@@ -188,3 +215,135 @@ def sqlseed_execute_fill(
|
|
|
188
215
|
"elapsed": result.elapsed,
|
|
189
216
|
"errors": result.errors,
|
|
190
217
|
}
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
@mcp.tool()
|
|
221
|
+
def sqlseed_gemma4_analyze(
|
|
222
|
+
db_path: str,
|
|
223
|
+
table_name: str,
|
|
224
|
+
model: str | None = None,
|
|
225
|
+
backend: str | None = None,
|
|
226
|
+
) -> dict[str, Any]:
|
|
227
|
+
"""Analyze a database table schema using Gemma 4 with native function calling.
|
|
228
|
+
|
|
229
|
+
This tool leverages Gemma 4's built-in tool use capability to analyze
|
|
230
|
+
table structure and recommend data generation configurations. It demonstrates
|
|
231
|
+
Gemma 4's Native Function Calling feature for the AI Agent track.
|
|
232
|
+
|
|
233
|
+
Supported backends: google_ai_studio (default), ollama, openai_compat.
|
|
234
|
+
Supported models: gemma-4-26b-it (default), gemma-4-31b-it, gemma-4-4b-it, gemma-4-2b-it.
|
|
235
|
+
"""
|
|
236
|
+
ai_config, err = _build_ai_config(db_path, model, backend)
|
|
237
|
+
if err is not None:
|
|
238
|
+
return err
|
|
239
|
+
|
|
240
|
+
with DataOrchestrator(db_path) as orch:
|
|
241
|
+
_validate_table_name(table_name, orch.get_table_names())
|
|
242
|
+
schema_ctx = orch.get_schema_context(table_name)
|
|
243
|
+
|
|
244
|
+
analyzer = SchemaAnalyzer(config=ai_config)
|
|
245
|
+
result = analyzer.analyze_table_from_ctx(**_serialize_schema_context(schema_ctx))
|
|
246
|
+
|
|
247
|
+
if result is None:
|
|
248
|
+
return {"error": "Gemma 4 analysis returned no result. Check API key and model availability."}
|
|
249
|
+
|
|
250
|
+
return {
|
|
251
|
+
"model": ai_config.model,
|
|
252
|
+
"backend": ai_config.backend.value,
|
|
253
|
+
"table_name": table_name,
|
|
254
|
+
"config": result,
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
@mcp.tool()
|
|
259
|
+
def sqlseed_gemma4_agent_fill(
|
|
260
|
+
db_path: str,
|
|
261
|
+
table_name: str,
|
|
262
|
+
count: int = 1000,
|
|
263
|
+
model: str | None = None,
|
|
264
|
+
backend: str | None = None,
|
|
265
|
+
max_retries: int = 3,
|
|
266
|
+
) -> dict[str, Any]:
|
|
267
|
+
"""End-to-end AI Agent: Gemma 4 analyzes schema → generates config → fills data.
|
|
268
|
+
|
|
269
|
+
This is a complete Agent workflow that demonstrates Gemma 4's Native Function
|
|
270
|
+
Calling capability for the AI Agent track:
|
|
271
|
+
1. Inspect schema (Tool Calling: analyze_schema)
|
|
272
|
+
2. Generate data configuration (self-correction loop)
|
|
273
|
+
3. Execute data fill
|
|
274
|
+
|
|
275
|
+
The agent uses Gemma 4's tool use to understand schema semantics and
|
|
276
|
+
produce appropriate data generation rules automatically.
|
|
277
|
+
"""
|
|
278
|
+
ai_config, err = _build_ai_config(db_path, model, backend)
|
|
279
|
+
if err is not None:
|
|
280
|
+
return err
|
|
281
|
+
|
|
282
|
+
# Step 1: AI analysis with self-correction
|
|
283
|
+
analyzer = SchemaAnalyzer(config=ai_config)
|
|
284
|
+
refiner = AiConfigRefiner(analyzer, db_path)
|
|
285
|
+
|
|
286
|
+
try:
|
|
287
|
+
ai_result = refiner.generate_and_refine(
|
|
288
|
+
table_name=table_name,
|
|
289
|
+
max_retries=max_retries,
|
|
290
|
+
)
|
|
291
|
+
except AISuggestionFailedError as e:
|
|
292
|
+
return {"error": f"AI suggestion failed: {e}", "model": ai_config.model}
|
|
293
|
+
except (ValueError, RuntimeError, OSError) as e:
|
|
294
|
+
return {"error": f"Error: {e}", "model": ai_config.model}
|
|
295
|
+
|
|
296
|
+
if not ai_result:
|
|
297
|
+
return {"error": "No AI suggestions available", "model": ai_config.model}
|
|
298
|
+
|
|
299
|
+
# Step 2: Execute fill with AI-generated config
|
|
300
|
+
with DataOrchestrator(db_path) as orch:
|
|
301
|
+
_validate_table_name(table_name, orch.get_table_names())
|
|
302
|
+
|
|
303
|
+
column_configs = [ColumnConfig(**c) for c in ai_result.get("columns", [])]
|
|
304
|
+
result = orch.fill_table(
|
|
305
|
+
table_name=table_name,
|
|
306
|
+
count=count,
|
|
307
|
+
column_configs=column_configs,
|
|
308
|
+
)
|
|
309
|
+
|
|
310
|
+
return {
|
|
311
|
+
"model": ai_config.model,
|
|
312
|
+
"backend": ai_config.backend.value,
|
|
313
|
+
"table_name": result.table_name,
|
|
314
|
+
"count": result.count,
|
|
315
|
+
"elapsed": result.elapsed,
|
|
316
|
+
"errors": result.errors,
|
|
317
|
+
"ai_config": ai_result,
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
@mcp.tool()
|
|
322
|
+
def sqlseed_list_gemma_models() -> dict[str, Any]:
|
|
323
|
+
"""List available Gemma 4 model variants with descriptions.
|
|
324
|
+
|
|
325
|
+
Returns information about all supported Gemma 4 models,
|
|
326
|
+
including recommended use cases for each variant.
|
|
327
|
+
"""
|
|
328
|
+
models = []
|
|
329
|
+
for member in GemmaModel:
|
|
330
|
+
models.append(
|
|
331
|
+
{
|
|
332
|
+
"id": member.value,
|
|
333
|
+
"display_name": member.display_name,
|
|
334
|
+
}
|
|
335
|
+
)
|
|
336
|
+
|
|
337
|
+
backends = [
|
|
338
|
+
{"id": "google_ai_studio", "description": "Google AI Studio API (free tier available, recommended)"},
|
|
339
|
+
{"id": "lm_studio", "description": "LM Studio local deployment (http://127.0.0.1:1234, GUI-based)"},
|
|
340
|
+
{"id": "ollama", "description": "Ollama local deployment (offline, CLI-based)"},
|
|
341
|
+
{"id": "openai_compat", "description": "Any OpenAI-compatible API endpoint"},
|
|
342
|
+
]
|
|
343
|
+
|
|
344
|
+
return {
|
|
345
|
+
"models": models,
|
|
346
|
+
"backends": backends,
|
|
347
|
+
"default_model": "gemma-4-26b-it",
|
|
348
|
+
"default_backend": "google_ai_studio",
|
|
349
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|