@unbrained/pm-cli 2026.8.24 → 2026.8.26
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/.claude-plugin/marketplace.json +2 -2
- package/CHANGELOG.md +46 -0
- package/dist/cli-bundle/bundle-manifest.json +149 -149
- package/dist/cli-bundle/chunks/chunk-E2GCFJSU.js +35 -0
- package/dist/cli-bundle/chunks/{chunk-TEQDR5KI.js → chunk-ES25LX3D.js} +62 -62
- package/dist/cli-bundle/chunks/{chunk-I5Q7QSZX.js → chunk-FRDWWB6R.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-X7WWQDYQ.js → chunk-ICQ3RVIY.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-YOLLRCLY.js → chunk-IV64RJVE.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-L22NP5MA.js → chunk-KBFP3E4E.js} +86 -86
- package/dist/cli-bundle/chunks/{chunk-AGUL3HUT.js → chunk-MVYLQ67M.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-DJNJBWAQ.js → chunk-S4U76VZF.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-IW72J5FW.js → chunk-UKBCRPA2.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-WRHJ3MB6.js +8 -0
- package/dist/cli-bundle/chunks/{chunk-ZAVCS2GH.js → chunk-ZNRLJ54C.js} +60 -60
- package/dist/cli-bundle/chunks/{register-list-query-37A4P6O4.js → register-list-query-EMCPMICY.js} +2 -2
- package/dist/cli-bundle/chunks/{register-mutation-TBJDHYIT.js → register-mutation-OJ67ABCB.js} +3 -3
- package/dist/cli-bundle/chunks/{register-operations-WRZNEBUM.js → register-operations-H2GLP7LT.js} +2 -2
- package/dist/cli-bundle/chunks/{register-setup-H4PDLACD.js → register-setup-GLZAHLVI.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-IMWTYKII.js → chunk-4K2II4TV.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-4XNH2HM7.js +2 -0
- package/dist/cli-bundle/focused-chunks/{chunk-GJR6YEMR.js → chunk-57XY346D.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-4WP7LNE3.js → chunk-66VGB23P.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-72T6JGAE.js +50 -0
- package/dist/cli-bundle/focused-chunks/{chunk-BFA6KKCI.js → chunk-7I23XGWO.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-6Z24ZMU3.js → chunk-7YCDTCBC.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-O4ZXNJMT.js → chunk-A644DUFQ.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-FXDLT6FL.js +16 -0
- package/dist/cli-bundle/focused-chunks/{chunk-RASVBJX5.js → chunk-IBHXMFE7.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-LMKG3DFE.js +5 -0
- package/dist/cli-bundle/focused-chunks/{chunk-6MUTDXMP.js → chunk-LV5N3LK5.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-CWCN5RLO.js → chunk-MMXUPDDJ.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-WZLSSGEU.js → chunk-OHIHZ7HS.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-P2E6LDAE.js +19 -0
- package/dist/cli-bundle/focused-chunks/{chunk-IZNRRCU3.js → chunk-TMJDFHVD.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-QBP5FSBX.js → chunk-UYBA57GY.js} +4 -4
- package/dist/cli-bundle/focused-chunks/{chunk-MNPECIRL.js → chunk-YO3ZF3FI.js} +2 -2
- package/dist/cli-bundle/main.js +2 -2
- package/dist/cli-bundle/sdk-authoring.js +1 -1
- package/dist/cli-bundle/sdk-contracts.js +2 -2
- package/dist/cli-bundle/sdk-core.js +41 -41
- package/dist/cli-bundle/sdk-governance.js +1 -1
- package/dist/cli-bundle/sdk-graph.js +1 -1
- package/dist/cli-bundle/sdk-merge.js +32 -33
- package/dist/cli-bundle/sdk-query.js +1 -1
- package/dist/cli-bundle/sdk-runtime.js +1 -1
- package/dist/cli-bundle/sdk-testing.js +1 -1
- package/dist/cli-bundle/sdk.js +7 -6
- package/dist/core/diagnostics/remediation.js +17 -2
- package/dist/core/extensions/manifest-schema.d.ts +20 -0
- package/dist/core/extensions/manifest-schema.js +28 -10
- package/dist/mcp/http-server.d.ts +60 -0
- package/dist/mcp/http-server.js +451 -0
- package/dist/mcp/legacy-adapter.d.ts +50 -0
- package/dist/mcp/legacy-adapter.js +64 -0
- package/dist/mcp/server.d.ts +42 -9
- package/dist/mcp/server.js +457 -58
- package/dist/sdk/agent/refusal-closure-census.d.ts +6 -2
- package/dist/sdk/agent/refusal-closure-census.js +16 -8
- package/dist/sdk/cli-contracts/runtime-contracts.d.ts +10 -0
- package/dist/sdk/cli-contracts/runtime-contracts.js +20 -3
- package/dist/sdk/compose.d.ts +4 -1
- package/dist/sdk/compose.js +23 -36
- package/dist/sdk/extension/author-manifest.d.ts +22 -0
- package/dist/sdk/extension/author-manifest.js +93 -0
- package/dist/sdk/extension.js +6 -3
- package/dist/sdk/generated/generated-error-code-catalog-part-1.js +67 -28
- package/dist/sdk/generated/generated-error-code-catalog-part-2.js +30 -3
- package/dist/sdk/governance/health.js +103 -11
- package/dist/sdk/governance/validate.js +15 -9
- package/dist/sdk/history-repair.d.ts +24 -0
- package/dist/sdk/history-repair.js +145 -4
- package/dist/sdk/index.d.ts +6 -0
- package/dist/sdk/index.js +8 -2
- package/dist/sdk/mcp/authorization.d.ts +134 -0
- package/dist/sdk/mcp/authorization.js +405 -0
- package/dist/sdk/mcp/interactions.d.ts +118 -0
- package/dist/sdk/mcp/interactions.js +337 -0
- package/dist/sdk/mcp/protocol.d.ts +142 -0
- package/dist/sdk/mcp/protocol.js +174 -0
- package/dist/sdk/mcp/subscriptions.d.ts +65 -0
- package/dist/sdk/mcp/subscriptions.js +212 -0
- package/dist/sdk/mcp/tasks.d.ts +107 -0
- package/dist/sdk/mcp/tasks.js +431 -0
- package/dist/sdk/mcp/transport.d.ts +30 -0
- package/dist/sdk/mcp/transport.js +261 -0
- package/dist/sdk/merge/driver.js +25 -4
- package/dist/sdk/merge/receipt-file-boundary.d.ts +21 -0
- package/dist/sdk/merge/receipt-file-boundary.js +47 -0
- package/dist/sdk/merge/receipts.d.ts +40 -1
- package/dist/sdk/merge/receipts.js +343 -36
- package/dist/sdk/merge/reconcile.js +117 -47
- package/dist/sdk/read-output/continuation.d.ts +15 -2
- package/dist/sdk/read-output/continuation.js +86 -6
- package/dist/sdk/read-output-contracts.d.ts +4 -1
- package/dist/sdk/read-output-contracts.js +9 -6
- package/dist/sdk/runtime-primitives.d.ts +1 -1
- package/dist/sdk/runtime-primitives.js +3 -3
- package/dist/sdk/test/execution.d.ts +6 -0
- package/dist/sdk/test/execution.js +32 -3
- package/docs/AGENT_PROVENANCE_ADR.md +6 -4
- package/docs/AGENT_RUNTIME_PRIMITIVES.md +6 -5
- package/docs/CLAUDE_CODE_PLUGIN.md +12 -5
- package/docs/DIAGNOSTIC_OUTPUT_CONTRACTS.md +8 -0
- package/docs/EXTENSIONS.md +3 -4
- package/docs/MCP_2026_07_28.md +138 -0
- package/docs/MCP_2026_07_28_CONFORMANCE.md +30 -0
- package/docs/MCP_REMOTE_TRANSPORT_SECURITY.md +180 -0
- package/docs/MERGE_SAFETY.md +34 -5
- package/docs/OUTPUT_PROJECTION_CONTRACTS.md +13 -1
- package/docs/README.md +4 -0
- package/docs/READ_OUTPUT_CONTRACTS.md +25 -2
- package/docs/RELEASING.md +3 -2
- package/docs/SDK.md +22 -1
- package/docs/SDK_AGENT_SESSION_CONTEXT.md +18 -13
- package/docs/SDK_MCP_INTERACTIONS.md +227 -0
- package/docs/TESTING.md +4 -0
- package/docs/generated/REFUSAL_CLOSURE_CENSUS.md +13 -8
- package/marketplace.json +2 -2
- package/package.json +7 -5
- package/packages/pm-beads/package.json +1 -1
- package/packages/pm-calendar/package.json +1 -1
- package/packages/pm-command-kit/package.json +1 -1
- package/packages/pm-digital-twin/package.json +1 -1
- package/packages/pm-governance-audit/package.json +1 -1
- package/packages/pm-guide-shell/package.json +1 -1
- package/packages/pm-kanban/package.json +1 -1
- package/packages/pm-lifecycle-hooks/package.json +1 -1
- package/packages/pm-linked-test-adapters/package.json +1 -1
- package/packages/pm-search-advanced/package.json +1 -1
- package/packages/pm-templates/package.json +1 -1
- package/packages/pm-todos/package.json +1 -1
- package/packages/pm-vcs/package.json +1 -1
- package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
- package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
- package/scripts/finalize-build.mjs +1 -0
- package/sdk/public-surface.json +762 -15
- package/dist/cli-bundle/chunks/chunk-MKE6MD2K.js +0 -36
- package/dist/cli-bundle/chunks/chunk-NXBFO63A.js +0 -8
- package/dist/cli-bundle/focused-chunks/chunk-FCTT4CZU.js +0 -5
- package/dist/cli-bundle/focused-chunks/chunk-Q63PSLO4.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-QV5UP27O.js +0 -51
- package/dist/cli-bundle/focused-chunks/chunk-RPRLENVA.js +0 -16
- package/dist/cli-bundle/focused-chunks/chunk-TOFVXBWA.js +0 -19
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { PmMcpHttpHeaders } from "./transport.js";
|
|
2
|
+
/** Authorization failure with an HTTP status and disclosure-safe context. */
|
|
3
|
+
export declare class PmMcpAuthorizationError extends Error {
|
|
4
|
+
/** HTTP status required at the remote MCP boundary. */
|
|
5
|
+
readonly httpStatus: 401 | 403;
|
|
6
|
+
/** Optional RFC 6750 challenge safe to send to an unauthenticated client. */
|
|
7
|
+
readonly challenge?: string;
|
|
8
|
+
/** Create one remote authorization refusal. */
|
|
9
|
+
constructor(message: string, httpStatus: 401 | 403, challenge?: string);
|
|
10
|
+
}
|
|
11
|
+
/** RFC 9728 metadata served by a protected pm MCP resource. */
|
|
12
|
+
export interface PmMcpProtectedResourceMetadata {
|
|
13
|
+
/** Canonical MCP resource URI used for token audience binding. */
|
|
14
|
+
resource: string;
|
|
15
|
+
/** Independent authorization-server issuers accepted by this resource. */
|
|
16
|
+
authorization_servers: string[];
|
|
17
|
+
/** Minimal scopes used for initial least-privilege authorization. */
|
|
18
|
+
scopes_supported?: string[];
|
|
19
|
+
}
|
|
20
|
+
/** Validated authorization-server discovery fields needed by MCP clients. */
|
|
21
|
+
export interface PmMcpAuthorizationServerMetadata {
|
|
22
|
+
/** Exact issuer identifier. */
|
|
23
|
+
issuer: string;
|
|
24
|
+
/** Authorization endpoint for code flows. */
|
|
25
|
+
authorization_endpoint?: string;
|
|
26
|
+
/** Token endpoint used to redeem authorization codes. */
|
|
27
|
+
token_endpoint?: string;
|
|
28
|
+
/** PKCE methods advertised by the authorization server. */
|
|
29
|
+
code_challenge_methods_supported: string[];
|
|
30
|
+
/** Whether URL-form Client ID Metadata Documents are supported. */
|
|
31
|
+
client_id_metadata_document_supported?: boolean;
|
|
32
|
+
/** Deprecated dynamic-registration fallback endpoint. */
|
|
33
|
+
registration_endpoint?: string;
|
|
34
|
+
}
|
|
35
|
+
/** Discovery metadata after endpoint and PKCE validation succeeds. */
|
|
36
|
+
export interface PmMcpValidatedAuthorizationServerMetadata extends PmMcpAuthorizationServerMetadata {
|
|
37
|
+
/** Validated HTTPS authorization endpoint for code flows. */
|
|
38
|
+
authorization_endpoint: string;
|
|
39
|
+
/** Validated HTTPS token endpoint used to redeem authorization codes. */
|
|
40
|
+
token_endpoint: string;
|
|
41
|
+
}
|
|
42
|
+
/** Client registration strategy ordered by current MCP preference. */
|
|
43
|
+
export type PmMcpClientRegistrationMode = "pre_registered" | "client_id_metadata_document" | "dynamic" | "user_supplied";
|
|
44
|
+
/** Bound access-token facts returned by a host-provided verifier. */
|
|
45
|
+
export interface PmMcpAccessTokenClaims {
|
|
46
|
+
/** Stable authenticated principal without raw token material. */
|
|
47
|
+
principal: string;
|
|
48
|
+
/** Issuer that minted the token. */
|
|
49
|
+
issuer: string;
|
|
50
|
+
/** Intended resource audiences. */
|
|
51
|
+
audience: string | string[];
|
|
52
|
+
/** Granted OAuth scopes. */
|
|
53
|
+
scopes: string[];
|
|
54
|
+
}
|
|
55
|
+
/** Policy a Streamable HTTP adapter enforces before dispatching MCP. */
|
|
56
|
+
export interface PmMcpHttpAuthorizationPolicy {
|
|
57
|
+
/** Exact accepted issuer. */
|
|
58
|
+
issuer: string;
|
|
59
|
+
/** Exact canonical MCP resource audience. */
|
|
60
|
+
resource: string;
|
|
61
|
+
/** Scopes required for this endpoint or operation. */
|
|
62
|
+
requiredScopes?: string[];
|
|
63
|
+
/** Protected-resource metadata location for RFC 6750 challenges. */
|
|
64
|
+
resourceMetadataUrl: string;
|
|
65
|
+
/** Validate an opaque or structured access token without passing it onward. */
|
|
66
|
+
verifyAccessToken: (token: string) => PmMcpAccessTokenClaims | Promise<PmMcpAccessTokenClaims>;
|
|
67
|
+
}
|
|
68
|
+
/** W3C trace context accepted from request `_meta`. */
|
|
69
|
+
export interface PmMcpTraceContext {
|
|
70
|
+
/** W3C trace-parent value. */
|
|
71
|
+
traceparent?: string;
|
|
72
|
+
/** W3C trace-state value. */
|
|
73
|
+
tracestate?: string;
|
|
74
|
+
/** Allowlisted W3C baggage members only. */
|
|
75
|
+
baggage?: string;
|
|
76
|
+
}
|
|
77
|
+
/** Build and validate protected-resource metadata for a remote pm endpoint. */
|
|
78
|
+
export declare function buildMcpProtectedResourceMetadata(input: {
|
|
79
|
+
resource: string;
|
|
80
|
+
authorizationServers: readonly string[];
|
|
81
|
+
scopes?: readonly string[];
|
|
82
|
+
}): PmMcpProtectedResourceMetadata;
|
|
83
|
+
/** Construct OAuth and OIDC discovery URLs in the MCP-required order. */
|
|
84
|
+
export declare function buildMcpAuthorizationDiscoveryUrls(issuer: string): string[];
|
|
85
|
+
/** Validate authorization-server metadata, exact issuer binding, and S256 PKCE. */
|
|
86
|
+
export declare function validateMcpAuthorizationServerMetadata(value: unknown, expectedIssuer: string): PmMcpValidatedAuthorizationServerMetadata;
|
|
87
|
+
/** Apply the current pre-registration, metadata-document, dynamic, prompt order. */
|
|
88
|
+
export declare function selectMcpClientRegistrationMode(input: {
|
|
89
|
+
hasPreRegisteredClient: boolean;
|
|
90
|
+
metadata: Pick<PmMcpAuthorizationServerMetadata, "client_id_metadata_document_supported" | "registration_endpoint">;
|
|
91
|
+
}): PmMcpClientRegistrationMode;
|
|
92
|
+
/** Validate a present authorization-response issuer before code redemption. */
|
|
93
|
+
export declare function validateMcpAuthorizationResponseIssuer(input: {
|
|
94
|
+
expectedIssuer: string;
|
|
95
|
+
responseIssuer?: string;
|
|
96
|
+
issuerParameterSupported?: boolean;
|
|
97
|
+
}): void;
|
|
98
|
+
/** Validate a self-hosted Client ID Metadata Document and exact redirect set. */
|
|
99
|
+
export declare function validateMcpClientMetadataDocument(value: unknown, documentUrl: string): Record<string, unknown>;
|
|
100
|
+
/** Build bounded dynamic-registration metadata for explicit legacy fallback. */
|
|
101
|
+
export declare function buildMcpDynamicRegistrationMetadata(input: {
|
|
102
|
+
redirectUris: readonly string[];
|
|
103
|
+
applicationType: "native" | "web";
|
|
104
|
+
clientName: string;
|
|
105
|
+
}): Record<string, unknown>;
|
|
106
|
+
/** In-memory issuer-keyed credential primitive that never reuses cross-issuer state. */
|
|
107
|
+
export declare class PmMcpIssuerCredentialStore<Credential extends Record<string, unknown>> {
|
|
108
|
+
#private;
|
|
109
|
+
/** Persist a cloned credential under the exact validated issuer. */
|
|
110
|
+
set(issuer: string, credential: Credential): void;
|
|
111
|
+
/** Read a cloned credential only for the exact issuer. */
|
|
112
|
+
get(issuer: string): Credential | undefined;
|
|
113
|
+
/** Remove credentials for one issuer during revocation or re-registration. */
|
|
114
|
+
delete(issuer: string): boolean;
|
|
115
|
+
}
|
|
116
|
+
/** Extract W3C trace context with strict syntax, size, and baggage allowlists. */
|
|
117
|
+
export declare function extractMcpTraceContext(params: unknown, options?: {
|
|
118
|
+
baggageAllowlist?: readonly string[];
|
|
119
|
+
}): PmMcpTraceContext;
|
|
120
|
+
/** Run one request with trace context isolated from every concurrent request. */
|
|
121
|
+
export declare function runWithMcpTraceContext<Result>(context: PmMcpTraceContext, callback: () => Result): Result;
|
|
122
|
+
/** Read a defensive copy of the current request's trace context. */
|
|
123
|
+
export declare function getActiveMcpTraceContext(): PmMcpTraceContext | undefined;
|
|
124
|
+
/** Enforce bearer location, issuer, audience, and least-privilege scopes. */
|
|
125
|
+
export declare function authorizeMcpHttpRequest(input: {
|
|
126
|
+
headers: PmMcpHttpHeaders;
|
|
127
|
+
requestUrl: string;
|
|
128
|
+
policy: PmMcpHttpAuthorizationPolicy;
|
|
129
|
+
}): Promise<PmMcpAccessTokenClaims>;
|
|
130
|
+
/** Create an exact opaque-token verifier without exposing token values in results. */
|
|
131
|
+
export declare function createMcpStaticBearerVerifier(input: {
|
|
132
|
+
token: string;
|
|
133
|
+
claims: PmMcpAccessTokenClaims;
|
|
134
|
+
}): (token: string) => PmMcpAccessTokenClaims;
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module sdk/mcp/authorization
|
|
3
|
+
*
|
|
4
|
+
* Defines issuer-bound OAuth resource-server, client-registration, credential,
|
|
5
|
+
* and privacy-bounded trace propagation primitives for remote MCP transports.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="a9aefc86-a8ce-5ecf-bb54-e5fa3ea277c7")}catch(e){}}();
|
|
9
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
10
|
+
import { createHash, timingSafeEqual } from "node:crypto";
|
|
11
|
+
import { isMcpRecord } from "./protocol.js";
|
|
12
|
+
/** Authorization failure with an HTTP status and disclosure-safe context. */
|
|
13
|
+
export class PmMcpAuthorizationError extends Error {
|
|
14
|
+
/** HTTP status required at the remote MCP boundary. */
|
|
15
|
+
httpStatus;
|
|
16
|
+
/** Optional RFC 6750 challenge safe to send to an unauthenticated client. */
|
|
17
|
+
challenge;
|
|
18
|
+
/** Create one remote authorization refusal. */
|
|
19
|
+
constructor(message, httpStatus, challenge) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.name = "PmMcpAuthorizationError";
|
|
22
|
+
this.httpStatus = httpStatus;
|
|
23
|
+
this.challenge = challenge;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const TRACE_PARENT_PATTERN = /^00-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/u;
|
|
27
|
+
const TRACE_STATE_SIMPLE_KEY_PATTERN = /^[a-z][a-z0-9_*/-]{0,255}$/u;
|
|
28
|
+
const TRACE_STATE_TENANT_KEY_PATTERN = /^(?:[a-z0-9][a-z0-9_*/-]{0,240})@[a-z][a-z0-9_*/-]{0,13}$/u;
|
|
29
|
+
const TRACE_STATE_VALUE_PATTERN = /^[\x20-\x2B\x2D-\x3C\x3E-\x7E]{0,255}[\x21-\x2B\x2D-\x3C\x3E-\x7E]$/u;
|
|
30
|
+
const SCOPE_PATTERN = /^[\x21\x23-\x5B\x5D-\x7E]+$/u;
|
|
31
|
+
const BAGGAGE_KEY_PATTERN = /^[A-Za-z0-9!#$%&'*+.^_`|~-]+$/u;
|
|
32
|
+
const BAGGAGE_VALUE_PATTERN = /^[\x21\x23-\x2B\x2D-\x3A\x3C-\x5B\x5D-\x7E]*$/u;
|
|
33
|
+
const INVALID_PERCENT_ENCODING_PATTERN = /%(?![0-9A-Fa-f]{2})/u;
|
|
34
|
+
const MAX_TRACE_STATE_BYTES = 512;
|
|
35
|
+
const MAX_TRACE_STATE_MEMBERS = 32;
|
|
36
|
+
const MAX_BAGGAGE_MEMBERS = 180;
|
|
37
|
+
const MAX_BAGGAGE_BYTES = 8_192;
|
|
38
|
+
const MAX_BEARER_TOKEN_BYTES = 8_192;
|
|
39
|
+
const MCP_TRACE_CONTEXT_STORAGE = new AsyncLocalStorage();
|
|
40
|
+
function requireAbsoluteAuthorizationUrl(value, field, allowLocalHttp = false) {
|
|
41
|
+
if (/\p{Cc}/u.test(value)) {
|
|
42
|
+
throw new PmMcpAuthorizationError(`Invalid ${field}`, 401);
|
|
43
|
+
}
|
|
44
|
+
let parsed;
|
|
45
|
+
try {
|
|
46
|
+
parsed = new URL(value);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
throw new PmMcpAuthorizationError(`Invalid ${field}`, 401);
|
|
50
|
+
}
|
|
51
|
+
const local = parsed.hostname === "127.0.0.1" || parsed.hostname === "localhost";
|
|
52
|
+
if (parsed.hash.length > 0 ||
|
|
53
|
+
(parsed.protocol !== "https:" &&
|
|
54
|
+
!(allowLocalHttp && local && parsed.protocol === "http:"))) {
|
|
55
|
+
throw new PmMcpAuthorizationError(`Invalid ${field}`, 401);
|
|
56
|
+
}
|
|
57
|
+
return parsed;
|
|
58
|
+
}
|
|
59
|
+
function readHeader(headers, name) {
|
|
60
|
+
const expected = name.toLowerCase();
|
|
61
|
+
for (const [candidate, value] of Object.entries(headers)) {
|
|
62
|
+
if (candidate.toLowerCase() !== expected || value === undefined)
|
|
63
|
+
continue;
|
|
64
|
+
return typeof value === "string" ? value : value.join(", ");
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
/** Build and validate protected-resource metadata for a remote pm endpoint. */
|
|
69
|
+
export function buildMcpProtectedResourceMetadata(input) {
|
|
70
|
+
const resource = requireAbsoluteAuthorizationUrl(input.resource, "protected resource URI", true).href.replace(/\/$/u, "");
|
|
71
|
+
if (input.authorizationServers.length === 0) {
|
|
72
|
+
throw new PmMcpAuthorizationError("Protected resource metadata requires an authorization server", 401);
|
|
73
|
+
}
|
|
74
|
+
const authorizationServers = input.authorizationServers.map((issuer) => requireAbsoluteAuthorizationUrl(issuer, "authorization server issuer").href.replace(/\/$/u, ""));
|
|
75
|
+
const scopes = [...new Set(input.scopes ?? [])];
|
|
76
|
+
if (scopes.some((scope) => !SCOPE_PATTERN.test(scope))) {
|
|
77
|
+
throw new PmMcpAuthorizationError("Invalid authorization scope", 401);
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
resource,
|
|
81
|
+
authorization_servers: authorizationServers,
|
|
82
|
+
...(scopes.length > 0 ? { scopes_supported: scopes.sort() } : {}),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/** Construct OAuth and OIDC discovery URLs in the MCP-required order. */
|
|
86
|
+
export function buildMcpAuthorizationDiscoveryUrls(issuer) {
|
|
87
|
+
const parsed = requireAbsoluteAuthorizationUrl(issuer, "authorization server issuer");
|
|
88
|
+
const suffix = parsed.pathname.replace(/^\/+|\/+$/gu, "");
|
|
89
|
+
const origin = parsed.origin;
|
|
90
|
+
return suffix
|
|
91
|
+
? [
|
|
92
|
+
`${origin}/.well-known/oauth-authorization-server/${suffix}`,
|
|
93
|
+
`${origin}/.well-known/openid-configuration/${suffix}`,
|
|
94
|
+
`${origin}/${suffix}/.well-known/openid-configuration`,
|
|
95
|
+
]
|
|
96
|
+
: [
|
|
97
|
+
`${origin}/.well-known/oauth-authorization-server`,
|
|
98
|
+
`${origin}/.well-known/openid-configuration`,
|
|
99
|
+
];
|
|
100
|
+
}
|
|
101
|
+
/** Validate authorization-server metadata, exact issuer binding, and S256 PKCE. */
|
|
102
|
+
export function validateMcpAuthorizationServerMetadata(value, expectedIssuer) {
|
|
103
|
+
if (!isMcpRecord(value) || typeof value.issuer !== "string") {
|
|
104
|
+
throw new PmMcpAuthorizationError("Invalid authorization server metadata", 401);
|
|
105
|
+
}
|
|
106
|
+
const expected = requireAbsoluteAuthorizationUrl(expectedIssuer, "expected issuer").href.replace(/\/$/u, "");
|
|
107
|
+
const observed = requireAbsoluteAuthorizationUrl(value.issuer, "metadata issuer").href.replace(/\/$/u, "");
|
|
108
|
+
if (observed !== expected) {
|
|
109
|
+
throw new PmMcpAuthorizationError("Authorization server issuer mismatch", 401);
|
|
110
|
+
}
|
|
111
|
+
if (!Array.isArray(value.code_challenge_methods_supported) ||
|
|
112
|
+
!value.code_challenge_methods_supported.includes("S256")) {
|
|
113
|
+
throw new PmMcpAuthorizationError("Authorization server does not support required S256 PKCE", 401);
|
|
114
|
+
}
|
|
115
|
+
const requiredUrl = (field) => {
|
|
116
|
+
const candidate = value[field];
|
|
117
|
+
if (typeof candidate !== "string") {
|
|
118
|
+
throw new PmMcpAuthorizationError(`Authorization server metadata requires ${field}`, 401);
|
|
119
|
+
}
|
|
120
|
+
return requireAbsoluteAuthorizationUrl(candidate, field).href;
|
|
121
|
+
};
|
|
122
|
+
const optionalUrl = (field) => {
|
|
123
|
+
const candidate = value[field];
|
|
124
|
+
return typeof candidate === "string"
|
|
125
|
+
? requireAbsoluteAuthorizationUrl(candidate, field).href
|
|
126
|
+
: undefined;
|
|
127
|
+
};
|
|
128
|
+
const authorizationEndpoint = requiredUrl("authorization_endpoint");
|
|
129
|
+
const tokenEndpoint = requiredUrl("token_endpoint");
|
|
130
|
+
const registrationEndpoint = optionalUrl("registration_endpoint");
|
|
131
|
+
return {
|
|
132
|
+
issuer: expected,
|
|
133
|
+
authorization_endpoint: authorizationEndpoint,
|
|
134
|
+
token_endpoint: tokenEndpoint,
|
|
135
|
+
code_challenge_methods_supported: [
|
|
136
|
+
...new Set(value.code_challenge_methods_supported.filter((entry) => typeof entry === "string")),
|
|
137
|
+
],
|
|
138
|
+
...(value.client_id_metadata_document_supported === true
|
|
139
|
+
? { client_id_metadata_document_supported: true }
|
|
140
|
+
: {}),
|
|
141
|
+
...(registrationEndpoint
|
|
142
|
+
? { registration_endpoint: registrationEndpoint }
|
|
143
|
+
: {}),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/** Apply the current pre-registration, metadata-document, dynamic, prompt order. */
|
|
147
|
+
export function selectMcpClientRegistrationMode(input) {
|
|
148
|
+
if (input.hasPreRegisteredClient)
|
|
149
|
+
return "pre_registered";
|
|
150
|
+
if (input.metadata.client_id_metadata_document_supported)
|
|
151
|
+
return "client_id_metadata_document";
|
|
152
|
+
if (input.metadata.registration_endpoint)
|
|
153
|
+
return "dynamic";
|
|
154
|
+
return "user_supplied";
|
|
155
|
+
}
|
|
156
|
+
/** Validate a present authorization-response issuer before code redemption. */
|
|
157
|
+
export function validateMcpAuthorizationResponseIssuer(input) {
|
|
158
|
+
if (input.responseIssuer === undefined) {
|
|
159
|
+
if (input.issuerParameterSupported) {
|
|
160
|
+
throw new PmMcpAuthorizationError("Authorization response omitted the advertised issuer", 401);
|
|
161
|
+
}
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (input.responseIssuer !== input.expectedIssuer) {
|
|
165
|
+
throw new PmMcpAuthorizationError("Authorization response issuer mismatch", 401);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/** Validate a self-hosted Client ID Metadata Document and exact redirect set. */
|
|
169
|
+
export function validateMcpClientMetadataDocument(value, documentUrl) {
|
|
170
|
+
const expected = requireAbsoluteAuthorizationUrl(documentUrl, "client metadata document URL");
|
|
171
|
+
if (expected.pathname === "/" ||
|
|
172
|
+
!isMcpRecord(value) ||
|
|
173
|
+
value.client_id !== expected.href ||
|
|
174
|
+
typeof value.client_name !== "string" ||
|
|
175
|
+
value.client_name.trim().length === 0 ||
|
|
176
|
+
!Array.isArray(value.redirect_uris) ||
|
|
177
|
+
value.redirect_uris.length === 0) {
|
|
178
|
+
throw new PmMcpAuthorizationError("Invalid Client ID Metadata Document", 401);
|
|
179
|
+
}
|
|
180
|
+
for (const redirect of value.redirect_uris) {
|
|
181
|
+
if (typeof redirect !== "string") {
|
|
182
|
+
throw new PmMcpAuthorizationError("Invalid client redirect URI", 401);
|
|
183
|
+
}
|
|
184
|
+
requireAbsoluteAuthorizationUrl(redirect, "client redirect URI", true);
|
|
185
|
+
}
|
|
186
|
+
return structuredClone(value);
|
|
187
|
+
}
|
|
188
|
+
/** Build bounded dynamic-registration metadata for explicit legacy fallback. */
|
|
189
|
+
export function buildMcpDynamicRegistrationMetadata(input) {
|
|
190
|
+
if (input.redirectUris.length === 0 || input.clientName.trim().length === 0) {
|
|
191
|
+
throw new PmMcpAuthorizationError("Invalid dynamic client registration metadata", 401);
|
|
192
|
+
}
|
|
193
|
+
const redirectUris = input.redirectUris.map((redirect) => requireAbsoluteAuthorizationUrl(redirect, "redirect URI", true).href);
|
|
194
|
+
return {
|
|
195
|
+
application_type: input.applicationType,
|
|
196
|
+
client_name: input.clientName.trim().slice(0, 128),
|
|
197
|
+
redirect_uris: redirectUris,
|
|
198
|
+
grant_types: ["authorization_code", "refresh_token"],
|
|
199
|
+
response_types: ["code"],
|
|
200
|
+
token_endpoint_auth_method: "none",
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/** In-memory issuer-keyed credential primitive that never reuses cross-issuer state. */
|
|
204
|
+
export class PmMcpIssuerCredentialStore {
|
|
205
|
+
#credentials = new Map();
|
|
206
|
+
/** Persist a cloned credential under the exact validated issuer. */
|
|
207
|
+
set(issuer, credential) {
|
|
208
|
+
const key = requireAbsoluteAuthorizationUrl(issuer, "credential issuer").href;
|
|
209
|
+
this.#credentials.set(key, structuredClone(credential));
|
|
210
|
+
}
|
|
211
|
+
/** Read a cloned credential only for the exact issuer. */
|
|
212
|
+
get(issuer) {
|
|
213
|
+
const key = requireAbsoluteAuthorizationUrl(issuer, "credential issuer").href;
|
|
214
|
+
const credential = this.#credentials.get(key);
|
|
215
|
+
return credential ? structuredClone(credential) : undefined;
|
|
216
|
+
}
|
|
217
|
+
/** Remove credentials for one issuer during revocation or re-registration. */
|
|
218
|
+
delete(issuer) {
|
|
219
|
+
const key = requireAbsoluteAuthorizationUrl(issuer, "credential issuer").href;
|
|
220
|
+
return this.#credentials.delete(key);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
function validateMcpTraceFields(meta) {
|
|
224
|
+
const traceparent = meta.traceparent;
|
|
225
|
+
const tracestate = meta.tracestate;
|
|
226
|
+
if (traceparent !== undefined) {
|
|
227
|
+
const match = typeof traceparent === "string"
|
|
228
|
+
? TRACE_PARENT_PATTERN.exec(traceparent)
|
|
229
|
+
: null;
|
|
230
|
+
if (!match) {
|
|
231
|
+
throw new PmMcpAuthorizationError("Invalid MCP traceparent", 403);
|
|
232
|
+
}
|
|
233
|
+
const traceId = match[1];
|
|
234
|
+
const parentId = match[2];
|
|
235
|
+
if (/^0+$/u.test(traceId) || /^0+$/u.test(parentId)) {
|
|
236
|
+
throw new PmMcpAuthorizationError("Invalid MCP traceparent", 403);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (tracestate !== undefined &&
|
|
240
|
+
(typeof tracestate !== "string" || !isValidMcpTraceState(tracestate))) {
|
|
241
|
+
throw new PmMcpAuthorizationError("Invalid MCP tracestate", 403);
|
|
242
|
+
}
|
|
243
|
+
return {
|
|
244
|
+
...(typeof traceparent === "string" ? { traceparent } : {}),
|
|
245
|
+
...(typeof tracestate === "string" ? { tracestate } : {}),
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
function trimOptionalWhitespace(value) {
|
|
249
|
+
return value.replace(/^[ \t]*|[ \t]*$/gu, "");
|
|
250
|
+
}
|
|
251
|
+
function isValidMcpTraceStateKey(key) {
|
|
252
|
+
return (TRACE_STATE_SIMPLE_KEY_PATTERN.test(key) ||
|
|
253
|
+
TRACE_STATE_TENANT_KEY_PATTERN.test(key));
|
|
254
|
+
}
|
|
255
|
+
function isValidMcpTraceState(value) {
|
|
256
|
+
if (Buffer.byteLength(value, "utf8") > MAX_TRACE_STATE_BYTES)
|
|
257
|
+
return false;
|
|
258
|
+
const members = value.split(",");
|
|
259
|
+
if (members.length > MAX_TRACE_STATE_MEMBERS)
|
|
260
|
+
return false;
|
|
261
|
+
const keys = new Set();
|
|
262
|
+
for (const source of members) {
|
|
263
|
+
const member = trimOptionalWhitespace(source);
|
|
264
|
+
if (member.length === 0)
|
|
265
|
+
continue;
|
|
266
|
+
const separator = member.indexOf("=");
|
|
267
|
+
const key = separator > 0 ? member.slice(0, separator) : "";
|
|
268
|
+
const memberValue = separator > 0 ? member.slice(separator + 1) : "";
|
|
269
|
+
if (!isValidMcpTraceStateKey(key) ||
|
|
270
|
+
!TRACE_STATE_VALUE_PATTERN.test(memberValue) ||
|
|
271
|
+
keys.has(key)) {
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
keys.add(key);
|
|
275
|
+
}
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
function isValidMcpBaggageValue(value) {
|
|
279
|
+
return (BAGGAGE_VALUE_PATTERN.test(value) &&
|
|
280
|
+
!INVALID_PERCENT_ENCODING_PATTERN.test(value));
|
|
281
|
+
}
|
|
282
|
+
function isValidMcpBaggageProperty(source) {
|
|
283
|
+
const property = trimOptionalWhitespace(source);
|
|
284
|
+
const separator = property.indexOf("=");
|
|
285
|
+
const key = trimOptionalWhitespace(separator >= 0 ? property.slice(0, separator) : property);
|
|
286
|
+
const value = separator >= 0
|
|
287
|
+
? trimOptionalWhitespace(property.slice(separator + 1))
|
|
288
|
+
: undefined;
|
|
289
|
+
return (BAGGAGE_KEY_PATTERN.test(key) &&
|
|
290
|
+
(value === undefined || isValidMcpBaggageValue(value)));
|
|
291
|
+
}
|
|
292
|
+
function parseMcpBaggageMember(source) {
|
|
293
|
+
const serialized = trimOptionalWhitespace(source);
|
|
294
|
+
const segments = serialized.split(";");
|
|
295
|
+
const pair = segments[0];
|
|
296
|
+
const properties = segments.slice(1);
|
|
297
|
+
const separator = pair.indexOf("=");
|
|
298
|
+
const key = trimOptionalWhitespace(separator > 0 ? pair.slice(0, separator) : "");
|
|
299
|
+
const value = separator > 0 ? trimOptionalWhitespace(pair.slice(separator + 1)) : "";
|
|
300
|
+
if (!BAGGAGE_KEY_PATTERN.test(key) ||
|
|
301
|
+
!isValidMcpBaggageValue(value) ||
|
|
302
|
+
!properties.every(isValidMcpBaggageProperty)) {
|
|
303
|
+
return undefined;
|
|
304
|
+
}
|
|
305
|
+
return { key, serialized };
|
|
306
|
+
}
|
|
307
|
+
function filterMcpBaggage(baggage, allowlistEntries) {
|
|
308
|
+
if (baggage === undefined)
|
|
309
|
+
return undefined;
|
|
310
|
+
if (typeof baggage !== "string" ||
|
|
311
|
+
Buffer.byteLength(baggage, "utf8") > MAX_BAGGAGE_BYTES) {
|
|
312
|
+
throw new PmMcpAuthorizationError("Invalid MCP baggage", 403);
|
|
313
|
+
}
|
|
314
|
+
const allowlist = new Set(allowlistEntries);
|
|
315
|
+
const sources = baggage.split(",");
|
|
316
|
+
if (sources.length > MAX_BAGGAGE_MEMBERS) {
|
|
317
|
+
throw new PmMcpAuthorizationError("Invalid MCP baggage", 403);
|
|
318
|
+
}
|
|
319
|
+
const entries = [];
|
|
320
|
+
for (const source of sources) {
|
|
321
|
+
const entry = parseMcpBaggageMember(source);
|
|
322
|
+
if (!entry) {
|
|
323
|
+
throw new PmMcpAuthorizationError("Invalid MCP baggage", 403);
|
|
324
|
+
}
|
|
325
|
+
if (allowlist.has(entry.key))
|
|
326
|
+
entries.push(entry.serialized);
|
|
327
|
+
}
|
|
328
|
+
return entries.length > 0 ? entries.join(",") : undefined;
|
|
329
|
+
}
|
|
330
|
+
/** Extract W3C trace context with strict syntax, size, and baggage allowlists. */
|
|
331
|
+
export function extractMcpTraceContext(params, options = {}) {
|
|
332
|
+
const meta = isMcpRecord(params) && isMcpRecord(params._meta) ? params._meta : {};
|
|
333
|
+
const allowedBaggage = filterMcpBaggage(meta.baggage, options.baggageAllowlist ?? []);
|
|
334
|
+
return {
|
|
335
|
+
...validateMcpTraceFields(meta),
|
|
336
|
+
...(allowedBaggage ? { baggage: allowedBaggage } : {}),
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
/** Run one request with trace context isolated from every concurrent request. */
|
|
340
|
+
export function runWithMcpTraceContext(context, callback) {
|
|
341
|
+
return MCP_TRACE_CONTEXT_STORAGE.run(structuredClone(context), callback);
|
|
342
|
+
}
|
|
343
|
+
/** Read a defensive copy of the current request's trace context. */
|
|
344
|
+
export function getActiveMcpTraceContext() {
|
|
345
|
+
const context = MCP_TRACE_CONTEXT_STORAGE.getStore();
|
|
346
|
+
return context ? { ...context } : undefined;
|
|
347
|
+
}
|
|
348
|
+
/** Enforce bearer location, issuer, audience, and least-privilege scopes. */
|
|
349
|
+
export async function authorizeMcpHttpRequest(input) {
|
|
350
|
+
const resourceMetadataUrl = requireAbsoluteAuthorizationUrl(input.policy.resourceMetadataUrl, "protected resource metadata URL", true).href;
|
|
351
|
+
const requiredScopes = [...new Set(input.policy.requiredScopes ?? [])];
|
|
352
|
+
if (requiredScopes.some((scope) => !SCOPE_PATTERN.test(scope))) {
|
|
353
|
+
throw new PmMcpAuthorizationError("Invalid authorization scope", 401);
|
|
354
|
+
}
|
|
355
|
+
const challenge = `Bearer resource_metadata="${resourceMetadataUrl}"`;
|
|
356
|
+
const parsedUrl = new URL(input.requestUrl, input.policy.resource);
|
|
357
|
+
if (parsedUrl.searchParams.has("access_token")) {
|
|
358
|
+
throw new PmMcpAuthorizationError("Access tokens must not appear in URI query parameters", 401, challenge);
|
|
359
|
+
}
|
|
360
|
+
const authorization = readHeader(input.headers, "authorization");
|
|
361
|
+
const match = authorization?.match(/^Bearer ([^\s]+)$/iu);
|
|
362
|
+
if (!match) {
|
|
363
|
+
throw new PmMcpAuthorizationError("Missing or malformed bearer token", 401, challenge);
|
|
364
|
+
}
|
|
365
|
+
const token = match[1];
|
|
366
|
+
if (Buffer.byteLength(token, "utf8") > MAX_BEARER_TOKEN_BYTES) {
|
|
367
|
+
throw new PmMcpAuthorizationError("Missing or malformed bearer token", 401, challenge);
|
|
368
|
+
}
|
|
369
|
+
let claims;
|
|
370
|
+
try {
|
|
371
|
+
claims = await input.policy.verifyAccessToken(token);
|
|
372
|
+
}
|
|
373
|
+
catch {
|
|
374
|
+
throw new PmMcpAuthorizationError("Invalid bearer token", 401, challenge);
|
|
375
|
+
}
|
|
376
|
+
const audiences = Array.isArray(claims.audience)
|
|
377
|
+
? claims.audience
|
|
378
|
+
: [claims.audience];
|
|
379
|
+
if (claims.issuer !== input.policy.issuer ||
|
|
380
|
+
!audiences.includes(input.policy.resource)) {
|
|
381
|
+
throw new PmMcpAuthorizationError("Bearer token issuer or audience mismatch", 401, challenge);
|
|
382
|
+
}
|
|
383
|
+
const missingScopes = requiredScopes.filter((scope) => !claims.scopes.includes(scope));
|
|
384
|
+
if (missingScopes.length > 0) {
|
|
385
|
+
throw new PmMcpAuthorizationError("Bearer token has insufficient scope", 403, `${challenge}, scope="${missingScopes.join(" ")}"`);
|
|
386
|
+
}
|
|
387
|
+
return {
|
|
388
|
+
...claims,
|
|
389
|
+
audience: [...audiences],
|
|
390
|
+
scopes: [...claims.scopes],
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
/** Create an exact opaque-token verifier without exposing token values in results. */
|
|
394
|
+
export function createMcpStaticBearerVerifier(input) {
|
|
395
|
+
const expected = createHash("sha256").update(input.token).digest();
|
|
396
|
+
return (token) => {
|
|
397
|
+
const observed = createHash("sha256").update(token).digest();
|
|
398
|
+
if (!timingSafeEqual(expected, observed)) {
|
|
399
|
+
throw new PmMcpAuthorizationError("Invalid bearer token", 401);
|
|
400
|
+
}
|
|
401
|
+
return structuredClone(input.claims);
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
//# sourceMappingURL=authorization.js.map
|
|
405
|
+
//# debugId=a9aefc86-a8ce-5ecf-bb54-e5fa3ea277c7
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { type PmMcpImplementation, type PmMcpRequestContext } from "./protocol.js";
|
|
2
|
+
/** Methods permitted inside a 2026-07-28 MRTR input request map. */
|
|
3
|
+
export declare const PM_MCP_INPUT_REQUEST_METHODS: readonly ["elicitation/create", "roots/list", "sampling/createMessage"];
|
|
4
|
+
/** One typed request that a host must fulfill before retrying an operation. */
|
|
5
|
+
export interface PmMcpInputRequest {
|
|
6
|
+
/** Current MCP server-to-client request method. */
|
|
7
|
+
method: (typeof PM_MCP_INPUT_REQUEST_METHODS)[number];
|
|
8
|
+
/** Method-specific parameters retained as an open protocol object. */
|
|
9
|
+
params: Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
/** Server-assigned MRTR input identifiers mapped to bounded requests. */
|
|
12
|
+
export type PmMcpInputRequests = Record<string, PmMcpInputRequest>;
|
|
13
|
+
/** Host responses keyed by the identifiers in an earlier input request map. */
|
|
14
|
+
export type PmMcpInputResponses = Record<string, Record<string, unknown>>;
|
|
15
|
+
/** Modern interim result returned when an operation needs more host input. */
|
|
16
|
+
export interface PmMcpInputRequiredResult {
|
|
17
|
+
/** MRTR discriminator required by the current protocol. */
|
|
18
|
+
resultType: "input_required";
|
|
19
|
+
/** Optional bounded requests the host must fulfill. */
|
|
20
|
+
inputRequests?: PmMcpInputRequests;
|
|
21
|
+
/** Optional integrity-protected state echoed unchanged on retry. */
|
|
22
|
+
requestState?: string;
|
|
23
|
+
/** Result-local MCP metadata. */
|
|
24
|
+
_meta: {
|
|
25
|
+
/** Server identity repeated on every modern result. */
|
|
26
|
+
"io.modelcontextprotocol/serverInfo": PmMcpImplementation;
|
|
27
|
+
};
|
|
28
|
+
/** Additional forward-compatible result fields. */
|
|
29
|
+
[key: string]: unknown;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Transport-neutral control signal used by SDK handlers to request an MRTR
|
|
33
|
+
* response without constructing or serializing JSON-RPC in domain code.
|
|
34
|
+
*/
|
|
35
|
+
export declare class PmMcpInputRequiredError extends Error {
|
|
36
|
+
/** Server-authored input requests validated by the adapter. */
|
|
37
|
+
readonly inputRequests?: unknown;
|
|
38
|
+
/** Optional opaque continuation state echoed on retry. */
|
|
39
|
+
readonly requestState?: string;
|
|
40
|
+
/** Create an input-required control signal. */
|
|
41
|
+
constructor(input: {
|
|
42
|
+
inputRequests?: unknown;
|
|
43
|
+
requestState?: string;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/** Cache fields required on current list and read results. */
|
|
47
|
+
export interface PmMcpCachePolicy {
|
|
48
|
+
/** Milliseconds for which a client may consider the response fresh. */
|
|
49
|
+
ttlMs: number;
|
|
50
|
+
/** Whether shared intermediaries may reuse the response. */
|
|
51
|
+
cacheScope: "private" | "public";
|
|
52
|
+
/** Additional forward-compatible cache fields. */
|
|
53
|
+
[key: string]: unknown;
|
|
54
|
+
}
|
|
55
|
+
/** Work bounds applied while validating an advertised JSON Schema. */
|
|
56
|
+
export interface PmMcpJsonSchemaBounds {
|
|
57
|
+
/** Maximum serialized schema bytes. */
|
|
58
|
+
maxBytes?: number;
|
|
59
|
+
/** Maximum nested object or array depth. */
|
|
60
|
+
maxDepth?: number;
|
|
61
|
+
/** Maximum visited object, array, and scalar nodes. */
|
|
62
|
+
maxNodes?: number;
|
|
63
|
+
}
|
|
64
|
+
/** State sealed into an opaque MRTR requestState value. */
|
|
65
|
+
export interface PmMcpRequestStatePayload {
|
|
66
|
+
/** Absolute expiration timestamp in milliseconds. */
|
|
67
|
+
expiresAt: number;
|
|
68
|
+
/** Original JSON-RPC method this state may resume. */
|
|
69
|
+
method: string;
|
|
70
|
+
/** Digest of the original request's salient parameters. */
|
|
71
|
+
parameterDigest: string;
|
|
72
|
+
/** Principal binding chosen by the host or authorization layer. */
|
|
73
|
+
principal: string;
|
|
74
|
+
/** Application-owned continuation data. */
|
|
75
|
+
state: unknown;
|
|
76
|
+
}
|
|
77
|
+
/** Validate and clone a server-authored MRTR request map. */
|
|
78
|
+
export declare function parseMcpInputRequests(value: unknown, requestContext: PmMcpRequestContext): PmMcpInputRequests;
|
|
79
|
+
/** Validate and clone client-supplied input responses from an MRTR retry. */
|
|
80
|
+
export declare function parseMcpInputResponses(value: unknown): PmMcpInputResponses;
|
|
81
|
+
/** Build a modern input-required result after validating capability and size bounds. */
|
|
82
|
+
export declare function buildMcpInputRequiredResult(input: {
|
|
83
|
+
requestContext: PmMcpRequestContext;
|
|
84
|
+
serverInfo: PmMcpImplementation;
|
|
85
|
+
inputRequests?: unknown;
|
|
86
|
+
requestState?: string;
|
|
87
|
+
}): PmMcpInputRequiredResult;
|
|
88
|
+
/** Seal integrity-protected continuation state for an MRTR retry. */
|
|
89
|
+
export declare function sealMcpRequestState(payload: PmMcpRequestStatePayload, secret: string | Uint8Array): string;
|
|
90
|
+
/** Verify an MRTR requestState value against method, principal, digest, and expiry. */
|
|
91
|
+
export declare function openMcpRequestState(value: string, secret: string | Uint8Array, expected: {
|
|
92
|
+
method: string;
|
|
93
|
+
parameterDigest: string;
|
|
94
|
+
principal: string;
|
|
95
|
+
nowMs?: number;
|
|
96
|
+
}): PmMcpRequestStatePayload;
|
|
97
|
+
/** Compute a stable-sized digest for application-selected salient request data. */
|
|
98
|
+
export declare function digestMcpRequestParameters(value: unknown): string;
|
|
99
|
+
/**
|
|
100
|
+
* Bound single-use MRTR state consumption within one server process. Callers
|
|
101
|
+
* requiring cross-process one-time semantics should persist the resulting hash.
|
|
102
|
+
*/
|
|
103
|
+
export declare class PmMcpRequestStateReplayGuard {
|
|
104
|
+
#private;
|
|
105
|
+
/** Create a bounded in-process replay guard. */
|
|
106
|
+
constructor(maximumEntries?: number);
|
|
107
|
+
/** Consume one opaque requestState value exactly once in this process. */
|
|
108
|
+
consume(value: string): void;
|
|
109
|
+
}
|
|
110
|
+
/** Validate and clone a required MCP cache policy. */
|
|
111
|
+
export declare function parseMcpCachePolicy(value: PmMcpCachePolicy): PmMcpCachePolicy;
|
|
112
|
+
/** Attach required cache fields without mutating a method-specific payload. */
|
|
113
|
+
export declare function withMcpCachePolicy<Payload extends Record<string, unknown>>(payload: Payload, policy: PmMcpCachePolicy): Payload & PmMcpCachePolicy;
|
|
114
|
+
/**
|
|
115
|
+
* Validate JSON Schema 2020-12 structure under explicit byte, depth, node, and
|
|
116
|
+
* local-reference work bounds while allowing the complete keyword vocabulary.
|
|
117
|
+
*/
|
|
118
|
+
export declare function validateMcpJsonSchema(schema: unknown, bounds?: PmMcpJsonSchemaBounds): unknown;
|