mirror of
https://github.com/davidkaya/aryx.git
synced 2026-08-06 19:58:43 +02:00
feat: auto-discover MCP servers from project and user config files
Scan .vscode/mcp.json, .mcp.json, .copilot/mcp.json (project-level) and ~/.copilot/mcp.json (user-level) for MCP server definitions. Discovered servers require explicit user acceptance before activation. Backend: - Add ConfigScannerRegistry with per-format scanners and substitution - Add discovered tooling domain model with fingerprint-based change detection - Integrate scanning into workspace load, project add, and project selection - Merge accepted discovered MCPs into effective runtime tooling - Extend sidecar contracts with env/headers for real-world MCP configs - Add IPC channels for accept/dismiss/rescan operations Frontend: - Add DiscoveredToolingModal for reviewing pending MCP servers - Auto-show modal when pending discoveries exist on load or project switch - Add amber badge on sidebar project headers for pending discoveries - Add discovered MCP section in Settings panel with accept/dismiss/rescan - Group InlinePills tool dropdown by Workspace MCP / User MCP / Project MCP - Pass effective project tooling (including accepted discoveries) to ChatPane Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,227 @@
|
||||
import { describe, expect, mock, test } from 'bun:test';
|
||||
|
||||
import type { RunTurnCommand } from '@shared/contracts/sidecar';
|
||||
import type { PatternDefinition } from '@shared/domain/pattern';
|
||||
import type { ProjectRecord } from '@shared/domain/project';
|
||||
import type { SessionRecord } from '@shared/domain/session';
|
||||
import { createWorkspaceSeed, type WorkspaceState } from '@shared/domain/workspace';
|
||||
|
||||
const TIMESTAMP = '2026-03-25T00:00:00.000Z';
|
||||
|
||||
mock.module('electron', () => ({
|
||||
app: {
|
||||
isPackaged: false,
|
||||
getAppPath: () => 'C:\\workspace\\personal\\repositories\\eryx',
|
||||
getPath: () => 'C:\\workspace\\personal\\repositories\\eryx\\tests\\fixtures',
|
||||
},
|
||||
dialog: {
|
||||
showOpenDialog: async () => ({ canceled: true, filePaths: [] }),
|
||||
},
|
||||
shell: {
|
||||
openPath: async () => '',
|
||||
},
|
||||
}));
|
||||
|
||||
mock.module('keytar', () => ({
|
||||
default: {
|
||||
getPassword: async () => null,
|
||||
setPassword: async () => undefined,
|
||||
deletePassword: async () => false,
|
||||
},
|
||||
}));
|
||||
|
||||
const { EryxAppService } = await import('@main/EryxAppService');
|
||||
|
||||
function createProject(overrides?: Partial<ProjectRecord>): ProjectRecord {
|
||||
return {
|
||||
id: 'project-alpha',
|
||||
name: 'alpha',
|
||||
path: 'C:\\workspace\\alpha',
|
||||
addedAt: TIMESTAMP,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
function createSession(projectId: string, patternId: string, overrides?: Partial<SessionRecord>): SessionRecord {
|
||||
return {
|
||||
id: 'session-alpha',
|
||||
projectId,
|
||||
patternId,
|
||||
title: 'Alpha session',
|
||||
createdAt: TIMESTAMP,
|
||||
updatedAt: TIMESTAMP,
|
||||
status: 'idle',
|
||||
messages: [],
|
||||
runs: [],
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
function createService(
|
||||
workspace: WorkspaceState,
|
||||
pattern: PatternDefinition,
|
||||
options?: {
|
||||
captureRunTurn?: (command: RunTurnCommand) => void;
|
||||
},
|
||||
): InstanceType<typeof EryxAppService> {
|
||||
const service = new EryxAppService();
|
||||
const internals = service as unknown as Record<string, unknown>;
|
||||
internals.loadWorkspace = async () => workspace;
|
||||
internals.persistAndBroadcast = async (nextWorkspace: WorkspaceState) => nextWorkspace;
|
||||
internals.buildEffectivePattern = async () => pattern;
|
||||
internals.awaitFinalResponseApproval = async () => undefined;
|
||||
internals.finalizeTurn = () => undefined;
|
||||
internals.emitSessionEvent = () => undefined;
|
||||
internals.pruneUnavailableApprovalTools = async () => false;
|
||||
internals.pruneUnavailableSessionToolingSelections = () => false;
|
||||
(
|
||||
service as unknown as {
|
||||
sidecar: {
|
||||
runTurn: (
|
||||
command: RunTurnCommand,
|
||||
onDelta: unknown,
|
||||
onActivity: unknown,
|
||||
onApproval: unknown,
|
||||
) => Promise<[]>;
|
||||
resolveApproval: () => Promise<void>;
|
||||
};
|
||||
}
|
||||
).sidecar = {
|
||||
runTurn: async (command) => {
|
||||
options?.captureRunTurn?.(command);
|
||||
return [];
|
||||
},
|
||||
resolveApproval: async () => undefined,
|
||||
};
|
||||
|
||||
return service;
|
||||
}
|
||||
|
||||
describe('EryxAppService discovered tooling', () => {
|
||||
test('allows project-discovered MCP servers to be accepted and used in project sessions', async () => {
|
||||
const workspace = createWorkspaceSeed();
|
||||
const pattern = workspace.patterns.find((candidate) => candidate.mode === 'single');
|
||||
if (!pattern) {
|
||||
throw new Error('Expected a single-agent pattern in the workspace seed.');
|
||||
}
|
||||
|
||||
const project = createProject({
|
||||
discoveredTooling: {
|
||||
mcpServers: [
|
||||
{
|
||||
id: 'discovered_project_project_alpha_vscode_mcp_git_mcp',
|
||||
name: 'Git MCP',
|
||||
transport: 'local',
|
||||
command: 'node',
|
||||
args: ['project-mcp.js'],
|
||||
cwd: 'C:\\workspace\\alpha',
|
||||
tools: ['git.status'],
|
||||
scope: 'project',
|
||||
scannerId: 'vscode-mcp',
|
||||
sourcePath: 'C:\\workspace\\alpha\\.vscode\\mcp.json',
|
||||
sourceLabel: '.vscode\\mcp.json',
|
||||
fingerprint: 'fingerprint-project',
|
||||
status: 'pending',
|
||||
},
|
||||
],
|
||||
lastScannedAt: TIMESTAMP,
|
||||
},
|
||||
});
|
||||
const session = createSession(project.id, pattern.id);
|
||||
|
||||
workspace.projects = [project];
|
||||
workspace.sessions = [session];
|
||||
workspace.selectedProjectId = project.id;
|
||||
workspace.selectedPatternId = pattern.id;
|
||||
workspace.selectedSessionId = session.id;
|
||||
|
||||
let command: RunTurnCommand | undefined;
|
||||
const service = createService(workspace, pattern, {
|
||||
captureRunTurn: (capturedCommand) => {
|
||||
command = capturedCommand;
|
||||
},
|
||||
});
|
||||
|
||||
await service.resolveProjectDiscoveredTooling(project.id, [project.discoveredTooling!.mcpServers[0]!.id], 'accept');
|
||||
await service.updateSessionTooling(session.id, [project.discoveredTooling!.mcpServers[0]!.id], []);
|
||||
await service.sendSessionMessage(session.id, 'Use the project MCP server.');
|
||||
|
||||
expect(command?.tooling?.mcpServers).toEqual([
|
||||
{
|
||||
id: 'discovered_project_project_alpha_vscode_mcp_git_mcp',
|
||||
name: 'Git MCP',
|
||||
transport: 'local',
|
||||
command: 'node',
|
||||
args: ['project-mcp.js'],
|
||||
cwd: 'C:\\workspace\\alpha',
|
||||
tools: ['git.status'],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test('allows accepted user-discovered MCP servers to be used across projects', async () => {
|
||||
const workspace = createWorkspaceSeed();
|
||||
const pattern = workspace.patterns.find((candidate) => candidate.mode === 'single');
|
||||
if (!pattern) {
|
||||
throw new Error('Expected a single-agent pattern in the workspace seed.');
|
||||
}
|
||||
|
||||
workspace.settings.discoveredUserTooling = {
|
||||
mcpServers: [
|
||||
{
|
||||
id: 'discovered_user_workspace_copilot_user_mcp_github',
|
||||
name: 'GitHub MCP',
|
||||
transport: 'http',
|
||||
url: 'https://example.com/mcp',
|
||||
headers: { Authorization: 'Bearer token' },
|
||||
tools: ['github.issues'],
|
||||
scope: 'user',
|
||||
scannerId: 'copilot-user-mcp',
|
||||
sourcePath: 'C:\\Users\\tester\\.copilot\\mcp.json',
|
||||
sourceLabel: '~\\.copilot\\mcp.json',
|
||||
fingerprint: 'fingerprint-user',
|
||||
status: 'pending',
|
||||
},
|
||||
],
|
||||
lastScannedAt: TIMESTAMP,
|
||||
};
|
||||
|
||||
const project = createProject();
|
||||
const session = createSession(project.id, pattern.id);
|
||||
|
||||
workspace.projects = [project];
|
||||
workspace.sessions = [session];
|
||||
workspace.selectedProjectId = project.id;
|
||||
workspace.selectedPatternId = pattern.id;
|
||||
workspace.selectedSessionId = session.id;
|
||||
|
||||
let command: RunTurnCommand | undefined;
|
||||
const service = createService(workspace, pattern, {
|
||||
captureRunTurn: (capturedCommand) => {
|
||||
command = capturedCommand;
|
||||
},
|
||||
});
|
||||
|
||||
await service.resolveWorkspaceDiscoveredTooling(
|
||||
[workspace.settings.discoveredUserTooling.mcpServers[0]!.id],
|
||||
'accept',
|
||||
);
|
||||
await service.updateSessionTooling(
|
||||
session.id,
|
||||
[workspace.settings.discoveredUserTooling.mcpServers[0]!.id],
|
||||
[],
|
||||
);
|
||||
await service.sendSessionMessage(session.id, 'Use the user MCP server.');
|
||||
|
||||
expect(command?.tooling?.mcpServers).toEqual([
|
||||
{
|
||||
id: 'discovered_user_workspace_copilot_user_mcp_github',
|
||||
name: 'GitHub MCP',
|
||||
transport: 'http',
|
||||
url: 'https://example.com/mcp',
|
||||
headers: { Authorization: 'Bearer token' },
|
||||
tools: ['github.issues'],
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,184 @@
|
||||
import { afterEach, describe, expect, test } from 'bun:test';
|
||||
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
|
||||
import { ConfigScannerRegistry } from '@main/services/configScanner';
|
||||
|
||||
const temporaryPaths: string[] = [];
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(
|
||||
temporaryPaths.splice(0).map((path) => rm(path, { recursive: true, force: true })),
|
||||
);
|
||||
});
|
||||
|
||||
async function createTempDirectory(): Promise<string> {
|
||||
const directory = await mkdtemp(join(tmpdir(), 'eryx-config-scanner-'));
|
||||
temporaryPaths.push(directory);
|
||||
return directory;
|
||||
}
|
||||
|
||||
describe('ConfigScannerRegistry', () => {
|
||||
test('scans supported project-level MCP config formats', async () => {
|
||||
const projectPath = await createTempDirectory();
|
||||
await mkdir(join(projectPath, '.vscode'), { recursive: true });
|
||||
await mkdir(join(projectPath, '.copilot'), { recursive: true });
|
||||
|
||||
await writeFile(
|
||||
join(projectPath, '.vscode', 'mcp.json'),
|
||||
JSON.stringify({
|
||||
servers: {
|
||||
filesystem: {
|
||||
command: 'node',
|
||||
args: ['${workspaceFolder}\\server.js'],
|
||||
cwd: '${workspaceFolder}',
|
||||
env: { DEBUG: 'true' },
|
||||
tools: ['fs.read'],
|
||||
},
|
||||
},
|
||||
}),
|
||||
'utf8',
|
||||
);
|
||||
await writeFile(
|
||||
join(projectPath, '.mcp.json'),
|
||||
JSON.stringify({
|
||||
mcpServers: {
|
||||
remote: {
|
||||
type: 'http',
|
||||
url: 'https://example.com/mcp',
|
||||
headers: { Authorization: 'Bearer token' },
|
||||
tools: ['remote.tool'],
|
||||
},
|
||||
},
|
||||
}),
|
||||
'utf8',
|
||||
);
|
||||
await writeFile(
|
||||
join(projectPath, '.copilot', 'mcp.json'),
|
||||
JSON.stringify({
|
||||
mcpServers: {
|
||||
local: {
|
||||
command: 'python',
|
||||
args: ['tool.py'],
|
||||
timeout: 1500,
|
||||
},
|
||||
},
|
||||
}),
|
||||
'utf8',
|
||||
);
|
||||
|
||||
const scanned = await new ConfigScannerRegistry().scanProject('project-alpha', projectPath);
|
||||
|
||||
expect(scanned.mcpServers).toHaveLength(3);
|
||||
expect(scanned.mcpServers).toContainEqual({
|
||||
id: 'discovered_project_project_alpha_vscode_mcp_filesystem',
|
||||
name: 'filesystem',
|
||||
transport: 'local',
|
||||
command: 'node',
|
||||
args: [`${projectPath}\\server.js`],
|
||||
cwd: projectPath,
|
||||
env: { DEBUG: 'true' },
|
||||
tools: ['fs.read'],
|
||||
scope: 'project',
|
||||
scannerId: 'vscode-mcp',
|
||||
sourcePath: join(projectPath, '.vscode', 'mcp.json'),
|
||||
sourceLabel: '.vscode\\mcp.json',
|
||||
fingerprint: expect.any(String),
|
||||
status: 'pending',
|
||||
});
|
||||
expect(scanned.mcpServers).toContainEqual({
|
||||
id: 'discovered_project_project_alpha_claude_code_mcp_remote',
|
||||
name: 'remote',
|
||||
transport: 'http',
|
||||
url: 'https://example.com/mcp',
|
||||
headers: { Authorization: 'Bearer token' },
|
||||
tools: ['remote.tool'],
|
||||
scope: 'project',
|
||||
scannerId: 'claude-code-mcp',
|
||||
sourcePath: join(projectPath, '.mcp.json'),
|
||||
sourceLabel: '.mcp.json',
|
||||
fingerprint: expect.any(String),
|
||||
status: 'pending',
|
||||
});
|
||||
expect(scanned.mcpServers).toContainEqual({
|
||||
id: 'discovered_project_project_alpha_copilot_project_mcp_local',
|
||||
name: 'local',
|
||||
transport: 'local',
|
||||
command: 'python',
|
||||
args: ['tool.py'],
|
||||
tools: [],
|
||||
timeoutMs: 1500,
|
||||
scope: 'project',
|
||||
scannerId: 'copilot-project-mcp',
|
||||
sourcePath: join(projectPath, '.copilot', 'mcp.json'),
|
||||
sourceLabel: '.copilot\\mcp.json',
|
||||
fingerprint: expect.any(String),
|
||||
status: 'pending',
|
||||
});
|
||||
});
|
||||
|
||||
test('scans user-level Copilot MCP config files', async () => {
|
||||
const homePath = await createTempDirectory();
|
||||
await mkdir(join(homePath, '.copilot'), { recursive: true });
|
||||
await writeFile(
|
||||
join(homePath, '.copilot', 'mcp.json'),
|
||||
JSON.stringify({
|
||||
mcpServers: {
|
||||
github: {
|
||||
command: 'gh',
|
||||
args: ['aw', 'mcp-server'],
|
||||
},
|
||||
},
|
||||
}),
|
||||
'utf8',
|
||||
);
|
||||
|
||||
const scanned = await new ConfigScannerRegistry().scanUser(undefined, homePath);
|
||||
|
||||
expect(scanned.mcpServers).toEqual([
|
||||
{
|
||||
id: 'discovered_user_workspace_copilot_user_mcp_github',
|
||||
name: 'github',
|
||||
transport: 'local',
|
||||
command: 'gh',
|
||||
args: ['aw', 'mcp-server'],
|
||||
tools: [],
|
||||
scope: 'user',
|
||||
scannerId: 'copilot-user-mcp',
|
||||
sourcePath: join(homePath, '.copilot', 'mcp.json'),
|
||||
sourceLabel: '~\\.copilot\\mcp.json',
|
||||
fingerprint: expect.any(String),
|
||||
status: 'pending',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test('retains previous scanner results when a config file becomes malformed', async () => {
|
||||
const projectPath = await createTempDirectory();
|
||||
await mkdir(join(projectPath, '.vscode'), { recursive: true });
|
||||
const filePath = join(projectPath, '.vscode', 'mcp.json');
|
||||
|
||||
await writeFile(
|
||||
filePath,
|
||||
JSON.stringify({
|
||||
servers: {
|
||||
filesystem: {
|
||||
command: 'node',
|
||||
args: ['server.js'],
|
||||
},
|
||||
},
|
||||
}),
|
||||
'utf8',
|
||||
);
|
||||
|
||||
const registry = new ConfigScannerRegistry();
|
||||
const firstScan = await registry.scanProject('project-alpha', projectPath);
|
||||
|
||||
await writeFile(filePath, '{ invalid json', 'utf8');
|
||||
|
||||
const secondScan = await registry.scanProject('project-alpha', projectPath, firstScan);
|
||||
|
||||
expect(secondScan.mcpServers).toEqual(firstScan.mcpServers);
|
||||
});
|
||||
});
|
||||
@@ -17,10 +17,21 @@ const TOOLING: WorkspaceToolingSettings = {
|
||||
command: 'node',
|
||||
args: ['server.js'],
|
||||
cwd: 'C:\\workspace\\repo',
|
||||
env: { DEBUG: 'true' },
|
||||
tools: ['git.status'],
|
||||
createdAt: TIMESTAMP,
|
||||
updatedAt: TIMESTAMP,
|
||||
},
|
||||
{
|
||||
id: 'mcp-remote',
|
||||
name: 'Remote MCP',
|
||||
transport: 'http',
|
||||
url: 'https://example.com/mcp',
|
||||
headers: { Authorization: 'Bearer token' },
|
||||
tools: ['remote.tool'],
|
||||
createdAt: TIMESTAMP,
|
||||
updatedAt: TIMESTAMP,
|
||||
},
|
||||
],
|
||||
lspProfiles: [
|
||||
{
|
||||
@@ -61,7 +72,7 @@ describe('session tooling config helpers', () => {
|
||||
test('builds a run-turn tooling config from selected MCP and LSP ids', () => {
|
||||
expect(
|
||||
buildRunTurnToolingConfig(TOOLING, {
|
||||
enabledMcpServerIds: ['mcp-git'],
|
||||
enabledMcpServerIds: ['mcp-git', 'mcp-remote'],
|
||||
enabledLspProfileIds: ['lsp-ts'],
|
||||
}),
|
||||
).toEqual({
|
||||
@@ -74,6 +85,15 @@ describe('session tooling config helpers', () => {
|
||||
command: 'node',
|
||||
args: ['server.js'],
|
||||
cwd: 'C:\\workspace\\repo',
|
||||
env: { DEBUG: 'true' },
|
||||
},
|
||||
{
|
||||
id: 'mcp-remote',
|
||||
name: 'Remote MCP',
|
||||
transport: 'http',
|
||||
tools: ['remote.tool'],
|
||||
url: 'https://example.com/mcp',
|
||||
headers: { Authorization: 'Bearer token' },
|
||||
},
|
||||
],
|
||||
lspProfiles: [
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
import { describe, expect, test } from 'bun:test';
|
||||
|
||||
import type { DiscoveredLocalMcpServer } from '@shared/domain/discoveredTooling';
|
||||
import { listPendingDiscoveredMcpServers, normalizeDiscoveredToolingState, type DiscoveredToolingState } from '@shared/domain/discoveredTooling';
|
||||
import { resolveProjectToolingSettings, createWorkspaceSettings, type WorkspaceSettings } from '@shared/domain/tooling';
|
||||
|
||||
function makeDiscoveredServer(
|
||||
overrides: Partial<DiscoveredLocalMcpServer> & { id: string; name: string },
|
||||
): DiscoveredLocalMcpServer {
|
||||
return {
|
||||
transport: 'local',
|
||||
command: 'test-cmd',
|
||||
args: [],
|
||||
tools: [],
|
||||
scope: 'user',
|
||||
scannerId: 'test-scanner',
|
||||
sourcePath: '/test/path',
|
||||
sourceLabel: 'test config',
|
||||
fingerprint: 'fnv1a_00000001',
|
||||
status: 'pending',
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe('frontend discovered tooling integration', () => {
|
||||
test('pending discovery detection drives modal visibility', () => {
|
||||
const emptyState: DiscoveredToolingState = { mcpServers: [], lastScannedAt: undefined };
|
||||
expect(listPendingDiscoveredMcpServers(emptyState)).toHaveLength(0);
|
||||
|
||||
const withPending: DiscoveredToolingState = {
|
||||
mcpServers: [
|
||||
makeDiscoveredServer({ id: 'discovered_user_test_scanner_alpha', name: 'alpha', status: 'pending' }),
|
||||
makeDiscoveredServer({ id: 'discovered_user_test_scanner_beta', name: 'beta', status: 'accepted' }),
|
||||
],
|
||||
};
|
||||
expect(listPendingDiscoveredMcpServers(withPending)).toHaveLength(1);
|
||||
expect(listPendingDiscoveredMcpServers(withPending)[0].name).toBe('alpha');
|
||||
});
|
||||
|
||||
test('effective project tooling merges accepted discovered MCPs for session UI', () => {
|
||||
const settings: WorkspaceSettings = {
|
||||
...createWorkspaceSettings(),
|
||||
discoveredUserTooling: normalizeDiscoveredToolingState({
|
||||
mcpServers: [
|
||||
makeDiscoveredServer({
|
||||
id: 'discovered_user_ws_scanner_user_mcp',
|
||||
name: 'user-mcp',
|
||||
status: 'accepted',
|
||||
scope: 'user',
|
||||
}),
|
||||
],
|
||||
}),
|
||||
};
|
||||
|
||||
const projectTooling = normalizeDiscoveredToolingState({
|
||||
mcpServers: [
|
||||
makeDiscoveredServer({
|
||||
id: 'discovered_project_proj_scanner_proj_mcp',
|
||||
name: 'proj-mcp',
|
||||
status: 'accepted',
|
||||
scope: 'project',
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
const effective = resolveProjectToolingSettings(settings, projectTooling);
|
||||
const serverIds = effective.mcpServers.map((s) => s.id);
|
||||
|
||||
expect(serverIds).toContain('discovered_user_ws_scanner_user_mcp');
|
||||
expect(serverIds).toContain('discovered_project_proj_scanner_proj_mcp');
|
||||
});
|
||||
|
||||
test('MCP server IDs are correctly categorized by prefix for tool grouping', () => {
|
||||
const settings: WorkspaceSettings = {
|
||||
...createWorkspaceSettings(),
|
||||
tooling: {
|
||||
mcpServers: [
|
||||
{ id: 'mcp-manual', name: 'manual', transport: 'local', command: 'cmd', args: [], tools: [], createdAt: '', updatedAt: '' },
|
||||
],
|
||||
lspProfiles: [],
|
||||
},
|
||||
discoveredUserTooling: normalizeDiscoveredToolingState({
|
||||
mcpServers: [
|
||||
makeDiscoveredServer({
|
||||
id: 'discovered_user_ws_scanner_user_srv',
|
||||
name: 'user-srv',
|
||||
status: 'accepted',
|
||||
scope: 'user',
|
||||
}),
|
||||
],
|
||||
}),
|
||||
};
|
||||
|
||||
const projectTooling = normalizeDiscoveredToolingState({
|
||||
mcpServers: [
|
||||
makeDiscoveredServer({
|
||||
id: 'discovered_project_proj_scanner_proj_srv',
|
||||
name: 'proj-srv',
|
||||
status: 'accepted',
|
||||
scope: 'project',
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
const effective = resolveProjectToolingSettings(settings, projectTooling);
|
||||
|
||||
const workspaceMcp = effective.mcpServers.filter((s) => !s.id.startsWith('discovered_'));
|
||||
const userDiscovered = effective.mcpServers.filter((s) => s.id.startsWith('discovered_user_'));
|
||||
const projectDiscovered = effective.mcpServers.filter((s) => s.id.startsWith('discovered_project_'));
|
||||
|
||||
expect(workspaceMcp).toHaveLength(1);
|
||||
expect(workspaceMcp[0].name).toBe('manual');
|
||||
|
||||
expect(userDiscovered).toHaveLength(1);
|
||||
expect(userDiscovered[0].name).toBe('user-srv');
|
||||
|
||||
expect(projectDiscovered).toHaveLength(1);
|
||||
expect(projectDiscovered[0].name).toBe('proj-srv');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,108 @@
|
||||
import { describe, expect, test } from 'bun:test';
|
||||
|
||||
import {
|
||||
applyDiscoveredMcpServerStatus,
|
||||
buildDiscoveredMcpServerFingerprint,
|
||||
buildDiscoveredMcpServerId,
|
||||
listAcceptedDiscoveredMcpServers,
|
||||
listPendingDiscoveredMcpServers,
|
||||
mergeDiscoveredToolingState,
|
||||
normalizeDiscoveredToolingState,
|
||||
type DiscoveredLocalMcpServer,
|
||||
} from '@shared/domain/discoveredTooling';
|
||||
|
||||
const TIMESTAMP = '2026-03-25T00:00:00.000Z';
|
||||
|
||||
function createDiscoveredServer(overrides?: Partial<DiscoveredLocalMcpServer>): DiscoveredLocalMcpServer {
|
||||
const server: DiscoveredLocalMcpServer = {
|
||||
id: buildDiscoveredMcpServerId('project', 'project-alpha', 'vscode-mcp', 'Git MCP'),
|
||||
name: 'Git MCP',
|
||||
transport: 'local',
|
||||
command: 'node',
|
||||
args: ['server.js'],
|
||||
cwd: 'C:\\workspace\\repo',
|
||||
tools: ['git.status'],
|
||||
scope: 'project',
|
||||
scannerId: 'vscode-mcp',
|
||||
sourcePath: 'C:\\workspace\\repo\\.vscode\\mcp.json',
|
||||
sourceLabel: '.vscode\\mcp.json',
|
||||
fingerprint: '',
|
||||
status: 'pending',
|
||||
};
|
||||
|
||||
return {
|
||||
...server,
|
||||
...overrides,
|
||||
fingerprint: buildDiscoveredMcpServerFingerprint({
|
||||
...server,
|
||||
...overrides,
|
||||
fingerprint: '',
|
||||
status: 'pending',
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
describe('discovered tooling helpers', () => {
|
||||
test('normalizes discovered servers and preserves accepted status when the fingerprint is unchanged', () => {
|
||||
const current = {
|
||||
mcpServers: [
|
||||
createDiscoveredServer({
|
||||
status: 'accepted',
|
||||
}),
|
||||
],
|
||||
lastScannedAt: TIMESTAMP,
|
||||
};
|
||||
|
||||
const merged = mergeDiscoveredToolingState(current, [createDiscoveredServer()], '2026-03-25T01:00:00.000Z');
|
||||
|
||||
expect(merged.mcpServers[0]?.status).toBe('accepted');
|
||||
expect(merged.lastScannedAt).toBe('2026-03-25T01:00:00.000Z');
|
||||
});
|
||||
|
||||
test('marks changed servers as pending on re-scan', () => {
|
||||
const current = {
|
||||
mcpServers: [
|
||||
createDiscoveredServer({
|
||||
status: 'accepted',
|
||||
}),
|
||||
],
|
||||
lastScannedAt: TIMESTAMP,
|
||||
};
|
||||
|
||||
const merged = mergeDiscoveredToolingState(
|
||||
current,
|
||||
[
|
||||
createDiscoveredServer({
|
||||
args: ['server.js', '--debug'],
|
||||
}),
|
||||
],
|
||||
'2026-03-25T01:00:00.000Z',
|
||||
);
|
||||
|
||||
expect(merged.mcpServers[0]?.status).toBe('pending');
|
||||
});
|
||||
|
||||
test('applies explicit accept and dismiss resolutions', () => {
|
||||
const state = normalizeDiscoveredToolingState({
|
||||
mcpServers: [
|
||||
createDiscoveredServer(),
|
||||
createDiscoveredServer({
|
||||
id: buildDiscoveredMcpServerId('user', 'workspace', 'copilot-user-mcp', 'Git MCP'),
|
||||
scope: 'user',
|
||||
scannerId: 'copilot-user-mcp',
|
||||
sourcePath: 'C:\\Users\\tester\\.copilot\\mcp.json',
|
||||
sourceLabel: '~\\.copilot\\mcp.json',
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
const accepted = applyDiscoveredMcpServerStatus(state, [state.mcpServers[0]!.id], 'accepted');
|
||||
const dismissed = applyDiscoveredMcpServerStatus(accepted, [state.mcpServers[1]!.id], 'dismissed');
|
||||
|
||||
expect(listAcceptedDiscoveredMcpServers(dismissed).map((server) => server.id)).toEqual([
|
||||
state.mcpServers[0]!.id,
|
||||
]);
|
||||
expect(listPendingDiscoveredMcpServers(dismissed)).toEqual([]);
|
||||
expect(dismissed.mcpServers[1]?.status).toBe('dismissed');
|
||||
});
|
||||
});
|
||||
@@ -3,6 +3,8 @@ import { describe, expect, test } from 'bun:test';
|
||||
import {
|
||||
listApprovalToolDefinitions,
|
||||
normalizeWorkspaceSettings,
|
||||
resolveProjectToolingSettings,
|
||||
resolveWorkspaceToolingSettings,
|
||||
validateLspProfileDefinition,
|
||||
validateMcpServerDefinition,
|
||||
type LspProfileDefinition,
|
||||
@@ -23,6 +25,7 @@ describe('tooling settings helpers', () => {
|
||||
command: ' node ',
|
||||
args: [' --stdio ', ' --stdio ', ''],
|
||||
cwd: ' C:\\workspace\\repo ',
|
||||
env: { ' DEBUG ': ' true ', EMPTY: ' ' },
|
||||
tools: [' git.status ', '', ' git.status '],
|
||||
createdAt: TIMESTAMP,
|
||||
updatedAt: TIMESTAMP,
|
||||
@@ -32,6 +35,7 @@ describe('tooling settings helpers', () => {
|
||||
name: ' Remote MCP ',
|
||||
transport: 'http',
|
||||
url: ' https://example.com/mcp ',
|
||||
headers: { ' Authorization ': ' Bearer token ', Empty: ' ' },
|
||||
tools: [],
|
||||
timeoutMs: 1000,
|
||||
createdAt: TIMESTAMP,
|
||||
@@ -64,6 +68,7 @@ describe('tooling settings helpers', () => {
|
||||
command: 'node',
|
||||
args: ['--stdio'],
|
||||
cwd: 'C:\\workspace\\repo',
|
||||
env: { DEBUG: 'true' },
|
||||
tools: ['git.status'],
|
||||
createdAt: TIMESTAMP,
|
||||
updatedAt: TIMESTAMP,
|
||||
@@ -73,6 +78,7 @@ describe('tooling settings helpers', () => {
|
||||
name: 'Remote MCP',
|
||||
transport: 'http',
|
||||
url: 'https://example.com/mcp',
|
||||
headers: { Authorization: 'Bearer token' },
|
||||
tools: [],
|
||||
timeoutMs: 1000,
|
||||
createdAt: TIMESTAMP,
|
||||
@@ -92,6 +98,9 @@ describe('tooling settings helpers', () => {
|
||||
},
|
||||
],
|
||||
},
|
||||
discoveredUserTooling: {
|
||||
mcpServers: [],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -241,4 +250,85 @@ describe('tooling settings helpers', () => {
|
||||
});
|
||||
expect(tools.some((tool) => tool.id === 'web_fetch')).toBe(false);
|
||||
});
|
||||
|
||||
test('resolves workspace and project tooling with accepted discovered MCP servers', () => {
|
||||
const workspaceTooling = resolveWorkspaceToolingSettings(normalizeWorkspaceSettings({
|
||||
tooling: {
|
||||
mcpServers: [
|
||||
{
|
||||
id: 'manual',
|
||||
name: 'Manual MCP',
|
||||
transport: 'local',
|
||||
command: 'node',
|
||||
args: ['manual.js'],
|
||||
tools: ['manual.tool'],
|
||||
createdAt: TIMESTAMP,
|
||||
updatedAt: TIMESTAMP,
|
||||
},
|
||||
],
|
||||
lspProfiles: [],
|
||||
},
|
||||
discoveredUserTooling: {
|
||||
mcpServers: [
|
||||
{
|
||||
id: 'user-discovered',
|
||||
name: 'User MCP',
|
||||
transport: 'local',
|
||||
command: 'node',
|
||||
args: ['user.js'],
|
||||
tools: ['user.tool'],
|
||||
scope: 'user',
|
||||
scannerId: 'copilot-user-mcp',
|
||||
sourcePath: 'C:\\Users\\tester\\.copilot\\mcp.json',
|
||||
sourceLabel: '~\\.copilot\\mcp.json',
|
||||
fingerprint: 'fp-user',
|
||||
status: 'accepted',
|
||||
},
|
||||
],
|
||||
},
|
||||
}));
|
||||
|
||||
expect(workspaceTooling.mcpServers.map((server) => server.id)).toEqual(['manual', 'user-discovered']);
|
||||
|
||||
const projectTooling = resolveProjectToolingSettings(
|
||||
normalizeWorkspaceSettings({
|
||||
tooling: {
|
||||
mcpServers: [],
|
||||
lspProfiles: [],
|
||||
},
|
||||
discoveredUserTooling: {
|
||||
mcpServers: [],
|
||||
},
|
||||
}),
|
||||
{
|
||||
mcpServers: [
|
||||
{
|
||||
id: 'project-discovered',
|
||||
name: 'Project MCP',
|
||||
transport: 'http',
|
||||
url: 'https://example.com/project',
|
||||
headers: { Authorization: 'Bearer token' },
|
||||
tools: ['project.tool'],
|
||||
scope: 'project',
|
||||
scannerId: 'vscode-mcp',
|
||||
sourcePath: 'C:\\workspace\\repo\\.vscode\\mcp.json',
|
||||
sourceLabel: '.vscode\\mcp.json',
|
||||
fingerprint: 'fp-project',
|
||||
status: 'accepted',
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
|
||||
expect(projectTooling.mcpServers).toContainEqual({
|
||||
id: 'project-discovered',
|
||||
name: 'Project MCP',
|
||||
transport: 'http',
|
||||
url: 'https://example.com/project',
|
||||
headers: { Authorization: 'Bearer token' },
|
||||
tools: ['project.tool'],
|
||||
createdAt: expect.any(String),
|
||||
updatedAt: expect.any(String),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14,6 +14,9 @@ describe('workspace seed', () => {
|
||||
mcpServers: [],
|
||||
lspProfiles: [],
|
||||
},
|
||||
discoveredUserTooling: {
|
||||
mcpServers: [],
|
||||
},
|
||||
});
|
||||
expect(workspace.selectedProjectId).toBeUndefined();
|
||||
expect(workspace.selectedPatternId).toBeUndefined();
|
||||
|
||||
Reference in New Issue
Block a user