-
Notifications
You must be signed in to change notification settings - Fork 129
feat(atlas-local): Added Atlas Local List Deployments tool #520
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 6 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4900b02
Implemented 'atlas-local-list-deployments'
jeroenvervaeke 5c660da
chore: made eslint happy
jeroenvervaeke 9e4e3c5
Fix MacOS tests + tool counting tests
jeroenvervaeke 3743557
Fix integration test when there's not deployment available
jeroenvervaeke f3e1064
Updated tool count
jeroenvervaeke e6b0d15
fixed typo and count
jeroenvervaeke 06da4c5
adressed PR remarks
jeroenvervaeke 50637ea
Marked atlas-local as an optional dependency
jeroenvervaeke da63baf
Load atlas-local tools async
jeroenvervaeke 1fd7ae3
Merge branch 'feat-MCP-40' into MCP-158
jeroenvervaeke db2f049
created waitUntilMcpClientIsSet and use test helper
jeroenvervaeke c436204
Expect timeout on MACOs on Github Actions
jeroenvervaeke 558411c
move include 'atlas-local' enabled check earlier
jeroenvervaeke c79cb48
Improve throw error comment
jeroenvervaeke e4fb282
handle potential future developer error more gracefully
jeroenvervaeke 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
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,55 @@ | ||
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js"; | ||
import { AtlasLocalToolBase } from "../atlasLocalTool.js"; | ||
import type { OperationType } from "../../tool.js"; | ||
import { formatUntrustedData } from "../../tool.js"; | ||
import type { Deployment } from "@mongodb-js-preview/atlas-local"; | ||
|
||
export class ListDeploymentsTool extends AtlasLocalToolBase { | ||
public name = "atlas-local-list-deployments"; | ||
protected description = "List MongoDB Atlas local deployments"; | ||
public operationType: OperationType = "read"; | ||
protected argsShape = {}; | ||
|
||
protected async execute(): Promise<CallToolResult> { | ||
// Get the client | ||
const client = this.client; | ||
kmruiz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
// If the client is not found, throw an error | ||
// This should never happen, because the tool should have been disabled. | ||
// verifyAllowed in the base class returns false if the client is not found | ||
if (!client) { | ||
throw new Error("Atlas Local client not found, tool should have been disabled."); | ||
} | ||
|
||
// List the deployments | ||
const deployments = await client.listDeployments(); | ||
|
||
// Format the deployments | ||
return this.formatDeploymentsTable(deployments); | ||
} | ||
|
||
private formatDeploymentsTable(deployments: Deployment[]): CallToolResult { | ||
// Check if deployments are absent | ||
if (!deployments?.length) { | ||
return { | ||
content: [{ type: "text", text: "No deployments found." }], | ||
}; | ||
} | ||
|
||
// Turn the deployments into a markdown table | ||
const rows = deployments | ||
.map((deployment) => { | ||
return `${deployment.name || "Unknown"} | ${deployment.state} | ${deployment.mongodbVersion}`; | ||
}) | ||
.join("\n"); | ||
|
||
return { | ||
content: formatUntrustedData( | ||
`Found ${deployments.length} deployments:`, | ||
`Deployment Name | State | MongoDB Version | ||
----------------|----------------|---------------- | ||
${rows}` | ||
), | ||
}; | ||
} | ||
} |
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 +1,33 @@ | ||
export const AtlasLocalTools = []; | ||
import { ListDeploymentsTool } from "./read/listDeployments.js"; | ||
import type AtlasLocal from "@mongodb-js-preview/atlas-local"; | ||
|
||
// Don't use this directly, use BuildAtlasLocalTools instead | ||
const atlasLocalTools = [ListDeploymentsTool]; | ||
|
||
// Build the Atlas Local tools | ||
export const BuildAtlasLocalTools = async (): Promise<typeof atlasLocalTools> => { | ||
// Initialize the Atlas Local client | ||
const client = await GetAtlasLocalClient(); | ||
|
||
// If the client is found, set it on the tools | ||
// On unsupported platforms, the client will be undefined | ||
if (client) { | ||
// Set the client on the tools | ||
atlasLocalTools.forEach((tool) => { | ||
tool.prototype.client = client; | ||
}); | ||
} | ||
|
||
return atlasLocalTools; | ||
}; | ||
|
||
export const GetAtlasLocalClient = async (): Promise<AtlasLocal.Client | undefined> => { | ||
try { | ||
const { Client: AtlasLocalClient } = await import("@mongodb-js-preview/atlas-local"); | ||
kmruiz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
return AtlasLocalClient.connect(); | ||
} catch (error) { | ||
// We only get here if the user is running atlas-local on a unsupported platform | ||
console.warn("Atlas Local native binding not available:", error); | ||
return undefined; | ||
} | ||
}; |
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
61 changes: 61 additions & 0 deletions
61
tests/integration/tools/atlas-local/listDeployments.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,61 @@ | ||
import { | ||
defaultDriverOptions, | ||
defaultTestConfig, | ||
expectDefined, | ||
getResponseElements, | ||
setupIntegrationTest, | ||
} from "../../helpers.js"; | ||
import { describe, expect, it } from "vitest"; | ||
|
||
const isMacOSInGitHubActions = process.platform === "darwin" && process.env.GITHUB_ACTIONS === "true"; | ||
|
||
describe("atlas-local-list-deployments", () => { | ||
const integration = setupIntegrationTest( | ||
() => defaultTestConfig, | ||
() => defaultDriverOptions | ||
); | ||
|
||
it.skipIf(isMacOSInGitHubActions)("should have the atlas-local-list-deployments tool", async () => { | ||
const { tools } = await integration.mcpClient().listTools(); | ||
const listDeployments = tools.find((tool) => tool.name === "atlas-local-list-deployments"); | ||
expectDefined(listDeployments); | ||
}); | ||
|
||
it.skipIf(!isMacOSInGitHubActions)( | ||
"[MacOS in GitHub Actions] should not have the atlas-local-list-deployments tool", | ||
blva marked this conversation as resolved.
Show resolved
Hide resolved
|
||
async () => { | ||
const { tools } = await integration.mcpClient().listTools(); | ||
const listDeployments = tools.find((tool) => tool.name === "atlas-local-list-deployments"); | ||
expect(listDeployments).toBeUndefined(); | ||
} | ||
); | ||
|
||
it.skipIf(isMacOSInGitHubActions)("should have correct metadata", async () => { | ||
const { tools } = await integration.mcpClient().listTools(); | ||
const listDeployments = tools.find((tool) => tool.name === "atlas-local-list-deployments"); | ||
expectDefined(listDeployments); | ||
expect(listDeployments.inputSchema.type).toBe("object"); | ||
expectDefined(listDeployments.inputSchema.properties); | ||
expect(listDeployments.inputSchema.properties).toEqual({}); | ||
}); | ||
|
||
it.skipIf(isMacOSInGitHubActions)("should not crash when calling the tool", async () => { | ||
const response = await integration.mcpClient().callTool({ | ||
name: "atlas-local-list-deployments", | ||
arguments: {}, | ||
}); | ||
const elements = getResponseElements(response.content); | ||
expect(elements.length).toBeGreaterThanOrEqual(1); | ||
|
||
if (elements.length === 1) { | ||
expect(elements[0]?.text).toContain("No deployments found."); | ||
} | ||
|
||
if (elements.length > 1) { | ||
expect(elements[0]?.text).toMatch(/Found \d+ deployments/); | ||
expect(elements[1]?.text).toContain( | ||
"Deployment Name | State | MongoDB Version\n----------------|----------------|----------------\n" | ||
); | ||
} | ||
}); | ||
}); |
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
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.