Skip to content

Conversation

@RomneyDa
Copy link
Collaborator

@RomneyDa RomneyDa commented Nov 17, 2025

Description

Adds a 401-detection wrapper to MCP service which attempts to get oauth token from hub if signed in


Summary by cubic

Adds automatic OAuth token refresh for CLI MCP HTTP/SSE connections. On 401/405, we fetch a new token from the hub and retry; agent files now support URL-based MCP references.

  • New Features

    • 401/405-aware wrapper around MCP operations (connect, listTools, listPrompts, callTool) with retry after token refresh; falls back to mcp-remote (stdio) when not headless.
    • Fetches token from /ide/mcp-auth and caches per server; updates Authorization header and retries.
    • Agent files support URL-based MCP references (http/https), including tool names, ports, paths, and query params; supports localhost/IP with validation and tests.
  • Bug Fixes

    • isAuthenticated is now async and properly refreshes expired tokens; updated all call sites.
    • More robust connection sequence: HTTP then SSE with token refresh.

Written for commit 26bb215. Summary will update automatically on new commits.

@RomneyDa RomneyDa requested a review from a team as a code owner November 17, 2025 23:51
@RomneyDa RomneyDa requested review from tingwai and removed request for a team November 17, 2025 23:51
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Nov 17, 2025
@github-actions
Copy link

github-actions bot commented Nov 17, 2025

✅ Review Complete

Code Review Summary

⚠️ Continue configuration error. Please verify that the assistant exists in Continue Hub.


Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 6 files

tingwai
tingwai previously approved these changes Nov 18, 2025
@github-project-automation github-project-automation bot moved this from Todo to In Progress in Issues and PRs Nov 18, 2025
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Nov 18, 2025
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 issues found across 4 files (reviewed changes from recent commits).

Prompt for AI agents (all 3 issues)

Understand the root cause of the following 3 issues and fix them.


<file name="extensions/cli/src/configLoader.ts">

<violation number="1" location="extensions/cli/src/configLoader.ts:211">
Treating CLI `--config` errors like user-assistant failures now masks problems with explicitly requested configs by falling back to the default agent, violating the documented precedence where the CLI flag should fail loudly if unreadable.</violation>
</file>

<file name="packages/config-yaml/src/markdown/agentFiles.ts">

<violation number="1" location="packages/config-yaml/src/markdown/agentFiles.ts:133">
Port detection in the URL branch only accepts bare numbers, so valid URLs such as https://host:4000/path (port plus path) are rejected, preventing configuration of those MCP servers.</violation>
</file>

<file name="extensions/cli/src/services/MCPService.ts">

<violation number="1" location="extensions/cli/src/services/MCPService.ts:563">
Catching the HTTP fallback error inside getConnectedClient hides 401/405 responses from withTokenRefresh, so HTTP-only servers with expired tokens never trigger the OAuth refresh and remain unauthenticated.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 19 files (reviewed changes from recent commits).

Prompt for AI agents (all 1 issues)

Understand the root cause of the following 1 issues and fix them.


<file name="extensions/cli/src/services/MCPService.ts">

<violation number="1" location="extensions/cli/src/services/MCPService.ts:477">
Rethrowing every `isAuthError` before the HTTP→SSE fallback means 405 responses (which `isAuthError` classifies as auth issues) never reach the SSE transport. SSE-only servers with no explicit `type` now fail to connect unless the user is signed in, because `withTokenRefresh` rethrows when `isAuthenticated()` is false, preventing the SSE fallback from running. Allow the SSE fallback to run for transport capability errors such as 405 so these servers remain reachable.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

const transport = this.constructHttpTransport(serverConfig);
await client.connect(transport, {});
} catch (e) {
if (isAuthError(e)) {
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rethrowing every isAuthError before the HTTP→SSE fallback means 405 responses (which isAuthError classifies as auth issues) never reach the SSE transport. SSE-only servers with no explicit type now fail to connect unless the user is signed in, because withTokenRefresh rethrows when isAuthenticated() is false, preventing the SSE fallback from running. Allow the SSE fallback to run for transport capability errors such as 405 so these servers remain reachable.

Prompt for AI agents
Address the following comment on extensions/cli/src/services/MCPService.ts at line 477:

<comment>Rethrowing every `isAuthError` before the HTTP→SSE fallback means 405 responses (which `isAuthError` classifies as auth issues) never reach the SSE transport. SSE-only servers with no explicit `type` now fail to connect unless the user is signed in, because `withTokenRefresh` rethrows when `isAuthenticated()` is false, preventing the SSE fallback from running. Allow the SSE fallback to run for transport capability errors such as 405 so these servers remain reachable.</comment>

<file context>
@@ -561,13 +474,9 @@ export class MCPService
-                  error: getErrorString(e),
-                },
-              );
+              if (isAuthError(e)) {
+                throw e;
+              }
</file context>

✅ Addressed in 317f6f4

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should work unless 405 is what a server throws when it tries to do http and it should be sse. But this is a bit of an edge case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but did this to fix case where someone throws 405 when auth is missing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! I've saved this as a new learning to improve future reviews.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 18, 2025
@RomneyDa RomneyDa merged commit abe18e8 into main Nov 19, 2025
58 checks passed
@RomneyDa RomneyDa deleted the dallin/mcp-oauth-cli branch November 19, 2025 01:00
@github-project-automation github-project-automation bot moved this from In Progress to Done in Issues and PRs Nov 19, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Nov 19, 2025
@sestinj
Copy link
Contributor

sestinj commented Nov 19, 2025

🎉 This PR is included in version 1.34.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@sestinj
Copy link
Contributor

sestinj commented Nov 19, 2025

🎉 This PR is included in version 1.30.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@sestinj
Copy link
Contributor

sestinj commented Nov 19, 2025

🎉 This PR is included in version 1.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

lgtm This PR has been approved by a maintainer released size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants