Skip to main content

Function: createProtectedResourceMetadataMiddleware()

createProtectedResourceMetadataMiddleware(args): Middleware

Defined in: index.ts:813

Creates a standalone Koa middleware that serves GET /.well-known/oauth-protected-resource (RFC 9728) without requiring the built-in auth option on createMcpRouter.

Mount this before your own auth middleware so the discovery endpoint remains unauthenticated (MCP clients fetch it before they have a token).

Parameters

ParameterTypeDescription
args{ authorizationServers: string[]; resource: string; }-
args.authorizationServersstring[]List of authorization server issuer URIs that issue tokens for this resource.
args.resourcestringThe protected resource's identifier URI (the MCP server URL).

Returns

Middleware

Example

import Koa from 'koa';
import { createProtectedResourceMetadataMiddleware } from '@ttoss/http-server-mcp';

const app = new Koa();
app.use(
createProtectedResourceMetadataMiddleware({
resource: 'https://mcp.example.com',
authorizationServers: ['https://api.example.com'],
})
);
app.use(myOwnAuthMiddleware);