Skip to content

Commit 55be4be

Browse files
committed
remove node-fetch
1 parent 14a5c0f commit 55be4be

File tree

8 files changed

+16
-248
lines changed

8 files changed

+16
-248
lines changed

dist/atlas-api.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { getToken } from "./auth.js";
22
import { log } from "./index.js";
3-
// Fetch polyfill for Node.js
4-
const fetchDynamic = async () => (await import("node-fetch")).default;
53
// Base URL for Atlas API
64
const BASE_URL = "https://cloud.mongodb.com/api/atlas/v2";
75
// Get project ID from environment variables or use a default value
@@ -24,13 +22,12 @@ export async function callAtlasAPI(endpoint, method = 'GET', body) {
2422
const url = `${BASE_URL}${endpoint}`;
2523
try {
2624
log("info", `Calling Atlas API: ${method} ${url}`);
27-
const fetch = await fetchDynamic();
2825
const response = await fetch(url, {
2926
method,
3027
headers: {
3128
'Authorization': `Bearer ${token}`,
3229
'Content-Type': 'application/json',
33-
'Accept': 'application/json'
30+
'Accept': 'application/vnd.atlas.2025-04-07+json'
3431
},
3532
body: body ? JSON.stringify(body) : undefined,
3633
});

dist/auth.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const __dirname = path.dirname(__filename);
99
const wait = (milliseconds) => {
1010
return new Promise(resolve => setTimeout(resolve, milliseconds));
1111
};
12-
const fetchDynamic = async () => (await import("node-fetch")).default;
1312
const TOKEN_FILE = path.resolve(__dirname, "token.json");
1413
export const authState = {
1514
deviceCode: "",
@@ -21,7 +20,7 @@ export async function authenticate() {
2120
log("info", "Starting authentication process...");
2221
const authUrl = "https://cloud.mongodb.com/api/private/unauth/account/device/authorize";
2322
log("info", `Client ID: ${authState.clientId}`);
24-
const deviceCodeResponse = await (await fetchDynamic())(authUrl, {
23+
const deviceCodeResponse = await fetch(authUrl, {
2524
method: "POST",
2625
headers: {
2726
"Content-Type": "application/x-www-form-urlencoded",
@@ -59,7 +58,7 @@ export async function pollToken() {
5958
const expiresAt = Date.now() + 2 * 60 * 1000;
6059
while (Date.now() < expiresAt) {
6160
await wait(interval);
62-
const OAuthToken = await (await fetchDynamic())(tokenEndpoint, {
61+
const OAuthToken = await fetch(tokenEndpoint, {
6362
method: "POST",
6463
headers: {
6564
"Content-Type": "application/x-www-form-urlencoded",
@@ -191,7 +190,7 @@ function validateToken(tokenData) {
191190
}
192191
async function refreshToken(token) {
193192
try {
194-
const response = await (await fetchDynamic())("https://cloud.mongodb.com/api/private/unauth/account/device/token", {
193+
const response = await fetch("https://cloud.mongodb.com/api/private/unauth/account/device/token", {
195194
method: "POST",
196195
headers: {
197196
"Content-Type": "application/x-www-form-urlencoded",
@@ -217,7 +216,7 @@ async function refreshToken(token) {
217216
}
218217
async function revokeToken(token) {
219218
try {
220-
const response = await (await fetchDynamic())("https://cloud.mongodb.com/api/private/unauth/account/device/revoke", {
219+
const response = await fetch("https://cloud.mongodb.com/api/private/unauth/account/device/revoke", {
221220
method: "POST",
222221
headers: {
223222
"Content-Type": "application/x-www-form-urlencoded",

dist/index.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
#!/usr/bin/env node
22
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
33
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4-
import dotenv from "dotenv";
54
import { defineTools } from "./tools.js";
6-
dotenv.config();
7-
function wait(milliseconds) {
8-
return new Promise(resolve => setTimeout(resolve, milliseconds));
9-
}
105
// Set process env version
116
process.env.VERSION = "1.0.0";
127
// Initialize server with logging capability
138
const server = new McpServer({
149
name: "MongoDB Atlas",
15-
version: process.env.VERSION,
10+
version: process.env.VERSION || "1.0.0",
1611
capabilities: {
1712
logging: { enabled: true },
1813
tools: { listChanged: false }

package-lock.json

Lines changed: 3 additions & 211 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
"zod": "^3.24.2"
2121
},
2222
"dependencies": {
23-
"@types/express": "^5.0.1",
24-
"dotenv": "^16.4.7",
25-
"node-fetch": "^3.3.2"
23+
"@types/express": "^5.0.1"
2624
}
2725
}

0 commit comments

Comments
 (0)