fix(claude): reopen queries after MCP credential rotation
Fixes review: https://github.com/pingdotgg/t3code/pull/2829#discussion_r3566081244 Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
39f02d9528
commit
da3b9da5f0
2 files changed
+44
-4
No files matched your search
@@ -436,6 +436,38 @@ describe("ClaudeAdapterV2 MCP query overrides", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("invalidates live-query reuse when MCP credentials rotate", () => {
|
||||
const threadId = ThreadId.make("thread-claude-mcp-credential-rotation");
|
||||
withMcpSession(threadId, () => {
|
||||
const queryPolicy = claudeRuntimeQueryPolicyForRuntimePolicy(
|
||||
ProviderAdapterV2RuntimePolicy.make({
|
||||
runtimeMode: "approval-required",
|
||||
interactionMode: "default",
|
||||
cwd: "/workspace",
|
||||
}),
|
||||
);
|
||||
const initialKey = claudeEffectiveQueryPolicyKey(
|
||||
queryPolicy,
|
||||
claudeMcpQueryOverrides({ threadId, readOnlySandbox: false }),
|
||||
);
|
||||
|
||||
McpProviderSession.setMcpProviderSession({
|
||||
environmentId: EnvironmentId.make(`environment-${threadId}`),
|
||||
threadId,
|
||||
providerSessionId: `mcp-session-${threadId}`,
|
||||
providerInstanceId: ProviderInstanceId.make("claudeAgent"),
|
||||
endpoint: "http://127.0.0.1:43123/mcp",
|
||||
authorizationHeader: "Bearer rotated-claude-token",
|
||||
});
|
||||
|
||||
const rotatedKey = claudeEffectiveQueryPolicyKey(
|
||||
queryPolicy,
|
||||
claudeMcpQueryOverrides({ threadId, readOnlySandbox: false }),
|
||||
);
|
||||
assert.notEqual(rotatedKey, initialKey);
|
||||
});
|
||||
});
|
||||
|
||||
it("matches the read-only allowlist to the orchestrator toolkit annotations", () => {
|
||||
const readOnlyToolNames = Object.values(OrchestratorToolkit.tools)
|
||||
.filter((tool) => Context.get(tool.annotations, Tool.Readonly))
|
||||
|
||||
@@ -1231,11 +1231,19 @@ function claudeRuntimeQueryPolicyKey(policy: ClaudeRuntimeQueryPolicy): string {
|
||||
// share a policy key can still differ in MCP pre-approvals.
|
||||
export function claudeEffectiveQueryPolicyKey(
|
||||
queryPolicy: ClaudeRuntimeQueryPolicy,
|
||||
mcpOverrides: { readonly allowedTools?: ReadonlyArray<string> },
|
||||
mcpOverrides: {
|
||||
readonly allowedTools?: ReadonlyArray<string>;
|
||||
readonly mcpServers?: ClaudeQueryOptions["mcpServers"];
|
||||
},
|
||||
): string {
|
||||
return claudeRuntimeQueryPolicyKey({
|
||||
...queryPolicy,
|
||||
...(mcpOverrides.allowedTools === undefined ? {} : { allowedTools: mcpOverrides.allowedTools }),
|
||||
return JSON.stringify({
|
||||
runtimePolicy: claudeRuntimeQueryPolicyKey({
|
||||
...queryPolicy,
|
||||
...(mcpOverrides.allowedTools === undefined
|
||||
? {}
|
||||
: { allowedTools: mcpOverrides.allowedTools }),
|
||||
}),
|
||||
mcpServers: mcpOverrides.mcpServers,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user