Skip to main content
Glama

MongoDB MCP Server

Official
by mongodb-js
connectDeployment.ts1.71 kB
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js"; import { AtlasLocalToolBase } from "../atlasLocalTool.js"; import type { OperationType, ToolArgs } from "../../tool.js"; import type { Client } from "@mongodb-js/atlas-local"; import { CommonArgs } from "../../args.js"; import type { ConnectionMetadata } from "../../../telemetry/types.js"; export class ConnectDeploymentTool extends AtlasLocalToolBase { public name = "atlas-local-connect-deployment"; protected description = "Connect to a MongoDB Atlas Local deployment"; public operationType: OperationType = "connect"; protected argsShape = { deploymentName: CommonArgs.string().describe("Name of the deployment to connect to"), }; protected async executeWithAtlasLocalClient( client: Client, { deploymentName }: ToolArgs<typeof this.argsShape> ): Promise<CallToolResult> { // Get the connection string for the deployment const connectionString = await client.getConnectionString(deploymentName); // Connect to the deployment await this.session.connectToMongoDB({ connectionString }); return { content: [ { type: "text", text: `Successfully connected to Atlas Local deployment "${deploymentName}".`, }, ], _meta: { ...(await this.lookupTelemetryMetadata(client, deploymentName)), }, }; } protected override resolveTelemetryMetadata(result: CallToolResult): ConnectionMetadata { return { ...super.resolveTelemetryMetadata(result), ...this.getConnectionInfoMetadata() }; } }

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