Skip to content

Comments

fix(mcp): use getBaseUrl for OAuth discovery metadata URLs#3283

Merged
waleedlatif1 merged 2 commits intostagingfrom
feat/mcp
Feb 21, 2026
Merged

fix(mcp): use getBaseUrl for OAuth discovery metadata URLs#3283
waleedlatif1 merged 2 commits intostagingfrom
feat/mcp

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • OAuth discovery endpoints were returning internal EC2 hostnames instead of the public URL
  • Use getBaseUrl() (reads NEXT_PUBLIC_APP_URL) instead of request.nextUrl.origin for metadata and WWW-Authenticate URLs

Type of Change

  • Bug fix

Testing

Tested manually — verified discovery endpoints return correct public URLs

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Feb 21, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Feb 21, 2026 9:56am

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 21, 2026

Greptile Summary

This PR fixes OAuth discovery endpoints to return public URLs instead of internal EC2 hostnames by replacing request.nextUrl.origin with getBaseUrl() which reads from NEXT_PUBLIC_APP_URL.

  • Changed getOrigin(request: NextRequest) to getOrigin() in oauth-discovery.ts to use getBaseUrl() instead of extracting origin from the request
  • Updated WWW-Authenticate header in copilot/route.ts to construct resource metadata URL using public base URL
  • Both files now consistently strip trailing slashes using .replace(/\/$/, '') before building OAuth endpoint URLs
  • This ensures OAuth clients receive correct public endpoints for authorization and token exchange instead of internal network addresses

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are straightforward and follow existing patterns in the codebase. The fix correctly addresses the issue of OAuth discovery endpoints returning internal hostnames by using the centralized getBaseUrl() utility, which is already widely used throughout the application for webhooks and callbacks. The trailing slash handling is consistent with patterns found elsewhere in the codebase.
  • No files require special attention

Important Files Changed

Filename Overview
apps/sim/lib/mcp/oauth-discovery.ts Replaced request.nextUrl.origin with getBaseUrl() to return public URLs instead of internal EC2 hostnames in OAuth discovery endpoints
apps/sim/app/api/mcp/copilot/route.ts Updated WWW-Authenticate header to use getBaseUrl() for resource metadata URL instead of request origin

Last reviewed commit: 1bae9d7

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1
Copy link
Collaborator Author

@cursor review

@waleedlatif1 waleedlatif1 merged commit 42020c3 into staging Feb 21, 2026
7 checks passed
@waleedlatif1 waleedlatif1 deleted the feat/mcp branch February 21, 2026 09:57
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant