Skip to content

Commit a91136d

Browse files
Prasanna721github-actions[bot]claude
authored
MCP connector fix (#849)
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 3cf7e77 commit a91136d

2 files changed

Lines changed: 29 additions & 16 deletions

File tree

apps/mcp/mcp-app.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
</div>
4040
</div>
4141

42-
<div id="legend">
42+
<div id="legend" class="collapsed">
4343
<div id="legend-toggle">
4444
<span>Legend</span>
4545
<svg class="legend-chevron" width="10" height="10" viewBox="0 0 10 10" aria-hidden="true"><path d="M3 2l4 3-4 3" fill="none" stroke="currentColor" stroke-width="1.5"/></svg>

apps/mcp/src/index.ts

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,17 @@ app.use(
2828
"*",
2929
cors({
3030
origin: "*",
31-
allowMethods: ["GET", "POST", "OPTIONS"],
32-
allowHeaders: ["Content-Type", "Authorization", "x-sm-project"],
31+
allowMethods: ["GET", "POST", "DELETE", "OPTIONS"],
32+
allowHeaders: [
33+
"Content-Type",
34+
"Authorization",
35+
"x-sm-project",
36+
"Accept",
37+
"Mcp-Session-Id",
38+
"MCP-Protocol-Version",
39+
"Last-Event-ID",
40+
],
41+
exposeHeaders: ["Mcp-Session-Id", "WWW-Authenticate"],
3342
}),
3443
)
3544

@@ -50,10 +59,9 @@ app.get("/", (c) => {
5059
// MCP clients use this to discover the authorization server
5160
app.get("/.well-known/oauth-protected-resource", (c) => {
5261
const apiUrl = c.env.API_URL || DEFAULT_API_URL
53-
const resourceUrl =
54-
c.env.API_URL === "http://localhost:8787"
55-
? "http://localhost:8788"
56-
: "https://mcp.supermemory.ai"
62+
const host = c.req.header("x-forwarded-host") || c.req.header("host")
63+
const proto = c.req.header("x-forwarded-proto") || "https"
64+
const resourceUrl = host ? `${proto}://${host}` : "https://mcp.supermemory.ai"
5765

5866
return c.json({
5967
resource: resourceUrl,
@@ -91,12 +99,13 @@ app.get("/.well-known/oauth-authorization-server", async (c) => {
9199
}
92100
})
93101

94-
const mcpHandler = SupermemoryMCP.mount("/mcp", {
102+
const mcpHandler = SupermemoryMCP.serve("/mcp", {
95103
binding: "MCP_SERVER",
96104
corsOptions: {
97105
origin: "*",
98-
methods: "GET, POST, OPTIONS",
99-
headers: "Content-Type, Authorization, x-sm-project",
106+
methods: "GET, POST, DELETE, OPTIONS",
107+
headers:
108+
"Content-Type, Authorization, x-sm-project, Accept, Mcp-Session-Id, MCP-Protocol-Version, Last-Event-ID",
100109
},
101110
})
102111

@@ -105,17 +114,20 @@ app.all("/mcp/*", async (c) => {
105114
const token = authHeader?.replace(/^Bearer\s+/i, "")
106115
const containerTag = c.req.header("x-sm-project")
107116
const apiUrl = c.env.API_URL || DEFAULT_API_URL
108-
const mcpURL =
109-
c.env.API_URL === "http://localhost:8787"
110-
? "http://localhost:8788"
111-
: "https://mcp.supermemory.ai"
117+
118+
const reqHost = c.req.header("x-forwarded-host") || c.req.header("host") || ""
119+
const reqProto = c.req.header("x-forwarded-proto") || "https"
120+
const resourceMetadataUrl = reqHost
121+
? `${reqProto}://${reqHost}/.well-known/oauth-protected-resource`
122+
: "/.well-known/oauth-protected-resource"
112123

113124
if (!token) {
114125
return new Response("Unauthorized", {
115126
status: 401,
116127
headers: {
117-
"WWW-Authenticate": `Bearer resource_metadata="${mcpURL}/.well-known/oauth-protected-resource"`,
128+
"WWW-Authenticate": `Bearer resource_metadata="${resourceMetadataUrl}"`,
118129
"Access-Control-Expose-Headers": "WWW-Authenticate",
130+
"Access-Control-Allow-Origin": "*",
119131
},
120132
})
121133
}
@@ -153,8 +165,9 @@ app.all("/mcp/*", async (c) => {
153165
status: 401,
154166
headers: {
155167
"Content-Type": "application/json",
156-
"WWW-Authenticate": `Bearer error="invalid_token", resource_metadata="${mcpURL}/.well-known/oauth-protected-resource"`,
168+
"WWW-Authenticate": `Bearer error="invalid_token", resource_metadata="${resourceMetadataUrl}"`,
157169
"Access-Control-Expose-Headers": "WWW-Authenticate",
170+
"Access-Control-Allow-Origin": "*",
158171
},
159172
},
160173
)

0 commit comments

Comments
 (0)