Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/angular/cli/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ts_project(
":node_modules/@angular-devkit/schematics",
":node_modules/@inquirer/prompts",
":node_modules/@listr2/prompt-adapter-inquirer",
":node_modules/@modelcontextprotocol/sdk",
":node_modules/@modelcontextprotocol/server",
":node_modules/jsonc-parser",
":node_modules/listr2",
":node_modules/npm-package-arg",
Expand Down Expand Up @@ -113,7 +113,7 @@ ts_project(
":angular-cli",
":node_modules/@angular-devkit/core",
":node_modules/@angular-devkit/schematics",
":node_modules/@modelcontextprotocol/sdk",
":node_modules/@modelcontextprotocol/server",
":node_modules/yargs",
"//:node_modules/@types/semver",
"//:node_modules/@types/yargs",
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@angular-devkit/schematics": "workspace:0.0.0-PLACEHOLDER",
"@inquirer/prompts": "8.5.2",
"@listr2/prompt-adapter-inquirer": "4.2.5",
"@modelcontextprotocol/sdk": "1.30.0",
"@modelcontextprotocol/server": "2.0.0",
"@schematics/angular": "workspace:0.0.0-PLACEHOLDER",
"jsonc-parser": "3.3.1",
"listr2": "11.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/cli/src/commands/mcp/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.dev/license
*/

import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { StdioServerTransport } from '@modelcontextprotocol/server/stdio';
import type { Argv } from 'yargs';
import {
CommandModule,
Expand Down
5 changes: 2 additions & 3 deletions packages/angular/cli/src/commands/mcp/mcp-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
* found in the LICENSE file at https://angular.dev/license
*/

import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { RootsListChangedNotificationSchema } from '@modelcontextprotocol/sdk/types.js';
import { McpServer } from '@modelcontextprotocol/server';
import { join, normalize } from 'node:path';
import { fileURLToPath } from 'node:url';
import type { AngularWorkspace } from '../../utilities/config';
Expand Down Expand Up @@ -134,7 +133,7 @@ for equivalent actions.
restrictedHost.setRoots(searchRoots);

if (clientCapabilities.roots.listChanged) {
server.server.setNotificationHandler(RootsListChangedNotificationSchema, async () => {
server.server.setNotificationHandler('notifications/roots/list_changed', async () => {
try {
const { roots: updatedRoots } = await server.server.listRoots();
const updatedSearchRoots =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.dev/license
*/

import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import type { McpServer } from '@modelcontextprotocol/server';
import { readFile } from 'node:fs/promises';
import { join } from 'node:path';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { workspaces } from '@angular-devkit/core';
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { McpServer } from '@modelcontextprotocol/server';
import { AngularWorkspace } from '../../../utilities/config';
import { type Devserver } from '../devserver';
import { Host } from '../host';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
* found in the LICENSE file at https://angular.dev/license
*/

import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol';
import type { ServerNotification, ServerRequest } from '@modelcontextprotocol/sdk/types';
import type { ServerContext } from '@modelcontextprotocol/server';
import type { SourceFile } from 'typescript';
import type { Host } from '../../host';
import { analyzeForUnsupportedZoneUses } from './analyze-for-unsupported-zone-uses';
Expand All @@ -22,7 +21,7 @@ const supportedStrategies: ReadonlySet<string> = new Set(['OnPush', 'Default', '
export async function migrateSingleFile(
sourceFile: SourceFile,
host: Host,
extras: RequestHandlerExtra<ServerRequest, ServerNotification>,
extras: ServerContext,
): Promise<MigrationResponse | null> {
const testBedSpecifier = await getImportSpecifier(sourceFile, '@angular/core/testing', 'TestBed');
const isTestFile = sourceFile.fileName.endsWith('.spec.ts') || !!testBedSpecifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
* found in the LICENSE file at https://angular.dev/license
*/

import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol';
import type { ServerNotification, ServerRequest } from '@modelcontextprotocol/sdk/types';
import type { ServerContext } from '@modelcontextprotocol/server';
import ts from 'typescript';
import { createMockHost } from '../../testing/test-utils';
import { migrateSingleFile } from './migrate-single-file';

const fakeExtras = {
sendDebugMessage: jasmine.createSpy(),
sendNotification: jasmine.createSpy(),
} as unknown as RequestHandlerExtra<ServerRequest, ServerNotification>;
mcpReq: {
log: jasmine.createSpy(),
notify: jasmine.createSpy(),
},
} as unknown as ServerContext;

describe('migrateSingleFile', () => {
const mockHost = createMockHost();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,8 @@
* found in the LICENSE file at https://angular.dev/license
*/

import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol';
import type { ServerNotification, ServerRequest } from '@modelcontextprotocol/sdk/types';
import type { ServerContext } from '@modelcontextprotocol/server';

export function sendDebugMessage(
message: string,
{ sendNotification }: RequestHandlerExtra<ServerRequest, ServerNotification>,
): void {
void sendNotification({
method: 'notifications/message',
params: {
level: 'debug',
data: message,
},
});
export function sendDebugMessage(message: string, ctx: ServerContext): void {
void ctx.mcpReq.log('debug', message);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
* found in the LICENSE file at https://angular.dev/license
*/

import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol';
import type { ServerNotification, ServerRequest } from '@modelcontextprotocol/sdk/types';
import type { ServerContext } from '@modelcontextprotocol/server';
import { join } from 'node:path';
import type { SourceFile } from 'typescript';
import { z } from 'zod';
Expand Down Expand Up @@ -57,7 +56,7 @@ change detection (a prerequisite for zoneless applications).
export async function registerZonelessMigrationTool(
fileOrDirPath: string,
host: Host,
extras: RequestHandlerExtra<ServerRequest, ServerNotification>,
extras: ServerContext,
) {
let filesWithComponents, componentTestFiles, zoneFiles, categorizationErrors;
try {
Expand Down Expand Up @@ -114,7 +113,7 @@ export async function registerZonelessMigrationTool(
async function discoverAndCategorizeFiles(
fileOrDirPath: string,
host: Host,
extras: RequestHandlerExtra<ServerRequest, ServerNotification>,
extras: ServerContext,
) {
const filePaths: string[] = [];
const componentTestFiles = new Set<SourceFile>();
Expand Down Expand Up @@ -175,7 +174,7 @@ async function discoverAndCategorizeFiles(
async function categorizeFile(
sourceFile: SourceFile,
host: Host,
extras: RequestHandlerExtra<ServerRequest, ServerNotification>,
extras: ServerContext,
categorizedFiles: {
filesWithComponents: Set<SourceFile>;
componentTestFiles: Set<SourceFile>;
Expand Down Expand Up @@ -216,11 +215,11 @@ async function categorizeFile(
}

async function rankComponentFilesForMigration(
{ sendRequest }: RequestHandlerExtra<ServerRequest, ServerNotification>,
ctx: ServerContext,
componentFiles: SourceFile[],
): Promise<SourceFile[]> {
try {
const response = await sendRequest(
const response = await ctx.mcpReq.send(
{
method: 'sampling/createMessage',
params: {
Expand Down
29 changes: 22 additions & 7 deletions packages/angular/cli/src/commands/mcp/tools/tool-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
* found in the LICENSE file at https://angular.dev/license
*/

import type { McpServer, ToolCallback } from '@modelcontextprotocol/sdk/server/mcp.js';
import type { ToolAnnotations } from '@modelcontextprotocol/sdk/types';
import type { ZodRawShape } from 'zod';
import type {
McpServer,
ServerContext,
ToolAnnotations,
ToolCallback,
} from '@modelcontextprotocol/server';
import { type ZodRawShape, z } from 'zod';
import type { AngularWorkspace } from '../../../utilities/config';
import type { Devserver } from '../devserver';
import type { Host } from '../host';

type ToolConfig = Parameters<McpServer['registerTool']>[1];

export interface McpToolContext {
server: McpServer;
workspace?: AngularWorkspace;
Expand All @@ -24,9 +26,14 @@ export interface McpToolContext {
host: Host;
}

export type McpToolCallback<TInput extends ZodRawShape = ZodRawShape> = (
args: z.infer<z.ZodObject<TInput>>,
ctx: ServerContext,
) => ReturnType<ToolCallback>;

export type McpToolFactory<TInput extends ZodRawShape> = (
context: McpToolContext,
) => ToolCallback<TInput> | Promise<ToolCallback<TInput>>;
) => McpToolCallback<TInput> | Promise<McpToolCallback<TInput>>;

export interface McpToolDeclaration<TInput extends ZodRawShape, TOutput extends ZodRawShape> {
name: string;
Expand Down Expand Up @@ -75,6 +82,14 @@ export async function registerTools(
config.annotations.openWorldHint = !isLocalOnly;
}

server.registerTool(name, config, handler);
server.registerTool(
name,
{
...config,
inputSchema: config.inputSchema ? z.object(config.inputSchema) : undefined,
outputSchema: config.outputSchema ? z.object(config.outputSchema) : undefined,
},
handler,
);
Comment thread
clydin marked this conversation as resolved.
}
}
Loading
Loading