Skip to content

Commit 7c58d25

Browse files
committed
refactor(@angular/cli): Update MCP tools to use host from context
1 parent 7872fc5 commit 7c58d25

File tree

4 files changed

+16
-20
lines changed

4 files changed

+16
-20
lines changed

packages/angular/cli/src/commands/mcp/tools/build.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import { z } from 'zod';
10-
import { CommandError, type Host, LocalWorkspaceHost } from '../host';
10+
import { CommandError, type Host } from '../host';
1111
import { createStructuredContentOutput } from '../utils';
1212
import { type McpToolDeclaration, declareTool } from './tool-registry';
1313

@@ -107,5 +107,5 @@ Perform a one-off, non-watched build using "ng build". Use this tool whenever th
107107
isLocalOnly: true,
108108
inputSchema: buildToolInputSchema.shape,
109109
outputSchema: buildToolOutputSchema.shape,
110-
factory: () => (input) => runBuild(input, LocalWorkspaceHost),
110+
factory: (context) => (input) => runBuild(input, context.host),
111111
});

packages/angular/cli/src/commands/mcp/tools/devserver/devserver-start.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import { z } from 'zod';
1010
import { LocalDevserver, devserverKey } from '../../devserver';
11-
import { type Host, LocalWorkspaceHost } from '../../host';
1211
import { createStructuredContentOutput } from '../../utils';
1312
import { type McpToolContext, type McpToolDeclaration, declareTool } from '../tool-registry';
1413

@@ -39,11 +38,7 @@ function localhostAddress(port: number) {
3938
return `http://localhost:${port}/`;
4039
}
4140

42-
export async function startDevserver(
43-
input: DevserverStartToolInput,
44-
context: McpToolContext,
45-
host: Host,
46-
) {
41+
export async function startDevserver(input: DevserverStartToolInput, context: McpToolContext) {
4742
const projectKey = devserverKey(input.project);
4843

4944
let devserver = context.devservers.get(projectKey);
@@ -54,9 +49,9 @@ export async function startDevserver(
5449
});
5550
}
5651

57-
const port = await host.getAvailablePort();
52+
const port = await context.host.getAvailablePort();
5853

59-
devserver = new LocalDevserver({ host, project: input.project, port });
54+
devserver = new LocalDevserver({ host: context.host, project: input.project, port });
6055
devserver.start();
6156

6257
context.devservers.set(projectKey, devserver);
@@ -98,6 +93,6 @@ the first build completes.
9893
inputSchema: devserverStartToolInputSchema.shape,
9994
outputSchema: devserverStartToolOutputSchema.shape,
10095
factory: (context) => (input) => {
101-
return startDevserver(input, context, LocalWorkspaceHost);
96+
return startDevserver(input, context);
10297
},
10398
});

packages/angular/cli/src/commands/mcp/tools/devserver/devserver_spec.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ describe('Serve Tools', () => {
3838

3939
mockContext = {
4040
devservers: new Map(),
41+
host: mockHost,
4142
} as Partial<McpToolContext> as McpToolContext;
4243
});
4344

4445
it('should start and stop a dev server', async () => {
45-
const startResult = await startDevserver({}, mockContext, mockHost);
46+
const startResult = await startDevserver({}, mockContext);
4647
expect(startResult.structuredContent.message).toBe(
4748
`Development server for project '<default>' started and watching for workspace changes.`,
4849
);
@@ -56,7 +57,7 @@ describe('Serve Tools', () => {
5657
});
5758

5859
it('should wait for a build to complete', async () => {
59-
await startDevserver({}, mockContext, mockHost);
60+
await startDevserver({}, mockContext);
6061

6162
const waitPromise = waitForDevserverBuild({ timeout: 10 }, mockContext);
6263

@@ -78,7 +79,7 @@ describe('Serve Tools', () => {
7879

7980
it('should handle multiple dev servers', async () => {
8081
// Start server for project 1. This uses the basic mockProcess created for the tests.
81-
const startResult1 = await startDevserver({ project: 'app-one' }, mockContext, mockHost);
82+
const startResult1 = await startDevserver({ project: 'app-one' }, mockContext);
8283
expect(startResult1.structuredContent.message).toBe(
8384
`Development server for project 'app-one' started and watching for workspace changes.`,
8485
);
@@ -87,7 +88,7 @@ describe('Serve Tools', () => {
8788
// Start server for project 2, returning a new mock process.
8889
const process2 = new MockChildProcess();
8990
mockHost.spawn.and.returnValue(process2 as unknown as ChildProcess);
90-
const startResult2 = await startDevserver({ project: 'app-two' }, mockContext, mockHost);
91+
const startResult2 = await startDevserver({ project: 'app-two' }, mockContext);
9192
expect(startResult2.structuredContent.message).toBe(
9293
`Development server for project 'app-two' started and watching for workspace changes.`,
9394
);
@@ -116,7 +117,7 @@ describe('Serve Tools', () => {
116117
});
117118

118119
it('should handle server crash', async () => {
119-
await startDevserver({ project: 'crash-app' }, mockContext, mockHost);
120+
await startDevserver({ project: 'crash-app' }, mockContext);
120121

121122
// Simulate a crash with exit code 1
122123
mockProcess.stdout.emit('data', 'Fatal error.');
@@ -128,7 +129,7 @@ describe('Serve Tools', () => {
128129
});
129130

130131
it('wait should timeout if build takes too long', async () => {
131-
await startDevserver({ project: 'timeout-app' }, mockContext, mockHost);
132+
await startDevserver({ project: 'timeout-app' }, mockContext);
132133
const waitResult = await waitForDevserverBuild(
133134
{ project: 'timeout-app', timeout: 10 },
134135
mockContext,
@@ -139,7 +140,7 @@ describe('Serve Tools', () => {
139140
it('should wait through multiple cycles for a build to complete', async () => {
140141
jasmine.clock().install();
141142
try {
142-
await startDevserver({}, mockContext, mockHost);
143+
await startDevserver({}, mockContext);
143144

144145
// Immediately simulate a build starting so isBuilding() is true.
145146
mockProcess.stdout.emit('data', '❯ Changes detected. Rebuilding...');

packages/angular/cli/src/commands/mcp/tools/modernize.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import { dirname, join, relative } from 'path';
1010
import { z } from 'zod';
11-
import { CommandError, type Host, LocalWorkspaceHost } from '../host';
11+
import { CommandError, type Host } from '../host';
1212
import { createStructuredContentOutput, findAngularJsonDir } from '../utils';
1313
import { type McpToolDeclaration, declareTool } from './tool-registry';
1414

@@ -205,5 +205,5 @@ ${TRANSFORMATIONS.map((t) => ` * ${t.name}: ${t.description}`).join('\n')}
205205
outputSchema: modernizeOutputSchema.shape,
206206
isLocalOnly: true,
207207
isReadOnly: false,
208-
factory: () => (input) => runModernization(input, LocalWorkspaceHost),
208+
factory: (context) => (input) => runModernization(input, context.host),
209209
});

0 commit comments

Comments
 (0)