Skip to content

Commit 54a2eab

Browse files
chore: make name, category, operationType static
To allow library consumers to make use of existing tool names, category and operationType, we are marking the name, category and operationType properties of a Tool as static so that library consumers can simply import AllTools from mongodb-mcp-server/tools export and make decision based on these static properties.
1 parent d9eb369 commit 54a2eab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+157
-117
lines changed

src/server.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
UnsubscribeRequestSchema,
1717
} from "@modelcontextprotocol/sdk/types.js";
1818
import assert from "assert";
19-
import type { ToolBase, ToolCategory, ToolConstructorParams } from "./tools/tool.js";
19+
import type { ToolBase, ToolCategory, ToolClass } from "./tools/tool.js";
2020
import { validateConnectionString } from "./helpers/connectionOptions.js";
2121
import { packageInfo } from "./common/packageInfo.js";
2222
import { type ConnectionErrorHandler } from "./common/connectionErrorHandler.js";
@@ -51,7 +51,7 @@ export interface ServerOptions {
5151
* });
5252
* ```
5353
*/
54-
additionalTools?: (new (params: ToolConstructorParams) => ToolBase)[];
54+
additionalTools?: ToolClass[];
5555
}
5656

5757
export class Server {
@@ -60,8 +60,8 @@ export class Server {
6060
private readonly telemetry: Telemetry;
6161
public readonly userConfig: UserConfig;
6262
public readonly elicitation: Elicitation;
63-
private readonly internalToolImplementations: (new (params: ToolConstructorParams) => ToolBase)[] = AllTools;
64-
private readonly additionalToolImplementations: (new (params: ToolConstructorParams) => ToolBase)[];
63+
private readonly internalToolImplementations: ToolClass[] = AllTools;
64+
private readonly additionalToolImplementations: ToolClass[];
6565
public readonly tools: ToolBase[] = [];
6666
public readonly connectionErrorHandler: ConnectionErrorHandler;
6767

@@ -255,6 +255,9 @@ export class Server {
255255

256256
for (const { source, toolConstructor } of toolImplementations) {
257257
const tool = new toolConstructor({
258+
name: toolConstructor.toolName,
259+
category: toolConstructor.category,
260+
operationType: toolConstructor.operationType,
258261
session: this.session,
259262
config: this.userConfig,
260263
telemetry: this.telemetry,

src/tools/atlas/atlasTool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { z } from "zod";
77
import { ApiClientError } from "../../common/atlas/apiClientError.js";
88

99
export abstract class AtlasToolBase extends ToolBase {
10-
public category: ToolCategory = "atlas";
10+
static category: ToolCategory = "atlas";
1111

1212
protected verifyAllowed(): boolean {
1313
if (!this.config.apiClientId || !this.config.apiClientSecret) {

src/tools/atlas/connect/connectCluster.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ export const ConnectClusterArgs = {
3030
};
3131

3232
export class ConnectClusterTool extends AtlasToolBase {
33-
public name = "atlas-connect-cluster";
33+
static toolName = "atlas-connect-cluster";
3434
protected description = "Connect to MongoDB Atlas cluster";
35-
public operationType: OperationType = "connect";
35+
static operationType: OperationType = "connect";
3636
protected argsShape = {
3737
...ConnectClusterArgs,
3838
};

src/tools/atlas/create/createAccessList.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ export const CreateAccessListArgs = {
1717
};
1818

1919
export class CreateAccessListTool extends AtlasToolBase {
20-
public name = "atlas-create-access-list";
20+
static toolName = "atlas-create-access-list";
2121
protected description = "Allow Ip/CIDR ranges to access your MongoDB Atlas clusters.";
22-
public operationType: OperationType = "create";
22+
static operationType: OperationType = "create";
2323
protected argsShape = {
2424
...CreateAccessListArgs,
2525
};

src/tools/atlas/create/createDBUser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ export const CreateDBUserArgs = {
3434
};
3535

3636
export class CreateDBUserTool extends AtlasToolBase {
37-
public name = "atlas-create-db-user";
37+
static toolName = "atlas-create-db-user";
3838
protected description = "Create an MongoDB Atlas database user";
39-
public operationType: OperationType = "create";
39+
static operationType: OperationType = "create";
4040
protected argsShape = {
4141
...CreateDBUserArgs,
4242
};

src/tools/atlas/create/createFreeCluster.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { ensureCurrentIpInAccessList } from "../../../common/atlas/accessListUti
66
import { AtlasArgs } from "../../args.js";
77

88
export class CreateFreeClusterTool extends AtlasToolBase {
9-
public name = "atlas-create-free-cluster";
9+
static toolName = "atlas-create-free-cluster";
1010
protected description = "Create a free MongoDB Atlas cluster";
11-
public operationType: OperationType = "create";
11+
static operationType: OperationType = "create";
1212
protected argsShape = {
1313
projectId: AtlasArgs.projectId().describe("Atlas project ID to create the cluster in"),
1414
name: AtlasArgs.clusterName().describe("Name of the cluster"),

src/tools/atlas/create/createProject.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import type { Group } from "../../../common/atlas/openapi.js";
55
import { AtlasArgs } from "../../args.js";
66

77
export class CreateProjectTool extends AtlasToolBase {
8-
public name = "atlas-create-project";
8+
static toolName = "atlas-create-project";
99
protected description = "Create a MongoDB Atlas project";
10-
public operationType: OperationType = "create";
10+
static operationType: OperationType = "create";
1111
protected argsShape = {
1212
projectName: AtlasArgs.projectName().optional().describe("Name for the new project"),
1313
organizationId: AtlasArgs.organizationId().optional().describe("Organization ID for the new project"),

src/tools/atlas/read/getPerformanceAdvisor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ const PerformanceAdvisorOperationType = z.enum([
2424
]);
2525

2626
export class GetPerformanceAdvisorTool extends AtlasToolBase {
27-
public name = "atlas-get-performance-advisor";
27+
static toolName = "atlas-get-performance-advisor";
2828
protected description = `Get MongoDB Atlas performance advisor recommendations, which includes the operations: suggested indexes, drop index suggestions, schema suggestions, and a sample of the most recent (max ${DEFAULT_SLOW_QUERY_LOGS_LIMIT}) slow query logs`;
29-
public operationType: OperationType = "read";
29+
static operationType: OperationType = "read";
3030
protected argsShape = {
3131
projectId: AtlasArgs.projectId().describe(
3232
"Atlas project ID to get performance advisor recommendations. The project ID is a hexadecimal identifier of 24 characters. If the user has only specified the name, use the `atlas-list-projects` tool to retrieve the user's projects with their ids."

src/tools/atlas/read/inspectAccessList.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ export const InspectAccessListArgs = {
88
};
99

1010
export class InspectAccessListTool extends AtlasToolBase {
11-
public name = "atlas-inspect-access-list";
11+
static toolName = "atlas-inspect-access-list";
1212
protected description = "Inspect Ip/CIDR ranges with access to your MongoDB Atlas clusters.";
13-
public operationType: OperationType = "read";
13+
static operationType: OperationType = "read";
1414
protected argsShape = {
1515
...InspectAccessListArgs,
1616
};

src/tools/atlas/read/inspectCluster.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ export const InspectClusterArgs = {
1111
};
1212

1313
export class InspectClusterTool extends AtlasToolBase {
14-
public name = "atlas-inspect-cluster";
14+
static toolName = "atlas-inspect-cluster";
1515
protected description = "Inspect MongoDB Atlas cluster";
16-
public operationType: OperationType = "read";
16+
static operationType: OperationType = "read";
1717
protected argsShape = {
1818
...InspectClusterArgs,
1919
};

0 commit comments

Comments
 (0)