Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: make hosted MCP connector compatible with Claude and Grok

Richie McIlroyaa9a7e7e4034
diff --git a/apps/web/__tests__/unit/mcp-auth.test.ts b/apps/web/__tests__/unit/mcp-auth.test.ts
index 550e14d8f..ba89ac047 100644
--- a/apps/web/__tests__/unit/mcp-auth.test.ts
+++ b/apps/web/__tests__/unit/mcp-auth.test.ts
@@ -97,9 +97,10 @@ describe("MCP OAuth authorization", () => {
true,
);
expect(isMcpRedirectUri("http://127.0.0.1:49152/callback")).toBe(true);
+ expect(isMcpRedirectUri("http://localhost:49152/callback")).toBe(true);
for (const uri of [
"http://chatgpt.com/connector/callback",
- "http://localhost:49152/callback",
+ "http://localhost.evil.example:49152/callback",
"http://127.0.0.1/callback",
"https://chatgpt.com/connector/callback#fragment",
"https://user:[email protected]/callback",
diff --git a/apps/web/__tests__/unit/mcp-server.test.ts b/apps/web/__tests__/unit/mcp-server.test.ts
index 1646bd6e3..ad91c8842 100644
--- a/apps/web/__tests__/unit/mcp-server.test.ts
+++ b/apps/web/__tests__/unit/mcp-server.test.ts
@@ -83,30 +83,31 @@ describe("hosted MCP transport", () => {
});
it("preserves browser preflight and OAuth challenge headers", async () => {
- const origin = "https://chatgpt.com";
- const preflight = await OPTIONS(
- new Request("https://cap.so/api/mcp", {
- method: "OPTIONS",
- headers: { Origin: origin },
- }),
- );
- expect(preflight.status).toBe(204);
- expect(preflight.headers.get("access-control-allow-origin")).toBe(origin);
- expect(preflight.headers.get("cache-control")).toBe("no-store");
- const unauthorized = await POST(
- new Request("https://cap.so/api/mcp", {
- method: "POST",
- headers: { Origin: origin, "Content-Type": "application/json" },
- body: "{}",
- }),
- );
- expect(unauthorized.status).toBe(401);
- expect(unauthorized.headers.get("access-control-allow-origin")).toBe(
- origin,
- );
- expect(unauthorized.headers.get("www-authenticate")).toContain(
- "resource_metadata",
- );
+ for (const origin of ["https://chatgpt.com", "https://grok.com"]) {
+ const preflight = await OPTIONS(
+ new Request("https://cap.so/api/mcp", {
+ method: "OPTIONS",
+ headers: { Origin: origin },
+ }),
+ );
+ expect(preflight.status).toBe(204);
+ expect(preflight.headers.get("access-control-allow-origin")).toBe(origin);
+ expect(preflight.headers.get("cache-control")).toBe("no-store");
+ const unauthorized = await POST(
+ new Request("https://cap.so/api/mcp", {
+ method: "POST",
+ headers: { Origin: origin, "Content-Type": "application/json" },
+ body: "{}",
+ }),
+ );
+ expect(unauthorized.status).toBe(401);
+ expect(unauthorized.headers.get("access-control-allow-origin")).toBe(
+ origin,
+ );
+ expect(unauthorized.headers.get("www-authenticate")).toContain(
+ "resource_metadata",
+ );
+ }
});
it("keeps host, origin, media type, and body limits ahead of MCP dispatch", async () => {
@@ -150,6 +151,7 @@ describe("hosted MCP transport", () => {
expect(listBody).toContain("caps_list");
expect(listBody).toContain("caps_get");
expect(listBody).toContain("caps_context");
+ expect(listBody).toContain('"openWorldHint":false');
expect(listBody).not.toContain("caps_delete");
const called = await POST(
request({
diff --git a/apps/web/app/api/mcp/route.ts b/apps/web/app/api/mcp/route.ts
index 32704c367..e59700e3e 100644
--- a/apps/web/app/api/mcp/route.ts
+++ b/apps/web/app/api/mcp/route.ts
@@ -24,6 +24,7 @@ const allowedOrigins = () =>
"https://chatgpt.com",
"https://claude.ai",
"https://muse.ai",
+ "https://grok.com",
]);
const corsHeaders = (request: Request) => {
diff --git a/apps/web/lib/mcp-auth.ts b/apps/web/lib/mcp-auth.ts
index c6c14c680..d61ea1fda 100644
--- a/apps/web/lib/mcp-auth.ts
+++ b/apps/web/lib/mcp-auth.ts
@@ -37,7 +37,9 @@ export const isMcpRedirectUri = (value: string) => {
const url = new URL(value);
const loopback =
url.protocol === "http:" &&
- (url.hostname === "127.0.0.1" || url.hostname === "[::1]") &&
+ (url.hostname === "localhost" ||
+ url.hostname === "127.0.0.1" ||
+ url.hostname === "[::1]") &&
url.port.length > 0;
return (
(url.protocol === "https:" || loopback) &&
diff --git a/apps/web/lib/mcp-server.ts b/apps/web/lib/mcp-server.ts
index 9725b3d55..16548cf1a 100644
--- a/apps/web/lib/mcp-server.ts
+++ b/apps/web/lib/mcp-server.ts
@@ -17,6 +17,7 @@ const readOnly = {
readOnlyHint: true,
destructiveHint: false,
idempotentHint: true,
+ openWorldHint: false,
};
const result = (value: Record<string, unknown>) => ({