Skip to content

Commit dd9fb27

Browse files
committed
test(@angular/cli): add initial e2e test for MCP server tool registration
Introduces the first end-to-end test for the MCP server. The new test, `registers-tools.ts`, verifies that the MCP server correctly initializes and registers its default set of tools. This provides a foundation for more comprehensive e2e testing of the MCP server and its features.
1 parent 1c34ee8 commit dd9fb27

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

packages/angular/cli/src/commands/mcp/mcp-server.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ export async function createMcpServer(
5959
registerBestPracticesTool(server);
6060

6161
// If run outside an Angular workspace (e.g., globally) skip the workspace specific tools.
62-
// Currently only the `list_projects` tool.
63-
if (!context.workspace) {
62+
if (context.workspace) {
6463
registerListProjectsTool(server, context);
6564
}
6665

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { chdir } from 'process';
2+
import { exec, ProcessOutput, silentNpm } from '../../utils/process';
3+
import assert from 'node:assert/strict';
4+
5+
const MCP_INSPECTOR_PACKAGE_NAME = '@modelcontextprotocol/inspector-cli';
6+
const MCP_INSPECTOR_PACKAGE_VERSION = '0.16.2';
7+
const MCP_INSPECTOR_COMMAND_NAME = 'mcp-inspector-cli';
8+
9+
async function runInspector(...args: string[]): Promise<ProcessOutput> {
10+
const result = await exec(
11+
MCP_INSPECTOR_COMMAND_NAME,
12+
'--cli',
13+
'npx',
14+
'--no',
15+
'@angular/cli',
16+
'mcp',
17+
...args,
18+
);
19+
20+
return result;
21+
}
22+
23+
export default async function () {
24+
await silentNpm(
25+
'install',
26+
'--ignore-scripts',
27+
'-g',
28+
`${MCP_INSPECTOR_PACKAGE_NAME}@${MCP_INSPECTOR_PACKAGE_VERSION}`,
29+
);
30+
31+
// Ensure 'list_projects' is registered when inside an Angular workspace
32+
const { stdout: stdoutInsideWorkspace } = await runInspector('--method', 'tools/list');
33+
34+
assert.match(stdoutInsideWorkspace, /"list_projects"/);
35+
assert.match(stdoutInsideWorkspace, /"get_best_practices"/);
36+
assert.match(stdoutInsideWorkspace, /"search_documentation"/);
37+
38+
chdir('..');
39+
40+
const { stdout: stdoutOutsideWorkspace } = await runInspector('--method', 'tools/list');
41+
42+
assert.doesNotMatch(stdoutOutsideWorkspace, /"list_projects"/);
43+
assert.match(stdoutOutsideWorkspace, /"get_best_practices"/);
44+
assert.match(stdoutInsideWorkspace, /"search_documentation"/);
45+
46+
silentNpm('uninstall', '-g', MCP_INSPECTOR_PACKAGE_NAME);
47+
}

0 commit comments

Comments
 (0)