Skip to content

Commit d1e0ee3

Browse files
authored
ci: add ipAccessList after creating project (#496)
1 parent f78fb4c commit d1e0ee3

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

.github/workflows/code_health.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
MDB_MCP_API_CLIENT_ID: ${{ secrets.TEST_ATLAS_CLIENT_ID }}
5555
MDB_MCP_API_CLIENT_SECRET: ${{ secrets.TEST_ATLAS_CLIENT_SECRET }}
5656
MDB_MCP_API_BASE_URL: ${{ vars.TEST_ATLAS_BASE_URL }}
57-
run: npm test -- --exclude "tests/unit/**" --exclude "tests/integration/tools/mongodb/**" --exclude "tests/integration/*.ts"
57+
run: npm test -- tests/integration/tools/atlas
5858
- name: Upload test results
5959
uses: actions/upload-artifact@v4
6060
if: always()

tests/integration/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export function setupIntegrationTest(
8484
});
8585

8686
// Mock hasValidAccessToken for tests
87-
if (userConfig.apiClientId && userConfig.apiClientSecret) {
87+
if (!userConfig.apiClientId && !userConfig.apiClientSecret) {
8888
const mockFn = vi.fn().mockResolvedValue(true);
8989
session.apiClient.validateAccessToken = mockFn;
9090
}

tests/integration/tools/atlas/atlasHelpers.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export function describeWithAtlas(name: string, fn: IntegrationTestFunction): vo
1919
...defaultTestConfig,
2020
apiClientId: process.env.MDB_MCP_API_CLIENT_ID,
2121
apiClientSecret: process.env.MDB_MCP_API_CLIENT_SECRET,
22+
apiBaseUrl: process.env.MDB_MCP_API_BASE_URL ?? "https://cloud-dev.mongodb.com",
2223
}),
2324
() => defaultDriverOptions
2425
);
@@ -39,6 +40,13 @@ export function withProject(integration: IntegrationTest, fn: ProjectTestFunctio
3940
beforeAll(async () => {
4041
const apiClient = integration.mcpServer().session.apiClient;
4142

43+
// check that it has credentials
44+
if (!apiClient.hasCredentials()) {
45+
throw new Error("No credentials available");
46+
}
47+
48+
// validate access token
49+
await apiClient.validateAccessToken();
4250
try {
4351
const group = await createProject(apiClient);
4452
projectId = group.id;
@@ -111,5 +119,22 @@ async function createProject(apiClient: ApiClient): Promise<Group & Required<Pic
111119
throw new Error("Failed to create project");
112120
}
113121

122+
// add current IP to project access list
123+
const { currentIpv4Address } = await apiClient.getIpInfo();
124+
await apiClient.createProjectIpAccessList({
125+
params: {
126+
path: {
127+
groupId: group.id,
128+
},
129+
},
130+
body: [
131+
{
132+
ipAddress: currentIpv4Address,
133+
groupId: group.id,
134+
comment: "Added by MongoDB MCP Server to enable tool access",
135+
},
136+
],
137+
});
138+
114139
return group as Group & Required<Pick<Group, "id">>;
115140
}

0 commit comments

Comments
 (0)