11import config from "../../config.js" ;
22import createClient , { Client , FetchOptions , Middleware } from "openapi-fetch" ;
33import { AccessToken , ClientCredentials } from "simple-oauth2" ;
4-
4+ import { ApiClientError } from "./apiClientError.js" ;
55import { paths , operations } from "./openapi.js" ;
66
77const ATLAS_API_VERSION = "2025-03-12" ;
88
9- export class ApiClientError extends Error {
10- response ?: Response ;
11-
12- constructor ( message : string , response : Response | undefined = undefined ) {
13- super ( message ) ;
14- this . name = "ApiClientError" ;
15- this . response = response ;
16- }
17-
18- static async fromResponse ( response : Response , message ?: string ) : Promise < ApiClientError > {
19- message ||= `error calling Atlas API` ;
20- try {
21- const text = await response . text ( ) ;
22- return new ApiClientError ( `${ message } : [${ response . status } ${ response . statusText } ] ${ text } ` , response ) ;
23- } catch {
24- return new ApiClientError ( `${ message } : ${ response . status } ${ response . statusText } ` , response ) ;
25- }
26- }
27- }
28-
299export interface ApiClientOptions {
3010 credentials ?: {
3111 clientId : string ;
@@ -79,14 +59,12 @@ export class ApiClient {
7959 } ) ;
8060
8161 constructor ( options ?: ApiClientOptions ) {
82- const defaultOptions = {
83- baseUrl : "https://cloud.mongodb.com/" ,
84- userAgent : `AtlasMCP/${ config . version } (${ process . platform } ; ${ process . arch } ; ${ process . env . HOSTNAME || "unknown" } )` ,
85- } ;
86-
8762 this . options = {
88- ...defaultOptions ,
8963 ...options ,
64+ baseUrl : options ?. baseUrl || "https://cloud.mongodb.com/" ,
65+ userAgent :
66+ options ?. userAgent ||
67+ `AtlasMCP/${ config . version } (${ process . platform } ; ${ process . arch } ; ${ process . env . HOSTNAME || "unknown" } )` ,
9068 } ;
9169
9270 this . client = createClient < paths > ( {
@@ -136,38 +114,39 @@ export class ApiClient {
136114 } ;
137115 }
138116
139- async listProjects ( options ?: FetchOptions < operations [ "listProjects" ] > ) {
140- const { data } = await this . client . GET ( `/api/atlas/v2/groups` , options ) ;
117+ // DO NOT EDIT. This is auto-generated code.
118+ async listClustersForAllProjects ( options ?: FetchOptions < operations [ "listClustersForAllProjects" ] > ) {
119+ const { data } = await this . client . GET ( "/api/atlas/v2/clusters" , options ) ;
141120 return data ;
142121 }
143122
144- async listProjectIpAccessLists ( options : FetchOptions < operations [ "listProjectIpAccessLists " ] > ) {
145- const { data } = await this . client . GET ( ` /api/atlas/v2/groups/{groupId}/accessList` , options ) ;
123+ async listProjects ( options ? : FetchOptions < operations [ "listProjects " ] > ) {
124+ const { data } = await this . client . GET ( " /api/atlas/v2/groups" , options ) ;
146125 return data ;
147126 }
148127
149- async createProjectIpAccessList ( options : FetchOptions < operations [ "createProjectIpAccessList " ] > ) {
150- const { data } = await this . client . POST ( ` /api/atlas/v2/groups/{groupId}/accessList` , options ) ;
128+ async createProject ( options : FetchOptions < operations [ "createProject " ] > ) {
129+ const { data } = await this . client . POST ( " /api/atlas/v2/groups" , options ) ;
151130 return data ;
152131 }
153132
154133 async getProject ( options : FetchOptions < operations [ "getProject" ] > ) {
155- const { data } = await this . client . GET ( ` /api/atlas/v2/groups/{groupId}` , options ) ;
134+ const { data } = await this . client . GET ( " /api/atlas/v2/groups/{groupId}" , options ) ;
156135 return data ;
157136 }
158137
159- async listClusters ( options : FetchOptions < operations [ "listClusters " ] > ) {
160- const { data } = await this . client . GET ( ` /api/atlas/v2/groups/{groupId}/clusters` , options ) ;
138+ async listProjectIpAccessLists ( options : FetchOptions < operations [ "listProjectIpAccessLists " ] > ) {
139+ const { data } = await this . client . GET ( " /api/atlas/v2/groups/{groupId}/accessList" , options ) ;
161140 return data ;
162141 }
163142
164- async listClustersForAllProjects ( options ? : FetchOptions < operations [ "listClustersForAllProjects " ] > ) {
165- const { data } = await this . client . GET ( ` /api/atlas/v2/clusters` , options ) ;
143+ async createProjectIpAccessList ( options : FetchOptions < operations [ "createProjectIpAccessList " ] > ) {
144+ const { data } = await this . client . POST ( " /api/atlas/v2/groups/{groupId}/accessList" , options ) ;
166145 return data ;
167146 }
168147
169- async getCluster ( options : FetchOptions < operations [ "getCluster " ] > ) {
170- const { data } = await this . client . GET ( ` /api/atlas/v2/groups/{groupId}/clusters/{clusterName}` , options ) ;
148+ async listClusters ( options : FetchOptions < operations [ "listClusters " ] > ) {
149+ const { data } = await this . client . GET ( " /api/atlas/v2/groups/{groupId}/clusters" , options ) ;
171150 return data ;
172151 }
173152
@@ -176,13 +155,19 @@ export class ApiClient {
176155 return data ;
177156 }
178157
179- async createDatabaseUser ( options : FetchOptions < operations [ "createDatabaseUser " ] > ) {
180- const { data } = await this . client . POST ( "/api/atlas/v2/groups/{groupId}/databaseUsers " , options ) ;
158+ async getCluster ( options : FetchOptions < operations [ "getCluster " ] > ) {
159+ const { data } = await this . client . GET ( "/api/atlas/v2/groups/{groupId}/clusters/{clusterName} " , options ) ;
181160 return data ;
182161 }
183162
184163 async listDatabaseUsers ( options : FetchOptions < operations [ "listDatabaseUsers" ] > ) {
185- const { data } = await this . client . GET ( `/api/atlas/v2/groups/{groupId}/databaseUsers` , options ) ;
164+ const { data } = await this . client . GET ( "/api/atlas/v2/groups/{groupId}/databaseUsers" , options ) ;
165+ return data ;
166+ }
167+
168+ async createDatabaseUser ( options : FetchOptions < operations [ "createDatabaseUser" ] > ) {
169+ const { data } = await this . client . POST ( "/api/atlas/v2/groups/{groupId}/databaseUsers" , options ) ;
186170 return data ;
187171 }
172+ // DO NOT EDIT. This is auto-generated code.
188173}
0 commit comments