forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcli.ts
More file actions
78 lines (69 loc) · 2.05 KB
/
cli.ts
File metadata and controls
78 lines (69 loc) · 2.05 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 { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { Argv } from 'yargs';
import { CommandModule, CommandModuleImplementation } from '../../command-builder/command-module';
import { isTTY } from '../../utilities/tty';
import { createMcpServer } from './mcp-server';
const INTERACTIVE_MESSAGE = `
To start using the Angular CLI MCP Server, add this configuration to your host:
{
"mcpServers": {
"angular-cli": {
"command": "npx",
"args": ["-y", "@angular/cli", "mcp"]
}
}
}
Exact configuration may differ depending on the host.
`;
export default class McpCommandModule extends CommandModule implements CommandModuleImplementation {
command = 'mcp';
describe = false as const;
longDescriptionPath = undefined;
builder(localYargs: Argv): Argv {
return localYargs
.option('read-only', {
type: 'boolean',
default: false,
describe: 'Only register read-only tools.',
})
.option('local-only', {
type: 'boolean',
default: false,
describe: 'Only register tools that do not require internet access.',
})
.option('experimental-tool', {
type: 'string',
alias: 'E',
array: true,
describe: 'Enable an experimental tool.',
});
}
async run(options: {
readOnly: boolean;
localOnly: boolean;
experimentalTool: string[] | undefined;
}): Promise<void> {
if (isTTY()) {
this.context.logger.info(INTERACTIVE_MESSAGE);
return;
}
const server = await createMcpServer(
{
workspace: this.context.workspace,
readOnly: options.readOnly,
localOnly: options.localOnly,
experimentalTools: options.experimentalTool,
},
this.context.logger,
);
const transport = new StdioServerTransport();
await server.connect(transport);
}
}