mcp-server-db2i 2.1.0 → 2.2.1

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 (58) hide show
  1. package/README.md +11 -0
  2. package/dist/config.d.ts +31 -5
  3. package/dist/config.d.ts.map +1 -1
  4. package/dist/config.js +71 -19
  5. package/dist/config.js.map +1 -1
  6. package/dist/customTools/context.d.ts +27 -0
  7. package/dist/customTools/context.d.ts.map +1 -0
  8. package/dist/customTools/context.js +35 -0
  9. package/dist/customTools/context.js.map +1 -0
  10. package/dist/customTools/execute.d.ts +22 -0
  11. package/dist/customTools/execute.d.ts.map +1 -0
  12. package/dist/customTools/execute.js +134 -0
  13. package/dist/customTools/execute.js.map +1 -0
  14. package/dist/customTools/loader.d.ts +56 -0
  15. package/dist/customTools/loader.d.ts.map +1 -0
  16. package/dist/customTools/loader.js +213 -0
  17. package/dist/customTools/loader.js.map +1 -0
  18. package/dist/customTools/params.d.ts +23 -0
  19. package/dist/customTools/params.d.ts.map +1 -0
  20. package/dist/customTools/params.js +93 -0
  21. package/dist/customTools/params.js.map +1 -0
  22. package/dist/customTools/registry.d.ts +18 -0
  23. package/dist/customTools/registry.d.ts.map +1 -0
  24. package/dist/customTools/registry.js +23 -0
  25. package/dist/customTools/registry.js.map +1 -0
  26. package/dist/customTools/schema.d.ts +127 -0
  27. package/dist/customTools/schema.d.ts.map +1 -0
  28. package/dist/customTools/schema.js +193 -0
  29. package/dist/customTools/schema.js.map +1 -0
  30. package/dist/db/connection.d.ts +9 -0
  31. package/dist/db/connection.d.ts.map +1 -1
  32. package/dist/db/connection.js +91 -0
  33. package/dist/db/connection.js.map +1 -1
  34. package/dist/db/sqlServices.d.ts +65 -0
  35. package/dist/db/sqlServices.d.ts.map +1 -0
  36. package/dist/db/sqlServices.js +311 -0
  37. package/dist/db/sqlServices.js.map +1 -0
  38. package/dist/index.js +12 -3
  39. package/dist/index.js.map +1 -1
  40. package/dist/server.d.ts.map +1 -1
  41. package/dist/server.js +146 -1
  42. package/dist/server.js.map +1 -1
  43. package/dist/tools/metadata.d.ts +24 -12
  44. package/dist/tools/metadata.d.ts.map +1 -1
  45. package/dist/tools/metadata.js +43 -8
  46. package/dist/tools/metadata.js.map +1 -1
  47. package/dist/tools/query.d.ts.map +1 -1
  48. package/dist/tools/query.js +36 -1
  49. package/dist/tools/query.js.map +1 -1
  50. package/dist/tools/sqlServices.d.ts +51 -0
  51. package/dist/tools/sqlServices.d.ts.map +1 -0
  52. package/dist/tools/sqlServices.js +122 -0
  53. package/dist/tools/sqlServices.js.map +1 -0
  54. package/dist/utils/security/schemaAllowlist.d.ts +5 -1
  55. package/dist/utils/security/schemaAllowlist.d.ts.map +1 -1
  56. package/dist/utils/security/schemaAllowlist.js +11 -1
  57. package/dist/utils/security/schemaAllowlist.js.map +1 -1
  58. package/package.json +3 -1
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Load business SQL tools and annotations from YAML files.
3
+ *
4
+ * Statements are checked with the same read-only rules and schema allowlist
5
+ * as execute_query. A failing file stops startup.
6
+ */
7
+ import { type ParameterDef, type RelationDef } from './schema.js';
8
+ export declare class CustomToolsError extends Error {
9
+ constructor(message: string);
10
+ }
11
+ export interface StoredRelation {
12
+ table: string;
13
+ join: Record<string, string>;
14
+ cardinality?: RelationDef['cardinality'];
15
+ description?: string;
16
+ }
17
+ export interface StoredAnnotation {
18
+ table: string;
19
+ entity?: string;
20
+ description?: string;
21
+ columns: Record<string, string>;
22
+ relations: StoredRelation[];
23
+ }
24
+ export interface StoredTool {
25
+ name: string;
26
+ title: string;
27
+ toolset?: string;
28
+ description: string;
29
+ parameters: Record<string, ParameterDef>;
30
+ maxRows?: number;
31
+ /** SQL with :name placeholders already rewritten to ? markers. */
32
+ sql: string;
33
+ /** Placeholder names in bind order. */
34
+ placeholderNames: string[];
35
+ source: string;
36
+ }
37
+ export interface LoadedCustomTools {
38
+ tools: StoredTool[];
39
+ annotations: StoredAnnotation[];
40
+ }
41
+ export interface LoadCustomToolsOptions {
42
+ /** Uppercased library names. Omit to skip the schema allowlist. */
43
+ allowedSchemas?: string[];
44
+ /** Schema unqualified names resolve to while the allowlist is on. */
45
+ defaultSchema?: string;
46
+ }
47
+ /**
48
+ * Load the files or directories listed in MCP_CUSTOM_TOOLS.
49
+ * An unset or blank value loads nothing.
50
+ */
51
+ export declare function loadCustomToolsFromEnv(): LoadedCustomTools;
52
+ /**
53
+ * Read YAML files and check every statement before the server accepts connections.
54
+ */
55
+ export declare function loadCustomTools(inputs: readonly string[], options?: LoadCustomToolsOptions): LoadedCustomTools;
56
+ //# sourceMappingURL=loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/customTools/loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,WAAW,EAEjB,MAAM,aAAa,CAAC;AAErB,qBAAa,gBAAiB,SAAQ,KAAK;gBAC7B,OAAO,EAAE,MAAM;CAI5B;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,WAAW,CAAC,EAAE,WAAW,CAAC,aAAa,CAAC,CAAC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,SAAS,EAAE,cAAc,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACzC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kEAAkE;IAClE,GAAG,EAAE,MAAM,CAAC;IACZ,uCAAuC;IACvC,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,WAAW,EAAE,gBAAgB,EAAE,CAAC;CACjC;AAED,MAAM,WAAW,sBAAsB;IACrC,mEAAmE;IACnE,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,qEAAqE;IACrE,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAID;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,iBAAiB,CAW1D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,OAAO,GAAE,sBAA2B,GACnC,iBAAiB,CAwCnB"}
@@ -0,0 +1,213 @@
1
+ /**
2
+ * Load business SQL tools and annotations from YAML files.
3
+ *
4
+ * Statements are checked with the same read-only rules and schema allowlist
5
+ * as execute_query. A failing file stops startup.
6
+ */
7
+ import { readdirSync, readFileSync, statSync } from 'node:fs';
8
+ import path from 'node:path';
9
+ import { parseDocument } from 'yaml';
10
+ import { getAllowedSchemas, TOOL_NAMES } from '../config.js';
11
+ import { checkQuerySchemas } from '../utils/security/schemaAllowlist.js';
12
+ import { validateQuery } from '../utils/security/sqlSecurityValidator.js';
13
+ import { PlaceholderError, rewriteNamedPlaceholders } from './params.js';
14
+ import { customToolsFileSchema, formatSchemaIssues, } from './schema.js';
15
+ export class CustomToolsError extends Error {
16
+ constructor(message) {
17
+ super(message);
18
+ this.name = 'CustomToolsError';
19
+ }
20
+ }
21
+ const EMPTY = { tools: [], annotations: [] };
22
+ /**
23
+ * Load the files or directories listed in MCP_CUSTOM_TOOLS.
24
+ * An unset or blank value loads nothing.
25
+ */
26
+ export function loadCustomToolsFromEnv() {
27
+ const raw = process.env.MCP_CUSTOM_TOOLS;
28
+ if (raw === undefined || raw.trim() === '') {
29
+ return EMPTY;
30
+ }
31
+ const paths = raw.split(',').map((entry) => entry.trim()).filter((entry) => entry.length > 0);
32
+ return loadCustomTools(paths, {
33
+ allowedSchemas: getAllowedSchemas(),
34
+ defaultSchema: process.env.DB2I_SCHEMA,
35
+ });
36
+ }
37
+ /**
38
+ * Read YAML files and check every statement before the server accepts connections.
39
+ */
40
+ export function loadCustomTools(inputs, options = {}) {
41
+ const files = inputs.flatMap((input) => collectFiles(input));
42
+ const tools = [];
43
+ const annotations = [];
44
+ const toolSources = new Map();
45
+ const annotationSources = new Map();
46
+ for (const file of files) {
47
+ const parsed = readFile(file);
48
+ for (const tool of parsed.tools ?? []) {
49
+ const stored = checkTool(tool, file, options);
50
+ const previous = toolSources.get(stored.name);
51
+ if (previous) {
52
+ throw new CustomToolsError(`Tool ${stored.name} is defined in both ${previous} and ${displayPath(file)}.`);
53
+ }
54
+ if (TOOL_NAMES.includes(stored.name)) {
55
+ throw new CustomToolsError(`${displayPath(file)}: tool ${stored.name} is already a built-in tool.`);
56
+ }
57
+ toolSources.set(stored.name, displayPath(file));
58
+ tools.push(stored);
59
+ }
60
+ for (const [table, annotation] of Object.entries(parsed.annotations ?? {})) {
61
+ const stored = storeAnnotation(table, annotation);
62
+ const previous = annotationSources.get(stored.table);
63
+ if (previous) {
64
+ throw new CustomToolsError(`Annotation ${stored.table} is defined in both ${previous} and ${displayPath(file)}.`);
65
+ }
66
+ annotationSources.set(stored.table, displayPath(file));
67
+ annotations.push(stored);
68
+ }
69
+ }
70
+ return { tools, annotations };
71
+ }
72
+ function readFile(file) {
73
+ let text;
74
+ try {
75
+ text = readFileSync(file, 'utf8');
76
+ }
77
+ catch (error) {
78
+ const message = error instanceof Error ? error.message : 'Could not read file';
79
+ throw new CustomToolsError(`${displayPath(file)}: ${message}`);
80
+ }
81
+ const doc = parseDocument(text, { schema: 'core' });
82
+ if (doc.errors.length > 0) {
83
+ throw new CustomToolsError(`${displayPath(file)}: ${doc.errors.map((error) => error.message).join('; ')}`);
84
+ }
85
+ const parsed = customToolsFileSchema.safeParse(doc.toJS());
86
+ if (!parsed.success) {
87
+ throw new CustomToolsError(`${displayPath(file)}: ${formatSchemaIssues(parsed.error)}`);
88
+ }
89
+ return parsed.data;
90
+ }
91
+ function checkTool(tool, file, options) {
92
+ const where = `${displayPath(file)}: tool ${tool.name}`;
93
+ const parameters = tool.parameters ?? {};
94
+ let rewritten;
95
+ try {
96
+ rewritten = rewriteNamedPlaceholders(tool.sql);
97
+ }
98
+ catch (error) {
99
+ if (error instanceof PlaceholderError) {
100
+ throw new CustomToolsError(`${where}: ${error.message}`);
101
+ }
102
+ throw error;
103
+ }
104
+ const declared = new Set(Object.keys(parameters));
105
+ const used = new Set(rewritten.names);
106
+ for (const name of used) {
107
+ if (!declared.has(name)) {
108
+ throw new CustomToolsError(`${where}: placeholder :${name} has no parameter definition.`);
109
+ }
110
+ }
111
+ for (const name of declared) {
112
+ if (!used.has(name)) {
113
+ throw new CustomToolsError(`${where}: parameter ${name} is not used in the SQL.`);
114
+ }
115
+ }
116
+ const security = validateQuery(rewritten.sql);
117
+ if (!security.isValid) {
118
+ throw new CustomToolsError(`${where}: Security validation failed: ${security.violations.join('; ')}`);
119
+ }
120
+ if (options.allowedSchemas && options.allowedSchemas.length > 0) {
121
+ const schemaResult = checkQuerySchemas(rewritten.sql, {
122
+ allowed: options.allowedSchemas,
123
+ defaultSchema: options.defaultSchema,
124
+ });
125
+ if (!schemaResult.ok) {
126
+ throw new CustomToolsError(`${where}: Schema allowlist rejected the query: ${schemaResult.violations.join('; ')}`);
127
+ }
128
+ }
129
+ return {
130
+ name: tool.name,
131
+ title: tool.title,
132
+ ...(tool.toolset ? { toolset: tool.toolset } : {}),
133
+ description: tool.description,
134
+ parameters,
135
+ ...(tool.maxRows !== undefined ? { maxRows: tool.maxRows } : {}),
136
+ sql: rewritten.sql,
137
+ placeholderNames: rewritten.names,
138
+ source: displayPath(file),
139
+ };
140
+ }
141
+ function storeAnnotation(table, annotation) {
142
+ const columns = {};
143
+ for (const [column, text] of Object.entries(annotation.columns ?? {})) {
144
+ columns[column.toUpperCase()] = text;
145
+ }
146
+ const relations = (annotation.relations ?? []).map((relation) => {
147
+ const join = {};
148
+ for (const [from, to] of Object.entries(relation.join)) {
149
+ join[from.toUpperCase()] = to.toUpperCase();
150
+ }
151
+ return {
152
+ table: relation.table.toUpperCase(),
153
+ join,
154
+ ...(relation.cardinality ? { cardinality: relation.cardinality } : {}),
155
+ ...(relation.description ? { description: relation.description } : {}),
156
+ };
157
+ });
158
+ return {
159
+ table: table.toUpperCase(),
160
+ ...(annotation.entity ? { entity: annotation.entity } : {}),
161
+ ...(annotation.description ? { description: annotation.description } : {}),
162
+ columns,
163
+ relations,
164
+ };
165
+ }
166
+ function collectFiles(input) {
167
+ const resolved = path.resolve(input);
168
+ let info;
169
+ try {
170
+ info = statSync(resolved);
171
+ }
172
+ catch {
173
+ throw new CustomToolsError(`Custom tools path not found: ${input}`);
174
+ }
175
+ if (info.isFile()) {
176
+ if (!isYaml(resolved)) {
177
+ throw new CustomToolsError(`Custom tools file must be .yaml or .yml: ${input}`);
178
+ }
179
+ return [resolved];
180
+ }
181
+ if (!info.isDirectory()) {
182
+ throw new CustomToolsError(`Custom tools path is not a file or directory: ${input}`);
183
+ }
184
+ const found = [];
185
+ walk(resolved, found);
186
+ found.sort((a, b) => a.localeCompare(b));
187
+ if (found.length === 0) {
188
+ throw new CustomToolsError(`No YAML files found in ${input}`);
189
+ }
190
+ return found;
191
+ }
192
+ function walk(dir, found) {
193
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
194
+ if (entry.name.startsWith('.')) {
195
+ continue;
196
+ }
197
+ const full = path.join(dir, entry.name);
198
+ if (entry.isDirectory()) {
199
+ walk(full, found);
200
+ }
201
+ else if (entry.isFile() && isYaml(entry.name)) {
202
+ found.push(full);
203
+ }
204
+ }
205
+ }
206
+ function isYaml(file) {
207
+ return file.toLowerCase().endsWith('.yaml') || file.toLowerCase().endsWith('.yml');
208
+ }
209
+ function displayPath(file) {
210
+ const relative = path.relative(process.cwd(), file);
211
+ return relative.startsWith('..') ? file : relative;
212
+ }
213
+ //# sourceMappingURL=loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/customTools/loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAErC,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,2CAA2C,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EACL,qBAAqB,EACrB,kBAAkB,GAKnB,MAAM,aAAa,CAAC;AAErB,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AA2CD,MAAM,KAAK,GAAsB,EAAE,KAAK,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC;AAEhE;;;GAGG;AACH,MAAM,UAAU,sBAAsB;IACpC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;IACzC,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC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C,EAAE,CAAC;YAChD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAS,MAAM,CAAC,IAAY;IAC1B,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AACrF,CAAC;AAED,SAAS,WAAW,CAAC,IAAY;IAC/B,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC;IACpD,OAAO,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC;AACrD,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Turn :name placeholders into positional ? markers.
3
+ *
4
+ * Names inside string literals, quoted identifiers, and comments stay as text.
5
+ * A bare ? is rejected so bind order cannot be mixed with hand-written markers.
6
+ */
7
+ export declare class PlaceholderError extends Error {
8
+ constructor(message: string);
9
+ }
10
+ export interface RewrittenSql {
11
+ /** SQL with :name placeholders replaced by ? markers. */
12
+ sql: string;
13
+ /** Placeholder names in bind order. Repeated names are kept. */
14
+ names: string[];
15
+ }
16
+ /**
17
+ * Replace :name placeholders with ? and return the names in bind order.
18
+ *
19
+ * @throws PlaceholderError when a colon is not a :name placeholder, a ? marker
20
+ * is already present, or a quote or block comment is left open.
21
+ */
22
+ export declare function rewriteNamedPlaceholders(sql: string): RewrittenSql;
23
+ //# sourceMappingURL=params.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../../src/customTools/params.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,qBAAa,gBAAiB,SAAQ,KAAK;gBAC7B,OAAO,EAAE,MAAM;CAI5B;AAED,MAAM,WAAW,YAAY;IAC3B,yDAAyD;IACzD,GAAG,EAAE,MAAM,CAAC;IACZ,gEAAgE;IAChE,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAwDlE"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Turn :name placeholders into positional ? markers.
3
+ *
4
+ * Names inside string literals, quoted identifiers, and comments stay as text.
5
+ * A bare ? is rejected so bind order cannot be mixed with hand-written markers.
6
+ */
7
+ const PLACEHOLDER_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
8
+ export class PlaceholderError extends Error {
9
+ constructor(message) {
10
+ super(message);
11
+ this.name = 'PlaceholderError';
12
+ }
13
+ }
14
+ /**
15
+ * Replace :name placeholders with ? and return the names in bind order.
16
+ *
17
+ * @throws PlaceholderError when a colon is not a :name placeholder, a ? marker
18
+ * is already present, or a quote or block comment is left open.
19
+ */
20
+ export function rewriteNamedPlaceholders(sql) {
21
+ let out = '';
22
+ const names = [];
23
+ let i = 0;
24
+ while (i < sql.length) {
25
+ const ch = sql[i];
26
+ const next = sql[i + 1];
27
+ if (ch === '-' && next === '-') {
28
+ const end = sql.indexOf('\n', i);
29
+ if (end === -1) {
30
+ out += sql.slice(i);
31
+ break;
32
+ }
33
+ out += sql.slice(i, end);
34
+ i = end;
35
+ continue;
36
+ }
37
+ if (ch === '/' && next === '*') {
38
+ const end = sql.indexOf('*/', i + 2);
39
+ if (end === -1) {
40
+ throw new PlaceholderError('Unclosed block comment.');
41
+ }
42
+ out += sql.slice(i, end + 2);
43
+ i = end + 2;
44
+ continue;
45
+ }
46
+ if (ch === "'" || ch === '"') {
47
+ const end = endOfQuoted(sql, i, ch);
48
+ out += sql.slice(i, end);
49
+ i = end;
50
+ continue;
51
+ }
52
+ if (ch === '?') {
53
+ throw new PlaceholderError('Use :name placeholders. Question marks are reserved for bound parameters.');
54
+ }
55
+ if (ch === ':') {
56
+ const name = readPlaceholderName(sql, i + 1);
57
+ names.push(name);
58
+ out += '?';
59
+ i += 1 + name.length;
60
+ continue;
61
+ }
62
+ out += ch;
63
+ i += 1;
64
+ }
65
+ return { sql: out, names };
66
+ }
67
+ function readPlaceholderName(sql, start) {
68
+ let end = start;
69
+ while (end < sql.length && /[A-Za-z0-9_]/.test(sql[end])) {
70
+ end += 1;
71
+ }
72
+ const name = sql.slice(start, end);
73
+ if (!PLACEHOLDER_NAME.test(name)) {
74
+ throw new PlaceholderError('Invalid placeholder. Write :name using letters, digits, and underscores.');
75
+ }
76
+ return name;
77
+ }
78
+ function endOfQuoted(sql, start, quote) {
79
+ let i = start + 1;
80
+ while (i < sql.length) {
81
+ if (sql[i] === quote) {
82
+ if (sql[i + 1] === quote) {
83
+ i += 2;
84
+ continue;
85
+ }
86
+ return i + 1;
87
+ }
88
+ i += 1;
89
+ }
90
+ const kind = quote === "'" ? 'string literal' : 'quoted identifier';
91
+ throw new PlaceholderError(`Unclosed ${kind}.`);
92
+ }
93
+ //# sourceMappingURL=params.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"params.js","sourceRoot":"","sources":["../../src/customTools/params.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,gBAAgB,GAAG,0BAA0B,CAAC;AAEpD,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AASD;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CAAC,GAAW;IAClD,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,CAAC,GAAG,CAAC,CAAC;IAEV,OAAO,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC;QACtB,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;QAClB,MAAM,IAAI,GAAG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S;YACX,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,CAAC;QACf,CAAC;QACD,CAAC,IAAI,CAAC,CAAC;IACT,CAAC;IACD,MAAM,IAAI,GAAG,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,mBAAmB,CAAC;IACpE,MAAM,IAAI,gBAAgB,CAAC,YAAY,IAAI,GAAG,CAAC,CAAC;AAClD,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Process-wide custom tools, loaded once at startup.
3
+ */
4
+ import type { LoadedCustomTools, StoredAnnotation, StoredTool } from './loader.js';
5
+ type ParseOutcome = {
6
+ ok: true;
7
+ } | {
8
+ ok: false;
9
+ error: string;
10
+ violations?: string[];
11
+ };
12
+ export declare function cachedParse(toolName: string): ParseOutcome | undefined;
13
+ export declare function cacheParse(toolName: string, outcome: ParseOutcome): void;
14
+ export declare function setCustomTools(loaded: LoadedCustomTools): void;
15
+ export declare function getCustomTools(): LoadedCustomTools;
16
+ export declare function resetCustomTools(): void;
17
+ export type { StoredAnnotation, StoredTool };
18
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/customTools/registry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAMnF,KAAK,YAAY,GACb;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GACZ;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAIxD,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAEtE;AAED,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI,CAExE;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAG9D;AAED,wBAAgB,cAAc,IAAI,iBAAiB,CAElD;AAED,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC;AAED,YAAY,EAAE,gBAAgB,EAAE,UAAU,EAAE,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Process-wide custom tools, loaded once at startup.
3
+ */
4
+ const EMPTY = { tools: [], annotations: [] };
5
+ let current = EMPTY;
6
+ const parseCache = new Map();
7
+ export function cachedParse(toolName) {
8
+ return parseCache.get(toolName);
9
+ }
10
+ export function cacheParse(toolName, outcome) {
11
+ parseCache.set(toolName, outcome);
12
+ }
13
+ export function setCustomTools(loaded) {
14
+ current = loaded;
15
+ parseCache.clear();
16
+ }
17
+ export function getCustomTools() {
18
+ return current;
19
+ }
20
+ export function resetCustomTools() {
21
+ setCustomTools(EMPTY);
22
+ }
23
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/customTools/registry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,MAAM,KAAK,GAAsB,EAAE,KAAK,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC;AAEhE,IAAI,OAAO,GAAsB,KAAK,CAAC;AAMvC,MAAM,UAAU,GAAG,IAAI,GAAG,EAAwB,CAAC;AAEnD,MAAM,UAAU,WAAW,CAAC,QAAgB;IAC1C,OAAO,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,QAAgB,EAAE,OAAqB;IAChE,UAAU,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,MAAyB;IACtD,OAAO,GAAG,MAAM,CAAC;IACjB,UAAU,CAAC,KAAK,EAAE,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,cAAc;IAC5B,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,cAAc,CAAC,KAAK,CAAC,CAAC;AACxB,CAAC"}
@@ -0,0 +1,127 @@
1
+ /**
2
+ * File format for business SQL tools and table annotations.
3
+ */
4
+ import { z } from 'zod';
5
+ export declare const parameterSchema: z.ZodObject<{
6
+ type: z.ZodEnum<{
7
+ string: "string";
8
+ number: "number";
9
+ boolean: "boolean";
10
+ integer: "integer";
11
+ date: "date";
12
+ enum: "enum";
13
+ }>;
14
+ required: z.ZodOptional<z.ZodBoolean>;
15
+ maxLength: z.ZodOptional<z.ZodNumber>;
16
+ description: z.ZodOptional<z.ZodString>;
17
+ enum: z.ZodOptional<z.ZodArray<z.ZodString>>;
18
+ default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
19
+ }, z.core.$strict>;
20
+ export type ParameterDef = z.infer<typeof parameterSchema>;
21
+ export declare const relationSchema: z.ZodObject<{
22
+ table: z.ZodString;
23
+ join: z.ZodRecord<z.ZodString, z.ZodString>;
24
+ cardinality: z.ZodOptional<z.ZodEnum<{
25
+ "one-to-one": "one-to-one";
26
+ "one-to-many": "one-to-many";
27
+ "many-to-one": "many-to-one";
28
+ "many-to-many": "many-to-many";
29
+ }>>;
30
+ description: z.ZodOptional<z.ZodString>;
31
+ }, z.core.$strict>;
32
+ export type RelationDef = z.infer<typeof relationSchema>;
33
+ export declare const annotationSchema: z.ZodObject<{
34
+ entity: z.ZodOptional<z.ZodString>;
35
+ description: z.ZodOptional<z.ZodString>;
36
+ columns: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
37
+ relations: z.ZodOptional<z.ZodArray<z.ZodObject<{
38
+ table: z.ZodString;
39
+ join: z.ZodRecord<z.ZodString, z.ZodString>;
40
+ cardinality: z.ZodOptional<z.ZodEnum<{
41
+ "one-to-one": "one-to-one";
42
+ "one-to-many": "one-to-many";
43
+ "many-to-one": "many-to-one";
44
+ "many-to-many": "many-to-many";
45
+ }>>;
46
+ description: z.ZodOptional<z.ZodString>;
47
+ }, z.core.$strict>>>;
48
+ }, z.core.$strict>;
49
+ export type AnnotationDef = z.infer<typeof annotationSchema>;
50
+ export declare const toolSchema: z.ZodObject<{
51
+ name: z.ZodString;
52
+ title: z.ZodString;
53
+ toolset: z.ZodOptional<z.ZodString>;
54
+ description: z.ZodString;
55
+ parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
56
+ type: z.ZodEnum<{
57
+ string: "string";
58
+ number: "number";
59
+ boolean: "boolean";
60
+ integer: "integer";
61
+ date: "date";
62
+ enum: "enum";
63
+ }>;
64
+ required: z.ZodOptional<z.ZodBoolean>;
65
+ maxLength: z.ZodOptional<z.ZodNumber>;
66
+ description: z.ZodOptional<z.ZodString>;
67
+ enum: z.ZodOptional<z.ZodArray<z.ZodString>>;
68
+ default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
69
+ }, z.core.$strict>>>;
70
+ maxRows: z.ZodOptional<z.ZodNumber>;
71
+ sql: z.ZodString;
72
+ }, z.core.$strict>;
73
+ export type ToolDef = z.infer<typeof toolSchema>;
74
+ export declare const customToolsFileSchema: z.ZodObject<{
75
+ version: z.ZodLiteral<1>;
76
+ tools: z.ZodOptional<z.ZodArray<z.ZodObject<{
77
+ name: z.ZodString;
78
+ title: z.ZodString;
79
+ toolset: z.ZodOptional<z.ZodString>;
80
+ description: z.ZodString;
81
+ parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
82
+ type: z.ZodEnum<{
83
+ string: "string";
84
+ number: "number";
85
+ boolean: "boolean";
86
+ integer: "integer";
87
+ date: "date";
88
+ enum: "enum";
89
+ }>;
90
+ required: z.ZodOptional<z.ZodBoolean>;
91
+ maxLength: z.ZodOptional<z.ZodNumber>;
92
+ description: z.ZodOptional<z.ZodString>;
93
+ enum: z.ZodOptional<z.ZodArray<z.ZodString>>;
94
+ default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
95
+ }, z.core.$strict>>>;
96
+ maxRows: z.ZodOptional<z.ZodNumber>;
97
+ sql: z.ZodString;
98
+ }, z.core.$strict>>>;
99
+ annotations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
100
+ entity: z.ZodOptional<z.ZodString>;
101
+ description: z.ZodOptional<z.ZodString>;
102
+ columns: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
103
+ relations: z.ZodOptional<z.ZodArray<z.ZodObject<{
104
+ table: z.ZodString;
105
+ join: z.ZodRecord<z.ZodString, z.ZodString>;
106
+ cardinality: z.ZodOptional<z.ZodEnum<{
107
+ "one-to-one": "one-to-one";
108
+ "one-to-many": "one-to-many";
109
+ "many-to-one": "many-to-one";
110
+ "many-to-many": "many-to-many";
111
+ }>>;
112
+ description: z.ZodOptional<z.ZodString>;
113
+ }, z.core.$strict>>>;
114
+ }, z.core.$strict>>>;
115
+ }, z.core.$strict>;
116
+ export type CustomToolsFile = z.infer<typeof customToolsFileSchema>;
117
+ /**
118
+ * A default makes the argument optional. Otherwise it is required unless required is false.
119
+ * An omitted optional argument is bound as NULL.
120
+ */
121
+ export declare function parameterIsOptional(param: ParameterDef): boolean;
122
+ /**
123
+ * MCP input schema for one tool. Optional arguments accept null, which binds as NULL.
124
+ */
125
+ export declare function inputSchemaFor(parameters: Record<string, ParameterDef>): z.ZodObject;
126
+ export declare function formatSchemaIssues(error: z.ZodError): string;
127
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/customTools/schema.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,eAAO,MAAM,eAAe;;;;;;;;;;;;;;kBAyF1B,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAE3D,eAAO,MAAM,cAAc;;;;;;;;;;kBAazB,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAEzD,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;kBAQ3B,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE7D,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;kBAWrB,CAAC;AAEH,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAEjD,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAgBhC,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAKhE;AAID;;GAEG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC,SAAS,CA6BpF;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,CAAC,CAAC,QAAQ,GAAG,MAAM,CAO5D"}