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
2 changes: 1 addition & 1 deletion .github/workflows/code_health.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
MDB_MCP_API_CLIENT_ID: ${{ secrets.TEST_ATLAS_CLIENT_ID }}
MDB_MCP_API_CLIENT_SECRET: ${{ secrets.TEST_ATLAS_CLIENT_SECRET }}
MDB_MCP_API_BASE_URL: ${{ vars.TEST_ATLAS_BASE_URL }}
run: npm test -- --exclude "tests/unit/**" --exclude "tests/integration/tools/mongodb/**" --exclude "tests/integration/*.ts"
run: npm test -- tests/integration/tools/atlas
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function setupIntegrationTest(
});

// Mock hasValidAccessToken for tests
if (userConfig.apiClientId && userConfig.apiClientSecret) {
if (!userConfig.apiClientId && !userConfig.apiClientSecret) {
const mockFn = vi.fn().mockResolvedValue(true);
session.apiClient.validateAccessToken = mockFn;
}
Expand Down
25 changes: 25 additions & 0 deletions tests/integration/tools/atlas/atlasHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function describeWithAtlas(name: string, fn: IntegrationTestFunction): vo
...defaultTestConfig,
apiClientId: process.env.MDB_MCP_API_CLIENT_ID,
apiClientSecret: process.env.MDB_MCP_API_CLIENT_SECRET,
apiBaseUrl: process.env.MDB_MCP_API_BASE_URL ?? "https://cloud-dev.mongodb.com",
}),
() => defaultDriverOptions
);
Expand All @@ -39,6 +40,13 @@ export function withProject(integration: IntegrationTest, fn: ProjectTestFunctio
beforeAll(async () => {
const apiClient = integration.mcpServer().session.apiClient;

// check that it has credentials
if (!apiClient.hasCredentials()) {
throw new Error("No credentials available");
}

// validate access token
await apiClient.validateAccessToken();
try {
const group = await createProject(apiClient);
projectId = group.id;
Expand Down Expand Up @@ -111,5 +119,22 @@ async function createProject(apiClient: ApiClient): Promise<Group & Required<Pic
throw new Error("Failed to create project");
}

// add current IP to project access list
const { currentIpv4Address } = await apiClient.getIpInfo();
await apiClient.createProjectIpAccessList({
params: {
path: {
groupId: group.id,
},
},
body: [
{
ipAddress: currentIpv4Address,
groupId: group.id,
comment: "Added by MongoDB MCP Server to enable tool access",
},
],
});
Comment on lines +123 to +137
Copy link
Preview

Copilot AI Aug 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The IP access list creation should be wrapped in a try-catch block to handle potential failures gracefully. If this operation fails, it could leave the project in an unusable state for tests, but the project creation itself succeeded.

Copilot uses AI. Check for mistakes.


return group as Group & Required<Pick<Group, "id">>;
}
Loading