Skip to content

Commit c7cf37b

Browse files
committed
feat: Implements atlasLocal tool atlas-local-connect-deployment
1 parent 0d14679 commit c7cf37b

File tree

4 files changed

+61
-26
lines changed

4 files changed

+61
-26
lines changed

package-lock.json

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
"node": "^20.19.0 || ^22.12.0 || >= 23.0.0"
122122
},
123123
"optionalDependencies": {
124-
"@mongodb-js-preview/atlas-local": "^0.0.0-preview.3",
124+
"@mongodb-js-preview/atlas-local": "^0.0.0-preview.6",
125125
"kerberos": "^2.2.2"
126126
}
127127
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
2+
import { AtlasLocalToolBase } from "../atlasLocalTool.js";
3+
import type { OperationType, ToolArgs } from "../../tool.js";
4+
import type { Client } from "@mongodb-js-preview/atlas-local";
5+
import { z } from "zod";
6+
7+
export class ConnectDeploymentTool extends AtlasLocalToolBase {
8+
public name = "atlas-local-connect-deployment";
9+
protected description = "Connect to a MongoDB Atlas Local deployment";
10+
public operationType: OperationType = "connect";
11+
protected argsShape = {
12+
deploymentIdOrName: z.string().describe("Name or ID of the deployment to connect to"),
13+
};
14+
15+
protected async executeWithAtlasLocalClient(
16+
client: Client,
17+
{ deploymentIdOrName }: ToolArgs<typeof this.argsShape>
18+
): Promise<CallToolResult> {
19+
// Get the connection string for the deployment
20+
const connectionString = await client.getConnectionString(deploymentIdOrName);
21+
22+
// Connect to the deployment
23+
await this.session.connectToMongoDB({ connectionString });
24+
25+
return {
26+
content: [
27+
{
28+
type: "text",
29+
text: `Successfully connected to Atlas Local deployment "${deploymentIdOrName}".`,
30+
},
31+
],
32+
};
33+
}
34+
}

src/tools/atlasLocal/tools.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { DeleteDeploymentTool } from "./delete/deleteDeployment.js";
22
import { ListDeploymentsTool } from "./read/listDeployments.js";
33
import { CreateDeploymentTool } from "./create/createDeployment.js";
4+
import { ConnectDeploymentTool } from "./connect/connectDeployment.js";
45

5-
export const AtlasLocalTools = [ListDeploymentsTool, DeleteDeploymentTool, CreateDeploymentTool];
6+
export const AtlasLocalTools = [ListDeploymentsTool, DeleteDeploymentTool, CreateDeploymentTool, ConnectDeploymentTool];

0 commit comments

Comments
 (0)