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
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 68/100
Vessel9817/onion-site-template#512 ·
维护者通常 1 天内回复
-
nightly-tests
难度 2/5 1-3 小时 新手友好度 68/100
BlackBeltTechnology/pi-agent-dashboard#1256 ·
维护者通常 1 天内回复
-
approved
难度 2/5 1-3 小时 新手友好度 85/100
fritzprix/libr-agent#3266 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
better-auth/better-auth#13101 · 1 条评论 · 1 个 reaction ·
维护者通常 1 天内回复