@happyvertical/smrt-app-mcp 0.53.3 → 0.53.4

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,87 @@
1
+ /**
2
+ * Defaults for an application MCP server built from the app's own declared
3
+ * models. The defaults can only narrow what `createMcpAppServer` exposes:
4
+ * the allow-list is the explicit model list, and every authenticated caller
5
+ * must be a principal of an accepted kind with a stable id, a tenant, and
6
+ * every required scope. Applications that need a wider policy compose
7
+ * `createMcpAppServer` directly.
8
+ *
9
+ * @packageDocumentation
10
+ */
11
+ import { ObjectRegistry } from '@happyvertical/smrt-core';
12
+ import type { McpResourcePolicy } from './resources.js';
13
+ import { type CreateMcpAppServerOptions, type McpAppPrincipal, type McpAppServer, type McpTaskPrincipalPolicy, type McpToolPolicy } from './server.js';
14
+ /** A `@smrt()` model constructor whose generated tools the app publishes. */
15
+ export type McpAppModel = Parameters<typeof ObjectRegistry.getClassByConstructor>[0];
16
+ /** Server identity used when an application does not supply one. */
17
+ export declare const DEFAULT_MCP_APP_SERVER_INFO: Readonly<{
18
+ name: "smrt-app";
19
+ version: "0.1.0";
20
+ }>;
21
+ /**
22
+ * Resolve the registered class names for an explicit list of model
23
+ * constructors. Every entry must be a registered `@smrt()` class; nothing is
24
+ * inferred from the registry, so an application never publishes framework or
25
+ * dependency models by accident.
26
+ */
27
+ export declare function mcpAllowedClassNames(models: readonly McpAppModel[]): string[];
28
+ /** Options for {@link mcpPrincipalScopePolicy}. */
29
+ export interface McpPrincipalScopePolicyOptions {
30
+ /** Every scope an authenticated principal must hold. May be empty. */
31
+ requiredScopes: readonly string[];
32
+ /** Accepted principal kinds. Defaults to `['human']`. */
33
+ principalKinds?: readonly string[];
34
+ }
35
+ /**
36
+ * Build the default principal policy shared by tools and resources.
37
+ *
38
+ * An authenticated principal passes only with an accepted `kind`, a stable
39
+ * `id`, a `tenantId`, and every required scope. An absent principal passes
40
+ * this policy because the server's base rule has already restricted it to
41
+ * tools selected by `publicToolPatterns` that are read-only, and to resources
42
+ * explicitly declared `public: true`; with neither configured an anonymous
43
+ * caller reaches nothing.
44
+ */
45
+ export declare function mcpPrincipalScopePolicy(options: McpPrincipalScopePolicyOptions): (context: {
46
+ principal: McpAppPrincipal | null;
47
+ }) => boolean;
48
+ /** Options for {@link createDefaultMcpAppServer}. */
49
+ export interface CreateDefaultMcpAppServerOptions extends Omit<CreateMcpAppServerOptions, 'allowedClassNames' | 'serverInfo' | 'toolPolicy' | 'resourcePolicy' | 'taskPrincipalPolicy'> {
50
+ /**
51
+ * The app's own `@smrt()` models to publish. Explicit: nothing else that is
52
+ * registered (framework, dependency or fixture models) is exposed.
53
+ */
54
+ models: readonly McpAppModel[];
55
+ /**
56
+ * Scopes every authenticated principal must hold for every tool and
57
+ * resource. With the SvelteKit session default these are the permission
58
+ * slugs from `locals.permissions` (for example `items.read`); with bearer
59
+ * authentication they are the token's granted scopes. Required so the
60
+ * permission gate is always an explicit application decision; pass `[]`
61
+ * only when every authenticated tenant member may use every published tool.
62
+ */
63
+ requiredScopes: readonly string[];
64
+ /** Accepted principal kinds. Defaults to `['human']`. */
65
+ principalKinds?: readonly string[];
66
+ /** Server identity. Defaults to {@link DEFAULT_MCP_APP_SERVER_INFO}. */
67
+ serverInfo?: CreateMcpAppServerOptions['serverInfo'];
68
+ /** Additional tool policy. Composed with the default; it can only narrow. */
69
+ toolPolicy?: McpToolPolicy;
70
+ /** Additional resource policy. Composed with the default; it can only narrow. */
71
+ resourcePolicy?: McpResourcePolicy;
72
+ /**
73
+ * Additional task lifecycle predicate. Composed with the default principal
74
+ * scope policy, which already gates `tasks/get`/`update`/`cancel`; it can
75
+ * only narrow.
76
+ */
77
+ taskPrincipalPolicy?: McpTaskPrincipalPolicy;
78
+ }
79
+ /**
80
+ * Create an `McpAppServer` from the app's declared models with the default
81
+ * principal policy. Unauthenticated callers keep the base public read-only
82
+ * rule; mutating tools always require an authenticated principal. Because the
83
+ * default policy is principal-aware, `tools/list` stays privately cacheable
84
+ * even when `toolListCache` requests public caching.
85
+ */
86
+ export declare function createDefaultMcpAppServer(options: CreateDefaultMcpAppServerOptions): McpAppServer;
87
+ //# sourceMappingURL=defaults.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EACL,KAAK,yBAAyB,EAE9B,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,sBAAsB,EAC3B,KAAK,aAAa,EACnB,MAAM,aAAa,CAAC;AAErB,6EAA6E;AAC7E,MAAM,MAAM,WAAW,GAAG,UAAU,CAClC,OAAO,cAAc,CAAC,qBAAqB,CAC5C,CAAC,CAAC,CAAC,CAAC;AAEL,oEAAoE;AACpE,eAAO,MAAM,2BAA2B;;;EAGtC,CAAC;AAEH;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,GAAG,MAAM,EAAE,CAkB7E;AAED,mDAAmD;AACnD,MAAM,WAAW,8BAA8B;IAC7C,sEAAsE;IACtE,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,yDAAyD;IACzD,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACpC;AAuBD;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,8BAA8B,GACtC,CAAC,OAAO,EAAE;IAAE,SAAS,EAAE,eAAe,GAAG,IAAI,CAAA;CAAE,KAAK,OAAO,CAoB7D;AAED,qDAAqD;AACrD,MAAM,WAAW,gCACf,SAAQ,IAAI,CACV,yBAAyB,EACvB,mBAAmB,GACnB,YAAY,GACZ,YAAY,GACZ,gBAAgB,GAChB,qBAAqB,CACxB;IACD;;;OAGG;IACH,MAAM,EAAE,SAAS,WAAW,EAAE,CAAC;IAC/B;;;;;;;OAOG;IACH,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,yDAAyD;IACzD,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,wEAAwE;IACxE,UAAU,CAAC,EAAE,yBAAyB,CAAC,YAAY,CAAC,CAAC;IACrD,6EAA6E;IAC7E,UAAU,CAAC,EAAE,aAAa,CAAC;IAC3B,iFAAiF;IACjF,cAAc,CAAC,EAAE,iBAAiB,CAAC;IACnC;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,sBAAsB,CAAC;CAC9C;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,gCAAgC,GACxC,YAAY,CA6Bd"}
package/dist/errors.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  /** Machine-readable code for a principal policy denial. */
2
2
  export declare const MCP_TOOL_ACCESS_DENIED_CODE = "mcp_tool_access_denied";
3
+ /** Machine-readable code for a request refused by the endpoint's origin check. */
4
+ export declare const MCP_ORIGIN_DENIED_CODE = "mcp_origin_denied";
3
5
  /**
4
6
  * Metadata that is safe to expose for an app-MCP access failure. Policy
5
7
  * implementations must not place principal, scope, tool, or internal-error
@@ -1 +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"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,eAAO,MAAM,2BAA2B,2BAA2B,CAAC;AAEpE,kFAAkF;AAClF,eAAO,MAAM,sBAAsB,sBAAsB,CAAC;AAE1D;;;;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
@@ -22,10 +22,11 @@
22
22
  * @packageDocumentation
23
23
  */
24
24
  export { continueMcpWorkflow, createMcpContinuationTool, type McpWorkflowContinuation, } from './continuation.js';
25
- export { MCP_TOOL_ACCESS_DENIED_CODE, McpAccessError, type McpAccessErrorMetadata, } from './errors.js';
25
+ export { type CreateDefaultMcpAppServerOptions, createDefaultMcpAppServer, DEFAULT_MCP_APP_SERVER_INFO, type McpAppModel, type McpPrincipalScopePolicyOptions, mcpAllowedClassNames, mcpPrincipalScopePolicy, } from './defaults.js';
26
+ export { MCP_ORIGIN_DENIED_CODE, MCP_TOOL_ACCESS_DENIED_CODE, McpAccessError, type McpAccessErrorMetadata, } from './errors.js';
26
27
  export { createMcpProtocolServer, createMcpProtocolServerForRequest, type McpProtocolRequestOptions, type McpProtocolServerOptions, } from './protocol.js';
27
28
  export { MCP_APP_RESOURCE_MAX_BYTES, MCP_APP_RESOURCE_MIME, type McpAppResource, type McpAppResourceContent, type McpAppResourceCsp, type McpAppResourceDefinition, type McpResourcePolicy, prepareMcpAppResource, } from './resources.js';
28
- 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';
29
- export { classNamePrefixes, isAllowedCoreTool, isPublicMcpTool, isPublicToolName, isReadOnlyToolName, matchesToolPattern, } from './tools.js';
29
+ export { type CallToolInput, type CreateMcpAppServerOptions, createMcpAppServer, type ListToolsInput, type McpAppPrincipal, type McpAppServer, type McpAppUser, type McpPublicToolPatternsThunk, type McpSmrtOptionsThunk, type McpTaskPrincipalPolicy, type McpToolListCacheHint, type McpToolListCacheOptions, type McpToolPolicy, type McpToolPolicyContext, type McpWorkflowAssertion, } from './server.js';
30
+ export { classNamePrefixes, isAllowedCoreTool, isPublicMcpTool, isPublicToolName, isReadOnlyToolName, MCP_TOOL_EFFECTS, type McpToolEffect, matchesToolPattern, mcpToolEffect, } from './tools.js';
30
31
  export { createMcpWorkflowTool, type McpWorkflowTool, type McpWorkflowToolContext, type McpWorkflowToolDefinition, type McpWorkflowToolVisibility, } from './workflow-tools.js';
31
32
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EACL,mBAAmB,EACnB,yBAAyB,EACzB,KAAK,uBAAuB,GAC7B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,2BAA2B,EAC3B,cAAc,EACd,KAAK,sBAAsB,GAC5B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,uBAAuB,EACvB,iCAAiC,EACjC,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,GAC9B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,0BAA0B,EAC1B,qBAAqB,EACrB,KAAK,cAAc,EACnB,K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