Skip to content

Commit 7b4901a

Browse files
committed
Enable MCP server if it exists
1 parent 7f6fe29 commit 7b4901a

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

ui/src/components/ChatView/ChatView.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
useTotalUsage,
3131
useCurrentConversationForExport,
3232
} from "@/stores/conversationStore";
33+
import { useMCPStore } from "@/stores/mcpStore";
3334
import { useMemo, useCallback, useState, useEffect } from "react";
3435

3536
export interface ChatFile {
@@ -117,14 +118,28 @@ export function ChatView({
117118
const mcpConfigModalOpen = useMCPConfigModalOpen();
118119
const [mcpPrefill, setMcpPrefill] = useState<MCPServerPrefill | null>(null);
119120

120-
// Check for ?mcp_server_url= query param to auto-open the MCP config modal
121+
// Check for ?mcp_server_url= query param. If the server is already
122+
// configured, just enable (and connect) it; otherwise open the config
123+
// modal pre-filled with the URL.
121124
useEffect(() => {
122125
const params = new URLSearchParams(window.location.search);
123126
const serverUrl = params.get("mcp_server_url");
124127
if (serverUrl) {
125128
const serverName = params.get("mcp_server_name") ?? undefined;
126-
setMcpPrefill({ url: serverUrl, name: serverName });
127-
setMCPConfigModalOpen(true);
129+
const mcp = useMCPStore.getState();
130+
const existing = mcp.servers.find((s) => s.url === serverUrl);
131+
if (existing) {
132+
if (!existing.enabled) {
133+
mcp.toggleServerEnabled(existing.id);
134+
} else if (existing.status !== "connected" && existing.status !== "connecting") {
135+
mcp.connectServer(existing.id).catch((err) => {
136+
console.debug("MCP connect from URL param failed:", err);
137+
});
138+
}
139+
} else {
140+
setMcpPrefill({ url: serverUrl, name: serverName });
141+
setMCPConfigModalOpen(true);
142+
}
128143
// Clean the URL to prevent re-triggering
129144
const cleanUrl = new URL(window.location.href);
130145
cleanUrl.searchParams.delete("mcp_server_url");

0 commit comments

Comments
 (0)