Skip to content

Conversation

patrickkang
Copy link

@patrickkang patrickkang commented Sep 2, 2025

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

📋 Changes

Adds MCP Server example with Auth0 integration

📎 References

🎯 Testing

Use a MCP client like MCP inspector to test your MCP server

@codecov-commenter
Copy link

codecov-commenter commented Sep 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.47%. Comparing base (59f79bc) to head (06e9dea).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2299   +/-   ##
=======================================
  Coverage   85.47%   85.47%           
=======================================
  Files          26       26           
  Lines        2636     2636           
  Branches      486      486           
=======================================
  Hits         2253     2253           
  Misses        377      377           
  Partials        6        6           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@patrickkang patrickkang marked this pull request as ready for review September 2, 2025 20:03
@patrickkang patrickkang requested a review from a team as a code owner September 2, 2025 20:03
@@ -0,0 +1,41 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

Choose a reason for hiding this comment

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

Can we review to see what's actually needed here? Most of this is already covered in the root .gitignore.

Copy link
Author

Choose a reason for hiding this comment

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

Cleaned up in 22d9446


## Auth0 Tenant Setup

For detailed instructions on setting up your Auth0 tenant for MCP server integration, please refer to the [Auth0 Tenant Setup guide](https://github.com/auth0/auth0-auth-js/blob/main/examples/example-fastmcp-mcp/README.md#auth0-tenant-setup).

Choose a reason for hiding this comment

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

This link 404s

Copy link
Author

Choose a reason for hiding this comment

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

This link should be available once auth0/auth0-auth-js#45 merges in

Copy link
Author

Choose a reason for hiding this comment

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

This is resolved now that the above PR is merged in

With the configuration in place, the example can be started by running:

```bash
npm run start

Choose a reason for hiding this comment

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

Why npm since we're using pnpm for build? Also why start? Probably need to either:

  • Include a run build step so start works (fails currently w/out it)
  • Or use run dev instead

Copy link
Author

Choose a reason for hiding this comment

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

addressed in 5882a9f

Comment on lines +1 to +7
lockfileVersion: '9.0'

settings:
autoInstallPeers: true
excludeLinksFromLockfile: false

importers:

Choose a reason for hiding this comment

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

Shouldn't we just have the one root pnpm-lock.yaml file? Why is this here?

Copy link
Author

Choose a reason for hiding this comment

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

I am following the pattern used in other examples: https://github.com/search?q=repo%3Aauth0%2Fnextjs-auth0%20pnpm-lock.yaml&type=code and

"install:examples": "pnpm install --filter ./examples/with-next-intl --shamefully-hoist && pnpm install --filter ./examples/with-shadcn --shamefully-hoist",

Not too sure on the reason here though. I will check in with the sdk team to confirm

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Confirmed with the sdk team. The examples here are meant to be standalone next applications https://auth0team.atlassian.net/browse/ESD-51351?focusedCommentId=1019127

@gyaneshgouraw-okta
Copy link
Contributor

@claude

Copy link
Contributor

github-actions bot commented Oct 6, 2025

Claude encountered an error —— View job

Failed with exit code 128

I'll analyze this and get back to you.

@gyaneshgouraw-okta
Copy link
Contributor

Hi @patrickkang, thank you for sharing this example! I noticed that it doesn’t appear to use nextjs-auth0. Could you help me understand the rationale for including it in the Next.js SDK repository?

clientId,
scopes:
typeof decoded.scope === "string"
? decoded.scope.split(" ").filter(Boolean)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we simplify this return block? I notice it contains ternary conditions, claims checks, and other logic all within the return statement, which makes the code a bit hard to follow and less intuitive.

Copy link
Author

Choose a reason for hiding this comment

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

I agree, but i think this can be addressed in a separate PR unless this is a real blocker. We also have other MCP examples that follows this


interface Auth0Mcp {
verifyToken: ReturnType<typeof createTokenVerifier>;
requireScopes: ReturnType<typeof createScopeValidator>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @patrickkang, just to clarify, does this example mainly aim to demonstrate how users can implement custom logic for token verification and scope validation, or does it also illustrate how to obtain a token?

Copy link
Author

Choose a reason for hiding this comment

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

It is mainly to demonstrate token verification, user identity extraction, and protected MCP tools(scope based access control)

},
"dependencies": {
"@auth0/auth0-api-js": "^1.0.2",
"@auth0/nextjs-auth0": "^4.5.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see @auth0/nextjs-auth0 used in this example, am i missing anything ?

Copy link
Author

Choose a reason for hiding this comment

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

My mistake - this example does not depend on nextjs-auth0

# Example Nextjs MCP Server with Auth0 Integration

This is a practical example of securing a [Model Context Protocol (MCP)](https://modelcontextprotocol.io/docs) server
with Auth0.
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel it might be helpful to include a bit more detail on how the application is being secured, particularly highlighting the key aspects of the security implementation.

Copy link
Author

Choose a reason for hiding this comment

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

We are working on additional docs and blogs to highlight this better

@patrickkang
Copy link
Author

Closing this in favour of auth0/auth0-auth-js#70

@patrickkang patrickkang closed this Oct 8, 2025
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.

4 participants