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
48 changes: 24 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"node": "^20.19.0 || ^22.12.0 || >= 23.0.0"
},
"optionalDependencies": {
"@mongodb-js-preview/atlas-local": "^0.0.0-preview.1",
"@mongodb-js-preview/atlas-local": "^0.0.0-preview.2",
"kerberos": "^2.2.2"
}
}
9 changes: 6 additions & 3 deletions src/tools/atlasLocal/atlasLocalTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export abstract class AtlasLocalToolBase extends ToolBase {
return this.session.atlasLocalClient !== undefined && super.verifyAllowed();
}

protected async execute(): Promise<CallToolResult> {
protected async execute(...args: Parameters<ToolCallback<typeof this.argsShape>>): Promise<CallToolResult> {
// Get the client
const client = this.session.atlasLocalClient;

Expand All @@ -35,10 +35,13 @@ please log a ticket here: https://github.com/mongodb-js/mongodb-mcp-server/issue
};
}

return this.executeWithAtlasLocalClient(client);
return this.executeWithAtlasLocalClient(client, ...args);
}

protected abstract executeWithAtlasLocalClient(client: Client): Promise<CallToolResult>;
protected abstract executeWithAtlasLocalClient(
client: Client,
...args: Parameters<ToolCallback<typeof this.argsShape>>
): Promise<CallToolResult>;

protected handleError(
error: unknown,
Expand Down
26 changes: 26 additions & 0 deletions src/tools/atlasLocal/delete/deleteDeployment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { z } from "zod";
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import { AtlasLocalToolBase } from "../atlasLocalTool.js";
import type { OperationType, ToolArgs } from "../../tool.js";
import type { Client } from "@mongodb-js-preview/atlas-local";

export class DeleteDeploymentTool extends AtlasLocalToolBase {
public name = "atlas-local-delete-deployment";
protected description = "Delete a MongoDB Atlas local deployment";
public operationType: OperationType = "delete";
protected argsShape = {
deploymentName: z.string().describe("Name of the deployment to delete"),
};

protected async executeWithAtlasLocalClient(
client: Client,
{ deploymentName }: ToolArgs<typeof this.argsShape>
): Promise<CallToolResult> {
// Delete the deployment
await client.deleteDeployment(deploymentName);

return {
content: [{ type: "text", text: `Deployment "${deploymentName}" deleted successfully.` }],
};
}
}
3 changes: 2 additions & 1 deletion src/tools/atlasLocal/tools.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DeleteDeploymentTool } from "./delete/deleteDeployment.js";
import { ListDeploymentsTool } from "./read/listDeployments.js";

export const AtlasLocalTools = [ListDeploymentsTool];
export const AtlasLocalTools = [ListDeploymentsTool, DeleteDeploymentTool];
67 changes: 67 additions & 0 deletions tests/integration/tools/atlas-local/deleteDeployment.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import {
defaultDriverOptions,
defaultTestConfig,
expectDefined,
getResponseElements,
setupIntegrationTest,
waitUntilMcpClientIsSet,
} from "../../helpers.js";
import { describe, expect, it } from "vitest";

const isMacOSInGitHubActions = process.platform === "darwin" && process.env.GITHUB_ACTIONS === "true";

// Docker is not available on macOS in GitHub Actions
// That's why we skip the tests on macOS in GitHub Actions
describe("atlas-local-delete-deployment", () => {
const integration = setupIntegrationTest(
() => defaultTestConfig,
() => defaultDriverOptions
);

it.skipIf(isMacOSInGitHubActions)("should have the atlas-local-delete-deployment tool", async ({ signal }) => {
await waitUntilMcpClientIsSet(integration.mcpServer(), signal);

const { tools } = await integration.mcpClient().listTools();
const deleteDeployment = tools.find((tool) => tool.name === "atlas-local-delete-deployment");
expectDefined(deleteDeployment);
});

it.skipIf(!isMacOSInGitHubActions)(
"[MacOS in GitHub Actions] should not have the atlas-local-delete-deployment tool",
async ({ signal }) => {
// This should throw an error because the client is not set within the timeout of 5 seconds (default)
await expect(waitUntilMcpClientIsSet(integration.mcpServer(), signal)).rejects.toThrow();

const { tools } = await integration.mcpClient().listTools();
const deleteDeployment = tools.find((tool) => tool.name === "atlas-local-delete-deployment");
expect(deleteDeployment).toBeUndefined();
}
);

it.skipIf(isMacOSInGitHubActions)("should have correct metadata", async ({ signal }) => {
await waitUntilMcpClientIsSet(integration.mcpServer(), signal);
const { tools } = await integration.mcpClient().listTools();
const deleteDeployment = tools.find((tool) => tool.name === "atlas-local-delete-deployment");
expectDefined(deleteDeployment);
expect(deleteDeployment.inputSchema.type).toBe("object");
expectDefined(deleteDeployment.inputSchema.properties);
expect(deleteDeployment.inputSchema.properties).toHaveProperty("deploymentName");
});

it.skipIf(isMacOSInGitHubActions)(
"should return 'no such container' error when deployment to delete does not exist",
async ({ signal }) => {
await waitUntilMcpClientIsSet(integration.mcpServer(), signal);

const response = await integration.mcpClient().callTool({
name: "atlas-local-delete-deployment",
arguments: { deploymentName: "non-existent" },
});
const elements = getResponseElements(response.content);
expect(elements.length).toBeGreaterThanOrEqual(1);
expect(elements[0]?.text).toContain(
"Docker responded with status code 404: No such container: non-existent"
);
}
);
});
Loading