-
Notifications
You must be signed in to change notification settings - Fork 132
feat(atlas-local): Add Atlas Local List Deployments tool #538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.` }], | ||
}; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
67
tests/integration/tools/atlas-local/deleteDeployment.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
); | ||
} | ||
); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.