You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en/docs/marketplace/platform-supported-content/modules/snowflake/snowflake-mcp.md
+73-69Lines changed: 73 additions & 69 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,74 +36,7 @@ To configure a Snowflake-managed MCP server, follow these steps:
36
36
37
37
2. Create the stored procedures which the MCP server will expose as tools.
38
38
39
-
The following is an example of a generic stored procdure which returns metadata:
40
-
41
-
```sql
42
-
-- You can run this example/demo under sysadmin role, for real production screnario's use proper authorisation
43
-
CREATE OR REPLACE PROCEDURE SNOWFLAKE_MCP_DEMO.TOOLS.GET_SCHEMA_METADATA(
44
-
db_name VARCHAR,
45
-
schema_name VARCHAR
46
-
)
47
-
RETURNS VARIANT
48
-
LANGUAGE PYTHON
49
-
RUNTIME_VERSION ='3.11'
50
-
PACKAGES = ('snowflake-snowpark-python')
51
-
HANDLER ='run'
52
-
AS
53
-
$$
54
-
import json
55
-
def run(session, db_name, schema_name):
56
-
rows =session.sql(f"""
57
-
SELECT
58
-
c.TABLE_CATALOG,
59
-
c.TABLE_SCHEMA,
60
-
c.TABLE_NAME,
61
-
t.TABLE_TYPE,
62
-
t.ROW_COUNT,
63
-
t.COMMENT AS TABLE_COMMENT,
64
-
c.COLUMN_NAME,
65
-
c.ORDINAL_POSITION,
66
-
c.DATA_TYPE,
67
-
c.IS_NULLABLE,
68
-
c.COLUMN_DEFAULT,
69
-
c.CHARACTER_MAXIMUM_LENGTH,
70
-
c.NUMERIC_PRECISION,
71
-
c.NUMERIC_SCALE,
72
-
c.COMMENT AS COLUMN_COMMENT
73
-
FROM {db_name}.INFORMATION_SCHEMA.COLUMNS c
74
-
JOIN {db_name}.INFORMATION_SCHEMA.TABLES t
75
-
ON c.TABLE_CATALOG = t.TABLE_CATALOG
76
-
AND c.TABLE_SCHEMA = t.TABLE_SCHEMA
77
-
AND c.TABLE_NAME = t.TABLE_NAME
78
-
WHERE c.TABLE_SCHEMA = '{schema_name}'
79
-
ORDER BY c.TABLE_NAME, c.ORDINAL_POSITION
80
-
""").collect()
81
-
tables = {}
82
-
for row in rows:
83
-
tname = row["TABLE_NAME"]
84
-
if tname not in tables:
85
-
tables[tname] = {
86
-
"database": row["TABLE_CATALOG"],
87
-
"schema": row["TABLE_SCHEMA"],
88
-
"table_type": row["TABLE_TYPE"],
89
-
"row_count": row["ROW_COUNT"],
90
-
"comment": row["TABLE_COMMENT"],
91
-
"columns": []
92
-
}
93
-
tables[tname]["columns"].append({
94
-
"name": row["COLUMN_NAME"],
95
-
"position": row["ORDINAL_POSITION"],
96
-
"data_type": row["DATA_TYPE"],
97
-
"nullable": row["IS_NULLABLE"],
98
-
"default": row["COLUMN_DEFAULT"],
99
-
"max_length": row["CHARACTER_MAXIMUM_LENGTH"],
100
-
"precision": row["NUMERIC_PRECISION"],
101
-
"scale": row["NUMERIC_SCALE"],
102
-
"comment": row["COLUMN_COMMENT"]
103
-
})
104
-
return tables
105
-
$$;
106
-
```
39
+
107
40
108
41
109
42
<summary>Expand for example code for a generic stored procdure for retrieving records</summary>
@@ -355,7 +288,7 @@ To configure a Snowflake-managed MCP server, follow these steps:
355
288
In this section, you can find sample code to help you configure a Snowflake-managed MCP server.
356
289
357
290
{{% alert color="info" %}}
358
-
The scripts are intended to show the range of available deployment options. They are presented as examples only, and may require significant adaptation to work in your own environment.
291
+
The code samples are intended to show the range of available options. They are presented as examples only, and may require significant adaptation to work in your own environment.
359
292
{{% /alert %}}
360
293
361
294
#### Database and Schema Setup {#code-db-schema}
@@ -384,6 +317,77 @@ VALUES
384
317
('Medium', 'Email notifications not being sent');
385
318
```
386
319
320
+
#### Procedure to Return Metadata {#code-metadata}
321
+
322
+
The following is an example of a generic stored procedure which returns metadata:
323
+
324
+
```sql
325
+
-- You can run this example/demo under sysadmin role, for real production screnario's use proper authorisation
326
+
CREATE OR REPLACE PROCEDURE SNOWFLAKE_MCP_DEMO.TOOLS.GET_SCHEMA_METADATA(
327
+
db_name VARCHAR,
328
+
schema_name VARCHAR
329
+
)
330
+
RETURNS VARIANT
331
+
LANGUAGE PYTHON
332
+
RUNTIME_VERSION = '3.11'
333
+
PACKAGES = ('snowflake-snowpark-python')
334
+
HANDLER = 'run'
335
+
AS
336
+
$$
337
+
import json
338
+
def run(session, db_name, schema_name):
339
+
rows = session.sql(f"""
340
+
SELECT
341
+
c.TABLE_CATALOG,
342
+
c.TABLE_SCHEMA,
343
+
c.TABLE_NAME,
344
+
t.TABLE_TYPE,
345
+
t.ROW_COUNT,
346
+
t.COMMENT AS TABLE_COMMENT,
347
+
c.COLUMN_NAME,
348
+
c.ORDINAL_POSITION,
349
+
c.DATA_TYPE,
350
+
c.IS_NULLABLE,
351
+
c.COLUMN_DEFAULT,
352
+
c.CHARACTER_MAXIMUM_LENGTH,
353
+
c.NUMERIC_PRECISION,
354
+
c.NUMERIC_SCALE,
355
+
c.COMMENT AS COLUMN_COMMENT
356
+
FROM {db_name}.INFORMATION_SCHEMA.COLUMNS c
357
+
JOIN {db_name}.INFORMATION_SCHEMA.TABLES t
358
+
ON c.TABLE_CATALOG = t.TABLE_CATALOG
359
+
AND c.TABLE_SCHEMA = t.TABLE_SCHEMA
360
+
AND c.TABLE_NAME = t.TABLE_NAME
361
+
WHERE c.TABLE_SCHEMA = '{schema_name}'
362
+
ORDER BY c.TABLE_NAME, c.ORDINAL_POSITION
363
+
""").collect()
364
+
tables = {}
365
+
for row in rows:
366
+
tname = row["TABLE_NAME"]
367
+
if tname not in tables:
368
+
tables[tname] = {
369
+
"database": row["TABLE_CATALOG"],
370
+
"schema": row["TABLE_SCHEMA"],
371
+
"table_type": row["TABLE_TYPE"],
372
+
"row_count": row["ROW_COUNT"],
373
+
"comment": row["TABLE_COMMENT"],
374
+
"columns": []
375
+
}
376
+
tables[tname]["columns"].append({
377
+
"name": row["COLUMN_NAME"],
378
+
"position": row["ORDINAL_POSITION"],
379
+
"data_type": row["DATA_TYPE"],
380
+
"nullable": row["IS_NULLABLE"],
381
+
"default": row["COLUMN_DEFAULT"],
382
+
"max_length": row["CHARACTER_MAXIMUM_LENGTH"],
383
+
"precision": row["NUMERIC_PRECISION"],
384
+
"scale": row["NUMERIC_SCALE"],
385
+
"comment": row["COLUMN_COMMENT"]
386
+
})
387
+
return tables
388
+
$$;
389
+
```
390
+
387
391
## Connecting a Mendix Agent to the MCP Server
388
392
389
393
After setting up the MCP server, you can now create a Mendix AI agent and connect it to the MCP server by performing the following steps:
0 commit comments