Client DPoP: support external signers (non-`CryptoKey` keys) in `DpopSession`
維護者通常 1 天內回覆
@Urdemonlord 已經在處理了。
開始於 2026年11月22日。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 18/100
- Issue 類型
- 功能
- 描述清晰度
- 基本清楚
- 活躍度
- 活躍
- 技術堆疊
- typescript, wasm
- 領域
- api, authentication
研究方向
Start with the DpopSession class and its create() factory, where buildProof() currently calls SignJWT.sign() with a CryptoKey, and with the DpopSessionSource type that OAuthClientProvider.dpop() returns. Option A adds a signer to create() and Option B adds a structural DpopProofSource interface. Done means a non-CryptoKey signer can complete auth() and a tool call in a test, and that DpopSession still passes its existing tests unchanged. The issue has no comments or maintainer decision on which option to take, so confirm the design before writing code.
由索引模型根據 Issue 內容生成。
描述
Problem
OAuthClientProvider.dpop() must return a DpopSession. Today the only way to get one is DpopSession.create({ alg?, keyPair? }), and keyPair.privateKey must be a WebCrypto CryptoKey, because buildProof() signs with jose's SignJWT(...).sign(privateKey). The constructor is private.
So the DPoP key must be a key that WebCrypto or jose can use in the same process. These keys do not work:
- A key in a cloud KMS or an HSM (for example PKCS#11).
- A platform authenticator or secure enclave key that is used through a native bridge.
- A remote signing service or a policy-controlled key custody service.
RFC 9449 §11 says that clients should protect the DPoP private key and that hardware-backed keys are preferred. generateDpopKeyPair already defaults to extractable: false for this reason. A key that is outside the process is the strongest form of that protection, but the SDK does not support it.
What we tried (SDK 2.3.1)
We wrote a class that builds the RFC 9449 §4.2 header and claims and sends the JWS signing input to an external sign(). It has the same public surface as DpopSession (buildProof, observeNonce, nonceFor, rememberNonce, thumbprint, alg, publicJwk).
TypeScript rejects every typed approach, because DpopSession has private members, so it is compared nominally:
| Attempt | Error |
|---|---|
const s: DpopSession = external |
TS2741: Property 'keyPair' is missing ... |
external as DpopSession |
TS2352: neither type sufficiently overlaps |
dpop: () => external |
TS2322 (same cause) |
new DpopSession(...) |
TS2673: constructor is private |
class X extends DpopSession |
TS2675: cannot extend, constructor is private |
DpopSession.create({ keyPair: { ...kp, privateKey: remote } }) |
TS2739: not a CryptoKey. If you force it with a cast, the first buildProof throws TypeError: Key for the ES256 algorithm must be one of type CryptoKey, KeyObject, or JSON Web Key. |
external as unknown as DpopSession compiles and works at runtime. In 2.3.1, the transports (withDpop) and the token request (executeTokenRequest) call only buildProof() and observeNonce() on the session, and they do no instanceof check. A bare object with only those methods completes auth() (client_credentials), AS and RS use_dpop_nonce retries, and tool calls against a DPoP-validating server (we used the #2630 preview). This works, but it depends on internals that can change in any release without a type error.
Proposal
Add a supported way to supply the signature. Either of these would work.
Option A: a signer in create.
interface DpopSigner {
alg: DpopAlg;
publicJwk: JWK; // public members only
sign(signingInput: Uint8Array): Promise<Uint8Array>; // raw JWS signature (for ES*, r || s)
}
const session = await DpopSession.create({ signer });
DpopSession keeps doing the RFC 9449 work, such as jti, htu normalization, ath, nonces, and the thumbprint. It calls signer.sign() instead of SignJWT.sign(). keyPair stays as it is, and signer is an alternative to it.
Option B: a structural type for the provider.
Type OAuthClientProvider.dpop() (and DpopSessionSource) as an interface:
interface DpopProofSource {
buildProof(request: DpopProofRequest): Promise<string>;
observeNonce(response: Response, url: string | URL): void;
}
DpopSession implements this interface, so current code does not change. Callers with special needs can bring their own implementation.
Option A keeps the RFC logic in one place. Option B makes the actual contract explicit. They can be combined.
Why the hook must be async and called once for each request
A proof binds htm, htu, ath, iat, and nonce, so it cannot be signed in advance or reused. With an external signer, each MCP HTTP request waits for one signature. In our measurement (N = 25 callTool calls, nearest-rank):
| Proof key | p50 | p95 |
|---|---|---|
DpopSession with a WebCrypto key |
1.1 ms | 1.5 ms |
| Same flow, external-signer object with a local key | 0.8 ms | 1.1 ms |
| Same flow, remote signing service (measured; the fixtures repo reproduces it with a mock signer delay) | 235 ms | 580 ms |
The adapter itself adds no time. The time comes from the signer, so sign() must be async and must not be cached. connect() signs 3 proofs (initialize, the initialized notification, and the GET stream), and the token request signs 1 more. If the hook received the DpopProofRequest along with the signing input, a signer could log or apply policy for each request. This is optional.
Related
- #2629 (client DPoP), #2630 (server DPoP validation), #2631 (conformance fixture).
- Reproduction (the duck-typing probe, its TypeScript errors, and the benchmark with a mock remote signer): https://github.com/tkhq/mcp-dpop-fixtures
- Small related point: the client does not read
dpop_signing_alg_values_supportedor the RSalgschallenge parameter. A signer with a fixed algorithm would benefit if the SDK checked these and failed early.
- 主要語言
- TypeScript
- 星號
- 13.8k
- 分支
- 2.5k
- 平均合併
- 6 天 23 小時
- 30 天內合併 PR
- 2
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
modelcontextprotocol/typescript-sdk 的其他 Issue
-
v2
難度 1/5 1 小時以內 新手友好度 72/100
modelcontextprotocol/typescript-sdk#3270 · 1 則留言 ·
維護者通常 1 天內回覆
-
`callTool` with `allowInputRequired: true` throws on an `input_required` result when the tool declares an `outputSchema`可能已有人在做 @mgoldsborough 於 6 天前認領。 未關閉v2
難度 2/5 1-3 小時 新手友好度 78/100
modelcontextprotocol/typescript-sdk#3249 ·
維護者通常 1 天內回覆
-
v2
難度 2/5 1-3 小時 新手友好度 68/100
modelcontextprotocol/typescript-sdk#3243 · 3 則留言 ·
維護者通常 1 天內回覆
-
TypeScript client accepts an unknown `resultType` in the first `server/discover` reply可能已有人在做 @Tidehyc 於 8 天前認領。 未關閉v2
難度 2/5 1-3 小時 新手友好度 72/100
modelcontextprotocol/typescript-sdk#3235 · 3 則留言 ·
維護者通常 1 天內回覆
-
UriTemplate.match() throws a TypeError on an empty expression it accepts可能已有人在做 @yunusemrejs 於 12 天前認領。 未關閉v1 v2
難度 2/5 1-3 小時 新手友好度 80/100
modelcontextprotocol/typescript-sdk#3221 · 3 則留言 ·
維護者通常 1 天內回覆
查看 modelcontextprotocol/typescript-sdk 的全部 Issue
相似的 Issue
-
triage
難度 2/5 1-3 小時 新手友好度 83/100
維護者通常 1 天內回覆
-
enhancement from-app needs-triage
難度 2/5 1-3 小時 新手友好度 68/100
nightly-labs/openbot#23943 ·
維護者通常 1 天內回覆
-
comp/desktop desktop/chat P3 type/bug
難度 2/5 1-3 小時 新手友好度 77/100
NousResearch/hermes-agent#164451 ·
維護者通常 1 天內回覆
-
shortkeys-2188:ready
難度 2/5 1-3 小時 新手友好度 82/100
crittermike/shortkeys#1121 · 1 個 reaction ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 67/100
Doist/todoist-cli#742 ·