Skip to content

Commit 7bf120e

Browse files
committed
fix: align with main
1 parent 5a03f03 commit 7bf120e

File tree

3 files changed

+52
-45
lines changed

3 files changed

+52
-45
lines changed

src/common/atlas/apiClient.ts

Lines changed: 30 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,11 @@
11
import config from "../../config.js";
22
import createClient, { Client, FetchOptions, Middleware } from "openapi-fetch";
33
import { AccessToken, ClientCredentials } from "simple-oauth2";
4-
4+
import { ApiClientError } from "./apiClientError.js";
55
import { paths, operations } from "./openapi.js";
6-
import { State } from "../../state.js";
76

87
const ATLAS_API_VERSION = "2025-03-12";
98

10-
export class ApiClientError extends Error {
11-
response?: Response;
12-
13-
constructor(message: string, response: Response | undefined = undefined) {
14-
super(message);
15-
this.name = "ApiClientError";
16-
this.response = response;
17-
}
18-
19-
static async fromResponse(response: Response, message?: string): Promise<ApiClientError> {
20-
message ||= `error calling Atlas API`;
21-
try {
22-
const text = await response.text();
23-
return new ApiClientError(`${message}: [${response.status} ${response.statusText}] ${text}`, response);
24-
} catch {
25-
return new ApiClientError(`${message}: ${response.status} ${response.statusText}`, response);
26-
}
27-
}
28-
}
29-
309
export interface ApiClientOptions {
3110
credentials?: {
3211
clientId: string;
@@ -71,6 +50,7 @@ export class ApiClient {
7150
}
7251
},
7352
};
53+
7454
private readonly errorMiddleware: Middleware = {
7555
async onResponse({ response }) {
7656
if (!response.ok) {
@@ -79,15 +59,13 @@ export class ApiClient {
7959
},
8060
};
8161

82-
constructor(options: ApiClientOptions) {
83-
const defaultOptions = {
84-
baseUrl: "https://cloud.mongodb.com/",
85-
userAgent: `AtlasMCP/${config.version} (${process.platform}; ${process.arch}; ${process.env.HOSTNAME || "unknown"})`,
86-
};
87-
62+
constructor(options?: ApiClientOptions) {
8863
this.options = {
89-
...defaultOptions,
9064
...options,
65+
baseUrl: options?.baseUrl || "https://cloud.mongodb.com/",
66+
userAgent:
67+
options?.userAgent ||
68+
`AtlasMCP/${config.version} (${process.platform}; ${process.arch}; ${process.env.HOSTNAME || "unknown"})`,
9169
};
9270

9371
this.client = createClient<paths>({
@@ -138,38 +116,39 @@ export class ApiClient {
138116
}>;
139117
}
140118

141-
async listProjects(options?: FetchOptions<operations["listProjects"]>) {
142-
const { data } = await this.client.GET(`/api/atlas/v2/groups`, options);
119+
// DO NOT EDIT. This is auto-generated code.
120+
async listClustersForAllProjects(options?: FetchOptions<operations["listClustersForAllProjects"]>) {
121+
const { data } = await this.client.GET("/api/atlas/v2/clusters", options);
143122
return data;
144123
}
145124

146-
async listProjectIpAccessLists(options: FetchOptions<operations["listProjectIpAccessLists"]>) {
147-
const { data } = await this.client.GET(`/api/atlas/v2/groups/{groupId}/accessList`, options);
125+
async listProjects(options?: FetchOptions<operations["listProjects"]>) {
126+
const { data } = await this.client.GET("/api/atlas/v2/groups", options);
148127
return data;
149128
}
150129

151-
async createProjectIpAccessList(options: FetchOptions<operations["createProjectIpAccessList"]>) {
152-
const { data } = await this.client.POST(`/api/atlas/v2/groups/{groupId}/accessList`, options);
130+
async createProject(options: FetchOptions<operations["createProject"]>) {
131+
const { data } = await this.client.POST("/api/atlas/v2/groups", options);
153132
return data;
154133
}
155134

156135
async getProject(options: FetchOptions<operations["getProject"]>) {
157-
const { data } = await this.client.GET(`/api/atlas/v2/groups/{groupId}`, options);
136+
const { data } = await this.client.GET("/api/atlas/v2/groups/{groupId}", options);
158137
return data;
159138
}
160139

161-
async listClusters(options: FetchOptions<operations["listClusters"]>) {
162-
const { data } = await this.client.GET(`/api/atlas/v2/groups/{groupId}/clusters`, options);
140+
async listProjectIpAccessLists(options: FetchOptions<operations["listProjectIpAccessLists"]>) {
141+
const { data } = await this.client.GET("/api/atlas/v2/groups/{groupId}/accessList", options);
163142
return data;
164143
}
165144

166-
async listClustersForAllProjects(options?: FetchOptions<operations["listClustersForAllProjects"]>) {
167-
const { data } = await this.client.GET(`/api/atlas/v2/clusters`, options);
145+
async createProjectIpAccessList(options: FetchOptions<operations["createProjectIpAccessList"]>) {
146+
const { data } = await this.client.POST("/api/atlas/v2/groups/{groupId}/accessList", options);
168147
return data;
169148
}
170149

171-
async getCluster(options: FetchOptions<operations["getCluster"]>) {
172-
const { data } = await this.client.GET(`/api/atlas/v2/groups/{groupId}/clusters/{clusterName}`, options);
150+
async listClusters(options: FetchOptions<operations["listClusters"]>) {
151+
const { data } = await this.client.GET("/api/atlas/v2/groups/{groupId}/clusters", options);
173152
return data;
174153
}
175154

@@ -178,13 +157,19 @@ export class ApiClient {
178157
return data;
179158
}
180159

181-
async createDatabaseUser(options: FetchOptions<operations["createDatabaseUser"]>) {
182-
const { data } = await this.client.POST("/api/atlas/v2/groups/{groupId}/databaseUsers", options);
160+
async getCluster(options: FetchOptions<operations["getCluster"]>) {
161+
const { data } = await this.client.GET("/api/atlas/v2/groups/{groupId}/clusters/{clusterName}", options);
183162
return data;
184163
}
185164

186165
async listDatabaseUsers(options: FetchOptions<operations["listDatabaseUsers"]>) {
187-
const { data } = await this.client.GET(`/api/atlas/v2/groups/{groupId}/databaseUsers`, options);
166+
const { data } = await this.client.GET("/api/atlas/v2/groups/{groupId}/databaseUsers", options);
167+
return data;
168+
}
169+
170+
async createDatabaseUser(options: FetchOptions<operations["createDatabaseUser"]>) {
171+
const { data } = await this.client.POST("/api/atlas/v2/groups/{groupId}/databaseUsers", options);
188172
return data;
189173
}
174+
// DO NOT EDIT. This is auto-generated code.
190175
}

src/common/atlas/apiClientError.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export class ApiClientError extends Error {
2+
response?: Response;
3+
4+
constructor(message: string, response: Response | undefined = undefined) {
5+
super(message);
6+
this.name = "ApiClientError";
7+
this.response = response;
8+
}
9+
10+
static async fromResponse(
11+
response: Response,
12+
message: string = `error calling Atlas API`
13+
): Promise<ApiClientError> {
14+
try {
15+
const text = await response.text();
16+
return new ApiClientError(`${message}: [${response.status} ${response.statusText}] ${text}`, response);
17+
} catch {
18+
return new ApiClientError(`${message}: ${response.status} ${response.statusText}`, response);
19+
}
20+
}
21+
}

src/tools/mongodb/tools.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ export const MongoDbTools = [
4141
RenameCollectionTool,
4242
DropDatabaseTool,
4343
DropCollectionTool,
44+
ExplainTool,
4445
];

0 commit comments

Comments
 (0)