Skip to content

Conversation

@dvoytenko
Copy link
Member

@dvoytenko dvoytenko commented Jun 4, 2025

See an alternative approach in #39

Provide a facility to use middleware, including auth, for createMcpHandler.

The @modelcontextprotocol/sdk is constructed around Express' middleware. E.g. see this sample. However, this is not normally available in Next.js.

The middleware is included like this:

const mcpHandler = createMcpHandler(
      ...
      {
        middleware: [
          (req) => {
            const header = req.headers.get("Authorization");
            if (header?.startsWith("Bearer ")) {
              const token = header.slice(7).trim();
              return {
                auth: { token, clientId: "client1", scopes: ["read:stuff"] },
              };
            }
          },
        ],
      }
);

@dvoytenko dvoytenko requested review from MaxLeiter and quuu June 4, 2025 02:01
@socket-security
Copy link

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedvitest@​3.2.1100100100100100
Updatedzod@​3.24.4 ⏵ 3.25.50100 +1100100100 +5100

View full report

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.

2 participants