sql-mcp 2.3.10__tar.gz → 2.3.11__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.
- {sql_mcp-2.3.10/sql_mcp.egg-info → sql_mcp-2.3.11}/PKG-INFO +1 -1
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/pyproject.toml +1 -1
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/kg_ingest.py +71 -6
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/mcp/mcp_sql.py +40 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/ontology/certification.json +2 -2
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/ontology/database.ttl +6 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11/sql_mcp.egg-info}/PKG-INFO +1 -1
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp.egg-info/SOURCES.txt +1 -0
- sql_mcp-2.3.11/tests/test_catalog_profile.py +88 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/LICENSE +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/README.md +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/setup.cfg +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/__init__.py +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/__main__.py +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/api/__init__.py +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/api/api_client_sql.py +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/api_client.py +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/auth.py +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/connector_contracts.py +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/connector_sources.py +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/dialects.py +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/kg_pgwire.py +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/mcp/__init__.py +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/mcp_config.json +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/mcp_server.py +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/ontology/__init__.py +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/ontology/fixtures/records.json +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/ontology/mappings/source.yaml +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/ontology/migrations/manifest.json +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/ontology/shapes/connector.shacl.ttl +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/prompts/sql-mcp-data-analyst.json +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/prompts/sql-mcp-data-steward.json +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/prompts/sql-mcp-database-administrator.json +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/prompts/sql-mcp-operator.json +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/safety.py +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/skills/sql-mcp-development/SKILL.md +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/skills/sql-mcp-knowledge-graph-ingestion/SKILL.md +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/skills/sql-mcp-knowledge-graph-ingestion/WORKFLOW.md +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/skills/sql-mcp-operations/SKILL.md +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/skills/sql-mcp-operations/agents/openai.yaml +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/skills/sql-mcp-operations/references/catalog.md +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/skills/sql-mcp-query-execution/SKILL.md +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/skills/sql-mcp-query-execution/WORKFLOW.md +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/skills/sql-mcp-schema-inspection/SKILL.md +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/skills/sql-mcp-schema-inspection/WORKFLOW.md +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/sql_response_models.py +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp.egg-info/dependency_links.txt +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp.egg-info/entry_points.txt +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp.egg-info/requires.txt +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp.egg-info/top_level.txt +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/tests/test_api_wrapper.py +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/tests/test_auth.py +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/tests/test_dialect_paths.py +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/tests/test_dialects.py +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/tests/test_identity_context_scoping.py +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/tests/test_init_dynamics.py +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/tests/test_kg_ingest.py +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/tests/test_kg_pgwire.py +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/tests/test_ontology_extends_core.py +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/tests/test_package_getattr.py +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/tests/test_safety.py +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/tests/test_scion_sdk_0_10_imports.py +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/tests/test_sql_mcp_validation.py +0 -0
- {sql_mcp-2.3.10 → sql_mcp-2.3.11}/tests/test_startup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sql-mcp
|
|
3
|
-
Version: 2.3.
|
|
3
|
+
Version: 2.3.11
|
|
4
4
|
Summary: Generic SQL database (Postgres, MySQL/MariaDB, MSSQL, Oracle, SQLite) API + MCP Server for Agentic AI!
|
|
5
5
|
Author-email: Repository Maintainers <maintainers@knuckles.team>
|
|
6
6
|
License: MIT
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "sql-mcp"
|
|
7
|
-
version = "2.3.
|
|
7
|
+
version = "2.3.11"
|
|
8
8
|
description = "Generic SQL database (Postgres, MySQL/MariaDB, MSSQL, Oracle, SQLite) API + MCP Server for Agentic AI!"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
classifiers = [ "Development Status :: 4 - Beta", "License :: OSI Approved :: MIT License", "Environment :: Console", "Operating System :: POSIX :: Linux", "Programming Language :: Python :: 3",]
|
|
@@ -10,18 +10,24 @@ propagate as ``IngestError``.
|
|
|
10
10
|
from __future__ import annotations
|
|
11
11
|
|
|
12
12
|
import hashlib
|
|
13
|
+
import json
|
|
14
|
+
from collections.abc import Mapping, Sequence
|
|
13
15
|
from pathlib import Path
|
|
14
16
|
from typing import Any
|
|
15
17
|
|
|
16
18
|
from scion_sdk.ingest import (
|
|
17
19
|
ChangeSet,
|
|
18
|
-
Entity,
|
|
19
20
|
ContractSource,
|
|
21
|
+
Entity,
|
|
20
22
|
IngestError,
|
|
21
23
|
KnowledgeIngest,
|
|
22
24
|
Relationship,
|
|
23
25
|
current_ingest,
|
|
24
26
|
)
|
|
27
|
+
from scion_sdk.ingest.sql_profile import ProfileRefusal, build_column_profile
|
|
28
|
+
|
|
29
|
+
#: Sampled values for the column profiles: table name -> column name -> values.
|
|
30
|
+
ColumnSamples = Mapping[str, Mapping[str, Sequence[object]]]
|
|
25
31
|
|
|
26
32
|
#: The local declaration the engine must have accepted: the connector's mappings.
|
|
27
33
|
_DECLARATION = Path(__file__).parent / "ontology" / "mappings" / "source.yaml"
|
|
@@ -38,12 +44,29 @@ _ENTITY_RESERVED_KEYS = frozenset({"id", "node_type"})
|
|
|
38
44
|
_RELATIONSHIP_RESERVED_KEYS = frozenset({"source", "target", "relationship"})
|
|
39
45
|
|
|
40
46
|
|
|
47
|
+
def _flat_property(value: Any) -> Any:
|
|
48
|
+
"""A nested value as canonical JSON text.
|
|
49
|
+
|
|
50
|
+
The ingest request builder refuses a nested dictionary the connector
|
|
51
|
+
mapping does not declare, so the column profile travels as one JSON string.
|
|
52
|
+
The persistence privacy guard redacts a bare run of ten digits as a phone
|
|
53
|
+
number, so the 32-bit fixed-point distinct ratio is written as the exact
|
|
54
|
+
float ``distinct_ratio`` (``distinct_ratio_q32 / 2**32``).
|
|
55
|
+
"""
|
|
56
|
+
if not isinstance(value, Mapping):
|
|
57
|
+
return value
|
|
58
|
+
flat = dict(value)
|
|
59
|
+
if "distinct_ratio_q32" in flat:
|
|
60
|
+
flat["distinct_ratio"] = flat.pop("distinct_ratio_q32") / (1 << 32)
|
|
61
|
+
return json.dumps(flat, sort_keys=True, separators=(",", ":"))
|
|
62
|
+
|
|
63
|
+
|
|
41
64
|
def _to_entity(record: dict[str, Any]) -> Entity:
|
|
42
65
|
return Entity(
|
|
43
66
|
id=record.get("id"),
|
|
44
67
|
node_type=record.get("node_type"),
|
|
45
68
|
properties={
|
|
46
|
-
key: value
|
|
69
|
+
key: _flat_property(value)
|
|
47
70
|
for key, value in record.items()
|
|
48
71
|
if key not in _ENTITY_RESERVED_KEYS
|
|
49
72
|
},
|
|
@@ -99,8 +122,14 @@ class _CatalogIngestState:
|
|
|
99
122
|
"""
|
|
100
123
|
|
|
101
124
|
def __init__(
|
|
102
|
-
self,
|
|
125
|
+
self,
|
|
126
|
+
connection: str,
|
|
127
|
+
label: str,
|
|
128
|
+
schema_id: str,
|
|
129
|
+
max_objects: int,
|
|
130
|
+
samples: ColumnSamples | None = None,
|
|
103
131
|
) -> None:
|
|
132
|
+
self.samples = samples
|
|
104
133
|
self.connection = connection
|
|
105
134
|
self.label = label
|
|
106
135
|
self.schema_id = schema_id
|
|
@@ -186,6 +215,31 @@ def _add_foreign_key_relationships(
|
|
|
186
215
|
return foreign_key_columns
|
|
187
216
|
|
|
188
217
|
|
|
218
|
+
def _column_profile(
|
|
219
|
+
state: _CatalogIngestState,
|
|
220
|
+
table_name: str,
|
|
221
|
+
column: dict,
|
|
222
|
+
column_name: str,
|
|
223
|
+
is_foreign_key: bool,
|
|
224
|
+
) -> dict[str, Any] | None:
|
|
225
|
+
"""The SDK column profile of one column, as entity property data.
|
|
226
|
+
|
|
227
|
+
A table without a sample (``samples`` absent or the table missing from it)
|
|
228
|
+
and a column without a declared type get no profile.
|
|
229
|
+
"""
|
|
230
|
+
if state.samples is None or table_name not in state.samples:
|
|
231
|
+
return None
|
|
232
|
+
try:
|
|
233
|
+
profile = build_column_profile(
|
|
234
|
+
data_type=column.get("type") and str(column.get("type")),
|
|
235
|
+
is_foreign_key=is_foreign_key,
|
|
236
|
+
values=state.samples[table_name].get(column_name, ()),
|
|
237
|
+
)
|
|
238
|
+
except ProfileRefusal:
|
|
239
|
+
return None
|
|
240
|
+
return profile.model_dump(mode="json")
|
|
241
|
+
|
|
242
|
+
|
|
189
243
|
def _add_column_entities(
|
|
190
244
|
state: _CatalogIngestState,
|
|
191
245
|
table_id: str,
|
|
@@ -203,6 +257,10 @@ def _add_column_entities(
|
|
|
203
257
|
f"database:column:{state.connection}.{state.label}."
|
|
204
258
|
f"{table_name}.{column_name}"
|
|
205
259
|
)
|
|
260
|
+
is_foreign_key = column_name in foreign_key_columns
|
|
261
|
+
profile = _column_profile(
|
|
262
|
+
state, table_name, column, column_name, is_foreign_key
|
|
263
|
+
)
|
|
206
264
|
state.add_entity(
|
|
207
265
|
{
|
|
208
266
|
"id": column_id,
|
|
@@ -214,10 +272,11 @@ def _add_column_entities(
|
|
|
214
272
|
"dataType": column.get("type"),
|
|
215
273
|
"isNullable": bool(column.get("nullable", True)),
|
|
216
274
|
"isPrimaryKey": bool(column.get("primary_key", False)),
|
|
217
|
-
"isForeignKey":
|
|
275
|
+
"isForeignKey": is_foreign_key,
|
|
218
276
|
"externalToolId": (
|
|
219
277
|
f"{state.connection}.{state.label}.{table_name}.{column_name}"
|
|
220
278
|
),
|
|
279
|
+
**({"column_profile": profile} if profile is not None else {}),
|
|
221
280
|
}
|
|
222
281
|
)
|
|
223
282
|
state.add_relationship(table_id, column_id, "hasColumn")
|
|
@@ -287,15 +346,21 @@ def catalog_to_entities(
|
|
|
287
346
|
*,
|
|
288
347
|
include_indexes: bool = True,
|
|
289
348
|
max_objects: int = _MAX_OBJECTS,
|
|
349
|
+
samples: ColumnSamples | None = None,
|
|
290
350
|
) -> tuple[list[dict[str, Any]], list[dict[str, Any]]]:
|
|
291
|
-
"""Map one bounded :meth:`SqlApi.schema_catalog` result into graph records.
|
|
351
|
+
"""Map one bounded :meth:`SqlApi.schema_catalog` result into graph records.
|
|
352
|
+
|
|
353
|
+
With ``samples`` (table -> column -> sampled values) each column entity of a
|
|
354
|
+
sampled table carries the SDK ``column_profile`` facts (type, foreign-key
|
|
355
|
+
flag, distinct ratio, sample count).
|
|
356
|
+
"""
|
|
292
357
|
_validate_max_objects(max_objects)
|
|
293
358
|
_validate_catalog_shape(catalog)
|
|
294
359
|
|
|
295
360
|
connection = str(catalog.get("connection") or "default")
|
|
296
361
|
label = _schema_label(catalog.get("schema"))
|
|
297
362
|
schema_id = f"database:schema:{connection}.{label}"
|
|
298
|
-
state = _CatalogIngestState(connection, label, schema_id, max_objects)
|
|
363
|
+
state = _CatalogIngestState(connection, label, schema_id, max_objects, samples)
|
|
299
364
|
state.add_entity(
|
|
300
365
|
{
|
|
301
366
|
"id": schema_id,
|
|
@@ -42,6 +42,44 @@ def _describe_dialects() -> list[dict[str, Any]]:
|
|
|
42
42
|
]
|
|
43
43
|
|
|
44
44
|
|
|
45
|
+
async def _column_samples(
|
|
46
|
+
api: Any, catalog: dict[str, Any], schema: str | None, connection: str | None
|
|
47
|
+
) -> dict[str, dict[str, list[Any]]]:
|
|
48
|
+
"""Sample each catalogued table (``SQL_PROFILE_SAMPLE_ROWS`` rows) by column.
|
|
49
|
+
|
|
50
|
+
A table whose sample query fails is left out and its columns carry no profile.
|
|
51
|
+
"""
|
|
52
|
+
from scion_sdk.ingest.sql_profile import sample_rows
|
|
53
|
+
|
|
54
|
+
limit = sample_rows()
|
|
55
|
+
samples: dict[str, dict[str, list[Any]]] = {}
|
|
56
|
+
for item in catalog.get("objects") or []:
|
|
57
|
+
if not isinstance(item, dict) or item.get("type") != "table":
|
|
58
|
+
continue
|
|
59
|
+
table = item.get("name")
|
|
60
|
+
if not isinstance(table, str) or not table:
|
|
61
|
+
continue
|
|
62
|
+
try:
|
|
63
|
+
result = await _invoke(
|
|
64
|
+
partial(
|
|
65
|
+
api.sample_rows,
|
|
66
|
+
table,
|
|
67
|
+
schema=schema,
|
|
68
|
+
limit=limit,
|
|
69
|
+
connection=connection,
|
|
70
|
+
)
|
|
71
|
+
)
|
|
72
|
+
except Exception:
|
|
73
|
+
continue
|
|
74
|
+
rows = result.get("rows") or []
|
|
75
|
+
samples[table] = {
|
|
76
|
+
column["name"]: [row.get(column["name"]) for row in rows]
|
|
77
|
+
for column in item.get("columns") or []
|
|
78
|
+
if isinstance(column, dict) and isinstance(column.get("name"), str)
|
|
79
|
+
}
|
|
80
|
+
return samples
|
|
81
|
+
|
|
82
|
+
|
|
45
83
|
def register_sql_tools(mcp: FastMCP) -> None:
|
|
46
84
|
"""Register the dialect catalogue and the schema ingest tool."""
|
|
47
85
|
|
|
@@ -97,10 +135,12 @@ def register_sql_tools(mcp: FastMCP) -> None:
|
|
|
97
135
|
max_objects=min(max_objects, api.max_rows),
|
|
98
136
|
)
|
|
99
137
|
)
|
|
138
|
+
samples = await _column_samples(api, catalog, schema, connection or None)
|
|
100
139
|
entities, relationships = catalog_to_entities(
|
|
101
140
|
catalog,
|
|
102
141
|
include_indexes=include_indexes,
|
|
103
142
|
max_objects=max_objects,
|
|
143
|
+
samples=samples,
|
|
104
144
|
)
|
|
105
145
|
# ingest_entities is async (scion_sdk.ingest does its own non-blocking
|
|
106
146
|
# I/O), so it runs directly on the event loop.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"api_version": "graphos.io/v1",
|
|
3
3
|
"artifacts": {
|
|
4
|
-
"sql_mcp/ontology/database.ttl": "
|
|
4
|
+
"sql_mcp/ontology/database.ttl": "a36ec89259adf403f5b66ac18ba31ee559ce58a82090293fd9365daa9e1f1100",
|
|
5
5
|
"sql_mcp/ontology/fixtures/records.json": "2a06e3f58c45c99a612d756419b9029fc7d14f5acaa1db77f964e32cc58c28d1",
|
|
6
6
|
"sql_mcp/ontology/mappings/source.yaml": "15faf4992ea561ea2ffa48bdd39ccb78823b11b31f32aeda2030479e700a521e",
|
|
7
7
|
"sql_mcp/ontology/migrations/manifest.json": "18189bd6a40c3683809ed9d80a2179361bbc8ea79d11ed1c3bed6152f64c3396",
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"signer": "UNSIGNED-PREVIEW",
|
|
30
30
|
"signing_public_key": "",
|
|
31
31
|
"status": "source-validated",
|
|
32
|
-
"validated_at": "2026-12-
|
|
32
|
+
"validated_at": "2026-12-03T23:08:11Z"
|
|
33
33
|
}
|
|
@@ -17,6 +17,12 @@
|
|
|
17
17
|
rdfs:domain :DatabaseColumn ;
|
|
18
18
|
rdfs:range xsd:string .
|
|
19
19
|
|
|
20
|
+
:column_profile a owl:DatatypeProperty ;
|
|
21
|
+
rdfs:label "column profile" ;
|
|
22
|
+
rdfs:comment "Facts about a sampled column: SQL type class, foreign-key flag, distinct ratio and sample count, as one JSON object." ;
|
|
23
|
+
rdfs:domain :DatabaseColumn ;
|
|
24
|
+
rdfs:range xsd:string .
|
|
25
|
+
|
|
20
26
|
:hasTable a owl:ObjectProperty ;
|
|
21
27
|
rdfs:label "has table" ;
|
|
22
28
|
rdfs:comment "Links a database schema to its constituent tables." ;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sql-mcp
|
|
3
|
-
Version: 2.3.
|
|
3
|
+
Version: 2.3.11
|
|
4
4
|
Summary: Generic SQL database (Postgres, MySQL/MariaDB, MSSQL, Oracle, SQLite) API + MCP Server for Agentic AI!
|
|
5
5
|
Author-email: Repository Maintainers <maintainers@knuckles.team>
|
|
6
6
|
License: MIT
|
|
@@ -47,6 +47,7 @@ sql_mcp/skills/sql-mcp-schema-inspection/SKILL.md
|
|
|
47
47
|
sql_mcp/skills/sql-mcp-schema-inspection/WORKFLOW.md
|
|
48
48
|
tests/test_api_wrapper.py
|
|
49
49
|
tests/test_auth.py
|
|
50
|
+
tests/test_catalog_profile.py
|
|
50
51
|
tests/test_dialect_paths.py
|
|
51
52
|
tests/test_dialects.py
|
|
52
53
|
tests/test_identity_context_scoping.py
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""The catalog ingest puts an SDK column profile on every column entity."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
from sqlalchemy import text
|
|
7
|
+
|
|
8
|
+
from sql_mcp.kg_ingest import catalog_to_entities
|
|
9
|
+
from sql_mcp.mcp.mcp_sql import _column_samples
|
|
10
|
+
from tests.test_sql_mcp_validation import call, mcp # noqa: F401 (served fixture)
|
|
11
|
+
|
|
12
|
+
Q32 = 1 << 32
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _columns(entities):
|
|
16
|
+
return [e for e in entities if e["node_type"] == "DatabaseColumn"]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@pytest.mark.spec("CONN-SQL-MCP-CONNECTOR-CONTENT-R003")
|
|
20
|
+
async def test_every_column_entity_has_a_profile(mcp, monkeypatch): # noqa: F811
|
|
21
|
+
"""A served ``sql_ingest_schema`` call over a fixture database."""
|
|
22
|
+
monkeypatch.setenv("SQL_ALLOW_KG_INGEST", "True")
|
|
23
|
+
submitted: list = []
|
|
24
|
+
|
|
25
|
+
async def record(entities, relationships=None, **_kwargs):
|
|
26
|
+
submitted.extend(entities)
|
|
27
|
+
return {"nodes": len(entities), "edges": 0}
|
|
28
|
+
|
|
29
|
+
monkeypatch.setattr("sql_mcp.kg_ingest.ingest_entities", record)
|
|
30
|
+
await call(mcp, "sql_ingest_schema", connection="primary")
|
|
31
|
+
columns = _columns(submitted)
|
|
32
|
+
assert len(columns) == 6
|
|
33
|
+
for column in columns:
|
|
34
|
+
assert set(column["column_profile"]) == {
|
|
35
|
+
"sql_type",
|
|
36
|
+
"is_foreign_key",
|
|
37
|
+
"distinct_ratio_q32",
|
|
38
|
+
"sample_count",
|
|
39
|
+
}
|
|
40
|
+
by_name = {c["externalToolId"].split(".", 2)[-1]: c for c in columns}
|
|
41
|
+
assert by_name["users.id"]["column_profile"]["sql_type"] == "numeric"
|
|
42
|
+
assert by_name["users.id"]["column_profile"]["distinct_ratio_q32"] == Q32
|
|
43
|
+
assert by_name["users.name"]["column_profile"]["sql_type"] == "text"
|
|
44
|
+
assert by_name["users.email"]["column_profile"]["sample_count"] == 2
|
|
45
|
+
assert by_name["orders.user_id"]["column_profile"]["is_foreign_key"] is True
|
|
46
|
+
assert by_name["orders.user_id"]["column_profile"]["distinct_ratio_q32"] == Q32
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_sample_size_comes_from_the_environment(api, monkeypatch):
|
|
50
|
+
import asyncio
|
|
51
|
+
|
|
52
|
+
with api.engine("primary").begin() as conn:
|
|
53
|
+
for i in range(20, 260):
|
|
54
|
+
conn.execute(text(f"INSERT INTO users (id, name) VALUES ({i}, 'u')"))
|
|
55
|
+
monkeypatch.setenv("SQL_PROFILE_SAMPLE_ROWS", "100")
|
|
56
|
+
catalog = api.schema_catalog(connection="primary")
|
|
57
|
+
samples = asyncio.run(_column_samples(api, catalog, None, "primary"))
|
|
58
|
+
assert len(samples["users"]["id"]) == 100
|
|
59
|
+
entities, _ = catalog_to_entities(catalog, samples=samples)
|
|
60
|
+
name = next(c for c in _columns(entities) if c["name"] == "name")
|
|
61
|
+
assert name["column_profile"]["sample_count"] == 100
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def test_no_samples_means_no_profile(api):
|
|
65
|
+
entities, _ = catalog_to_entities(api.schema_catalog(connection="primary"))
|
|
66
|
+
assert all("column_profile" not in c for c in _columns(entities))
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@pytest.mark.asyncio
|
|
70
|
+
async def test_a_profiled_column_passes_the_sdk_request_builder():
|
|
71
|
+
from scion_sdk.ingest import KnowledgeIngest
|
|
72
|
+
|
|
73
|
+
from sql_mcp.kg_ingest import ingest_entities
|
|
74
|
+
from tests.test_kg_ingest import _catalog, _FakeTransport
|
|
75
|
+
|
|
76
|
+
samples = {"users": {"id": [1, 2, 3], "org_id": [7, 7]}}
|
|
77
|
+
entities, relationships = catalog_to_entities(_catalog(), samples=samples)
|
|
78
|
+
transport = _FakeTransport()
|
|
79
|
+
await ingest_entities(
|
|
80
|
+
entities, relationships, ingest=KnowledgeIngest(transport, loop=None)
|
|
81
|
+
)
|
|
82
|
+
records = {r.record_id: r for r in transport.requests[0].records}
|
|
83
|
+
profile = json.loads(
|
|
84
|
+
records["database:column:default.public.users.org_id"].payload["column_profile"]
|
|
85
|
+
)
|
|
86
|
+
assert profile["is_foreign_key"] is True
|
|
87
|
+
assert profile["sample_count"] == 2
|
|
88
|
+
assert profile["distinct_ratio"] == 0.5
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sql_mcp-2.3.10 → sql_mcp-2.3.11}/sql_mcp/skills/sql-mcp-knowledge-graph-ingestion/WORKFLOW.md
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|