Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: make the claude mcp add command work in every project (#16839)

Nilay1f5b3352b05d
diff --git a/studio/frontend/src/features/settings/components/mcp-agent-snippet.ts b/studio/frontend/src/features/settings/components/mcp-agent-snippet.ts
index 14ca8972cb2..637f9d57fda 100644
--- a/studio/frontend/src/features/settings/components/mcp-agent-snippet.ts
+++ b/studio/frontend/src/features/settings/components/mcp-agent-snippet.ts
@@ -47,14 +47,9 @@ function claudeSnippet(
os: AgentCommandOs,
apiKey: string | null,
): string {
- const command = `claude mcp add --transport http ${MCP_SERVER_NAME} ${quoteShellArg(url, os)}`;
- if (apiKey) {
- return `${command} --header ${quoteShellArg(`Authorization: Bearer ${apiKey}`, os)}`;
- }
- // In PowerShell $UNSLOTH_API_KEY is an unset shell variable, not the environment.
- const envRef =
- os === "windows" ? `$env:${MCP_API_KEY_ENV}` : `$${MCP_API_KEY_ENV}`;
- return `${command} --header "Authorization: Bearer ${envRef}"`;
+ const command = `claude mcp add --transport http --scope user ${MCP_SERVER_NAME} ${quoteShellArg(url, os)}`;
+ const token = apiKey ?? `\${${MCP_API_KEY_ENV}}`;
+ return `${command} --header ${quoteShellArg(`Authorization: Bearer ${token}`, os)}`;
}
function codexSnippet(url: string, os: AgentCommandOs): string {
diff --git a/studio/frontend/tests/mcp-agent-snippet.test.ts b/studio/frontend/tests/mcp-agent-snippet.test.ts
index 95a7d9515b6..9450145b546 100644
--- a/studio/frontend/tests/mcp-agent-snippet.test.ts
+++ b/studio/frontend/tests/mcp-agent-snippet.test.ts
@@ -75,15 +75,11 @@ test("the endpoint is always the origin plus /mcp/", () => {
assert.equal(buildMcpSnippet("claude", "not a url", "unix"), null);
});
-test("Claude Code reads the key from the shell it runs in", () => {
- assert.equal(
- snippet("claude", "unix").text,
- 'claude mcp add --transport http unsloth-studio http://127.0.0.1:8888/mcp/ --header "Authorization: Bearer $UNSLOTH_API_KEY"',
- );
- assert.equal(
- snippet("claude", "windows").text,
- 'claude mcp add --transport http unsloth-studio http://127.0.0.1:8888/mcp/ --header "Authorization: Bearer $env:UNSLOTH_API_KEY"',
- );
+test("Claude Code adds the server for every project and reads the key when it starts", () => {
+ const expected =
+ "claude mcp add --transport http --scope user unsloth-studio http://127.0.0.1:8888/mcp/ --header 'Authorization: Bearer ${UNSLOTH_API_KEY}'";
+ assert.equal(snippet("claude", "unix").text, expected);
+ assert.equal(snippet("claude", "windows").text, expected);
assert.equal(snippet("claude").readsKeyEnv, true);
});
@@ -91,7 +87,7 @@ test("Claude Code quotes a real key for each shell", () => {
const unix = snippet("claude", "unix", KEY);
assert.equal(
unix.text,
- `claude mcp add --transport http unsloth-studio http://127.0.0.1:8888/mcp/ --header 'Authorization: Bearer ${KEY}'`,
+ `claude mcp add --transport http --scope user unsloth-studio http://127.0.0.1:8888/mcp/ --header 'Authorization: Bearer ${KEY}'`,
);
assert.equal(unix.readsKeyEnv, false);
assert.ok(