The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
remove operation.security
Pedro Ladeirae6bbadf5d7c7
diff --git a/apps/web/lib/openapi/mcp-document.ts b/apps/web/lib/openapi/mcp-document.tsindex bee9aa0618..42e48d8673 100644--- a/apps/web/lib/openapi/mcp-document.ts+++ b/apps/web/lib/openapi/mcp-document.ts@@ -4,7 +4,8 @@ import { OAUTH_SCOPE_DESCRIPTIONS, OAUTH_SCOPES } from "../api/oauth/constants";// OpenAPI document served at `api.dub.co/?mcp` for MCP clients.// Copies the public spec, adds an OAuth 2.0 (authorization code) security scheme// with the scopes from OAUTH_SCOPES, and accepts either the API key (`token`) or-// OAuth at the document level. Operation-level security is left unchanged.+// OAuth at the document level. Token-only operation security is removed so those+// operations inherit that rule. Operations with no security stay public.//// Example (truncated):// {@@ -57,5 +58,32 @@ export function getMcpDocument(): typeof document {mcpDocument.security = [{ token: [] }, { oauth: [] }];+ for (const pathItem of Object.values(mcpDocument.paths ?? {})) {+ for (const method of [+ "get",+ "put",+ "post",+ "delete",+ "options",+ "head",+ "patch",+ "trace",+ ] as const) {+ const operation = pathItem?.[method];+ if (!operation) continue;++ if (operation.security === undefined) {+ operation.security = [];+ continue;+ }++ if (+ JSON.stringify(operation.security) === JSON.stringify([{ token: [] }])+ ) {+ delete operation.security;+ }+ }+ }+return mcpDocument;}diff --git a/apps/web/tests/openapi/mcp-document.test.ts b/apps/web/tests/openapi/mcp-document.test.tsindex 5376448b49..1731017261 100644--- a/apps/web/tests/openapi/mcp-document.test.ts+++ b/apps/web/tests/openapi/mcp-document.test.ts@@ -33,11 +33,29 @@ describe("getMcpDocument", () => {expect(getMcpDocument().security).toEqual([{ token: [] }, { oauth: [] }]);});- test("leaves paths and the default document unchanged", () => {- const mcpDocument = getMcpDocument();+ test("lets authenticated operations inherit the document security rule", () => {+ const operations = Object.values(getMcpDocument().paths ?? {}).flatMap(+ (pathItem) =>+ (["get", "put", "post", "delete", "patch"] as const).flatMap(+ (method) => pathItem?.[method] ?? [],+ ),+ );++ for (const operation of operations) {+ if (["trackOpen", "getQRCode"].includes(operation.operationId ?? "")) {+ expect(operation.security).toEqual([]);+ continue;+ }++ expect(operation.security).toBeUndefined();+ }+ });++ test("does not mutate the default document", () => {+ const snapshot = structuredClone(document);++ getMcpDocument();- expect(mcpDocument.paths).toEqual(document.paths);- expect(document.security).toBeUndefined();- expect(document.components?.securitySchemes).not.toHaveProperty("oauth");+ expect(document).toEqual(snapshot);});});