router.d.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import express, { RequestHandler } from 'express';
  2. import { ClientRegistrationHandlerOptions } from './handlers/register.js';
  3. import { TokenHandlerOptions } from './handlers/token.js';
  4. import { AuthorizationHandlerOptions } from './handlers/authorize.js';
  5. import { RevocationHandlerOptions } from './handlers/revoke.js';
  6. import { OAuthServerProvider } from './provider.js';
  7. import { OAuthMetadata } from '../../shared/auth.js';
  8. export type AuthRouterOptions = {
  9. /**
  10. * A provider implementing the actual authorization logic for this router.
  11. */
  12. provider: OAuthServerProvider;
  13. /**
  14. * The authorization server's issuer identifier, which is a URL that uses the "https" scheme and has no query or fragment components.
  15. */
  16. issuerUrl: URL;
  17. /**
  18. * The base URL of the authorization server to use for the metadata endpoints.
  19. *
  20. * If not provided, the issuer URL will be used as the base URL.
  21. */
  22. baseUrl?: URL;
  23. /**
  24. * An optional URL of a page containing human-readable information that developers might want or need to know when using the authorization server.
  25. */
  26. serviceDocumentationUrl?: URL;
  27. /**
  28. * An optional list of scopes supported by this authorization server
  29. */
  30. scopesSupported?: string[];
  31. /**
  32. * The resource name to be displayed in protected resource metadata
  33. */
  34. resourceName?: string;
  35. /**
  36. * The URL of the protected resource (RS) whose metadata we advertise.
  37. * If not provided, falls back to `baseUrl` and then to `issuerUrl` (AS=RS).
  38. */
  39. resourceServerUrl?: URL;
  40. authorizationOptions?: Omit<AuthorizationHandlerOptions, 'provider'>;
  41. clientRegistrationOptions?: Omit<ClientRegistrationHandlerOptions, 'clientsStore'>;
  42. revocationOptions?: Omit<RevocationHandlerOptions, 'provider'>;
  43. tokenOptions?: Omit<TokenHandlerOptions, 'provider'>;
  44. };
  45. export declare const createOAuthMetadata: (options: {
  46. provider: OAuthServerProvider;
  47. issuerUrl: URL;
  48. baseUrl?: URL;
  49. serviceDocumentationUrl?: URL;
  50. scopesSupported?: string[];
  51. }) => OAuthMetadata;
  52. /**
  53. * Installs standard MCP authorization server endpoints, including dynamic client registration and token revocation (if supported).
  54. * Also advertises standard authorization server metadata, for easier discovery of supported configurations by clients.
  55. * Note: if your MCP server is only a resource server and not an authorization server, use mcpAuthMetadataRouter instead.
  56. *
  57. * By default, rate limiting is applied to all endpoints to prevent abuse.
  58. *
  59. * This router MUST be installed at the application root, like so:
  60. *
  61. * const app = express();
  62. * app.use(mcpAuthRouter(...));
  63. */
  64. export declare function mcpAuthRouter(options: AuthRouterOptions): RequestHandler;
  65. export type AuthMetadataOptions = {
  66. /**
  67. * OAuth Metadata as would be returned from the authorization server
  68. * this MCP server relies on
  69. */
  70. oauthMetadata: OAuthMetadata;
  71. /**
  72. * The url of the MCP server, for use in protected resource metadata
  73. */
  74. resourceServerUrl: URL;
  75. /**
  76. * The url for documentation for the MCP server
  77. */
  78. serviceDocumentationUrl?: URL;
  79. /**
  80. * An optional list of scopes supported by this MCP server
  81. */
  82. scopesSupported?: string[];
  83. /**
  84. * An optional resource name to display in resource metadata
  85. */
  86. resourceName?: string;
  87. };
  88. export declare function mcpAuthMetadataRouter(options: AuthMetadataOptions): express.Router;
  89. /**
  90. * Helper function to construct the OAuth 2.0 Protected Resource Metadata URL
  91. * from a given server URL. This replaces the path with the standard metadata endpoint.
  92. *
  93. * @param serverUrl - The base URL of the protected resource server
  94. * @returns The URL for the OAuth protected resource metadata endpoint
  95. *
  96. * @example
  97. * getOAuthProtectedResourceMetadataUrl(new URL('https://api.example.com/mcp'))
  98. * // Returns: 'https://api.example.com/.well-known/oauth-protected-resource/mcp'
  99. */
  100. export declare function getOAuthProtectedResourceMetadataUrl(serverUrl: URL): string;
  101. //# sourceMappingURL=router.d.ts.map