Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/agents/src/mcp/client/do-oauth-client-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ function isExpired(createdAt: number): boolean {
export type AgentsOAuthProvider = AgentMcpOAuthProvider;

export class DurableObjectOAuthClientProvider implements AgentMcpOAuthProvider {
/**
* When a refresh is refused and the SDK starts a new authorization, also
* request the scope the dropped tokens held, so step-up grants survive.
*/
readonly includePreviouslyGrantedScopes = true;
private _authUrl_: string | undefined;
private _serverId_: string | undefined;
private _clientId_: string | undefined;
Expand Down
6 changes: 6 additions & 0 deletions packages/agents/src/tests/mcp/mid-session-reauth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,12 @@ describe("MCPClientManager mid-session re-authorization", () => {
expect(error).toBeInstanceOf(MCPAuthorizationRequiredError);
const reauth = error as MCPAuthorizationRequiredError;
expect(reauth.authUrl).not.toBe(connectUrl);
// The server challenged with its base scope, but the new link must keep
// the write scope the user already granted, or the write tools fail
// again and the user is sent back through step-up.
expect(
new URL(reauth.authUrl).searchParams.get("scope")?.split(" ").sort()
).toEqual(`${BASE_SCOPE} ${WRITE_SCOPE}`.split(" ").sort());
expect(manager.mcpConnections[serverId].connectionState).toBe(
"authenticating"
);
Expand Down
68 changes: 25 additions & 43 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,10 @@ minimumReleaseAgeExclude:
- "@opencode/*"
overrides:
"@earendil-works/pi-agent-core>@earendil-works/pi-ai": "~1.4.0"
# Preview of modelcontextprotocol/typescript-sdk#2448 (keep granted scopes on 401 re-authorization).
# The preview client depends on the preview core by URL, which needs blockExoticSubdeps off below.
"@modelcontextprotocol/client": "https://pkg.pr.new/@modelcontextprotocol/client@9f7c248"
"@modelcontextprotocol/core": "https://pkg.pr.new/@modelcontextprotocol/core@9f7c248"

# Only for the typescript-sdk#2448 preview above; pnpm 10.x blocks URL subdependencies by default.
blockExoticSubdeps: false
Loading