-
Notifications
You must be signed in to change notification settings - Fork 128
feat(atlas-local): Adds Atlas Local Connect Deployment tool #612
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
10 commits
Select commit
Hold shift + click to select a range
c7cf37b
feat: Implements atlasLocal tool atlas-local-connect-deployment
cveticm 0d0581d
Adds integration tests
cveticm 0c53f48
adds accuracy tests
cveticm ba884f8
Adds hints to llm on which connect tool to use and fixes atlas test
cveticm 975909e
Moves cleanup to afterEach block
cveticm 9ad0257
adds error handling for when container non-existent
cveticm fa6d616
tool input doesnt take deployment id
cveticm a169d63
cluster integ test to handle macos in github runner
cveticm 6bf04ce
restructures test
cveticm 74fe9fe
Improves llmConntectHint
cveticm 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,34 @@ | ||
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"; | ||
import { z } from "zod"; | ||
|
||
export class ConnectDeploymentTool extends AtlasLocalToolBase { | ||
public name = "atlas-local-connect-deployment"; | ||
protected description = "Connect to a MongoDB Atlas Local deployment"; | ||
public operationType: OperationType = "connect"; | ||
protected argsShape = { | ||
deploymentName: z.string().describe("Name of the deployment to connect to"), | ||
}; | ||
|
||
protected async executeWithAtlasLocalClient( | ||
client: Client, | ||
{ deploymentName }: ToolArgs<typeof this.argsShape> | ||
): Promise<CallToolResult> { | ||
// Get the connection string for the deployment | ||
const connectionString = await client.getConnectionString(deploymentName); | ||
|
||
// Connect to the deployment | ||
await this.session.connectToMongoDB({ connectionString }); | ||
|
||
return { | ||
content: [ | ||
{ | ||
type: "text", | ||
text: `Successfully connected to Atlas Local deployment "${deploymentName}".`, | ||
}, | ||
], | ||
}; | ||
} | ||
} |
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,5 +1,6 @@ | ||
import { DeleteDeploymentTool } from "./delete/deleteDeployment.js"; | ||
import { ListDeploymentsTool } from "./read/listDeployments.js"; | ||
import { CreateDeploymentTool } from "./create/createDeployment.js"; | ||
import { ConnectDeploymentTool } from "./connect/connectDeployment.js"; | ||
|
||
export const AtlasLocalTools = [ListDeploymentsTool, DeleteDeploymentTool, CreateDeploymentTool]; | ||
export const AtlasLocalTools = [ListDeploymentsTool, DeleteDeploymentTool, CreateDeploymentTool, ConnectDeploymentTool]; |
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,70 @@ | ||
import { describeAccuracyTests } from "./sdk/describeAccuracyTests.js"; | ||
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js"; | ||
|
||
describeAccuracyTests([ | ||
{ | ||
prompt: "Connect to the local MongoDB cluster called 'my-database'", | ||
expectedToolCalls: [ | ||
{ | ||
toolName: "atlas-local-connect-deployment", | ||
parameters: { | ||
deploymentIdOrName: "my-database", | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
prompt: "Connect to the local MongoDB atlas database called 'my-instance'", | ||
expectedToolCalls: [ | ||
{ | ||
toolName: "atlas-local-connect-deployment", | ||
parameters: { | ||
deploymentIdOrName: "my-instance", | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
prompt: "If and only if, the local MongoDB deployment 'local-mflix' exists, then connect to it", | ||
mockedTools: { | ||
"atlas-local-list-deployments": (): CallToolResult => ({ | ||
content: [ | ||
{ type: "text", text: "Found 1 deployment:" }, | ||
{ | ||
type: "text", | ||
text: "Deployment Name | State | MongoDB Version\n----------------|----------------|----------------\nlocal-mflix | Running | 6.0", | ||
}, | ||
], | ||
}), | ||
}, | ||
expectedToolCalls: [ | ||
{ | ||
toolName: "atlas-local-list-deployments", | ||
parameters: {}, | ||
}, | ||
{ | ||
toolName: "atlas-local-connect-deployment", | ||
parameters: { | ||
deploymentIdOrName: "local-mflix", | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
prompt: "Connect to a new local MongoDB cluster named 'local-mflix'", | ||
expectedToolCalls: [ | ||
{ | ||
toolName: "atlas-local-create-deployment", | ||
parameters: { | ||
deploymentName: "local-mflix", | ||
}, | ||
}, | ||
{ | ||
toolName: "atlas-local-connect-deployment", | ||
parameters: { | ||
deploymentIdOrName: "local-mflix", | ||
}, | ||
}, | ||
], | ||
}, | ||
]); |
114 changes: 114 additions & 0 deletions
114
tests/integration/tools/atlas-local/connectDeployment.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,114 @@ | ||
import { beforeEach } from "vitest"; | ||
import { | ||
defaultDriverOptions, | ||
defaultTestConfig, | ||
expectDefined, | ||
getResponseElements, | ||
setupIntegrationTest, | ||
validateToolMetadata, | ||
waitUntilMcpClientIsSet, | ||
} from "../../helpers.js"; | ||
import { afterEach, describe, expect, it } from "vitest"; | ||
|
||
const isMacOSInGitHubActions = process.platform === "darwin" && process.env.GITHUB_ACTIONS === "true"; | ||
const integration = setupIntegrationTest( | ||
() => defaultTestConfig, | ||
() => defaultDriverOptions | ||
); | ||
|
||
// Docker is not available on macOS in GitHub Actions | ||
// That's why we skip the tests on macOS in GitHub Actions | ||
describe.skipIf(isMacOSInGitHubActions)("atlas-local-connect-deployment", () => { | ||
beforeEach(async ({ signal }) => { | ||
await waitUntilMcpClientIsSet(integration.mcpServer(), signal); | ||
}); | ||
|
||
validateToolMetadata(integration, "atlas-local-connect-deployment", "Connect to a MongoDB Atlas Local deployment", [ | ||
{ | ||
name: "deploymentName", | ||
type: "string", | ||
description: "Name of the deployment to connect to", | ||
required: true, | ||
}, | ||
]); | ||
|
||
it("should have the atlas-local-connect-deployment tool", async () => { | ||
const { tools } = await integration.mcpClient().listTools(); | ||
const connectDeployment = tools.find((tool) => tool.name === "atlas-local-connect-deployment"); | ||
expectDefined(connectDeployment); | ||
}); | ||
|
||
it("should return 'no such container' error when connecting to non-existent deployment", async () => { | ||
const deploymentName = "non-existent"; | ||
const response = await integration.mcpClient().callTool({ | ||
name: "atlas-local-connect-deployment", | ||
arguments: { deploymentName }, | ||
}); | ||
const elements = getResponseElements(response.content); | ||
expect(elements.length).toBeGreaterThanOrEqual(1); | ||
expect(elements[0]?.text).toContain( | ||
`The Atlas Local deployment "${deploymentName}" was not found. Please check the deployment name or use "atlas-local-list-deployments" to see available deployments.` | ||
); | ||
}); | ||
}); | ||
|
||
describe.skipIf(isMacOSInGitHubActions)("atlas-local-connect-deployment with deployments", () => { | ||
let deploymentName: string = ""; | ||
let deploymentNamesToCleanup: string[] = []; | ||
|
||
beforeEach(async ({ signal }) => { | ||
await waitUntilMcpClientIsSet(integration.mcpServer(), signal); | ||
|
||
// Create deployments | ||
deploymentName = `test-deployment-1-${Date.now()}`; | ||
deploymentNamesToCleanup.push(deploymentName); | ||
await integration.mcpClient().callTool({ | ||
name: "atlas-local-create-deployment", | ||
arguments: { deploymentName }, | ||
}); | ||
|
||
const anotherDeploymentName = `test-deployment-2-${Date.now()}`; | ||
deploymentNamesToCleanup.push(anotherDeploymentName); | ||
await integration.mcpClient().callTool({ | ||
name: "atlas-local-create-deployment", | ||
arguments: { deploymentName: anotherDeploymentName }, | ||
}); | ||
}); | ||
|
||
afterEach(async () => { | ||
// Delete all created deployments | ||
for (const deploymentNameToCleanup of deploymentNamesToCleanup) { | ||
try { | ||
await integration.mcpClient().callTool({ | ||
name: "atlas-local-delete-deployment", | ||
arguments: { deploymentName: deploymentNameToCleanup }, | ||
}); | ||
} catch (error) { | ||
console.warn(`Failed to delete deployment ${deploymentNameToCleanup}:`, error); | ||
} | ||
} | ||
deploymentNamesToCleanup = []; | ||
}); | ||
|
||
it("should connect to correct deployment when calling the tool", async () => { | ||
// Connect to the deployment | ||
const response = await integration.mcpClient().callTool({ | ||
name: "atlas-local-connect-deployment", | ||
arguments: { deploymentName }, | ||
}); | ||
const elements = getResponseElements(response.content); | ||
expect(elements.length).toBeGreaterThanOrEqual(1); | ||
expect(elements[0]?.text).toContain(`Successfully connected to Atlas Local deployment "${deploymentName}".`); | ||
}); | ||
}); | ||
|
||
describe.skipIf(!isMacOSInGitHubActions)("atlas-local-connect-deployment [MacOS in GitHub Actions]", () => { | ||
it("should not have the atlas-local-connect-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 connectDeployment = tools.find((tool) => tool.name === "atlas-local-connect-deployment"); | ||
expect(connectDeployment).toBeUndefined(); | ||
}); | ||
}); |
Oops, something went wrong.
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.