@mcpfn/core 0.0.3 → 0.0.5

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/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { ServerCapabilities, ToolAnnotations, ToolExecution, Icon, Resource, ResourceTemplate, PromptArgument, Annotations, ServerRequest, ServerNotification, ReadResourceResult, ElicitRequestFormParams, ElicitRequestURLParams, ElicitResult, Tool, GetPromptResult, CompleteResult, CallToolResult, CreateTaskResult, ListResourcesResult, ListRootsResult, CreateMessageRequest, CreateMessageResult, CreateMessageResultWithTools, Implementation, LoggingMessageNotification, ResourceUpdatedNotification, ContentBlock } from '@modelcontextprotocol/sdk/types.js';
1
+ import { ServerCapabilities, ToolAnnotations, ToolExecution, Icon, Resource, ResourceTemplate, PromptArgument, Annotations, ServerRequest, ServerNotification, ReadResourceResult, Implementation, ClientCapabilities, Tool, ElicitRequestFormParams, ElicitRequestURLParams, ElicitResult, GetPromptResult, CompleteResult, CallToolResult, CreateTaskResult, ListResourcesResult, ListRootsResult, CreateMessageRequest, CreateMessageResult, CreateMessageResultWithTools, LoggingMessageNotification, ResourceUpdatedNotification, ContentBlock } from '@modelcontextprotocol/sdk/types.js';
2
2
  import { RequestHandlerExtra, RequestOptions, RequestTaskStore } from '@modelcontextprotocol/sdk/shared/protocol.js';
3
3
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
4
4
  import { WebStandardStreamableHTTPServerTransport, HandleRequestOptions } from '@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js';
@@ -16,6 +16,29 @@ type McpFnRequestExtra = RequestHandlerExtra<ServerRequest, ServerNotification>;
16
16
  type McpFnTaskRequestExtra = McpFnRequestExtra & {
17
17
  taskStore: RequestTaskStore;
18
18
  };
19
+ /** Safe structural JSON Schema diagnostic. Argument values are never retained. */
20
+ interface McpFnSchemaIssue {
21
+ /** Backwards-compatible alias for instancePath; `/` represents the root. */
22
+ path: string;
23
+ /** RFC 6901 path to the rejected input location; `/` represents the root. */
24
+ instancePath: string;
25
+ /** JSON Schema path reported by the validator. */
26
+ schemaPath: string;
27
+ keyword: string;
28
+ message: string;
29
+ /** Exact unknown property name for additionalProperties failures. */
30
+ rejectedProperty?: string;
31
+ /** Exact missing property name for required failures. */
32
+ missingProperty?: string;
33
+ }
34
+ type McpFnToolLifecycleStage = "input-validation" | "invalid-arguments-handler" | "handler" | "output-validation";
35
+ interface McpFnToolLifecycleObserver {
36
+ onStage?(stage: McpFnToolLifecycleStage): void;
37
+ /** Task results can be validated after createTask has returned. */
38
+ onTaskOutput?(outcome: "succeeded" | "failed", error?: unknown): void | Promise<void>;
39
+ /** Result persistence can fail after the task-creation request has settled. */
40
+ onTaskStorageFailure?(error: unknown): void | Promise<void>;
41
+ }
19
42
  interface McpFnTaskHandler<TContext = undefined> {
20
43
  createTask(args: Record<string, unknown>, context: TContext, extra: McpFnTaskRequestExtra): CreateTaskResult | Promise<CreateTaskResult>;
21
44
  }
@@ -33,11 +56,7 @@ interface McpFnToolDefinition<TContext = undefined> {
33
56
  /** Implements call-now/fetch-later execution when execution.taskSupport allows it. */
34
57
  taskHandler?: McpFnTaskHandler<TContext>;
35
58
  /** Optional domain-specific mapping for JSON Schema argument failures. */
36
- handleInvalidArguments?(args: Record<string, unknown>, issues: Array<{
37
- path: string;
38
- message: string;
39
- keyword: string;
40
- }>, context: TContext, extra: McpFnRequestExtra): CallToolResult | Promise<CallToolResult>;
59
+ handleInvalidArguments?(args: Record<string, unknown>, issues: McpFnSchemaIssue[], context: TContext, extra: McpFnRequestExtra): CallToolResult | Promise<CallToolResult>;
41
60
  }
42
61
  interface McpFnResourceDefinition<TContext = undefined> {
43
62
  uri: string;
@@ -152,6 +171,11 @@ interface McpFnDiffResult {
152
171
  type McpFnListedTool = Tool;
153
172
  type McpFnListedResource = Resource;
154
173
  type McpFnListedResourceTemplate = ResourceTemplate;
174
+ /** Self-reported initialization information. It is compatibility input, never identity. */
175
+ interface McpFnReportedClient {
176
+ info?: Implementation;
177
+ capabilities?: ClientCapabilities;
178
+ }
155
179
  type McpFnSamplingParams = CreateMessageRequest["params"];
156
180
  type McpFnSamplingResult = CreateMessageResult | CreateMessageResultWithTools;
157
181
  type McpFnElicitationParams = ElicitRequestFormParams | ElicitRequestURLParams;
@@ -173,7 +197,7 @@ declare function promptArguments<TContext>(definition: McpFnPromptDefinition<TCo
173
197
  required?: boolean | undefined;
174
198
  }[] | undefined;
175
199
  declare class McpFnRegistry<TContext = undefined> {
176
- private readonly ajv;
200
+ private readonly schemaCompiler;
177
201
  private readonly tools;
178
202
  private readonly resources;
179
203
  private readonly resourceTemplates;
@@ -194,6 +218,8 @@ declare class McpFnRegistry<TContext = undefined> {
194
218
  listChanged?: boolean;
195
219
  }): ServerCapabilities;
196
220
  listTools(): McpFnListedTool[];
221
+ getListedTool(name: string): McpFnListedTool | undefined;
222
+ private listedTool;
197
223
  listResources(context: TContext, extra: McpFnRequestExtra): Promise<Resource[]>;
198
224
  listResourceTemplates(): ResourceTemplate[];
199
225
  listPrompts(): {
@@ -214,9 +240,9 @@ declare class McpFnRegistry<TContext = undefined> {
214
240
  name: string;
215
241
  }[];
216
242
  private normalizeAndValidateArgs;
217
- callTool(name: string, args: unknown, context: TContext, extra: McpFnRequestExtra): Promise<CallToolResult>;
243
+ callTool(name: string, args: unknown, context: TContext, extra: McpFnRequestExtra, observer?: McpFnToolLifecycleObserver): Promise<CallToolResult>;
218
244
  taskSupport(name: string): "optional" | "required" | "forbidden";
219
- createToolTask(name: string, args: unknown, context: TContext, extra: McpFnTaskRequestExtra): Promise<CreateTaskResult>;
245
+ createToolTask(name: string, args: unknown, context: TContext, extra: McpFnTaskRequestExtra, observer?: McpFnToolLifecycleObserver): Promise<CreateTaskResult>;
220
246
  private matchResource;
221
247
  readResource(uri: string, context: TContext, extra: McpFnRequestExtra): Promise<ReadResourceResult>;
222
248
  changeSubscription(uri: string, subscribed: boolean, context: TContext, extra: McpFnRequestExtra): Promise<void>;
@@ -276,6 +302,89 @@ declare function canonicalize(value: unknown): unknown;
276
302
  declare function canonicalJson(value: unknown): string;
277
303
  declare function sha256(value: unknown): string;
278
304
 
305
+ interface McpFnVerifiedClientIdentity {
306
+ /** Stable authenticated subject. Never derived from initialize.clientInfo. */
307
+ subject: string;
308
+ /** Optional non-secret attributes used by product-owned profile selection. */
309
+ attributes?: Record<string, string | number | boolean | null>;
310
+ }
311
+ interface McpFnClientProfileHookInput<TContext> {
312
+ context: TContext;
313
+ extra: McpFnRequestExtra;
314
+ verifiedIdentity: McpFnVerifiedClientIdentity;
315
+ reportedClient: McpFnReportedClient;
316
+ }
317
+ interface McpFnClientProfileCatalogInput<TContext> extends McpFnClientProfileHookInput<TContext> {
318
+ tools: McpFnListedTool[];
319
+ }
320
+ interface McpFnClientProfileCallInput<TContext> extends McpFnClientProfileHookInput<TContext> {
321
+ tool: McpFnListedTool;
322
+ arguments: Record<string, unknown>;
323
+ }
324
+ interface McpFnClientProfile<TContext = undefined> {
325
+ id: string;
326
+ version: string;
327
+ /** Defaults to true. Set false only when hooks do not use initialization metadata. */
328
+ requiresReportedClient?: boolean;
329
+ /** Selection is deliberately restricted to verified identity. */
330
+ matches(identity: McpFnVerifiedClientIdentity): boolean | Promise<boolean>;
331
+ projectCatalog?(input: McpFnClientProfileCatalogInput<TContext>): Tool[] | Promise<Tool[]>;
332
+ /** Root argument names owned by the server for each tool. */
333
+ serverOwnedArguments?: Readonly<Record<string, readonly string[]>>;
334
+ enrichArguments?(input: McpFnClientProfileCallInput<TContext>): Record<string, unknown> | Promise<Record<string, unknown>>;
335
+ }
336
+ type McpFnClientProfileLifecycleStage = "profile-resolution" | "catalog-projection" | "argument-enrichment" | "input-validation" | "invalid-arguments-handler" | "handler" | "output-validation" | "task-result-storage";
337
+ interface McpFnClientProfileEvidence {
338
+ formatVersion: 1;
339
+ stage: McpFnClientProfileLifecycleStage;
340
+ outcome: "started" | "succeeded" | "failed";
341
+ profile?: {
342
+ id: string;
343
+ version: string;
344
+ };
345
+ tool?: string;
346
+ code?: string;
347
+ issues?: McpFnSchemaIssue[];
348
+ }
349
+ interface McpFnClientProfilesOptions<TContext = undefined> {
350
+ profiles: readonly McpFnClientProfile<TContext>[];
351
+ resolveVerifiedIdentity(input: {
352
+ context: TContext;
353
+ extra: McpFnRequestExtra;
354
+ }): McpFnVerifiedClientIdentity | undefined | Promise<McpFnVerifiedClientIdentity | undefined>;
355
+ evidence?(event: McpFnClientProfileEvidence): void | Promise<void>;
356
+ }
357
+ interface McpFnCatalogChange {
358
+ kind: "removed" | "modified";
359
+ path: string;
360
+ tool: string;
361
+ beforeHash: string;
362
+ afterHash?: string;
363
+ }
364
+ interface McpFnResolvedClientProfile<TContext> {
365
+ context: TContext;
366
+ extra: McpFnRequestExtra;
367
+ verifiedIdentity?: McpFnVerifiedClientIdentity;
368
+ reportedClient: McpFnReportedClient;
369
+ profile?: McpFnClientProfile<TContext>;
370
+ }
371
+ declare function validateMcpFnClientProfiles<TContext>(options: McpFnClientProfilesOptions<TContext>): void;
372
+ declare function resolveMcpFnClientProfile<TContext>(options: McpFnClientProfilesOptions<TContext>, input: Omit<McpFnResolvedClientProfile<TContext>, "verifiedIdentity" | "profile">): Promise<McpFnResolvedClientProfile<TContext>>;
373
+ declare function buildMcpFnEffectiveCatalog<TContext>(input: {
374
+ canonicalTools: McpFnListedTool[];
375
+ /** Complete registry inventory when canonicalTools has already been visibility-filtered. */
376
+ knownTools?: McpFnListedTool[];
377
+ resolved: McpFnResolvedClientProfile<TContext>;
378
+ }): Promise<{
379
+ tools: McpFnListedTool[];
380
+ changes: McpFnCatalogChange[];
381
+ }>;
382
+ declare function enrichMcpFnClientProfileCall<TContext>(input: {
383
+ resolved: McpFnResolvedClientProfile<TContext>;
384
+ tool: McpFnListedTool;
385
+ arguments: unknown;
386
+ }): Promise<unknown>;
387
+
279
388
  interface CreateManifestOptions {
280
389
  protocolVersions?: string[];
281
390
  transports?: Array<"stdio" | "streamable-http">;
@@ -301,6 +410,8 @@ interface McpFnServerOptions<TContext> extends CreateManifestOptions {
301
410
  * unknown tool. Static manifests remain the complete server contract.
302
411
  */
303
412
  toolVisibility?: (input: McpFnToolVisibilityInput<TContext>) => boolean | Promise<boolean>;
413
+ /** Authenticated client catalog projection and trusted call enrichment. */
414
+ clientProfiles?: McpFnClientProfilesOptions<TContext>;
304
415
  /** Maximum entries returned by each list request. Defaults to 100. */
305
416
  pageSize?: number;
306
417
  additionalCapabilities?: ServerCapabilities;
@@ -310,6 +421,16 @@ interface McpFnServerOptions<TContext> extends CreateManifestOptions {
310
421
  maxTaskQueueSize?: number;
311
422
  enforceStrictCapabilities?: boolean;
312
423
  }
424
+ type McpFnWebStandardHandlerOptions<TContext> = ConstructorParameters<typeof WebStandardStreamableHTTPServerTransport>[0] & {
425
+ /**
426
+ * Configure the live isolated server before its transport connects. This
427
+ * runs once per stateless request, or once per session initialization
428
+ * attempt before the SDK validates the request. Rejected attempts may
429
+ * therefore invoke it without retaining a session. This is the correct
430
+ * place to attach protocol instrumentation.
431
+ */
432
+ configureRequestServer?: (server: McpFnServer<TContext>) => void | Promise<void>;
433
+ };
313
434
  /** Resolve the exact protocol/manifest capabilities from one registry contract. */
314
435
  declare function resolveMcpFnServerCapabilities<TContext>(registry: McpFnRegistry<TContext>, additionalCapabilities: ServerCapabilities | undefined, includeTaskOperations: boolean): ServerCapabilities;
315
436
  declare class McpFnServer<TContext = undefined> {
@@ -319,6 +440,7 @@ declare class McpFnServer<TContext = undefined> {
319
440
  readonly capabilities: ServerCapabilities;
320
441
  private readonly contextFactory;
321
442
  private readonly toolVisibility?;
443
+ private readonly clientProfiles?;
322
444
  private readonly manifestOptions;
323
445
  private readonly pageSize;
324
446
  private readonly serverOptions;
@@ -327,10 +449,15 @@ declare class McpFnServer<TContext = undefined> {
327
449
  constructor(options: McpFnServerOptions<TContext>);
328
450
  private installHandlers;
329
451
  private filterVisibleTools;
452
+ private profileReference;
453
+ private resolveProfile;
454
+ private buildEffectiveCatalog;
455
+ private emitCompletedToolStages;
456
+ private emitProfileEvidence;
330
457
  manifest(): McpFnManifest;
331
458
  connect(transport: Transport): Promise<void>;
332
459
  serveStdio(): Promise<void>;
333
- createWebStandardHandler(options?: ConstructorParameters<typeof WebStandardStreamableHTTPServerTransport>[0]): Promise<(request: Request, options?: HandleRequestOptions) => Promise<Response>>;
460
+ createWebStandardHandler(options?: McpFnWebStandardHandlerOptions<TContext>): Promise<(request: Request, options?: HandleRequestOptions) => Promise<Response>>;
334
461
  sample(params: McpFnSamplingParams, options?: McpFnClientRequestOptions): Promise<McpFnSamplingResult>;
335
462
  sampleForRequest(extra: McpFnRequestExtra, params: McpFnSamplingParams, options?: McpFnClientRequestOptions): Promise<McpFnSamplingResult>;
336
463
  elicit(params: McpFnElicitationParams, options?: McpFnClientRequestOptions): Promise<McpFnElicitationResult>;
@@ -384,6 +511,9 @@ declare class McpFnValidationError extends McpFnError {
384
511
  declare class McpFnOutputValidationError extends McpFnError {
385
512
  constructor(message: string, details?: unknown);
386
513
  }
514
+ declare class McpFnClientProfileError extends McpFnError {
515
+ constructor(code: string, message: string, details?: unknown);
516
+ }
387
517
  declare function errorResult(error: unknown, options?: {
388
518
  includeStructuredContent?: boolean;
389
519
  }): CallToolResult;
@@ -391,4 +521,50 @@ declare function errorResult(error: unknown, options?: {
391
521
  declare function textResult(text: string): CallToolResult;
392
522
  declare function structuredResult(structuredContent: Record<string, unknown>, content?: ContentBlock[]): CallToolResult;
393
523
 
394
- export { type CreateManifestOptions, MCP_APP_EXTENSION_ID, MCP_APP_MIME_TYPE, type McpAppCsp, type McpAppPermissions, type McpAppResourceMetadata, type McpAppResourceOptions, type McpAppToolMetadata, type McpFnChangeSeverity, type McpFnClientRequestOptions, type McpFnContractChange, type McpFnDiffResult, type McpFnElicitationParams, type McpFnElicitationResult, McpFnError, type McpFnJsonSchema, type McpFnListedResource, type McpFnListedResourceTemplate, type McpFnListedTool, type McpFnManifest, type McpFnManifestPrompt, type McpFnManifestResource, type McpFnManifestResourceTemplate, type McpFnManifestTool, type McpFnObjectSchema, McpFnOutputValidationError, type McpFnPromptDefinition, McpFnRegistry, type McpFnRequestExtra, type McpFnResourceDefinition, type McpFnResourceTemplateDefinition, type McpFnRootsResult, type McpFnSamplingParams, type McpFnSamplingResult, McpFnServer, McpFnServerDeclaration, type McpFnServerDeclarationOptions, type McpFnServerInfo, type McpFnServerOptions, type McpFnServerRuntimeOptions, type McpFnTaskHandler, type McpFnTaskRequestExtra, type McpFnToolDefinition, type McpFnToolVisibilityInput, McpFnValidationError, assertMcpAppContracts, assertPromptSchemaSupportsStringValues, canonicalJson, canonicalize, compareCodeUnits, createManifest, createMcpAppResource, createMcpFnServer, defineMcpFnServer, diffManifests, errorResult, jsonSafe, mcpAppToolMetadata, promptArguments, resolveMcpFnServerCapabilities, schemaPromptArguments, sha256, structuredResult, textResult, validateManifest };
524
+ /**
525
+ * A single schema validation failure, normalized across validation engines so
526
+ * that error reporting is identical regardless of the runtime.
527
+ */
528
+ interface SchemaIssue {
529
+ instancePath: string;
530
+ message?: string;
531
+ keyword: string;
532
+ schemaPath?: string;
533
+ rejectedProperty?: string;
534
+ missingProperty?: string;
535
+ params?: Record<string, unknown>;
536
+ }
537
+ /**
538
+ * A compiled JSON Schema validator. Calling it returns whether `data` is valid
539
+ * and, on failure, populates `errors` with the normalized issues.
540
+ */
541
+ interface CompiledSchema {
542
+ (data: unknown): boolean;
543
+ errors: SchemaIssue[] | null;
544
+ }
545
+ type SchemaEngine = "ajv" | "cfworker";
546
+ interface SchemaCompiler {
547
+ readonly engine: SchemaEngine;
548
+ compile(schema: object): CompiledSchema;
549
+ }
550
+ /**
551
+ * Validate a related collection of JSON Schema resources without changing each
552
+ * schema's root. All resources are indexed before references are checked, so
553
+ * forward references do not depend on canonical manifest ordering.
554
+ */
555
+ declare function validateSchemaCollection(schemas: readonly object[], engine?: SchemaEngine): void;
556
+ /**
557
+ * Compile a JSON Schema into a runtime-appropriate validator.
558
+ *
559
+ * On Node the validator uses Ajv (with formats) so behavior is unchanged. On
560
+ * edge runtimes that forbid code generation it uses `@cfworker/json-schema`.
561
+ * Throws when the schema itself is invalid, mirroring Ajv's compile-time
562
+ * rejection so callers can surface an "invalid JSON Schema" error.
563
+ */
564
+ declare function createSchemaCompiler(engine?: SchemaEngine): SchemaCompiler;
565
+ /** Whether the current runtime validates schemas via Ajv (Node) or the edge fallback. */
566
+ declare const schemaEngine: SchemaEngine;
567
+ /** Convert normalized engine failures into a bounded public diagnostic shape. */
568
+ declare function formatMcpFnSchemaIssues(errors: SchemaIssue[] | null | undefined): McpFnSchemaIssue[];
569
+
570
+ export { type CompiledSchema, type CreateManifestOptions, MCP_APP_EXTENSION_ID, MCP_APP_MIME_TYPE, type McpAppCsp, type McpAppPermissions, type McpAppResourceMetadata, type McpAppResourceOptions, type McpAppToolMetadata, type McpFnCatalogChange, type McpFnChangeSeverity, type McpFnClientProfile, type McpFnClientProfileCallInput, type McpFnClientProfileCatalogInput, McpFnClientProfileError, type McpFnClientProfileEvidence, type McpFnClientProfileHookInput, type McpFnClientProfileLifecycleStage, type McpFnClientProfilesOptions, type McpFnClientRequestOptions, type McpFnContractChange, type McpFnDiffResult, type McpFnElicitationParams, type McpFnElicitationResult, McpFnError, type McpFnJsonSchema, type McpFnListedResource, type McpFnListedResourceTemplate, type McpFnListedTool, type McpFnManifest, type McpFnManifestPrompt, type McpFnManifestResource, type McpFnManifestResourceTemplate, type McpFnManifestTool, type McpFnObjectSchema, McpFnOutputValidationError, type McpFnPromptDefinition, McpFnRegistry, type McpFnReportedClient, type McpFnRequestExtra, type McpFnResolvedClientProfile, type McpFnResourceDefinition, type McpFnResourceTemplateDefinition, type McpFnRootsResult, type McpFnSamplingParams, type McpFnSamplingResult, type McpFnSchemaIssue, McpFnServer, McpFnServerDeclaration, type McpFnServerDeclarationOptions, type McpFnServerInfo, type McpFnServerOptions, type McpFnServerRuntimeOptions, type McpFnTaskHandler, type McpFnTaskRequestExtra, type McpFnToolDefinition, type McpFnToolLifecycleObserver, type McpFnToolLifecycleStage, type McpFnToolVisibilityInput, McpFnValidationError, type McpFnVerifiedClientIdentity, type McpFnWebStandardHandlerOptions, type SchemaCompiler, type SchemaEngine, type SchemaIssue, assertMcpAppContracts, assertPromptSchemaSupportsStringValues, buildMcpFnEffectiveCatalog, canonicalJson, canonicalize, compareCodeUnits, createManifest, createMcpAppResource, createMcpFnServer, createSchemaCompiler, defineMcpFnServer, diffManifests, enrichMcpFnClientProfileCall, errorResult, formatMcpFnSchemaIssues, jsonSafe, mcpAppToolMetadata, promptArguments, resolveMcpFnClientProfile, resolveMcpFnServerCapabilities, schemaEngine, schemaPromptArguments, sha256, structuredResult, textResult, validateManifest, validateMcpFnClientProfiles, validateSchemaCollection };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ServerCapabilities, ToolAnnotations, ToolExecution, Icon, Resource, ResourceTemplate, PromptArgument, Annotations, ServerRequest, ServerNotification, ReadResourceResult, ElicitRequestFormParams, ElicitRequestURLParams, ElicitResult, Tool, GetPromptResult, CompleteResult, CallToolResult, CreateTaskResult, ListResourcesResult, ListRootsResult, CreateMessageRequest, CreateMessageResult, CreateMessageResultWithTools, Implementation, LoggingMessageNotification, ResourceUpdatedNotification, ContentBlock } from '@modelcontextprotocol/sdk/types.js';
1
+ import { ServerCapabilities, ToolAnnotations, ToolExecution, Icon, Resource, ResourceTemplate, PromptArgument, Annotations, ServerRequest, ServerNotification, ReadResourceResult, Implementation, ClientCapabilities, Tool, ElicitRequestFormParams, ElicitRequestURLParams, ElicitResult, GetPromptResult, CompleteResult, CallToolResult, CreateTaskResult, ListResourcesResult, ListRootsResult, CreateMessageRequest, CreateMessageResult, CreateMessageResultWithTools, LoggingMessageNotification, ResourceUpdatedNotification, ContentBlock } from '@modelcontextprotocol/sdk/types.js';
2
2
  import { RequestHandlerExtra, RequestOptions, RequestTaskStore } from '@modelcontextprotocol/sdk/shared/protocol.js';
3
3
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
4
4
  import { WebStandardStreamableHTTPServerTransport, HandleRequestOptions } from '@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js';
@@ -16,6 +16,29 @@ type McpFnRequestExtra = RequestHandlerExtra<ServerRequest, ServerNotification>;
16
16
  type McpFnTaskRequestExtra = McpFnRequestExtra & {
17
17
  taskStore: RequestTaskStore;
18
18
  };
19
+ /** Safe structural JSON Schema diagnostic. Argument values are never retained. */
20
+ interface McpFnSchemaIssue {
21
+ /** Backwards-compatible alias for instancePath; `/` represents the root. */
22
+ path: string;
23
+ /** RFC 6901 path to the rejected input location; `/` represents the root. */
24
+ instancePath: string;
25
+ /** JSON Schema path reported by the validator. */
26
+ schemaPath: string;
27
+ keyword: string;
28
+ message: string;
29
+ /** Exact unknown property name for additionalProperties failures. */
30
+ rejectedProperty?: string;
31
+ /** Exact missing property name for required failures. */
32
+ missingProperty?: string;
33
+ }
34
+ type McpFnToolLifecycleStage = "input-validation" | "invalid-arguments-handler" | "handler" | "output-validation";
35
+ interface McpFnToolLifecycleObserver {
36
+ onStage?(stage: McpFnToolLifecycleStage): void;
37
+ /** Task results can be validated after createTask has returned. */
38
+ onTaskOutput?(outcome: "succeeded" | "failed", error?: unknown): void | Promise<void>;
39
+ /** Result persistence can fail after the task-creation request has settled. */
40
+ onTaskStorageFailure?(error: unknown): void | Promise<void>;
41
+ }
19
42
  interface McpFnTaskHandler<TContext = undefined> {
20
43
  createTask(args: Record<string, unknown>, context: TContext, extra: McpFnTaskRequestExtra): CreateTaskResult | Promise<CreateTaskResult>;
21
44
  }
@@ -33,11 +56,7 @@ interface McpFnToolDefinition<TContext = undefined> {
33
56
  /** Implements call-now/fetch-later execution when execution.taskSupport allows it. */
34
57
  taskHandler?: McpFnTaskHandler<TContext>;
35
58
  /** Optional domain-specific mapping for JSON Schema argument failures. */
36
- handleInvalidArguments?(args: Record<string, unknown>, issues: Array<{
37
- path: string;
38
- message: string;
39
- keyword: string;
40
- }>, context: TContext, extra: McpFnRequestExtra): CallToolResult | Promise<CallToolResult>;
59
+ handleInvalidArguments?(args: Record<string, unknown>, issues: McpFnSchemaIssue[], context: TContext, extra: McpFnRequestExtra): CallToolResult | Promise<CallToolResult>;
41
60
  }
42
61
  interface McpFnResourceDefinition<TContext = undefined> {
43
62
  uri: string;
@@ -152,6 +171,11 @@ interface McpFnDiffResult {
152
171
  type McpFnListedTool = Tool;
153
172
  type McpFnListedResource = Resource;
154
173
  type McpFnListedResourceTemplate = ResourceTemplate;
174
+ /** Self-reported initialization information. It is compatibility input, never identity. */
175
+ interface McpFnReportedClient {
176
+ info?: Implementation;
177
+ capabilities?: ClientCapabilities;
178
+ }
155
179
  type McpFnSamplingParams = CreateMessageRequest["params"];
156
180
  type McpFnSamplingResult = CreateMessageResult | CreateMessageResultWithTools;
157
181
  type McpFnElicitationParams = ElicitRequestFormParams | ElicitRequestURLParams;
@@ -173,7 +197,7 @@ declare function promptArguments<TContext>(definition: McpFnPromptDefinition<TCo
173
197
  required?: boolean | undefined;
174
198
  }[] | undefined;
175
199
  declare class McpFnRegistry<TContext = undefined> {
176
- private readonly ajv;
200
+ private readonly schemaCompiler;
177
201
  private readonly tools;
178
202
  private readonly resources;
179
203
  private readonly resourceTemplates;
@@ -194,6 +218,8 @@ declare class McpFnRegistry<TContext = undefined> {
194
218
  listChanged?: boolean;
195
219
  }): ServerCapabilities;
196
220
  listTools(): McpFnListedTool[];
221
+ getListedTool(name: string): McpFnListedTool | undefined;
222
+ private listedTool;
197
223
  listResources(context: TContext, extra: McpFnRequestExtra): Promise<Resource[]>;
198
224
  listResourceTemplates(): ResourceTemplate[];
199
225
  listPrompts(): {
@@ -214,9 +240,9 @@ declare class McpFnRegistry<TContext = undefined> {
214
240
  name: string;
215
241
  }[];
216
242
  private normalizeAndValidateArgs;
217
- callTool(name: string, args: unknown, context: TContext, extra: McpFnRequestExtra): Promise<CallToolResult>;
243
+ callTool(name: string, args: unknown, context: TContext, extra: McpFnRequestExtra, observer?: McpFnToolLifecycleObserver): Promise<CallToolResult>;
218
244
  taskSupport(name: string): "optional" | "required" | "forbidden";
219
- createToolTask(name: string, args: unknown, context: TContext, extra: McpFnTaskRequestExtra): Promise<CreateTaskResult>;
245
+ createToolTask(name: string, args: unknown, context: TContext, extra: McpFnTaskRequestExtra, observer?: McpFnToolLifecycleObserver): Promise<CreateTaskResult>;
220
246
  private matchResource;
221
247
  readResource(uri: string, context: TContext, extra: McpFnRequestExtra): Promise<ReadResourceResult>;
222
248
  changeSubscription(uri: string, subscribed: boolean, context: TContext, extra: McpFnRequestExtra): Promise<void>;
@@ -276,6 +302,89 @@ declare function canonicalize(value: unknown): unknown;
276
302
  declare function canonicalJson(value: unknown): string;
277
303
  declare function sha256(value: unknown): string;
278
304
 
305
+ interface McpFnVerifiedClientIdentity {
306
+ /** Stable authenticated subject. Never derived from initialize.clientInfo. */
307
+ subject: string;
308
+ /** Optional non-secret attributes used by product-owned profile selection. */
309
+ attributes?: Record<string, string | number | boolean | null>;
310
+ }
311
+ interface McpFnClientProfileHookInput<TContext> {
312
+ context: TContext;
313
+ extra: McpFnRequestExtra;
314
+ verifiedIdentity: McpFnVerifiedClientIdentity;
315
+ reportedClient: McpFnReportedClient;
316
+ }
317
+ interface McpFnClientProfileCatalogInput<TContext> extends McpFnClientProfileHookInput<TContext> {
318
+ tools: McpFnListedTool[];
319
+ }
320
+ interface McpFnClientProfileCallInput<TContext> extends McpFnClientProfileHookInput<TContext> {
321
+ tool: McpFnListedTool;
322
+ arguments: Record<string, unknown>;
323
+ }
324
+ interface McpFnClientProfile<TContext = undefined> {
325
+ id: string;
326
+ version: string;
327
+ /** Defaults to true. Set false only when hooks do not use initialization metadata. */
328
+ requiresReportedClient?: boolean;
329
+ /** Selection is deliberately restricted to verified identity. */
330
+ matches(identity: McpFnVerifiedClientIdentity): boolean | Promise<boolean>;
331
+ projectCatalog?(input: McpFnClientProfileCatalogInput<TContext>): Tool[] | Promise<Tool[]>;
332
+ /** Root argument names owned by the server for each tool. */
333
+ serverOwnedArguments?: Readonly<Record<string, readonly string[]>>;
334
+ enrichArguments?(input: McpFnClientProfileCallInput<TContext>): Record<string, unknown> | Promise<Record<string, unknown>>;
335
+ }
336
+ type McpFnClientProfileLifecycleStage = "profile-resolution" | "catalog-projection" | "argument-enrichment" | "input-validation" | "invalid-arguments-handler" | "handler" | "output-validation" | "task-result-storage";
337
+ interface McpFnClientProfileEvidence {
338
+ formatVersion: 1;
339
+ stage: McpFnClientProfileLifecycleStage;
340
+ outcome: "started" | "succeeded" | "failed";
341
+ profile?: {
342
+ id: string;
343
+ version: string;
344
+ };
345
+ tool?: string;
346
+ code?: string;
347
+ issues?: McpFnSchemaIssue[];
348
+ }
349
+ interface McpFnClientProfilesOptions<TContext = undefined> {
350
+ profiles: readonly McpFnClientProfile<TContext>[];
351
+ resolveVerifiedIdentity(input: {
352
+ context: TContext;
353
+ extra: McpFnRequestExtra;
354
+ }): McpFnVerifiedClientIdentity | undefined | Promise<McpFnVerifiedClientIdentity | undefined>;
355
+ evidence?(event: McpFnClientProfileEvidence): void | Promise<void>;
356
+ }
357
+ interface McpFnCatalogChange {
358
+ kind: "removed" | "modified";
359
+ path: string;
360
+ tool: string;
361
+ beforeHash: string;
362
+ afterHash?: string;
363
+ }
364
+ interface McpFnResolvedClientProfile<TContext> {
365
+ context: TContext;
366
+ extra: McpFnRequestExtra;
367
+ verifiedIdentity?: McpFnVerifiedClientIdentity;
368
+ reportedClient: McpFnReportedClient;
369
+ profile?: McpFnClientProfile<TContext>;
370
+ }
371
+ declare function validateMcpFnClientProfiles<TContext>(options: McpFnClientProfilesOptions<TContext>): void;
372
+ declare function resolveMcpFnClientProfile<TContext>(options: McpFnClientProfilesOptions<TContext>, input: Omit<McpFnResolvedClientProfile<TContext>, "verifiedIdentity" | "profile">): Promise<McpFnResolvedClientProfile<TContext>>;
373
+ declare function buildMcpFnEffectiveCatalog<TContext>(input: {
374
+ canonicalTools: McpFnListedTool[];
375
+ /** Complete registry inventory when canonicalTools has already been visibility-filtered. */
376
+ knownTools?: McpFnListedTool[];
377
+ resolved: McpFnResolvedClientProfile<TContext>;
378
+ }): Promise<{
379
+ tools: McpFnListedTool[];
380
+ changes: McpFnCatalogChange[];
381
+ }>;
382
+ declare function enrichMcpFnClientProfileCall<TContext>(input: {
383
+ resolved: McpFnResolvedClientProfile<TContext>;
384
+ tool: McpFnListedTool;
385
+ arguments: unknown;
386
+ }): Promise<unknown>;
387
+
279
388
  interface CreateManifestOptions {
280
389
  protocolVersions?: string[];
281
390
  transports?: Array<"stdio" | "streamable-http">;
@@ -301,6 +410,8 @@ interface McpFnServerOptions<TContext> extends CreateManifestOptions {
301
410
  * unknown tool. Static manifests remain the complete server contract.
302
411
  */
303
412
  toolVisibility?: (input: McpFnToolVisibilityInput<TContext>) => boolean | Promise<boolean>;
413
+ /** Authenticated client catalog projection and trusted call enrichment. */
414
+ clientProfiles?: McpFnClientProfilesOptions<TContext>;
304
415
  /** Maximum entries returned by each list request. Defaults to 100. */
305
416
  pageSize?: number;
306
417
  additionalCapabilities?: ServerCapabilities;
@@ -310,6 +421,16 @@ interface McpFnServerOptions<TContext> extends CreateManifestOptions {
310
421
  maxTaskQueueSize?: number;
311
422
  enforceStrictCapabilities?: boolean;
312
423
  }
424
+ type McpFnWebStandardHandlerOptions<TContext> = ConstructorParameters<typeof WebStandardStreamableHTTPServerTransport>[0] & {
425
+ /**
426
+ * Configure the live isolated server before its transport connects. This
427
+ * runs once per stateless request, or once per session initialization
428
+ * attempt before the SDK validates the request. Rejected attempts may
429
+ * therefore invoke it without retaining a session. This is the correct
430
+ * place to attach protocol instrumentation.
431
+ */
432
+ configureRequestServer?: (server: McpFnServer<TContext>) => void | Promise<void>;
433
+ };
313
434
  /** Resolve the exact protocol/manifest capabilities from one registry contract. */
314
435
  declare function resolveMcpFnServerCapabilities<TContext>(registry: McpFnRegistry<TContext>, additionalCapabilities: ServerCapabilities | undefined, includeTaskOperations: boolean): ServerCapabilities;
315
436
  declare class McpFnServer<TContext = undefined> {
@@ -319,6 +440,7 @@ declare class McpFnServer<TContext = undefined> {
319
440
  readonly capabilities: ServerCapabilities;
320
441
  private readonly contextFactory;
321
442
  private readonly toolVisibility?;
443
+ private readonly clientProfiles?;
322
444
  private readonly manifestOptions;
323
445
  private readonly pageSize;
324
446
  private readonly serverOptions;
@@ -327,10 +449,15 @@ declare class McpFnServer<TContext = undefined> {
327
449
  constructor(options: McpFnServerOptions<TContext>);
328
450
  private installHandlers;
329
451
  private filterVisibleTools;
452
+ private profileReference;
453
+ private resolveProfile;
454
+ private buildEffectiveCatalog;
455
+ private emitCompletedToolStages;
456
+ private emitProfileEvidence;
330
457
  manifest(): McpFnManifest;
331
458
  connect(transport: Transport): Promise<void>;
332
459
  serveStdio(): Promise<void>;
333
- createWebStandardHandler(options?: ConstructorParameters<typeof WebStandardStreamableHTTPServerTransport>[0]): Promise<(request: Request, options?: HandleRequestOptions) => Promise<Response>>;
460
+ createWebStandardHandler(options?: McpFnWebStandardHandlerOptions<TContext>): Promise<(request: Request, options?: HandleRequestOptions) => Promise<Response>>;
334
461
  sample(params: McpFnSamplingParams, options?: McpFnClientRequestOptions): Promise<McpFnSamplingResult>;
335
462
  sampleForRequest(extra: McpFnRequestExtra, params: McpFnSamplingParams, options?: McpFnClientRequestOptions): Promise<McpFnSamplingResult>;
336
463
  elicit(params: McpFnElicitationParams, options?: McpFnClientRequestOptions): Promise<McpFnElicitationResult>;
@@ -384,6 +511,9 @@ declare class McpFnValidationError extends McpFnError {
384
511
  declare class McpFnOutputValidationError extends McpFnError {
385
512
  constructor(message: string, details?: unknown);
386
513
  }
514
+ declare class McpFnClientProfileError extends McpFnError {
515
+ constructor(code: string, message: string, details?: unknown);
516
+ }
387
517
  declare function errorResult(error: unknown, options?: {
388
518
  includeStructuredContent?: boolean;
389
519
  }): CallToolResult;
@@ -391,4 +521,50 @@ declare function errorResult(error: unknown, options?: {
391
521
  declare function textResult(text: string): CallToolResult;
392
522
  declare function structuredResult(structuredContent: Record<string, unknown>, content?: ContentBlock[]): CallToolResult;
393
523
 
394
- export { type CreateManifestOptions, MCP_APP_EXTENSION_ID, MCP_APP_MIME_TYPE, type McpAppCsp, type McpAppPermissions, type McpAppResourceMetadata, type McpAppResourceOptions, type McpAppToolMetadata, type McpFnChangeSeverity, type McpFnClientRequestOptions, type McpFnContractChange, type McpFnDiffResult, type McpFnElicitationParams, type McpFnElicitationResult, McpFnError, type McpFnJsonSchema, type McpFnListedResource, type McpFnListedResourceTemplate, type McpFnListedTool, type McpFnManifest, type McpFnManifestPrompt, type McpFnManifestResource, type McpFnManifestResourceTemplate, type McpFnManifestTool, type McpFnObjectSchema, McpFnOutputValidationError, type McpFnPromptDefinition, McpFnRegistry, type McpFnRequestExtra, type McpFnResourceDefinition, type McpFnResourceTemplateDefinition, type McpFnRootsResult, type McpFnSamplingParams, type McpFnSamplingResult, McpFnServer, McpFnServerDeclaration, type McpFnServerDeclarationOptions, type McpFnServerInfo, type McpFnServerOptions, type McpFnServerRuntimeOptions, type McpFnTaskHandler, type McpFnTaskRequestExtra, type McpFnToolDefinition, type McpFnToolVisibilityInput, McpFnValidationError, assertMcpAppContracts, assertPromptSchemaSupportsStringValues, canonicalJson, canonicalize, compareCodeUnits, createManifest, createMcpAppResource, createMcpFnServer, defineMcpFnServer, diffManifests, errorResult, jsonSafe, mcpAppToolMetadata, promptArguments, resolveMcpFnServerCapabilities, schemaPromptArguments, sha256, structuredResult, textResult, validateManifest };
524
+ /**
525
+ * A single schema validation failure, normalized across validation engines so
526
+ * that error reporting is identical regardless of the runtime.
527
+ */
528
+ interface SchemaIssue {
529
+ instancePath: string;
530
+ message?: string;
531
+ keyword: string;
532
+ schemaPath?: string;
533
+ rejectedProperty?: string;
534
+ missingProperty?: string;
535
+ params?: Record<string, unknown>;
536
+ }
537
+ /**
538
+ * A compiled JSON Schema validator. Calling it returns whether `data` is valid
539
+ * and, on failure, populates `errors` with the normalized issues.
540
+ */
541
+ interface CompiledSchema {
542
+ (data: unknown): boolean;
543
+ errors: SchemaIssue[] | null;
544
+ }
545
+ type SchemaEngine = "ajv" | "cfworker";
546
+ interface SchemaCompiler {
547
+ readonly engine: SchemaEngine;
548
+ compile(schema: object): CompiledSchema;
549
+ }
550
+ /**
551
+ * Validate a related collection of JSON Schema resources without changing each
552
+ * schema's root. All resources are indexed before references are checked, so
553
+ * forward references do not depend on canonical manifest ordering.
554
+ */
555
+ declare function validateSchemaCollection(schemas: readonly object[], engine?: SchemaEngine): void;
556
+ /**
557
+ * Compile a JSON Schema into a runtime-appropriate validator.
558
+ *
559
+ * On Node the validator uses Ajv (with formats) so behavior is unchanged. On
560
+ * edge runtimes that forbid code generation it uses `@cfworker/json-schema`.
561
+ * Throws when the schema itself is invalid, mirroring Ajv's compile-time
562
+ * rejection so callers can surface an "invalid JSON Schema" error.
563
+ */
564
+ declare function createSchemaCompiler(engine?: SchemaEngine): SchemaCompiler;
565
+ /** Whether the current runtime validates schemas via Ajv (Node) or the edge fallback. */
566
+ declare const schemaEngine: SchemaEngine;
567
+ /** Convert normalized engine failures into a bounded public diagnostic shape. */
568
+ declare function formatMcpFnSchemaIssues(errors: SchemaIssue[] | null | undefined): McpFnSchemaIssue[];
569
+
570
+ export { type CompiledSchema, type CreateManifestOptions, MCP_APP_EXTENSION_ID, MCP_APP_MIME_TYPE, type McpAppCsp, type McpAppPermissions, type McpAppResourceMetadata, type McpAppResourceOptions, type McpAppToolMetadata, type McpFnCatalogChange, type McpFnChangeSeverity, type McpFnClientProfile, type McpFnClientProfileCallInput, type McpFnClientProfileCatalogInput, McpFnClientProfileError, type McpFnClientProfileEvidence, type McpFnClientProfileHookInput, type McpFnClientProfileLifecycleStage, type McpFnClientProfilesOptions, type McpFnClientRequestOptions, type McpFnContractChange, type McpFnDiffResult, type McpFnElicitationParams, type McpFnElicitationResult, McpFnError, type McpFnJsonSchema, type McpFnListedResource, type McpFnListedResourceTemplate, type McpFnListedTool, type McpFnManifest, type McpFnManifestPrompt, type McpFnManifestResource, type McpFnManifestResourceTemplate, type McpFnManifestTool, type McpFnObjectSchema, McpFnOutputValidationError, type McpFnPromptDefinition, McpFnRegistry, type McpFnReportedClient, type McpFnRequestExtra, type McpFnResolvedClientProfile, type McpFnResourceDefinition, type McpFnResourceTemplateDefinition, type McpFnRootsResult, type McpFnSamplingParams, type McpFnSamplingResult, type McpFnSchemaIssue, McpFnServer, McpFnServerDeclaration, type McpFnServerDeclarationOptions, type McpFnServerInfo, type McpFnServerOptions, type McpFnServerRuntimeOptions, type McpFnTaskHandler, type McpFnTaskRequestExtra, type McpFnToolDefinition, type McpFnToolLifecycleObserver, type McpFnToolLifecycleStage, type McpFnToolVisibilityInput, McpFnValidationError, type McpFnVerifiedClientIdentity, type McpFnWebStandardHandlerOptions, type SchemaCompiler, type SchemaEngine, type SchemaIssue, assertMcpAppContracts, assertPromptSchemaSupportsStringValues, buildMcpFnEffectiveCatalog, canonicalJson, canonicalize, compareCodeUnits, createManifest, createMcpAppResource, createMcpFnServer, createSchemaCompiler, defineMcpFnServer, diffManifests, enrichMcpFnClientProfileCall, errorResult, formatMcpFnSchemaIssues, jsonSafe, mcpAppToolMetadata, promptArguments, resolveMcpFnClientProfile, resolveMcpFnServerCapabilities, schemaEngine, schemaPromptArguments, sha256, structuredResult, textResult, validateManifest, validateMcpFnClientProfiles, validateSchemaCollection };