The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Serve OpenAPI with OAuth security scheme at /?mcp
Kiran Kc0a77d08a7ad
diff --git a/apps/web/tests/openapi/mcp-document.test.ts b/apps/web/tests/openapi/mcp-document.test.tsnew file mode 100644index 0000000000..5376448b49--- /dev/null+++ b/apps/web/tests/openapi/mcp-document.test.ts@@ -0,0 +1,43 @@+import { OAUTH_SCOPES } from "@/lib/api/oauth/constants";+import { document } from "@/lib/openapi";+import { getMcpDocument } from "@/lib/openapi/mcp-document";+import { describe, expect, test, vi } from "vitest";++vi.mock("server-only", () => ({}));++describe("getMcpDocument", () => {+ test("adds the OAuth security scheme with every OAuth scope", () => {+ const { components } = getMcpDocument();++ expect(components?.securitySchemes?.token).toEqual(+ document.components?.securitySchemes?.token,+ );+ expect(components?.securitySchemes?.oauth).toMatchObject({+ type: "oauth2",+ flows: {+ authorizationCode: {+ authorizationUrl: "https://app.dub.co/oauth/authorize",+ tokenUrl: "https://api.dub.co/oauth/token",+ },+ },+ });+ expect(+ Object.keys(+ (components?.securitySchemes?.oauth as any).flows.authorizationCode+ .scopes,+ ),+ ).toEqual([...OAUTH_SCOPES]);+ });++ test("accepts either the API key or OAuth at the document level", () => {+ expect(getMcpDocument().security).toEqual([{ token: [] }, { oauth: [] }]);+ });++ test("leaves paths and the default document unchanged", () => {+ const mcpDocument = getMcpDocument();++ expect(mcpDocument.paths).toEqual(document.paths);+ expect(document.security).toBeUndefined();+ expect(document.components?.securitySchemes).not.toHaveProperty("oauth");+ });+});