forked from microsoft/rushstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRushMcpPluginSession.ts
More file actions
50 lines (43 loc) · 1.32 KB
/
RushMcpPluginSession.ts
File metadata and controls
50 lines (43 loc) · 1.32 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
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import * as zod from 'zod';
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp';
import type { IRushMcpTool } from './IRushMcpTool';
import type { zodModule } from './zodTypes';
/**
* Each plugin gets its own session.
*
* @public
*/
export interface IRegisterToolOptions {
toolName: string;
description?: string;
}
/**
* Each plugin gets its own session.
*
* @public
*/
export abstract class RushMcpPluginSession {
public readonly zod: typeof zodModule = zod;
public abstract registerTool(options: IRegisterToolOptions, tool: IRushMcpTool): void;
}
export class RushMcpPluginSessionInternal extends RushMcpPluginSession {
private readonly _mcpServer: McpServer;
public constructor(mcpServer: McpServer) {
super();
this._mcpServer = mcpServer;
}
public override registerTool(options: IRegisterToolOptions, tool: IRushMcpTool): void {
if (options.description) {
this._mcpServer.tool(
options.toolName,
options.description,
tool.schema.shape,
tool.executeAsync.bind(tool)
);
} else {
this._mcpServer.tool(options.toolName, tool.schema.shape, tool.executeAsync.bind(tool));
}
}
}