@terreno/api 57.0.0-beta.1 → 57.1.0
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.
- package/.ai/skills/mongoose-schema-safety/SKILL.md +8 -0
- package/dist/actions.d.ts +7 -2
- package/dist/actions.js +60 -25
- package/dist/adminModelRouter.d.ts +14 -0
- package/dist/adminModelRouter.js +199 -0
- package/dist/adminTypes.d.ts +156 -0
- package/dist/adminTypes.js +5 -0
- package/dist/api.d.ts +44 -3
- package/dist/api.js +74 -26
- package/dist/auth.d.ts +18 -1
- package/dist/auth.js +122 -20
- package/dist/consentApp.d.ts +2 -0
- package/dist/consentApp.js +98 -0
- package/dist/index.d.ts +22 -1
- package/dist/index.js +51 -7
- package/dist/mcp/auth.d.ts +11 -0
- package/dist/mcp/auth.js +133 -0
- package/dist/mcp/createMCPRequest.d.ts +16 -0
- package/dist/mcp/createMCPRequest.js +26 -0
- package/dist/mcp/handlers.d.ts +8 -0
- package/dist/mcp/handlers.js +793 -0
- package/dist/mcp/query.d.ts +32 -0
- package/dist/mcp/query.js +232 -0
- package/dist/mcp/registry.d.ts +21 -0
- package/dist/mcp/registry.js +54 -0
- package/dist/mcp/schemaGenerator.d.ts +14 -0
- package/dist/mcp/schemaGenerator.js +379 -0
- package/dist/mcp/server.d.ts +8 -0
- package/dist/mcp/server.js +133 -0
- package/dist/mcp/toolGenerator.d.ts +14 -0
- package/dist/mcp/toolGenerator.js +246 -0
- package/dist/mcp/types.d.ts +85 -0
- package/dist/mcp/types.js +2 -0
- package/dist/openApi.d.ts +1 -1
- package/dist/openApi.js +26 -8
- package/dist/permissions.js +15 -15
- package/dist/rbac/access.d.ts +3 -0
- package/dist/rbac/access.js +294 -0
- package/dist/rbac/auditModel.d.ts +31 -0
- package/dist/rbac/auditModel.js +112 -0
- package/dist/rbac/backfillAdmins.d.ts +18 -0
- package/dist/rbac/backfillAdmins.js +139 -0
- package/dist/rbac/fieldViews.d.ts +3 -0
- package/dist/rbac/fieldViews.js +201 -0
- package/dist/rbac/middleware.d.ts +21 -0
- package/dist/rbac/middleware.js +108 -0
- package/dist/rbac/modelRouterAccess.d.ts +42 -0
- package/dist/rbac/modelRouterAccess.js +388 -0
- package/dist/rbac/permissionUtils.d.ts +8 -0
- package/dist/rbac/permissionUtils.js +209 -0
- package/dist/rbac/realtimeAccess.d.ts +18 -0
- package/dist/rbac/realtimeAccess.js +173 -0
- package/dist/rbac/resolve.d.ts +28 -0
- package/dist/rbac/resolve.js +387 -0
- package/dist/rbac/roleManager.d.ts +20 -0
- package/dist/rbac/roleManager.js +741 -0
- package/dist/rbac/roleModel.d.ts +42 -0
- package/dist/rbac/roleModel.js +267 -0
- package/dist/rbac/routes.d.ts +9 -0
- package/dist/rbac/routes.js +211 -0
- package/dist/rbac/scopes.d.ts +15 -0
- package/dist/rbac/scopes.js +155 -0
- package/dist/rbac/statements.d.ts +20 -0
- package/dist/rbac/statements.js +115 -0
- package/dist/rbac/types.d.ts +202 -0
- package/dist/rbac/types.js +2 -0
- package/dist/rbac/userPlugin.d.ts +12 -0
- package/dist/rbac/userPlugin.js +41 -0
- package/dist/realtime/changeStreamWatcher.d.ts +1 -1
- package/dist/realtime/changeStreamWatcher.js +48 -39
- package/dist/realtime/realtimeApp.js +4 -8
- package/dist/realtime/registry.d.ts +5 -0
- package/dist/realtime/registry.js +13 -1
- package/dist/scrubAdminFields.d.ts +17 -0
- package/dist/scrubAdminFields.js +192 -0
- package/dist/sync/executors.d.ts +1 -1
- package/dist/sync/executors.js +63 -40
- package/dist/sync/loadHarness.js +4 -5
- package/dist/sync/registry.d.ts +5 -0
- package/dist/sync/registry.js +13 -1
- package/dist/sync/routes.js +41 -36
- package/dist/sync/serialize.js +5 -6
- package/dist/terrenoApp.d.ts +18 -0
- package/dist/terrenoApp.js +46 -3
- package/dist/terrenoPlugin.d.ts +8 -1
- package/dist/tests/createTestData.js +8 -0
- package/dist/tests/models.d.ts +1 -0
- package/dist/tests/models.js +5 -0
- package/dist/tests/testHelper.js +1 -2
- package/dist/transformers.js +16 -1
- package/package.json +16 -12
- package/src/__snapshots__/openApi.test.ts.snap +192 -0
- package/src/actions.test.ts +194 -1
- package/src/actions.ts +65 -8
- package/src/adminModelRouter.ts +154 -0
- package/src/adminTypes.ts +183 -0
- package/src/api.test.ts +66 -1
- package/src/api.ts +131 -12
- package/src/auth.test.ts +135 -1
- package/src/auth.ts +81 -3
- package/src/consentApp.test.ts +24 -0
- package/src/consentApp.ts +100 -0
- package/src/index.ts +56 -0
- package/src/mcp/auth.test.ts +197 -0
- package/src/mcp/auth.ts +100 -0
- package/src/mcp/createMCPRequest.test.ts +47 -0
- package/src/mcp/createMCPRequest.ts +32 -0
- package/src/mcp/customTools.test.ts +54 -0
- package/src/mcp/handlers.ts +639 -0
- package/src/mcp/integration.test.ts +1493 -0
- package/src/mcp/query.test.ts +172 -0
- package/src/mcp/query.ts +179 -0
- package/src/mcp/registry.ts +70 -0
- package/src/mcp/schemaGenerator.test.ts +182 -0
- package/src/mcp/schemaGenerator.ts +354 -0
- package/src/mcp/server.test.ts +226 -0
- package/src/mcp/server.ts +86 -0
- package/src/mcp/toolGenerator.test.ts +284 -0
- package/src/mcp/toolGenerator.ts +199 -0
- package/src/mcp/types.ts +95 -0
- package/src/openApi.test.ts +107 -0
- package/src/openApi.ts +32 -1
- package/src/permissions.ts +3 -2
- package/src/rbac/access.test.ts +357 -0
- package/src/rbac/access.ts +201 -0
- package/src/rbac/auditModel.ts +103 -0
- package/src/rbac/backfillAdmins.ts +54 -0
- package/src/rbac/fieldViews.test.ts +39 -0
- package/src/rbac/fieldViews.ts +122 -0
- package/src/rbac/middleware.ts +55 -0
- package/src/rbac/modelRouterAccess.test.ts +336 -0
- package/src/rbac/modelRouterAccess.ts +331 -0
- package/src/rbac/permissionUtils.test.ts +112 -0
- package/src/rbac/permissionUtils.ts +83 -0
- package/src/rbac/realtimeAccess.test.ts +242 -0
- package/src/rbac/realtimeAccess.ts +138 -0
- package/src/rbac/resolve.test.ts +358 -0
- package/src/rbac/resolve.ts +285 -0
- package/src/rbac/roleManager.test.ts +915 -0
- package/src/rbac/roleManager.ts +440 -0
- package/src/rbac/roleModel.test.ts +114 -0
- package/src/rbac/roleModel.ts +196 -0
- package/src/rbac/routes.ts +170 -0
- package/src/rbac/scopes.test.ts +105 -0
- package/src/rbac/scopes.ts +81 -0
- package/src/rbac/statements.test.ts +65 -0
- package/src/rbac/statements.ts +62 -0
- package/src/rbac/types.ts +198 -0
- package/src/rbac/userPlugin.test.ts +55 -0
- package/src/rbac/userPlugin.ts +25 -0
- package/src/realtime/changeStreamWatcher.ts +20 -15
- package/src/realtime/realtime.test.ts +25 -1
- package/src/realtime/realtimeApp.ts +2 -5
- package/src/realtime/registry.ts +15 -0
- package/src/scrubAdminFields.test.ts +113 -0
- package/src/scrubAdminFields.ts +158 -0
- package/src/sync/executors.ts +31 -1
- package/src/sync/loadHarness.ts +8 -7
- package/src/sync/models.test.ts +262 -0
- package/src/sync/registry.ts +15 -0
- package/src/sync/routes.ts +25 -11
- package/src/sync/scripts/compactTombstones.test.ts +4 -6
- package/src/sync/serialize.ts +17 -9
- package/src/sync/sync.test.ts +52 -0
- package/src/sync/syncRoutes.test.ts +5 -2
- package/src/sync/syncSocket.test.ts +28 -0
- package/src/terrenoApp.test.ts +100 -0
- package/src/terrenoApp.ts +65 -3
- package/src/terrenoPlugin.ts +10 -1
- package/src/tests/bunSetup.ts +2 -0
- package/src/tests/createTestData.ts +5 -1
- package/src/tests/models.ts +6 -0
- package/src/tests/testHelper.ts +1 -3
- package/src/transformers.test.ts +12 -0
- package/src/transformers.ts +7 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ModelRouterOptions } from "../api";
|
|
2
|
+
import type { MCPConfig, MCPToolArgs } from "./types";
|
|
3
|
+
/** Args consumed by pagination/population, never treated as filters. */
|
|
4
|
+
export declare const RESERVED_LIST_ARGS: Set<string>;
|
|
5
|
+
/**
|
|
6
|
+
* Top-level logical operators an MCP client may send. Mirrors the REST list endpoint,
|
|
7
|
+
* which allows `$and` / `$or` and validates every nested key against `queryFields`.
|
|
8
|
+
*/
|
|
9
|
+
export declare const ALLOWED_LOGICAL_OPERATORS: Set<string>;
|
|
10
|
+
/**
|
|
11
|
+
* Comparison operators allowed inside a field's value, e.g. `{completed: {$ne: true}}`.
|
|
12
|
+
* Deliberately excludes evaluation operators that can run arbitrary code or ignore
|
|
13
|
+
* indexes ($where, $expr, $function, $accumulator, $jsonSchema, $text).
|
|
14
|
+
*/
|
|
15
|
+
export declare const ALLOWED_FIELD_OPERATORS: Set<string>;
|
|
16
|
+
export interface BuildListQueryResult {
|
|
17
|
+
query?: Record<string, unknown>;
|
|
18
|
+
error?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Build a Mongo query from MCP list tool args.
|
|
22
|
+
*
|
|
23
|
+
* Only fields in `options.queryFields` may be filtered on, and values may use the
|
|
24
|
+
* comparison operators in {@link ALLOWED_FIELD_OPERATORS} plus top-level `$and` / `$or`.
|
|
25
|
+
* Anything else is rejected rather than silently dropped so the calling LLM can correct
|
|
26
|
+
* itself instead of receiving results for a query it did not ask for.
|
|
27
|
+
*/
|
|
28
|
+
export declare const buildListQuery: ({ args, config, options, }: {
|
|
29
|
+
args: MCPToolArgs;
|
|
30
|
+
config: MCPConfig;
|
|
31
|
+
options: ModelRouterOptions<any>;
|
|
32
|
+
}) => BuildListQueryResult;
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __values = (this && this.__values) || function(o) {
|
|
14
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
15
|
+
if (m) return m.call(o);
|
|
16
|
+
if (o && typeof o.length === "number") return {
|
|
17
|
+
next: function () {
|
|
18
|
+
if (o && i >= o.length) o = void 0;
|
|
19
|
+
return { value: o && o[i++], done: !o };
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
23
|
+
};
|
|
24
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
25
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
26
|
+
if (!m) return o;
|
|
27
|
+
var i = m.call(o), r, ar = [], e;
|
|
28
|
+
try {
|
|
29
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
30
|
+
}
|
|
31
|
+
catch (error) { e = { error: error }; }
|
|
32
|
+
finally {
|
|
33
|
+
try {
|
|
34
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
35
|
+
}
|
|
36
|
+
finally { if (e) throw e.error; }
|
|
37
|
+
}
|
|
38
|
+
return ar;
|
|
39
|
+
};
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.buildListQuery = exports.ALLOWED_FIELD_OPERATORS = exports.ALLOWED_LOGICAL_OPERATORS = exports.RESERVED_LIST_ARGS = void 0;
|
|
42
|
+
var schemaGenerator_1 = require("./schemaGenerator");
|
|
43
|
+
/** Args consumed by pagination/population, never treated as filters. */
|
|
44
|
+
exports.RESERVED_LIST_ARGS = new Set(["limit", "page", "populate", "sort"]);
|
|
45
|
+
/**
|
|
46
|
+
* Top-level logical operators an MCP client may send. Mirrors the REST list endpoint,
|
|
47
|
+
* which allows `$and` / `$or` and validates every nested key against `queryFields`.
|
|
48
|
+
*/
|
|
49
|
+
exports.ALLOWED_LOGICAL_OPERATORS = new Set(["$and", "$or"]);
|
|
50
|
+
/**
|
|
51
|
+
* Comparison operators allowed inside a field's value, e.g. `{completed: {$ne: true}}`.
|
|
52
|
+
* Deliberately excludes evaluation operators that can run arbitrary code or ignore
|
|
53
|
+
* indexes ($where, $expr, $function, $accumulator, $jsonSchema, $text).
|
|
54
|
+
*/
|
|
55
|
+
exports.ALLOWED_FIELD_OPERATORS = new Set([
|
|
56
|
+
"$all",
|
|
57
|
+
"$eq",
|
|
58
|
+
"$exists",
|
|
59
|
+
"$gt",
|
|
60
|
+
"$gte",
|
|
61
|
+
"$in",
|
|
62
|
+
"$lt",
|
|
63
|
+
"$lte",
|
|
64
|
+
"$ne",
|
|
65
|
+
"$nin",
|
|
66
|
+
"$options",
|
|
67
|
+
"$regex",
|
|
68
|
+
"$size",
|
|
69
|
+
]);
|
|
70
|
+
var isPlainObject = function (value) {
|
|
71
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Recursively reject `$`-prefixed keys that are not in the field-operator allowlist.
|
|
75
|
+
* Non-operator keys are left alone so exact matches on embedded documents still work.
|
|
76
|
+
*
|
|
77
|
+
* @returns The offending operator name, or undefined when the value is safe.
|
|
78
|
+
*/
|
|
79
|
+
var findDisallowedOperator = function (value) {
|
|
80
|
+
var e_1, _a, e_2, _b;
|
|
81
|
+
if (Array.isArray(value)) {
|
|
82
|
+
try {
|
|
83
|
+
for (var value_1 = __values(value), value_1_1 = value_1.next(); !value_1_1.done; value_1_1 = value_1.next()) {
|
|
84
|
+
var item = value_1_1.value;
|
|
85
|
+
var found = findDisallowedOperator(item);
|
|
86
|
+
if (found) {
|
|
87
|
+
return found;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
92
|
+
finally {
|
|
93
|
+
try {
|
|
94
|
+
if (value_1_1 && !value_1_1.done && (_a = value_1.return)) _a.call(value_1);
|
|
95
|
+
}
|
|
96
|
+
finally { if (e_1) throw e_1.error; }
|
|
97
|
+
}
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
if (!isPlainObject(value)) {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
for (var _c = __values(Object.entries(value)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
105
|
+
var _e = __read(_d.value, 2), key = _e[0], nested = _e[1];
|
|
106
|
+
if (key.startsWith("$") && !exports.ALLOWED_FIELD_OPERATORS.has(key)) {
|
|
107
|
+
return key;
|
|
108
|
+
}
|
|
109
|
+
var found = findDisallowedOperator(nested);
|
|
110
|
+
if (found) {
|
|
111
|
+
return found;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
116
|
+
finally {
|
|
117
|
+
try {
|
|
118
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
119
|
+
}
|
|
120
|
+
finally { if (e_2) throw e_2.error; }
|
|
121
|
+
}
|
|
122
|
+
return undefined;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Validate one branch of a `$and` / `$or` clause. Every key must either be another
|
|
126
|
+
* logical operator or a field listed in `queryFields`, matching REST's behavior.
|
|
127
|
+
*/
|
|
128
|
+
var validateLogicalBranch = function (branch, allowedQueryFields) {
|
|
129
|
+
var e_3, _a;
|
|
130
|
+
if (!isPlainObject(branch)) {
|
|
131
|
+
return "Logical operators ($and/$or) take an array of filter objects";
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
for (var _b = __values(Object.entries(branch)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
135
|
+
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
136
|
+
if (exports.ALLOWED_LOGICAL_OPERATORS.has(key)) {
|
|
137
|
+
var error = validateLogicalClause(key, value, allowedQueryFields);
|
|
138
|
+
if (error) {
|
|
139
|
+
return error;
|
|
140
|
+
}
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (!allowedQueryFields.has(key)) {
|
|
144
|
+
return "".concat(key, " is not allowed as a filter field");
|
|
145
|
+
}
|
|
146
|
+
var disallowed = findDisallowedOperator(value);
|
|
147
|
+
if (disallowed) {
|
|
148
|
+
return "".concat(disallowed, " is not an allowed query operator");
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
153
|
+
finally {
|
|
154
|
+
try {
|
|
155
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
156
|
+
}
|
|
157
|
+
finally { if (e_3) throw e_3.error; }
|
|
158
|
+
}
|
|
159
|
+
return undefined;
|
|
160
|
+
};
|
|
161
|
+
var validateLogicalClause = function (operator, value, allowedQueryFields) {
|
|
162
|
+
var e_4, _a;
|
|
163
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
164
|
+
return "".concat(operator, " takes a non-empty array of filter objects");
|
|
165
|
+
}
|
|
166
|
+
try {
|
|
167
|
+
for (var value_2 = __values(value), value_2_1 = value_2.next(); !value_2_1.done; value_2_1 = value_2.next()) {
|
|
168
|
+
var branch = value_2_1.value;
|
|
169
|
+
var error = validateLogicalBranch(branch, allowedQueryFields);
|
|
170
|
+
if (error) {
|
|
171
|
+
return error;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
176
|
+
finally {
|
|
177
|
+
try {
|
|
178
|
+
if (value_2_1 && !value_2_1.done && (_a = value_2.return)) _a.call(value_2);
|
|
179
|
+
}
|
|
180
|
+
finally { if (e_4) throw e_4.error; }
|
|
181
|
+
}
|
|
182
|
+
return undefined;
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* Build a Mongo query from MCP list tool args.
|
|
186
|
+
*
|
|
187
|
+
* Only fields in `options.queryFields` may be filtered on, and values may use the
|
|
188
|
+
* comparison operators in {@link ALLOWED_FIELD_OPERATORS} plus top-level `$and` / `$or`.
|
|
189
|
+
* Anything else is rejected rather than silently dropped so the calling LLM can correct
|
|
190
|
+
* itself instead of receiving results for a query it did not ask for.
|
|
191
|
+
*/
|
|
192
|
+
var buildListQuery = function (_a) {
|
|
193
|
+
var e_5, _b;
|
|
194
|
+
var _c, _d, _e;
|
|
195
|
+
var args = _a.args, config = _a.config, options = _a.options;
|
|
196
|
+
var query = __assign({}, ((_c = options.defaultQueryParams) !== null && _c !== void 0 ? _c : {}));
|
|
197
|
+
var excludeFields = (_d = config.excludeFields) !== null && _d !== void 0 ? _d : [];
|
|
198
|
+
var allowedQueryFields = new Set(((_e = options.queryFields) !== null && _e !== void 0 ? _e : []).filter(function (field) { return !(0, schemaGenerator_1.isFieldExcluded)(field, excludeFields); }));
|
|
199
|
+
try {
|
|
200
|
+
for (var _f = __values(Object.entries(args)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
201
|
+
var _h = __read(_g.value, 2), key = _h[0], value = _h[1];
|
|
202
|
+
if (exports.RESERVED_LIST_ARGS.has(key) || value === undefined) {
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
if (exports.ALLOWED_LOGICAL_OPERATORS.has(key)) {
|
|
206
|
+
var error = validateLogicalClause(key, value, allowedQueryFields);
|
|
207
|
+
if (error) {
|
|
208
|
+
return { error: error };
|
|
209
|
+
}
|
|
210
|
+
query[key] = value;
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (!allowedQueryFields.has(key)) {
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
var disallowed = findDisallowedOperator(value);
|
|
217
|
+
if (disallowed) {
|
|
218
|
+
return { error: "".concat(disallowed, " is not an allowed query operator") };
|
|
219
|
+
}
|
|
220
|
+
query[key] = value;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
224
|
+
finally {
|
|
225
|
+
try {
|
|
226
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
227
|
+
}
|
|
228
|
+
finally { if (e_5) throw e_5.error; }
|
|
229
|
+
}
|
|
230
|
+
return { query: query };
|
|
231
|
+
};
|
|
232
|
+
exports.buildListQuery = buildListQuery;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Model } from "mongoose";
|
|
2
|
+
import type { ZodType } from "zod";
|
|
3
|
+
import type { ModelRouterOptions } from "../api";
|
|
4
|
+
import type { User } from "../auth";
|
|
5
|
+
import type { MCPConfig, MCPRegistryEntry, MCPToolArgs, MCPToolResult } from "./types";
|
|
6
|
+
export interface MCPCustomTool {
|
|
7
|
+
description: string;
|
|
8
|
+
handler: (args: MCPToolArgs, user?: User) => Promise<MCPToolResult>;
|
|
9
|
+
name: string;
|
|
10
|
+
zodSchema: ZodType;
|
|
11
|
+
}
|
|
12
|
+
export declare const registerMCPModel: (model: Model<any>, config: MCPConfig, options: ModelRouterOptions<any>) => void;
|
|
13
|
+
/**
|
|
14
|
+
* Replace options on an existing MCP registry entry after TerrenoApp injects
|
|
15
|
+
* accessControl (same contract as updateRealtimeRegistryOptions).
|
|
16
|
+
*/
|
|
17
|
+
export declare const updateMCPRegistryOptions: (modelName: string, options: ModelRouterOptions<unknown>) => void;
|
|
18
|
+
export declare const registerMCPTool: (tool: MCPCustomTool) => void;
|
|
19
|
+
export declare const getMCPRegistry: () => MCPRegistryEntry[];
|
|
20
|
+
export declare const getMCPCustomTools: () => MCPCustomTool[];
|
|
21
|
+
export declare const clearMCPRegistry: () => void;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.clearMCPRegistry = exports.getMCPCustomTools = exports.getMCPRegistry = exports.registerMCPTool = exports.updateMCPRegistryOptions = exports.registerMCPModel = void 0;
|
|
4
|
+
var mcpRegistry = [];
|
|
5
|
+
var mcpCustomTools = [];
|
|
6
|
+
var registerMCPModel = function (
|
|
7
|
+
// noExplicitAny: Mongoose's invariant generics require any to accept arbitrary consumer models
|
|
8
|
+
// biome-ignore lint/suspicious/noExplicitAny: Mongoose's invariant generics require any to accept arbitrary consumer models
|
|
9
|
+
model, config,
|
|
10
|
+
// noExplicitAny: ModelRouterOptions is generic over the consumer's document type
|
|
11
|
+
// biome-ignore lint/suspicious/noExplicitAny: ModelRouterOptions is generic over the consumer's document type
|
|
12
|
+
options) {
|
|
13
|
+
mcpRegistry.push({
|
|
14
|
+
config: config,
|
|
15
|
+
model: model,
|
|
16
|
+
modelName: model.modelName,
|
|
17
|
+
options: options,
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
exports.registerMCPModel = registerMCPModel;
|
|
21
|
+
/**
|
|
22
|
+
* Replace options on an existing MCP registry entry after TerrenoApp injects
|
|
23
|
+
* accessControl (same contract as updateRealtimeRegistryOptions).
|
|
24
|
+
*/
|
|
25
|
+
var updateMCPRegistryOptions = function (modelName, options) {
|
|
26
|
+
var existing = mcpRegistry.find(function (entry) { return entry.modelName === modelName; });
|
|
27
|
+
if (!existing) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
existing.options = options;
|
|
31
|
+
};
|
|
32
|
+
exports.updateMCPRegistryOptions = updateMCPRegistryOptions;
|
|
33
|
+
var registerMCPTool = function (tool) {
|
|
34
|
+
var existingIndex = mcpCustomTools.findIndex(function (registered) { return registered.name === tool.name; });
|
|
35
|
+
if (existingIndex >= 0) {
|
|
36
|
+
mcpCustomTools[existingIndex] = tool;
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
mcpCustomTools.push(tool);
|
|
40
|
+
};
|
|
41
|
+
exports.registerMCPTool = registerMCPTool;
|
|
42
|
+
var getMCPRegistry = function () {
|
|
43
|
+
return mcpRegistry;
|
|
44
|
+
};
|
|
45
|
+
exports.getMCPRegistry = getMCPRegistry;
|
|
46
|
+
var getMCPCustomTools = function () {
|
|
47
|
+
return mcpCustomTools;
|
|
48
|
+
};
|
|
49
|
+
exports.getMCPCustomTools = getMCPCustomTools;
|
|
50
|
+
var clearMCPRegistry = function () {
|
|
51
|
+
mcpRegistry.length = 0;
|
|
52
|
+
mcpCustomTools.length = 0;
|
|
53
|
+
};
|
|
54
|
+
exports.clearMCPRegistry = clearMCPRegistry;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Model } from "mongoose";
|
|
2
|
+
import { type ZodType } from "zod";
|
|
3
|
+
import type { PopulatePath } from "../populate";
|
|
4
|
+
import type { MCPConfig, MCPMethod } from "./types";
|
|
5
|
+
export declare const isFieldExcluded: (fieldPath: string, excludeFields: string[]) => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* REST write denylist from `validation.excludeFromCreate` / `excludeFromUpdate`.
|
|
8
|
+
* MCP create/update must apply the same keys REST strips in `validateModelRequestBody`.
|
|
9
|
+
*/
|
|
10
|
+
export declare const restWriteExcludeFields: (method: MCPMethod, validation: unknown) => string[];
|
|
11
|
+
/** MCP `excludeFields` plus REST write denylist — used for tool schemas and persist. */
|
|
12
|
+
export declare const writeExcludeFields: (config: MCPConfig, restExcludeFields: string[]) => string[];
|
|
13
|
+
export declare const generateInputSchema: (model: Model<any>, method: MCPMethod, config: MCPConfig, queryFields?: string[], populatePaths?: PopulatePath[], restExcludeFields?: string[]) => ZodType;
|
|
14
|
+
export declare const generateToolDescription: (model: Model<any>, method: MCPMethod, config: MCPConfig, queryFields?: string[], populatePaths?: PopulatePath[], restExcludeFields?: string[]) => string;
|