Skip to content

Commit cf97806

Browse files
committed
mcp: switch HF MCP login to https://hf.co/mcp?login and accept hf.co in strict checks
- Update examples and Helm envs to use hf.co endpoint - Relax isStrictHfMcpLogin to allow both hf.co and huggingface.co - Keeps functionality identical while preferring the shorter domain
1 parent 3be409e commit cf97806

File tree

6 files changed

+30
-26
lines changed

6 files changed

+30
-26
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ LLM_SUMMARIZATION=true # generate conversation titles with LLMs
119119

120120
ALLOW_IFRAME=true # Allow the app to be embedded in an iframe
121121

122-
# Base servers list (JSON array). Example: MCP_SERVERS=[{"name": "Web Search (Exa)", "url": "https://mcp.exa.ai/mcp"}, {"name": "Hugging Face", "url": "https://huggingface.co/mcp"}]
122+
# Base servers list (JSON array). Example: MCP_SERVERS=[{"name": "Web Search (Exa)", "url": "https://mcp.exa.ai/mcp"}, {"name": "Hugging Face", "url": "https://hf.co/mcp"}]
123123
MCP_SERVERS=
124124
# When true, forward the logged-in user's Hugging Face access token
125125
MCP_FORWARD_HF_USER_TOKEN=

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ Configure servers (base list for all users):
157157
# JSON array of servers: name, url, optional headers
158158
MCP_SERVERS=[
159159
{"name": "Web Search (Exa)", "url": "https://mcp.exa.ai/mcp"},
160-
{"name": "Hugging Face MCP Login", "url": "https://huggingface.co/mcp?login"}
160+
{"name": "Hugging Face MCP Login", "url": "https://hf.co/mcp?login"}
161161
]
162162
163163
# Forward the signed-in user's Hugging Face token to the official HF MCP login endpoint

chart/env/dev.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ envVars:
7171
LLM_ROUTER_ENABLE_TOOLS: "true"
7272
LLM_ROUTER_TOOLS_MODEL: "moonshotai/Kimi-K2-Instruct-0905"
7373
MCP_SERVERS: >
74-
[{"name": "Web Search (Exa)", "url": "https://mcp.exa.ai/mcp"}, {"name": "Hugging Face", "url": "https://huggingface.co/mcp?login"}]
74+
[{"name": "Web Search (Exa)", "url": "https://mcp.exa.ai/mcp"}, {"name": "Hugging Face", "url": "https://hf.co/mcp?login"}]
7575
PUBLIC_LLM_ROUTER_DISPLAY_NAME: "Omni"
7676
PUBLIC_LLM_ROUTER_LOGO_URL: "https://cdn-uploads.huggingface.co/production/uploads/5f17f0a0925b9863e28ad517/C5V0v1xZXv6M7FXsdJH9b.png"
7777
PUBLIC_LLM_ROUTER_ALIAS_ID: "omni"

chart/env/prod.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ envVars:
8181
LLM_ROUTER_ENABLE_TOOLS: "true"
8282
LLM_ROUTER_TOOLS_MODEL: "moonshotai/Kimi-K2-Instruct-0905"
8383
MCP_SERVERS: >
84-
[{"name": "Web Search (Exa)", "url": "https://mcp.exa.ai/mcp"}, {"name": "Hugging Face", "url": "https://huggingface.co/mcp?login"}]
84+
[{"name": "Web Search (Exa)", "url": "https://mcp.exa.ai/mcp"}, {"name": "Hugging Face", "url": "https://hf.co/mcp?login"}]
8585
PUBLIC_LLM_ROUTER_DISPLAY_NAME: "Omni"
8686
PUBLIC_LLM_ROUTER_LOGO_URL: "https://cdn-uploads.huggingface.co/production/uploads/5f17f0a0925b9863e28ad517/C5V0v1xZXv6M7FXsdJH9b.png"
8787
PUBLIC_LLM_ROUTER_ALIAS_ID: "omni"

src/lib/server/mcp/hf.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@ export const hasAuthHeader = (h?: Record<string, string>) =>
44
!!h && Object.keys(h).some((k) => k.toLowerCase() === "authorization");
55

66
export const isStrictHfMcpLogin = (urlString: string) => {
7-
try {
8-
const u = new URL(urlString);
9-
return (
10-
u.protocol === "https:" &&
11-
u.hostname === "huggingface.co" &&
12-
u.pathname === "/mcp" &&
13-
u.search === "?login"
14-
);
15-
} catch {
16-
return false;
17-
}
7+
try {
8+
const u = new URL(urlString);
9+
const host = u.hostname.toLowerCase();
10+
const allowedHosts = new Set(["hf.co", "huggingface.co"]);
11+
return (
12+
u.protocol === "https:" &&
13+
allowedHosts.has(host) &&
14+
u.pathname === "/mcp" &&
15+
u.search === "?login"
16+
);
17+
} catch {
18+
return false;
19+
}
1820
};
1921

2022
export const hasNonEmptyToken = (tok: unknown): tok is string =>

src/lib/utils/hf.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
// Client-safe HF utilities used in UI components
22

33
export function isStrictHfMcpLogin(urlString: string): boolean {
4-
try {
5-
const u = new URL(urlString);
6-
return (
7-
u.protocol === "https:" &&
8-
u.hostname === "huggingface.co" &&
9-
u.pathname === "/mcp" &&
10-
u.search === "?login"
11-
);
12-
} catch {
13-
return false;
14-
}
4+
try {
5+
const u = new URL(urlString);
6+
const host = u.hostname.toLowerCase();
7+
const allowedHosts = new Set(["hf.co", "huggingface.co"]);
8+
return (
9+
u.protocol === "https:" &&
10+
allowedHosts.has(host) &&
11+
u.pathname === "/mcp" &&
12+
u.search === "?login"
13+
);
14+
} catch {
15+
return false;
16+
}
1517
}

0 commit comments

Comments
 (0)