@happyvertical/smrt-app-mcp 0.51.32 → 0.51.33

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.
@@ -0,0 +1,22 @@
1
+ /** Machine-readable code for a principal policy denial. */
2
+ export declare const MCP_TOOL_ACCESS_DENIED_CODE = "mcp_tool_access_denied";
3
+ /**
4
+ * Metadata that is safe to expose for an app-MCP access failure. Policy
5
+ * implementations must not place principal, scope, tool, or internal-error
6
+ * details here.
7
+ */
8
+ export interface McpAccessErrorMetadata {
9
+ code?: string;
10
+ retryable?: boolean;
11
+ }
12
+ /**
13
+ * Error returned by the MCP app server when a caller tries to use a tool
14
+ * they are not allowed to access. The HTTP layer should map `status` onto
15
+ * the response status code.
16
+ */
17
+ export declare class McpAccessError extends Error {
18
+ readonly status: number;
19
+ readonly metadata: McpAccessErrorMetadata;
20
+ constructor(status: number, message: string, metadata?: McpAccessErrorMetadata);
21
+ }
22
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,eAAO,MAAM,2BAA2B,2BAA2B,CAAC;AAEpE;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;;GAIG;AACH,qBAAa,cAAe,SAAQ,KAAK;IAErC,QAAQ,CAAC,MAAM,EAAE,MAAM;IAEvB,QAAQ,CAAC,QAAQ,EAAE,sBAAsB;gBAFhC,MAAM,EAAE,MAAM,EACvB,OAAO,EAAE,MAAM,EACN,QAAQ,GAAE,sBAA2B;CAKjD"}
package/dist/index.d.ts CHANGED
@@ -1,291 +1,28 @@
1
- /**
2
- * `@happyvertical/smrt-app-mcp` — app-runtime MCP server scaffolding for
3
- * SMRT apps. Exposes a SMRT app's MCP surface over HTTP, regardless of how
4
- * the app is deployed.
5
- *
6
- * - **Core** (this module): `createMcpAppServer` wraps
7
- * `@happyvertical/smrt-core/generators/mcp` with allow-listing, a public
8
- * tool policy, and per-tool workflow assertions. Returns
9
- * `{ listTools, callTool }` you can mount however you like.
10
- *
11
- * - **SvelteKit** (`@happyvertical/smrt-app-mcp/sveltekit`): thin route
12
- * adapters that turn an `McpAppServer` into the GET/POST handlers a
13
- * SvelteKit `+server.ts` expects. Additional transport adapters
14
- * (standalone Node HTTP, serverless, Express/Hono/Fastify) can be added
15
- * as sibling subpaths without changes to the core.
16
- *
17
- * For piping a deployed app's MCP surface to a local stdio MCP client
18
- * (e.g. for editor/AI client integration), see
19
- * `@happyvertical/smrt-app-cli` — the client-side counterpart owns the
20
- * stdio bridge.
21
- *
22
- * @packageDocumentation
23
- */
24
-
25
- import { MCPConfig } from '@happyvertical/smrt-core/generators/mcp';
26
- import { MCPResponse } from '@happyvertical/smrt-core/generators/mcp';
27
- import { McpTask } from '@happyvertical/smrt-jobs';
28
- import { MCPTool } from '@happyvertical/smrt-core/generators/mcp';
29
- import { Server } from '@modelcontextprotocol/server';
30
- import { ServerContext } from '@modelcontextprotocol/server';
31
-
32
- /** Tool call inputs. */
33
- export declare interface CallToolInput {
34
- name: string;
35
- arguments?: Record<string, unknown>;
36
- /** Caller used for public/authenticated and optional tool-policy checks. */
37
- principal?: McpAppPrincipal | null;
38
- /**
39
- * Backwards-compatible user input. New callers should pass `principal`.
40
- * Null/undefined means unauthenticated.
41
- */
42
- user?: McpAppUser | null;
43
- }
44
-
45
- /**
46
- * Lower-case `<class>_` prefixes the app considers "allowed core tools"
47
- * given a list of SMRT class names. Used to build the allow-list for
48
- * `McpAppServer.listTools`.
49
- */
50
- export declare function classNamePrefixes(classNames: readonly string[]): ReadonlySet<string>;
51
-
52
- /**
53
- * Build the app-runtime MCP server core. The returned object is intentionally
54
- * framework-agnostic: HTTP wrappers live in `@happyvertical/smrt-app-mcp/sveltekit`,
55
- * this package's only other export.
56
- *
57
- * This package ships no stdio bridge. To pipe a deployed app's HTTP MCP surface
58
- * to a local stdio MCP client, use `@happyvertical/smrt-app-cli`, which provides
59
- * a generic `smrt-mcp-bridge` bin plus `runMcpStdioBridge` and
60
- * `createAppCli().startMcpBridge()` for branded entry points.
61
- */
62
- export declare function createMcpAppServer(options: CreateMcpAppServerOptions): McpAppServer;
63
-
64
- /**
65
- * Options for `createMcpAppServer`.
66
- */
67
- export declare interface CreateMcpAppServerOptions {
68
- /** SMRT context bag (db, etc.) passed to MCPGenerator per call. */
69
- smrtOptions: McpSmrtOptionsThunk;
70
- /** Server identity surfaced in the MCP protocol. */
71
- serverInfo: Required<Pick<MCPConfig, 'name' | 'version'>> & Pick<MCPConfig, 'description'>;
72
- /**
73
- * SMRT class names the app wants to publish. Tools whose name does not
74
- * start with any of these classes (lowercased + underscore) are filtered
75
- * out, even if SMRT generated them.
76
- */
77
- allowedClassNames: readonly string[];
78
- /**
79
- * Optional thunk returning glob-ish patterns for read-only tools that
80
- * unauthenticated callers are allowed to use. Defaults to an empty list
81
- * (everything requires auth).
82
- */
83
- publicToolPatterns?: McpPublicToolPatternsThunk;
84
- /**
85
- * Cache policy for the MCP tools/list result. Public caching is honored only
86
- * when this explicitly opts in and every allowed tool is a non-tenant,
87
- * unauthenticated read-only tool with no principal-aware policy.
88
- */
89
- toolListCache?: McpToolListCacheOptions;
90
- /**
91
- * Optional generic principal-aware tool policy. It is evaluated for every
92
- * tool that passes the app allow-list and base public/authenticated policy,
93
- * for both discovery and a direct call.
94
- */
95
- toolPolicy?: McpToolPolicy;
96
- /**
97
- * Optional per-tool guards. Keyed by tool name. The assertion runs after
98
- * tool resolution and before `MCPGenerator.handleToolCall`; throwing
99
- * `McpAccessError` aborts the call with the error's status. Implementations
100
- * may mutate `args` to inject trusted fields.
101
- */
102
- workflowAssertions?: Record<string, McpWorkflowAssertion>;
103
- }
104
-
105
- /**
106
- * Adapt an app MCP core to the SDK v2 low-level server protocol.
107
- *
108
- * Transport ownership remains with the caller. In particular, this does not
109
- * add a production HTTP endpoint; it is safe to compose with `serveStdio` or
110
- * `createMcpHandler` in a deployment that supplies its own authentication.
111
- */
112
- export declare function createMcpProtocolServer(appServer: McpAppServer, options?: McpProtocolServerOptions): Server;
113
-
114
- /**
115
- * Whether a given tool name starts with any of the configured class
116
- * prefixes.
117
- */
118
- export declare function isAllowedCoreTool(toolName: string, prefixes: ReadonlySet<string>): boolean;
119
-
120
- /**
121
- * Check whether a tool name is currently allowed for unauthenticated callers
122
- * given the configured public-tool patterns. Only read-only tools may ever
123
- * be public, regardless of pattern.
124
- */
125
- export declare function isPublicToolName(toolName: string, patterns: readonly string[]): boolean;
126
-
127
- /**
128
- * Read-only tool detection. Generated SMRT MCP tools follow the naming
129
- * convention `<class>_<verb>`; we treat `_list` and `_get` as read-only.
130
- */
131
- export declare function isReadOnlyToolName(toolName: string): boolean;
132
-
133
- /** Tool listing inputs. */
134
- export declare interface ListToolsInput {
135
- /** Caller used for public/authenticated and optional tool-policy checks. */
136
- principal?: McpAppPrincipal | null;
137
- /**
138
- * Backwards-compatible authenticated marker. New mounts should pass
139
- * `principal` so discovery and direct calls use the same identity.
140
- */
141
- authenticated?: boolean;
142
- }
143
-
144
- /**
145
- * Match a tool name against a glob-ish pattern with `*` wildcards.
146
- *
147
- * - Empty pattern → never matches.
148
- * - `*` → matches everything.
149
- * - `prefix_*` → matches anything starting with `prefix_`.
150
- * - `*_suffix` → matches anything ending with `_suffix`.
151
- * - `a_*_b` → matches any name containing `a_`, then any text, then `_b`.
152
- *
153
- * No regex characters are special besides `*` — the input is treated as a
154
- * literal string with star wildcards.
155
- */
156
- export declare function matchesToolPattern(toolName: string, pattern: string): boolean;
157
-
158
- /** Machine-readable code for a principal policy denial. */
159
- export declare const MCP_TOOL_ACCESS_DENIED_CODE = "mcp_tool_access_denied";
160
-
161
- /**
162
- * Error returned by the MCP app server when a caller tries to use a tool
163
- * they are not allowed to access. The HTTP layer should map `status` onto
164
- * the response status code.
165
- */
166
- export declare class McpAccessError extends Error {
167
- readonly status: number;
168
- readonly metadata: McpAccessErrorMetadata;
169
- constructor(status: number, message: string, metadata?: McpAccessErrorMetadata);
170
- }
171
-
172
- /**
173
- * Metadata that is safe to expose for an app-MCP access failure. Policy
174
- * implementations must not place principal, scope, tool, or internal-error
175
- * details here.
176
- */
177
- export declare interface McpAccessErrorMetadata {
178
- code?: string;
179
- retryable?: boolean;
180
- }
181
-
182
- /**
183
- * Generic authenticated caller information available to app-MCP policy.
184
- *
185
- * `kind`, `roles`, and `scopes` are deliberately unconstrained so an app can
186
- * represent a human or a scoped service without this package encoding an
187
- * application's identity or capability model. A missing principal means the
188
- * request is unauthenticated.
189
- */
190
- export declare interface McpAppPrincipal {
191
- id?: string;
192
- /** Tenant boundary for task ownership and generated tenant-scoped actions. */
193
- tenantId?: string;
194
- /** Trusted operator override for generated tenant-scoped actions. */
195
- allowCrossTenant?: boolean;
196
- kind?: string;
197
- roles?: string[];
198
- scopes?: string[];
199
- }
200
-
201
- /** Shape returned by `createMcpAppServer`. */
202
- export declare interface McpAppServer {
203
- listTools(input: ListToolsInput): Promise<MCPTool[]>;
204
- callTool(input: CallToolInput): Promise<MCPResponse>;
205
- /** Whether this app has any explicitly enabled Tasks extension action. */
206
- hasTaskSupport?(): Promise<boolean>;
207
- /** Whether a particular visible tool is task-enabled. */
208
- isTaskTool?(name: string): Promise<boolean>;
209
- /** Static declaration used by the protocol discovery capability surface. */
210
- readonly tasksEnabled?: boolean;
211
- /** Create a durable task after applying the same tool policy as tools/call. */
212
- callTask?(input: CallToolInput): Promise<MCPResponse>;
213
- /** Principal-scoped task lifecycle operations. */
214
- getTask?(input: {
215
- taskId: string;
216
- principal?: McpAppPrincipal | null;
217
- }): Promise<McpTask>;
218
- updateTask?(input: {
219
- taskId: string;
220
- inputResponses: Record<string, unknown>;
221
- principal?: McpAppPrincipal | null;
222
- }): Promise<void>;
223
- cancelTask?(input: {
224
- taskId: string;
225
- principal?: McpAppPrincipal | null;
226
- }): Promise<void>;
227
- /** Cache policy for protocol tools/list responses. */
228
- getToolsListCacheHint?(): Promise<McpToolListCacheHint>;
229
- /** Read-only view of the configured server identity. */
230
- readonly serverInfo: CreateMcpAppServerOptions['serverInfo'];
231
- }
232
-
233
- /** Minimal legacy user shape used for generated tool-call attribution. */
234
- export declare interface McpAppUser extends McpAppPrincipal {
235
- id: string;
236
- }
237
-
238
- export declare interface McpProtocolServerOptions {
239
- /** Resolve the authenticated application principal for each MCP request. */
240
- principal?: McpAppPrincipal | null | ((context: ServerContext) => McpAppPrincipal | null | Promise<McpAppPrincipal | null>);
241
- }
242
-
243
- /** Public-tool patterns thunk — same lazy-evaluation rationale. */
244
- export declare type McpPublicToolPatternsThunk = () => readonly string[];
245
-
246
- /**
247
- * SMRT options thunk — returns the `{ db }` (and similar) bag to pass into
248
- * MCPGenerator's per-request context. A function is used so apps can lazily
249
- * resolve env vars at call time.
250
- */
251
- export declare type McpSmrtOptionsThunk = () => Record<string, unknown>;
252
-
253
- export declare interface McpToolListCacheHint {
254
- ttlMs: number;
255
- cacheScope: 'private' | 'public';
256
- }
257
-
258
- export declare interface McpToolListCacheOptions {
259
- /** Cache lifetime in milliseconds. Defaults to one day for a deploy-static catalog. */
260
- ttlMs?: number;
261
- /** Requested cache visibility. Defaults to private. */
262
- cacheScope?: 'private' | 'public';
263
- /**
264
- * Explicit attestation that every allowed tool is global, unauthenticated,
265
- * and safe to share through an intermediary cache.
266
- */
267
- publicCatalog?: true;
268
- }
269
-
270
- /**
271
- * Per-tool access policy. Return `true` to expose/allow the tool and `false`
272
- * to hide it from discovery and deny a direct call. A thrown error is treated
273
- * as a denial so policy implementation details cannot escape the app-MCP
274
- * boundary.
275
- */
276
- export declare type McpToolPolicy = (context: McpToolPolicyContext) => boolean | Promise<boolean>;
277
-
278
- /** Context supplied to the optional per-tool principal policy. */
279
- export declare interface McpToolPolicyContext {
280
- principal: McpAppPrincipal | null;
281
- tool: MCPTool;
282
- }
283
-
284
- /**
285
- * Workflow assertion hook signature. Throw `McpAccessError` to reject the
286
- * call. Implementations may mutate `args` in place to inject server-trusted
287
- * fields (e.g. clamping `approvedByUserId` to the authenticated user's id).
288
- */
289
- export declare type McpWorkflowAssertion = (args: Record<string, unknown>, user: McpAppUser | null) => void;
290
-
291
- export { }
1
+ /**
2
+ * `@happyvertical/smrt-app-mcp` — app-runtime MCP server scaffolding for
3
+ * SMRT apps. Exposes a SMRT app's MCP surface over HTTP, regardless of how
4
+ * the app is deployed.
5
+ *
6
+ * - **Core** (this module): `createMcpAppServer` wraps
7
+ * `@happyvertical/smrt-core/generators/mcp` with allow-listing, a public
8
+ * tool policy, and per-tool workflow assertions. Returns
9
+ * `{ listTools, callTool }` you can mount however you like.
10
+ *
11
+ * - **SvelteKit** (`@happyvertical/smrt-app-mcp/sveltekit`): thin route
12
+ * adapters that turn an `McpAppServer` into the GET/POST handlers a
13
+ * SvelteKit `+server.ts` expects. Additional transport adapters
14
+ * (standalone Node HTTP, serverless, Express/Hono/Fastify) can be added
15
+ * as sibling subpaths without changes to the core.
16
+ *
17
+ * For piping a deployed app's MCP surface to a local stdio MCP client
18
+ * (e.g. for editor/AI client integration), see
19
+ * `@happyvertical/smrt-app-cli` — the client-side counterpart owns the
20
+ * stdio bridge.
21
+ *
22
+ * @packageDocumentation
23
+ */
24
+ export { MCP_TOOL_ACCESS_DENIED_CODE, McpAccessError, type McpAccessErrorMetadata, } from './errors.js';
25
+ export { createMcpProtocolServer, type McpProtocolServerOptions, } from './protocol.js';
26
+ export { type CallToolInput, type CreateMcpAppServerOptions, createMcpAppServer, type ListToolsInput, type McpAppPrincipal, type McpAppServer, type McpAppUser, type McpPublicToolPatternsThunk, type McpSmrtOptionsThunk, type McpToolListCacheHint, type McpToolListCacheOptions, type McpToolPolicy, type McpToolPolicyContext, type McpWorkflowAssertion, } from './server.js';
27
+ export { classNamePrefixes, isAllowedCoreTool, isPublicToolName, isReadOnlyToolName, matchesToolPattern, } from './tools.js';
28
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EACL,2BAA2B,EAC3B,cAAc,EACd,KAAK,sBAAsB,GAC5B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,uBAAuB,EACvB,KAAK,wBAAwB,GAC9B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,yBAAyB,EAC9B,kBAAkB,EAClB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,0BAA0B,EAC/B,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,GAC1B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,YAAY,CAAC"}
@@ -2,7 +2,7 @@
2
2
  "version": "1.0.0",
3
3
  "timestamp": 0,
4
4
  "packageName": "@happyvertical/smrt-app-mcp",
5
- "packageVersion": "0.51.32",
5
+ "packageVersion": "0.51.33",
6
6
  "objects": {},
7
7
  "moduleType": "smrt",
8
8
  "smrtDependencies": [
@@ -0,0 +1,17 @@
1
+ /** MCP SDK v2 protocol adapter for the framework-neutral app server core. */
2
+ import { Server, type ServerContext } from '@modelcontextprotocol/server';
3
+ import type { McpAppPrincipal, McpAppServer } from './server.js';
4
+ export declare const MCP_TASKS_EXTENSION = "io.modelcontextprotocol/tasks";
5
+ export interface McpProtocolServerOptions {
6
+ /** Resolve the authenticated application principal for each MCP request. */
7
+ principal?: McpAppPrincipal | null | ((context: ServerContext) => McpAppPrincipal | null | Promise<McpAppPrincipal | null>);
8
+ }
9
+ /**
10
+ * Adapt an app MCP core to the SDK v2 low-level server protocol.
11
+ *
12
+ * Transport ownership remains with the caller. In particular, this does not
13
+ * add a production HTTP endpoint; it is safe to compose with `serveStdio` or
14
+ * `createMcpHandler` in a deployment that supplies its own authentication.
15
+ */
16
+ export declare function createMcpProtocolServer(appServer: McpAppServer, options?: McpProtocolServerOptions): Server;
17
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,OAAO,EAIL,MAAM,EACN,KAAK,aAAa,EAEnB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGjE,eAAO,MAAM,mBAAmB,kCAAkC,CAAC;AAOnE,MAAM,WAAW,wBAAwB;IACvC,4EAA4E;IAC5E,SAAS,CAAC,EACN,eAAe,GACf,IAAI,GACJ,CAAC,CACC,OAAO,EAAE,aAAa,KACnB,eAAe,GAAG,IAAI,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC,CAAC;CACpE;AAUD;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,YAAY,EACvB,OAAO,GAAE,wBAA6B,GACrC,MAAM,CAsDR"}
@@ -0,0 +1,187 @@
1
+ /**
2
+ * `createMcpAppServer` returns the framework-agnostic core that backs an
3
+ * app's HTTP MCP endpoints and transport-neutral protocol adapter. It wraps
4
+ * `MCPGenerator` from `@happyvertical/smrt-core` with:
5
+ *
6
+ * - an allow-list of SMRT class names (so apps publish a subset of their
7
+ * objects, not everything decorated with `@smrt()`),
8
+ * - a public-tool policy for unauthenticated callers (read-only patterns
9
+ * via `publicToolPatterns`),
10
+ * - an optional principal-aware `toolPolicy`, used for both discovery and
11
+ * direct calls,
12
+ * - a pluggable `workflowAssertions` hook so apps can guard their own
13
+ * domain-specific tool calls (e.g. "approval requires an authenticated
14
+ * user") without that policy living in this package.
15
+ *
16
+ * @packageDocumentation
17
+ */
18
+ import type { MCPConfig, MCPResponse, MCPTool } from '@happyvertical/smrt-core/generators/mcp';
19
+ import { type McpTask } from '@happyvertical/smrt-jobs';
20
+ /**
21
+ * Generic authenticated caller information available to app-MCP policy.
22
+ *
23
+ * `kind`, `roles`, and `scopes` are deliberately unconstrained so an app can
24
+ * represent a human or a scoped service without this package encoding an
25
+ * application's identity or capability model. A missing principal means the
26
+ * request is unauthenticated.
27
+ */
28
+ export interface McpAppPrincipal {
29
+ id?: string;
30
+ /** Tenant boundary for task ownership and generated tenant-scoped actions. */
31
+ tenantId?: string;
32
+ /** Trusted operator override for generated tenant-scoped actions. */
33
+ allowCrossTenant?: boolean;
34
+ kind?: string;
35
+ roles?: string[];
36
+ scopes?: string[];
37
+ }
38
+ /** Minimal legacy user shape used for generated tool-call attribution. */
39
+ export interface McpAppUser extends McpAppPrincipal {
40
+ id: string;
41
+ }
42
+ /** Context supplied to the optional per-tool principal policy. */
43
+ export interface McpToolPolicyContext {
44
+ principal: McpAppPrincipal | null;
45
+ tool: MCPTool;
46
+ }
47
+ /**
48
+ * Per-tool access policy. Return `true` to expose/allow the tool and `false`
49
+ * to hide it from discovery and deny a direct call. A thrown error is treated
50
+ * as a denial so policy implementation details cannot escape the app-MCP
51
+ * boundary.
52
+ */
53
+ export type McpToolPolicy = (context: McpToolPolicyContext) => boolean | Promise<boolean>;
54
+ /**
55
+ * Workflow assertion hook signature. Throw `McpAccessError` to reject the
56
+ * call. Implementations may mutate `args` in place to inject server-trusted
57
+ * fields (e.g. clamping `approvedByUserId` to the authenticated user's id).
58
+ */
59
+ export type McpWorkflowAssertion = (args: Record<string, unknown>, user: McpAppUser | null) => void;
60
+ /**
61
+ * SMRT options thunk — returns the `{ db }` (and similar) bag to pass into
62
+ * MCPGenerator's per-request context. A function is used so apps can lazily
63
+ * resolve env vars at call time.
64
+ */
65
+ export type McpSmrtOptionsThunk = () => Record<string, unknown>;
66
+ /** Public-tool patterns thunk — same lazy-evaluation rationale. */
67
+ export type McpPublicToolPatternsThunk = () => readonly string[];
68
+ export interface McpToolListCacheHint {
69
+ ttlMs: number;
70
+ cacheScope: 'private' | 'public';
71
+ }
72
+ export interface McpToolListCacheOptions {
73
+ /** Cache lifetime in milliseconds. Defaults to one day for a deploy-static catalog. */
74
+ ttlMs?: number;
75
+ /** Requested cache visibility. Defaults to private. */
76
+ cacheScope?: 'private' | 'public';
77
+ /**
78
+ * Explicit attestation that every allowed tool is global, unauthenticated,
79
+ * and safe to share through an intermediary cache.
80
+ */
81
+ publicCatalog?: true;
82
+ }
83
+ /**
84
+ * Options for `createMcpAppServer`.
85
+ */
86
+ export interface CreateMcpAppServerOptions {
87
+ /** SMRT context bag (db, etc.) passed to MCPGenerator per call. */
88
+ smrtOptions: McpSmrtOptionsThunk;
89
+ /** Server identity surfaced in the MCP protocol. */
90
+ serverInfo: Required<Pick<MCPConfig, 'name' | 'version'>> & Pick<MCPConfig, 'description'>;
91
+ /**
92
+ * SMRT class names the app wants to publish. Tools whose name does not
93
+ * start with any of these classes (lowercased + underscore) are filtered
94
+ * out, even if SMRT generated them.
95
+ */
96
+ allowedClassNames: readonly string[];
97
+ /**
98
+ * Optional thunk returning glob-ish patterns for read-only tools that
99
+ * unauthenticated callers are allowed to use. Defaults to an empty list
100
+ * (everything requires auth).
101
+ */
102
+ publicToolPatterns?: McpPublicToolPatternsThunk;
103
+ /**
104
+ * Cache policy for the MCP tools/list result. Public caching is honored only
105
+ * when this explicitly opts in and every allowed tool is a non-tenant,
106
+ * unauthenticated read-only tool with no principal-aware policy.
107
+ */
108
+ toolListCache?: McpToolListCacheOptions;
109
+ /**
110
+ * Optional generic principal-aware tool policy. It is evaluated for every
111
+ * tool that passes the app allow-list and base public/authenticated policy,
112
+ * for both discovery and a direct call.
113
+ */
114
+ toolPolicy?: McpToolPolicy;
115
+ /**
116
+ * Optional per-tool guards. Keyed by tool name. The assertion runs after
117
+ * tool resolution and before `MCPGenerator.handleToolCall`; throwing
118
+ * `McpAccessError` aborts the call with the error's status. Implementations
119
+ * may mutate `args` to inject trusted fields.
120
+ */
121
+ workflowAssertions?: Record<string, McpWorkflowAssertion>;
122
+ }
123
+ /** Tool listing inputs. */
124
+ export interface ListToolsInput {
125
+ /** Caller used for public/authenticated and optional tool-policy checks. */
126
+ principal?: McpAppPrincipal | null;
127
+ /**
128
+ * Backwards-compatible authenticated marker. New mounts should pass
129
+ * `principal` so discovery and direct calls use the same identity.
130
+ */
131
+ authenticated?: boolean;
132
+ }
133
+ /** Tool call inputs. */
134
+ export interface CallToolInput {
135
+ name: string;
136
+ arguments?: Record<string, unknown>;
137
+ /** Caller used for public/authenticated and optional tool-policy checks. */
138
+ principal?: McpAppPrincipal | null;
139
+ /**
140
+ * Backwards-compatible user input. New callers should pass `principal`.
141
+ * Null/undefined means unauthenticated.
142
+ */
143
+ user?: McpAppUser | null;
144
+ }
145
+ /** Shape returned by `createMcpAppServer`. */
146
+ export interface McpAppServer {
147
+ listTools(input: ListToolsInput): Promise<MCPTool[]>;
148
+ callTool(input: CallToolInput): Promise<MCPResponse>;
149
+ /** Whether this app has any explicitly enabled Tasks extension action. */
150
+ hasTaskSupport?(): Promise<boolean>;
151
+ /** Whether a particular visible tool is task-enabled. */
152
+ isTaskTool?(name: string): Promise<boolean>;
153
+ /** Static declaration used by the protocol discovery capability surface. */
154
+ readonly tasksEnabled?: boolean;
155
+ /** Create a durable task after applying the same tool policy as tools/call. */
156
+ callTask?(input: CallToolInput): Promise<MCPResponse>;
157
+ /** Principal-scoped task lifecycle operations. */
158
+ getTask?(input: {
159
+ taskId: string;
160
+ principal?: McpAppPrincipal | null;
161
+ }): Promise<McpTask>;
162
+ updateTask?(input: {
163
+ taskId: string;
164
+ inputResponses: Record<string, unknown>;
165
+ principal?: McpAppPrincipal | null;
166
+ }): Promise<void>;
167
+ cancelTask?(input: {
168
+ taskId: string;
169
+ principal?: McpAppPrincipal | null;
170
+ }): Promise<void>;
171
+ /** Cache policy for protocol tools/list responses. */
172
+ getToolsListCacheHint?(): Promise<McpToolListCacheHint>;
173
+ /** Read-only view of the configured server identity. */
174
+ readonly serverInfo: CreateMcpAppServerOptions['serverInfo'];
175
+ }
176
+ /**
177
+ * Build the app-runtime MCP server core. The returned object is intentionally
178
+ * framework-agnostic: HTTP wrappers live in `@happyvertical/smrt-app-mcp/sveltekit`,
179
+ * this package's only other export.
180
+ *
181
+ * This package ships no stdio bridge. To pipe a deployed app's HTTP MCP surface
182
+ * to a local stdio MCP client, use `@happyvertical/smrt-app-cli`, which provides
183
+ * a generic `smrt-mcp-bridge` bin plus `runMcpStdioBridge` and
184
+ * `createAppCli().startMcpBridge()` for branded entry points.
185
+ */
186
+ export declare function createMcpAppServer(options: CreateMcpAppServerOptions): McpAppServer;
187
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"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"}
@@ -3,12 +3,12 @@
3
3
  "sensitiveFieldsExcluded": true,
4
4
  "generatedAt": "1970-01-01T00:00:00.000Z",
5
5
  "packageName": "@happyvertical/smrt-app-mcp",
6
- "packageVersion": "0.51.32",
6
+ "packageVersion": "0.51.33",
7
7
  "sourceManifestPath": "dist/manifest.json",
8
8
  "agentDocPath": "AGENTS.md",
9
9
  "sourceHashes": {
10
- "manifest": "ff679d29e866c2fee7c465e1860d8f036cac83610dfbdfaba577fef4e7a668fa",
11
- "packageJson": "837f8bf64bd6996a2be0dce093a69251e1c1bdbc363da8942e9304fa673939b8",
10
+ "manifest": "fc2779973c05bfe3e70eca1edaa988f026a9f7ea579ceb3e2e17bbd29953b982",
11
+ "packageJson": "3ff32319c69910aec08b54929baa3d05372995cf3c63418aed7ca860b481251a",
12
12
  "agents": "b4f2b874e2c5c83b91b77ccf4aeaae3fd58ad9eb2aba2e5d1efd118564aa0730"
13
13
  },
14
14
  "exports": [
@@ -24,7 +24,7 @@
24
24
  "@modelcontextprotocol/conformance": "0.2.0-alpha.11",
25
25
  "@modelcontextprotocol/node": "2.0.0",
26
26
  "@types/node": "24.13.6",
27
- "typescript": "5.9.3",
27
+ "typescript": "6.0.3",
28
28
  "vite": "8.1.4",
29
29
  "vitest": "4.1.10"
30
30
  },
@@ -1,257 +1,72 @@
1
- import { MCPConfig } from '@happyvertical/smrt-core/generators/mcp';
2
- import { MCPResponse } from '@happyvertical/smrt-core/generators/mcp';
3
- import { McpTask } from '@happyvertical/smrt-jobs';
4
- import { MCPTool } from '@happyvertical/smrt-core/generators/mcp';
5
-
6
- /** Tool call inputs. */
7
- declare interface CallToolInput {
8
- name: string;
9
- arguments?: Record<string, unknown>;
10
- /** Caller used for public/authenticated and optional tool-policy checks. */
11
- principal?: McpAppPrincipal | null;
12
- /**
13
- * Backwards-compatible user input. New callers should pass `principal`.
14
- * Null/undefined means unauthenticated.
15
- */
16
- user?: McpAppUser | null;
17
- }
18
-
19
- /**
20
- * Options for `createMcpAppServer`.
21
- */
22
- declare interface CreateMcpAppServerOptions {
23
- /** SMRT context bag (db, etc.) passed to MCPGenerator per call. */
24
- smrtOptions: McpSmrtOptionsThunk;
25
- /** Server identity surfaced in the MCP protocol. */
26
- serverInfo: Required<Pick<MCPConfig, 'name' | 'version'>> & Pick<MCPConfig, 'description'>;
27
- /**
28
- * SMRT class names the app wants to publish. Tools whose name does not
29
- * start with any of these classes (lowercased + underscore) are filtered
30
- * out, even if SMRT generated them.
31
- */
32
- allowedClassNames: readonly string[];
33
- /**
34
- * Optional thunk returning glob-ish patterns for read-only tools that
35
- * unauthenticated callers are allowed to use. Defaults to an empty list
36
- * (everything requires auth).
37
- */
38
- publicToolPatterns?: McpPublicToolPatternsThunk;
39
- /**
40
- * Cache policy for the MCP tools/list result. Public caching is honored only
41
- * when this explicitly opts in and every allowed tool is a non-tenant,
42
- * unauthenticated read-only tool with no principal-aware policy.
43
- */
44
- toolListCache?: McpToolListCacheOptions;
45
- /**
46
- * Optional generic principal-aware tool policy. It is evaluated for every
47
- * tool that passes the app allow-list and base public/authenticated policy,
48
- * for both discovery and a direct call.
49
- */
50
- toolPolicy?: McpToolPolicy;
51
- /**
52
- * Optional per-tool guards. Keyed by tool name. The assertion runs after
53
- * tool resolution and before `MCPGenerator.handleToolCall`; throwing
54
- * `McpAccessError` aborts the call with the error's status. Implementations
55
- * may mutate `args` to inject trusted fields.
56
- */
57
- workflowAssertions?: Record<string, McpWorkflowAssertion>;
58
- }
59
-
60
- /** Tool listing inputs. */
61
- declare interface ListToolsInput {
62
- /** Caller used for public/authenticated and optional tool-policy checks. */
63
- principal?: McpAppPrincipal | null;
64
- /**
65
- * Backwards-compatible authenticated marker. New mounts should pass
66
- * `principal` so discovery and direct calls use the same identity.
67
- */
68
- authenticated?: boolean;
69
- }
70
-
71
- /**
72
- * Error returned by the MCP app server when a caller tries to use a tool
73
- * they are not allowed to access. The HTTP layer should map `status` onto
74
- * the response status code.
75
- */
76
- export declare class McpAccessError extends Error {
77
- readonly status: number;
78
- readonly metadata: McpAccessErrorMetadata;
79
- constructor(status: number, message: string, metadata?: McpAccessErrorMetadata);
80
- }
81
-
82
- /**
83
- * Metadata that is safe to expose for an app-MCP access failure. Policy
84
- * implementations must not place principal, scope, tool, or internal-error
85
- * details here.
86
- */
87
- declare interface McpAccessErrorMetadata {
88
- code?: string;
89
- retryable?: boolean;
90
- }
91
-
92
- /**
93
- * Generic authenticated caller information available to app-MCP policy.
94
- *
95
- * `kind`, `roles`, and `scopes` are deliberately unconstrained so an app can
96
- * represent a human or a scoped service without this package encoding an
97
- * application's identity or capability model. A missing principal means the
98
- * request is unauthenticated.
99
- */
100
- export declare interface McpAppPrincipal {
101
- id?: string;
102
- /** Tenant boundary for task ownership and generated tenant-scoped actions. */
103
- tenantId?: string;
104
- /** Trusted operator override for generated tenant-scoped actions. */
105
- allowCrossTenant?: boolean;
106
- kind?: string;
107
- roles?: string[];
108
- scopes?: string[];
109
- }
110
-
111
- /** Shape returned by `createMcpAppServer`. */
112
- export declare interface McpAppServer {
113
- listTools(input: ListToolsInput): Promise<MCPTool[]>;
114
- callTool(input: CallToolInput): Promise<MCPResponse>;
115
- /** Whether this app has any explicitly enabled Tasks extension action. */
116
- hasTaskSupport?(): Promise<boolean>;
117
- /** Whether a particular visible tool is task-enabled. */
118
- isTaskTool?(name: string): Promise<boolean>;
119
- /** Static declaration used by the protocol discovery capability surface. */
120
- readonly tasksEnabled?: boolean;
121
- /** Create a durable task after applying the same tool policy as tools/call. */
122
- callTask?(input: CallToolInput): Promise<MCPResponse>;
123
- /** Principal-scoped task lifecycle operations. */
124
- getTask?(input: {
125
- taskId: string;
126
- principal?: McpAppPrincipal | null;
127
- }): Promise<McpTask>;
128
- updateTask?(input: {
129
- taskId: string;
130
- inputResponses: Record<string, unknown>;
131
- principal?: McpAppPrincipal | null;
132
- }): Promise<void>;
133
- cancelTask?(input: {
134
- taskId: string;
135
- principal?: McpAppPrincipal | null;
136
- }): Promise<void>;
137
- /** Cache policy for protocol tools/list responses. */
138
- getToolsListCacheHint?(): Promise<McpToolListCacheHint>;
139
- /** Read-only view of the configured server identity. */
140
- readonly serverInfo: CreateMcpAppServerOptions['serverInfo'];
141
- }
142
-
143
- /** Minimal legacy user shape used for generated tool-call attribution. */
144
- declare interface McpAppUser extends McpAppPrincipal {
145
- id: string;
146
- }
147
-
148
- /** Locals reader used to pull the request principal out of `event.locals`. */
149
- export declare type McpPrincipalResolver = (event: SvelteKitRequestEvent) => McpAppPrincipal | null | undefined;
150
-
151
- /** Public-tool patterns thunk — same lazy-evaluation rationale. */
152
- declare type McpPublicToolPatternsThunk = () => readonly string[];
153
-
154
- /**
155
- * SMRT options thunk — returns the `{ db }` (and similar) bag to pass into
156
- * MCPGenerator's per-request context. A function is used so apps can lazily
157
- * resolve env vars at call time.
158
- */
159
- declare type McpSmrtOptionsThunk = () => Record<string, unknown>;
160
-
161
- /** A SvelteKit `+server.ts` request handler with no SvelteKit dependency. */
162
- export declare type McpSvelteKitHandler = (event: SvelteKitRequestEvent) => Promise<Response>;
163
-
164
- declare interface McpToolListCacheHint {
165
- ttlMs: number;
166
- cacheScope: 'private' | 'public';
167
- }
168
-
169
- declare interface McpToolListCacheOptions {
170
- /** Cache lifetime in milliseconds. Defaults to one day for a deploy-static catalog. */
171
- ttlMs?: number;
172
- /** Requested cache visibility. Defaults to private. */
173
- cacheScope?: 'private' | 'public';
174
- /**
175
- * Explicit attestation that every allowed tool is global, unauthenticated,
176
- * and safe to share through an intermediary cache.
177
- */
178
- publicCatalog?: true;
179
- }
180
-
181
- /**
182
- * Per-tool access policy. Return `true` to expose/allow the tool and `false`
183
- * to hide it from discovery and deny a direct call. A thrown error is treated
184
- * as a denial so policy implementation details cannot escape the app-MCP
185
- * boundary.
186
- */
187
- declare type McpToolPolicy = (context: McpToolPolicyContext) => boolean | Promise<boolean>;
188
-
189
- /** Context supplied to the optional per-tool principal policy. */
190
- declare interface McpToolPolicyContext {
191
- principal: McpAppPrincipal | null;
192
- tool: MCPTool;
193
- }
194
-
195
- /** Backwards-compatible alias for callers that name the principal a user. */
196
- export declare type McpUserResolver = McpPrincipalResolver;
197
-
198
- /**
199
- * Workflow assertion hook signature. Throw `McpAccessError` to reject the
200
- * call. Implementations may mutate `args` in place to inject server-trusted
201
- * fields (e.g. clamping `approvedByUserId` to the authenticated user's id).
202
- */
203
- declare type McpWorkflowAssertion = (args: Record<string, unknown>, user: McpAppUser | null) => void;
204
-
205
- /**
206
- * Mount `server.callTool` as a `POST` handler that expects
207
- * `{ name, arguments }` in the JSON body.
208
- *
209
- * @deprecated Use {@link mountMcpRoute}. Existing REST-shaped mounts can use
210
- * this compatibility alias while migrating without a coordinated cutover.
211
- */
212
- export declare function mountMcpCallRoute(server: McpAppServer, options?: MountMcpRouteOptions): McpSvelteKitHandler;
213
-
214
- /**
215
- * Mount a modern, stateless Streamable HTTP MCP endpoint as a SvelteKit
216
- * `POST` handler. The scoped SDK validates the 2026-07-28 envelope plus the
217
- * required `Mcp-Method` and `Mcp-Name` headers, returning `-32020` on a
218
- * mismatch. A fresh protocol server is created for each HTTP request, so this
219
- * route holds neither MCP sessions nor request principal state between nodes.
220
- */
221
- export declare function mountMcpRoute(server: McpAppServer, options?: MountMcpRouteOptions): McpSvelteKitHandler;
222
-
223
- /** Options shared by both route mounts. */
224
- export declare interface MountMcpRouteOptions {
225
- /**
226
- * Resolve the request principal once for both discovery and direct calls.
227
- * Defaults to `event.locals.user`.
228
- */
229
- resolvePrincipal?: McpPrincipalResolver;
230
- /**
231
- * Backwards-compatible alias for `resolvePrincipal`.
232
- */
233
- resolveUser?: McpUserResolver;
234
- /**
235
- * Deprecated legacy authentication gate. When `resolvePrincipal` is not
236
- * supplied, a false result makes the principal null for both routes.
237
- */
238
- resolveAuthenticated?: (event: SvelteKitRequestEvent) => boolean;
239
- }
240
-
241
- /**
242
- * Mount `server.listTools` as a `GET` handler. Returns the tool list shape
243
- * `{ tools }` for compatibility with the stock MCP bridge.
244
- *
245
- * @deprecated Use {@link mountMcpRoute}. Existing REST-shaped mounts can use
246
- * this compatibility alias while migrating without a coordinated cutover.
247
- */
248
- export declare function mountMcpToolsRoute(server: McpAppServer, options?: MountMcpRouteOptions): McpSvelteKitHandler;
249
-
250
- /** Minimal subset of a SvelteKit RequestEvent we actually touch. */
251
- declare type SvelteKitRequestEvent = {
252
- locals?: Record<string, unknown>;
253
- request: Request;
254
- url: URL;
255
- };
256
-
257
- export { }
1
+ /**
2
+ * SvelteKit route adapters for an `McpAppServer`. Mirrors the
3
+ * `@happyvertical/smrt-users/sveltekit` pattern: minimal `HandleInput` type
4
+ * so we never need `@sveltejs/kit` as a real dependency.
5
+ *
6
+ * @packageDocumentation
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * // src/routes/api/mcp/+server.ts
11
+ * import { mountMcpRoute } from '@happyvertical/smrt-app-mcp/sveltekit';
12
+ * import { mcpServer } from '$lib/server/mcp';
13
+ * export const POST = mountMcpRoute(mcpServer);
14
+ * ```
15
+ */
16
+ import type { McpAppPrincipal, McpAppServer } from './server.js';
17
+ /** Minimal subset of a SvelteKit RequestEvent we actually touch. */
18
+ type SvelteKitRequestEvent = {
19
+ locals?: Record<string, unknown>;
20
+ request: Request;
21
+ url: URL;
22
+ };
23
+ /** A SvelteKit `+server.ts` request handler with no SvelteKit dependency. */
24
+ export type McpSvelteKitHandler = (event: SvelteKitRequestEvent) => Promise<Response>;
25
+ /** Locals reader used to pull the request principal out of `event.locals`. */
26
+ export type McpPrincipalResolver = (event: SvelteKitRequestEvent) => McpAppPrincipal | null | undefined;
27
+ /** Backwards-compatible alias for callers that name the principal a user. */
28
+ export type McpUserResolver = McpPrincipalResolver;
29
+ /** Options shared by both route mounts. */
30
+ export interface MountMcpRouteOptions {
31
+ /**
32
+ * Resolve the request principal once for both discovery and direct calls.
33
+ * Defaults to `event.locals.user`.
34
+ */
35
+ resolvePrincipal?: McpPrincipalResolver;
36
+ /**
37
+ * Backwards-compatible alias for `resolvePrincipal`.
38
+ */
39
+ resolveUser?: McpUserResolver;
40
+ /**
41
+ * Deprecated legacy authentication gate. When `resolvePrincipal` is not
42
+ * supplied, a false result makes the principal null for both routes.
43
+ */
44
+ resolveAuthenticated?: (event: SvelteKitRequestEvent) => boolean;
45
+ }
46
+ /**
47
+ * Mount a modern, stateless Streamable HTTP MCP endpoint as a SvelteKit
48
+ * `POST` handler. The scoped SDK validates the 2026-07-28 envelope plus the
49
+ * required `Mcp-Method` and `Mcp-Name` headers, returning `-32020` on a
50
+ * mismatch. A fresh protocol server is created for each HTTP request, so this
51
+ * route holds neither MCP sessions nor request principal state between nodes.
52
+ */
53
+ export declare function mountMcpRoute(server: McpAppServer, options?: MountMcpRouteOptions): McpSvelteKitHandler;
54
+ /**
55
+ * Mount `server.listTools` as a `GET` handler. Returns the tool list shape
56
+ * `{ tools }` for compatibility with the stock MCP bridge.
57
+ *
58
+ * @deprecated Use {@link mountMcpRoute}. Existing REST-shaped mounts can use
59
+ * this compatibility alias while migrating without a coordinated cutover.
60
+ */
61
+ export declare function mountMcpToolsRoute(server: McpAppServer, options?: MountMcpRouteOptions): McpSvelteKitHandler;
62
+ /**
63
+ * Mount `server.callTool` as a `POST` handler that expects
64
+ * `{ name, arguments }` in the JSON body.
65
+ *
66
+ * @deprecated Use {@link mountMcpRoute}. Existing REST-shaped mounts can use
67
+ * this compatibility alias while migrating without a coordinated cutover.
68
+ */
69
+ export declare function mountMcpCallRoute(server: McpAppServer, options?: MountMcpRouteOptions): McpSvelteKitHandler;
70
+ export { McpAccessError } from './errors.js';
71
+ export type { McpAppPrincipal, McpAppServer } from './server.js';
72
+ //# sourceMappingURL=sveltekit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sveltekit.d.ts","sourceRoot":"","sources":["../src/sveltekit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AASH,OAAO,KAAK,EAAiB,eAAe,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhF,oEAAoE;AACpE,KAAK,qBAAqB,GAAG;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,GAAG,CAAC;CACV,CAAC;AAEF,6EAA6E;AAC7E,MAAM,MAAM,mBAAmB,GAAG,CAChC,KAAK,EAAE,qBAAqB,KACzB,OAAO,CAAC,QAAQ,CAAC,CAAC;AAQvB,8EAA8E;AAC9E,MAAM,MAAM,oBAAoB,GAAG,CACjC,KAAK,EAAE,qBAAqB,KACzB,eAAe,GAAG,IAAI,GAAG,SAAS,CAAC;AAExC,6EAA6E;AAC7E,MAAM,MAAM,eAAe,GAAG,oBAAoB,CAAC;AAwCnD,2CAA2C;AAC3C,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,oBAAoB,CAAC;IACxC;;OAEG;IACH,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B;;;OAGG;IACH,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,qBAAqB,KAAK,OAAO,CAAC;CAClE;AAiBD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,YAAY,EACpB,OAAO,GAAE,oBAAyB,GACjC,mBAAmB,CA0BrB;AA6OD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,YAAY,EACpB,OAAO,GAAE,oBAAyB,GACjC,mBAAmB,CAcrB;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,YAAY,EACpB,OAAO,GAAE,oBAAyB,GACjC,mBAAmB,CA0BrB;AAyBD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Tool-name policy helpers — used by `McpAppServer` to filter the full set
3
+ * of generated tools down to what the calling principal is allowed to see,
4
+ * and to decide whether an unauthenticated tool call should be permitted.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ /**
9
+ * Match a tool name against a glob-ish pattern with `*` wildcards.
10
+ *
11
+ * - Empty pattern → never matches.
12
+ * - `*` → matches everything.
13
+ * - `prefix_*` → matches anything starting with `prefix_`.
14
+ * - `*_suffix` → matches anything ending with `_suffix`.
15
+ * - `a_*_b` → matches any name containing `a_`, then any text, then `_b`.
16
+ *
17
+ * No regex characters are special besides `*` — the input is treated as a
18
+ * literal string with star wildcards.
19
+ */
20
+ export declare function matchesToolPattern(toolName: string, pattern: string): boolean;
21
+ /**
22
+ * Read-only tool detection. Generated SMRT MCP tools follow the naming
23
+ * convention `<class>_<verb>`; we treat `_list` and `_get` as read-only.
24
+ */
25
+ export declare function isReadOnlyToolName(toolName: string): boolean;
26
+ /**
27
+ * Check whether a tool name is currently allowed for unauthenticated callers
28
+ * given the configured public-tool patterns. Only read-only tools may ever
29
+ * be public, regardless of pattern.
30
+ */
31
+ export declare function isPublicToolName(toolName: string, patterns: readonly string[]): boolean;
32
+ /**
33
+ * Lower-case `<class>_` prefixes the app considers "allowed core tools"
34
+ * given a list of SMRT class names. Used to build the allow-list for
35
+ * `McpAppServer.listTools`.
36
+ */
37
+ export declare function classNamePrefixes(classNames: readonly string[]): ReadonlySet<string>;
38
+ /**
39
+ * Whether a given tool name starts with any of the configured class
40
+ * prefixes.
41
+ */
42
+ export declare function isAllowedCoreTool(toolName: string, prefixes: ReadonlySet<string>): boolean;
43
+ /**
44
+ * Compare tool names by Unicode code unit, rather than the host locale, so a
45
+ * catalog has one byte-stable order across every runtime.
46
+ */
47
+ export declare function compareMcpToolNames(left: string, right: string): number;
48
+ //# sourceMappingURL=tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAkB7E;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAE5D;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,SAAS,MAAM,EAAE,GAC1B,OAAO,CAKT;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,SAAS,MAAM,EAAE,GAC5B,WAAW,CAAC,MAAM,CAAC,CAErB;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,GAC5B,OAAO,CAKT;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAEvE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@happyvertical/smrt-app-mcp",
3
- "version": "0.51.32",
3
+ "version": "0.51.33",
4
4
  "description": "App-runtime MCP server scaffolding for SMRT apps — `createMcpAppServer` plus transport adapters (SvelteKit today) for exposing a SMRT app's MCP surface over HTTP.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -43,8 +43,8 @@
43
43
  ],
44
44
  "author": "HappyVertical",
45
45
  "dependencies": {
46
- "@happyvertical/smrt-core": "0.51.32",
47
- "@happyvertical/smrt-jobs": "0.51.32",
46
+ "@happyvertical/smrt-core": "0.51.33",
47
+ "@happyvertical/smrt-jobs": "0.51.33",
48
48
  "@happyvertical/sql": "^0.94.1",
49
49
  "@modelcontextprotocol/server": "2.0.0"
50
50
  },
@@ -53,7 +53,7 @@
53
53
  "@modelcontextprotocol/conformance": "0.2.0-alpha.11",
54
54
  "@modelcontextprotocol/node": "2.0.0",
55
55
  "@types/node": "24.13.6",
56
- "typescript": "5.9.3",
56
+ "typescript": "6.0.3",
57
57
  "vite": "8.1.4",
58
58
  "vitest": "4.1.10"
59
59
  },