Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/web-console/ui/connect-catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,8 @@ export function coreConnectionClients(artifacts) {
] },
],
},
];
].map(client => ({
...client,
connectionNote: 'OAuth opens in your browser. Sign in with this account and approve the MCP connection. Copying or opening setup does not mean the client is connected.',
}));
}
46 changes: 38 additions & 8 deletions src/web-console/ui/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import { escapeHtml, relAgo } from './ui-utils.js';
import { connectionArtifacts, DEFAULT_CONNECTION_NAME, validateConnectionName, validateHostedMcpEndpoint } from './connect-config.js';
import { coreConnectionClients } from './connect-catalog.js';
import { nativeConnectionClients } from './connect-native-clients.js';
import { additionalConnectionClients } from './connect-extra-clients.js';

const METADATA_PATH = '/.well-known/oauth-protected-resource';

Expand All @@ -14,6 +16,7 @@
let sessionsTabAvailable = false;
let selectedClient = 'claude-code';
let selectedRoute = '';
let catalogReady = false;

export function connectedAppsMarkup(sessions, failed = false) {
if (failed) return '<div class="connect-state connect-state--error"><strong>Could not check connected apps.</strong><span>Use Refresh to try again.</span></div>';
Expand All @@ -35,6 +38,7 @@
host = panelEl;
selectedClient = 'claude-code';
selectedRoute = '';
catalogReady = false;
notify = ctx.toast || notify;
sessionsTabAvailable = ctx.hasRoute?.('GET', '/me/sessions') === true
&& ctx.hasRoute?.('GET', '/me/security/sessions') === true;
Expand Down Expand Up @@ -144,7 +148,16 @@
}
nameInput.removeAttribute('aria-invalid');
nameError.textContent = '';
const clients = coreConnectionClients(connectionArtifacts(endpoint, globalThis.location.origin, connectionName));
const artifacts = connectionArtifacts(endpoint, globalThis.location.origin, connectionName);
const clients = [
...coreConnectionClients(artifacts),
...nativeConnectionClients(artifacts.profile, globalThis.location.origin),
...additionalConnectionClients(artifacts.profile, globalThis.location.origin),
];
if (!catalogReady) {
renderClientList(clients);
catalogReady = true;
}
const client = clients.find(item => item.id === selectedClient) || clients[0];
target.replaceChildren(renderClientPanel(client));
}
Expand Down Expand Up @@ -188,7 +201,7 @@
host.querySelector('#connect-search-empty').hidden = matches > 0;
}

function renderClientPanel(client) {

Check failure on line 204 in src/web-console/ui/connect.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 17 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=DollhouseMCP_mcp-server&issues=AaDfbx-A2339CDgUtOw7&open=AaDfbx-A2339CDgUtOw7&pullRequest=2849
const panel = document.createElement('section');
panel.className = 'connect-client-panel';
const head = document.createElement('div'); head.className = 'connect-client-heading';
Expand Down Expand Up @@ -224,7 +237,7 @@
if (item.href) {
const link = safeLink(item.href, item.linkLabel || 'Open setup');
if (link) {
if (item.href.startsWith('cursor:') || item.href.startsWith('vscode:')) {
if (activeRoute.id === 'native') {
link.className = 'btn btn-primary';
link.addEventListener('click', () => notify(`Finish setup and OAuth in ${item.linkLabel?.replace('Open in ', '') || client.label}, then refresh connected apps.`, 'info'));
}
Expand All @@ -236,16 +249,33 @@
steps.append(li);
}
panel.append(steps);
panel.append(oauthNote());
if (client.connectionNote) panel.append(connectionNote(client.connectionNote));
return panel;
}

export function safeSetupHref(href) {
return typeof href === 'string' && (/^https:\/\/(?:code\.claude\.com|claude\.ai|support\.claude\.com|developers\.openai\.com|code\.visualstudio\.com|cursor\.com)\//.test(href)
|| href.startsWith('cursor://anysphere.cursor-deeplink/mcp/install?')
|| href.startsWith('vscode:mcp/install?'));
if (typeof href !== 'string') return false;
if (href.startsWith('cursor://anysphere.cursor-deeplink/mcp/install?')
|| href.startsWith('vscode:mcp/install?')
|| href.startsWith('lmstudio://add_mcp?')) return true;
let url;
try { url = new URL(href); } catch { return false; }
return url.protocol === 'https:' && !url.username && !url.password
&& OFFICIAL_SETUP_HOSTS.has(url.hostname);
}

const OFFICIAL_SETUP_HOSTS = new Set([
'code.claude.com', 'claude.ai', 'support.claude.com', 'developers.openai.com',
'code.visualstudio.com', 'cursor.com', 'kiro.dev', 'lmstudio.ai',
'github.com', 'opencode.ai', 'docs.openclaw.ai', 'zed.dev',
'junie.jetbrains.com', 'docs.github.com', 'developer.apple.com',
'support.microsoft.com', 'learn.microsoft.com', 'support.google.com',
'docs.cloud.google.com', 'ai.google.dev', 'www.antigravity.google',
'roocodeinc.github.io', 'docs.continue.dev', 'docs.windsurf.com',
'www.librechat.ai', 'docs.openwebui.com', 'www.perplexity.ai',
'www.jetbrains.com',
]);

function safeLink(href, label) {
if (!safeSetupHref(href)) return null;
const link = document.createElement('a');
Expand Down Expand Up @@ -289,9 +319,9 @@
}
}

function oauthNote() {
function connectionNote(text) {
const note = document.createElement('p'); note.className = 'connect-oauth-note';
note.textContent = 'OAuth opens in your browser. Sign in with this account and approve the MCP connection. Copying or opening setup does not mean the client is connected.';
note.textContent = text;
return note;
}

Expand Down
57 changes: 57 additions & 0 deletions tests/unit/web-console/ui/ConnectUi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,61 @@ describe('hosted connection UI', () => {
const native = panel.querySelector<HTMLAnchorElement>('[href^="cursor:"]')!;
expect(native.target).toBe('');
});

it('renders every catalog client and each route with approved links', async () => {
const panel = document.querySelector<HTMLElement>('#panel')!;
await connect.init(panel, { toast: jest.fn() });
const clientIds = [...panel.querySelectorAll<HTMLButtonElement>('[data-client]')].map(button => button.dataset.client!);
expect(clientIds).toHaveLength(40);
expect(new Set(clientIds).size).toBe(40);
for (const id of clientIds) {
panel.querySelector<HTMLButtonElement>(`[data-client="${id}"]`)!.click();
const routeIds = [...panel.querySelectorAll<HTMLButtonElement>('[data-route]')].map(button => button.dataset.route!);
expect(routeIds.length).toBeGreaterThan(0);
expect(panel.querySelector('.connect-client-heading a')).not.toBeNull();
for (const routeId of routeIds) {
panel.querySelector<HTMLButtonElement>(`[data-route="${routeId}"]`)!.click();
expect(panel.querySelectorAll('.connect-steps li').length).toBeGreaterThan(0);
for (const link of panel.querySelectorAll<HTMLAnchorElement>('.connect-client-panel a[href]')) {
expect(connect.safeSetupHref(link.href)).toBe(true);
}
}
}
});

it('shows qualification limits instead of setup payloads for unsupported clients', async () => {
const panel = document.querySelector<HTMLElement>('#panel')!;
await connect.init(panel, { toast: jest.fn() });
for (const id of ['microsoft-copilot-personal', 'google-ai-studio']) {
panel.querySelector<HTMLButtonElement>(`[data-client="${id}"]`)!.click();
expect(panel.querySelector('#connect-client-panel')?.textContent).toMatch(/No verified|unverified/i);
expect(panel.querySelector('.connect-client-panel .connect-value')).toBeNull();
expect(panel.querySelector('.connect-client-panel .connect-oauth-note')).toBeNull();
}
});

it('finds agent and platform clients and regenerates native payloads with the connection name', async () => {
const panel = document.querySelector<HTMLElement>('#panel')!;
await connect.init(panel, { toast: jest.fn() });
const search = panel.querySelector<HTMLInputElement>('#connect-search')!;
for (const term of ['Hermes', 'Copilot', 'Gemini']) {
search.value = term;
search.dispatchEvent(new dom.window.Event('input', { bubbles: true }));
expect([...panel.querySelectorAll<HTMLButtonElement>('[data-client]')].some(button => !button.hidden)).toBe(true);
}
search.value = '';
search.dispatchEvent(new dom.window.Event('input', { bubbles: true }));
panel.querySelector<HTMLButtonElement>('[data-client="kiro"]')!.click();
expect(panel.querySelector<HTMLAnchorElement>('[href^="https://kiro.dev/launch/mcp/add"]')?.classList.contains('btn-primary')).toBe(true);
panel.querySelector<HTMLButtonElement>('[data-client="lm-studio"]')!.click();
const input = panel.querySelector<HTMLInputElement>('#connect-name')!;
input.value = 'Research_2';
input.dispatchEvent(new dom.window.Event('input', { bubbles: true }));
const native = panel.querySelector<HTMLAnchorElement>('[href^="lmstudio:"]')!;
expect(native.classList.contains('btn-primary')).toBe(true);
expect(new URL(native.href).searchParams.get('name')).toBe('Research_2');
input.value = 'bad name';
input.dispatchEvent(new dom.window.Event('input', { bubbles: true }));
expect(panel.querySelector('[href^="lmstudio:"]')).toBeNull();
});
});
Loading