Skip to main content
Glama

MongoDB MCP Server

Official
by mongodb-js
debug.test.ts5.14 kB
import { beforeEach, describe, expect, it, vi } from "vitest"; import { DebugResource } from "../../../../src/resources/common/debug.js"; import { Session } from "../../../../src/common/session.js"; import { Telemetry } from "../../../../src/telemetry/telemetry.js"; import { config } from "../../../../src/common/config.js"; import { driverOptions } from "../../../integration/helpers.js"; import { CompositeLogger } from "../../../../src/common/logger.js"; import { MCPConnectionManager } from "../../../../src/common/connectionManager.js"; import { ExportsManager } from "../../../../src/common/exportsManager.js"; import { DeviceId } from "../../../../src/helpers/deviceId.js"; import { Keychain } from "../../../../src/common/keychain.js"; import { VectorSearchEmbeddingsManager } from "../../../../src/common/search/vectorSearchEmbeddingsManager.js"; describe("debug resource", () => { const logger = new CompositeLogger(); const deviceId = DeviceId.create(logger); const connectionManager = new MCPConnectionManager(config, driverOptions, logger, deviceId); const session = vi.mocked( new Session({ apiBaseUrl: "", logger, exportsManager: ExportsManager.init(config, logger), connectionManager, keychain: new Keychain(), vectorSearchEmbeddingsManager: new VectorSearchEmbeddingsManager(config, connectionManager), }) ); const telemetry = Telemetry.create(session, { ...config, telemetry: "disabled" }, deviceId); let debugResource: DebugResource = new DebugResource(session, config, telemetry); beforeEach(() => { debugResource = new DebugResource(session, config, telemetry); }); it("should be connected when a connected event happens", async () => { debugResource.reduceApply("connect", undefined); const output = await debugResource.toOutput(); expect(output).toContain( `The user is connected to the MongoDB cluster without any support for search indexes.` ); }); it("should be disconnected when a disconnect event happens", async () => { debugResource.reduceApply("disconnect", undefined); const output = await debugResource.toOutput(); expect(output).toContain(`The user is not connected to a MongoDB cluster.`); }); it("should be disconnected when a close event happens", async () => { debugResource.reduceApply("close", undefined); const output = await debugResource.toOutput(); expect(output).toContain(`The user is not connected to a MongoDB cluster.`); }); it("should be disconnected and contain an error when an error event occurred", async () => { debugResource.reduceApply("connection-error", { tag: "errored", errorReason: "Error message from the server", }); const output = await debugResource.toOutput(); expect(output).toContain(`The user is not connected to a MongoDB cluster because of an error.`); expect(output).toContain(`<error>Error message from the server</error>`); }); it("should show the inferred authentication type", async () => { debugResource.reduceApply("connection-error", { tag: "errored", connectionStringAuthType: "scram", errorReason: "Error message from the server", }); const output = await debugResource.toOutput(); expect(output).toContain(`The user is not connected to a MongoDB cluster because of an error.`); expect(output).toContain(`The inferred authentication mechanism is "scram".`); expect(output).toContain(`<error>Error message from the server</error>`); }); it("should show the atlas cluster information when provided", async () => { debugResource.reduceApply("connection-error", { tag: "errored", connectionStringAuthType: "scram", errorReason: "Error message from the server", connectedAtlasCluster: { clusterName: "My Test Cluster", projectId: "COFFEEFABADA", username: "", expiryDate: new Date(), }, }); const output = await debugResource.toOutput(); expect(output).toContain(`The user is not connected to a MongoDB cluster because of an error.`); expect(output).toContain( `Attempted connecting to Atlas Cluster "My Test Cluster" in project with id "COFFEEFABADA".` ); expect(output).toContain(`The inferred authentication mechanism is "scram".`); expect(output).toContain(`<error>Error message from the server</error>`); }); it("should notify if a cluster supports search indexes", async () => { vi.spyOn(session, "isSearchSupported").mockImplementation(() => Promise.resolve(true)); debugResource.reduceApply("connect", undefined); const output = await debugResource.toOutput(); expect(output).toContain(`The user is connected to the MongoDB cluster with support for search indexes.`); }); });

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mongodb-js/mongodb-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server