forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdevserver-stop.ts
More file actions
78 lines (68 loc) · 2.68 KB
/
devserver-stop.ts
File metadata and controls
78 lines (68 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { z } from 'zod';
import { devserverKey } from '../../devserver';
import { createStructuredContentOutput } from '../../utils';
import { type McpToolContext, type McpToolDeclaration, declareTool } from '../tool-registry';
const devserverStopToolInputSchema = z.object({
project: z
.string()
.optional()
.describe(
'Which project to stop serving in a monorepo context. If not provided, stops the default project server.',
),
});
export type DevserverStopToolInput = z.infer<typeof devserverStopToolInputSchema>;
const devserverStopToolOutputSchema = z.object({
message: z.string().describe('A message indicating the result of the operation.'),
logs: z.array(z.string()).optional().describe('The full logs from the dev server.'),
});
export type DevserverStopToolOutput = z.infer<typeof devserverStopToolOutputSchema>;
export function stopDevserver(input: DevserverStopToolInput, context: McpToolContext) {
const projectKey = devserverKey(input.project);
const devServer = context.devservers.get(projectKey);
if (!devServer) {
return createStructuredContentOutput({
message: `Development server for project '${projectKey}' was not running.`,
logs: undefined,
});
}
devServer.stop();
context.devservers.delete(projectKey);
return createStructuredContentOutput({
message: `Development server for project '${projectKey}' stopped.`,
logs: devServer.getServerLogs(),
});
}
export const DEVSERVER_STOP_TOOL: McpToolDeclaration<
typeof devserverStopToolInputSchema.shape,
typeof devserverStopToolOutputSchema.shape
> = declareTool({
name: 'devserver.stop',
title: 'Stop Development Server',
description: `
<Purpose>
Stops a running Angular development server ("ng serve") that was started with the "devserver.start" tool.
</Purpose>
<Use Cases>
* **Stopping the Server:** Use this tool to terminate a running development server and retrieve the logs.
</Use Cases>
<Operational Notes>
* This should be called to gracefully shut down the server and access the full log output.
* This just sends a SIGTERM to the server and returns immediately; so the server might still be functional for a short
time after this is called. However note that this is not a blocker for starting a new devserver.
</Operational Notes>
`,
isReadOnly: true,
isLocalOnly: true,
inputSchema: devserverStopToolInputSchema.shape,
outputSchema: devserverStopToolOutputSchema.shape,
factory: (context) => (input) => {
return stopDevserver(input, context);
},
});