-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.ts
53 lines (52 loc) · 1.92 KB
/
tools.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { z } from "zod";
import { escapeSQL, runSQLMCP } from "./utils.js";
import { Tool } from "fastmcp";
export default [
{
name: "list_databases",
description: "List available databases",
parameters: z.object({}), // Always needs a parameter (even if empty)
execute: async ({ reportProgress }) => {
return runSQLMCP("SHOW DATABASES LIKE '%db_out'", reportProgress);
},
},
{
name: "list_tables",
description: "List available tables from a database",
parameters: z.object({
database: z.string() // TODO: Add validation for allowed databases on ClickHouse side (user permissions)
}),
execute: async (args, { reportProgress }) => {
// Filter out backfill tables as well (TODO: could be done with user permissions ?)
const query = `SELECT name
FROM system.tables
WHERE database = ${escapeSQL(args.database)}
AND name NOT LIKE '%backfill%'
AND name NOT LIKE '.inner%'
AND name NOT LIKE '%_mv'
AND name != 'cursors'`;
return runSQLMCP(query, reportProgress);
},
},
{
name: "describe_table",
description: "Describe the schema of a table from a database",
parameters: z.object({
database: z.string(),
table: z.string(),
}),
execute: async (args, { reportProgress }) => {
return runSQLMCP(`DESCRIBE ${escapeSQL(args.database)}.${escapeSQL(args.table)}`, reportProgress);
},
},
{
name: "run_query",
description: "Run a read-only SQL query",
parameters: z.object({
query: z.string()
}),
execute: async (args, { reportProgress }) => {
return runSQLMCP(args.query, reportProgress);
},
},
] as Tool<undefined, z.ZodTypeAny>[];