File tree Expand file tree Collapse file tree 4 files changed +15
-11
lines changed
Expand file tree Collapse file tree 4 files changed +15
-11
lines changed Original file line number Diff line number Diff line change 11import { ZodRawShape } from "zod" ;
22import { ToolBase } from "../tool.js" ;
33import { ApiClient } from "../../client.js" ;
4+ import { State } from "../../state.js" ;
45
56export abstract class AtlasToolBase < Args extends ZodRawShape = ZodRawShape > extends ToolBase < Args > {
6- constructor ( protected apiClient : ApiClient ) {
7- super ( ) ;
7+ constructor (
8+ state : State ,
9+ protected apiClient : ApiClient
10+ ) {
11+ super ( state ) ;
812 }
913}
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { config } from "../../config.js";
44import { ensureAuthenticated } from "./auth.js" ;
55import { CallToolResult } from "@modelcontextprotocol/sdk/types.js" ;
66import { AtlasToolBase } from "./atlasTool.js" ;
7+ import { State } from "../../state.js" ;
78
89export class ListClustersTool extends AtlasToolBase < {
910 projectId : ZodString | ZodOptional < ZodString > ;
@@ -12,8 +13,8 @@ export class ListClustersTool extends AtlasToolBase<{
1213 protected description = "List MongoDB Atlas clusters" ;
1314 protected argsShape ;
1415
15- constructor ( apiClient : ApiClient ) {
16- super ( apiClient ) ;
16+ constructor ( state : State , apiClient : ApiClient ) {
17+ super ( state , apiClient ) ;
1718
1819 let projectIdFilter : ZodString | ZodOptional < ZodString > = z
1920 . string ( )
Original file line number Diff line number Diff line change @@ -9,12 +9,12 @@ import { ListProjectsTool } from "./listProjects.js";
99
1010export function registerAtlasTools ( server : McpServer , state : State , apiClient : ApiClient ) {
1111 const tools : ToolBase < ZodRawShape > [ ] = [
12- new AuthTool ( apiClient ) ,
13- new ListClustersTool ( apiClient ) ,
14- new ListProjectsTool ( apiClient ) ,
12+ new AuthTool ( state , apiClient ) ,
13+ new ListClustersTool ( state , apiClient ) ,
14+ new ListProjectsTool ( state , apiClient ) ,
1515 ] ;
1616
1717 for ( const tool of tools ) {
18- tool . register ( server , state ) ;
18+ tool . register ( server ) ;
1919 }
2020}
Original file line number Diff line number Diff line change @@ -5,7 +5,6 @@ import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
55import { State } from "../state.js" ;
66
77export abstract class ToolBase < Args extends ZodRawShape > {
8- protected state : State = undefined ! ; // We should never use this before it's set
98 protected abstract name : string ;
109
1110 protected abstract description : string ;
@@ -14,9 +13,9 @@ export abstract class ToolBase<Args extends ZodRawShape> {
1413
1514 protected abstract execute ( args : z . objectOutputType < Args , ZodTypeAny > ) : Promise < CallToolResult > ;
1615
17- public register ( server : McpServer , state : State ) : void {
18- this . state = state ;
16+ protected constructor ( protected state : State ) { }
1917
18+ public register ( server : McpServer ) : void {
2019 const callback = async ( args : z . objectOutputType < Args , ZodTypeAny > ) : Promise < CallToolResult > => {
2120 try {
2221 // TODO: add telemetry here
You can’t perform that action at this time.
0 commit comments