|
| 1 | +#!/usr/bin/env node |
| 2 | +"use strict"; |
| 3 | +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { |
| 4 | + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } |
| 5 | + return new (P || (P = Promise))(function (resolve, reject) { |
| 6 | + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
| 7 | + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
| 8 | + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } |
| 9 | + step((generator = generator.apply(thisArg, _arguments || [])).next()); |
| 10 | + }); |
| 11 | +}; |
| 12 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 13 | +const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js"); |
| 14 | +const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js"); |
| 15 | +function wait(milliseconds) { |
| 16 | + return new Promise(resolve => setTimeout(resolve, milliseconds)); |
| 17 | +} |
| 18 | +const server = new mcp_js_1.McpServer({ |
| 19 | + name: "MongoDB Atlas", |
| 20 | + version: "1.0.0" |
| 21 | +}); |
| 22 | +var state = { |
| 23 | + auth: false, |
| 24 | +}; |
| 25 | +server.tool("auth", "Authenticate to atlas", (_a) => __awaiter(void 0, [_a], void 0, function* ({}) { |
| 26 | + yield wait(1000); |
| 27 | + setTimeout(() => { |
| 28 | + console.error("Authenticated"); |
| 29 | + state.auth = true; |
| 30 | + }, 10000); |
| 31 | + return { |
| 32 | + content: [{ type: "text", text: "Navigate to http://cloud.mongodb.com and input code A56T88." }], |
| 33 | + }; |
| 34 | +})); |
| 35 | +server.tool("list-clusters", "Lists clusters", (_a) => __awaiter(void 0, [_a], void 0, function* ({}) { |
| 36 | + yield wait(1000); |
| 37 | + if (!state.auth) { |
| 38 | + return { |
| 39 | + content: [{ type: "text", text: "Not authenticated" }], |
| 40 | + }; |
| 41 | + } |
| 42 | + const clusters = [ |
| 43 | + { name: "Cluster0", state: "IDLE", connectionString: "mongodb+srv://<username>:<password>@cluster0.mongodb.net/test" }, |
| 44 | + { name: "Cluster1", state: "IDLE", connectionString: "mongodb+srv://<username>:<password>@cluster1.mongodb.net/test" }, |
| 45 | + { name: "Cluster2", state: "IDLE", connectionString: "mongodb+srv://<username>:<password>@cluster2.mongodb.net/test" }, |
| 46 | + ]; |
| 47 | + const text = `Cluster Name | State | Connection String |
| 48 | +----------------|----------------|---------------- |
| 49 | +` + clusters.map(cluster => `${cluster.name} | ${cluster.state} | ${cluster.connectionString}`).join("\n"); |
| 50 | + return { |
| 51 | + content: [{ type: "text", text }], |
| 52 | + }; |
| 53 | +})); |
| 54 | +function runServer() { |
| 55 | + return __awaiter(this, void 0, void 0, function* () { |
| 56 | + const transport = new stdio_js_1.StdioServerTransport(); |
| 57 | + yield server.connect(transport); |
| 58 | + }); |
| 59 | +} |
| 60 | +runServer().catch((error) => { |
| 61 | + console.error("Fatal error running server:", error); |
| 62 | + process.exit(1); |
| 63 | +}); |
0 commit comments