Skip to main content
Glama

MongoDB MCP Server

Official
by mongodb-js
createProject.ts2.57 kB
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js"; import { type OperationType, type ToolArgs } from "../../tool.js"; import { AtlasToolBase } from "../atlasTool.js"; import type { Group } from "../../../common/atlas/openapi.js"; import { AtlasArgs } from "../../args.js"; export class CreateProjectTool extends AtlasToolBase { public name = "atlas-create-project"; protected description = "Create a MongoDB Atlas project"; public operationType: OperationType = "create"; protected argsShape = { projectName: AtlasArgs.projectName().optional().describe("Name for the new project"), organizationId: AtlasArgs.organizationId().optional().describe("Organization ID for the new project"), }; protected async execute({ projectName, organizationId }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> { let assumedOrg = false; if (!projectName) { projectName = "Atlas Project"; } if (!organizationId) { try { const organizations = await this.session.apiClient.listOrgs(); if (!organizations?.results?.length) { throw new Error( "No organizations were found in your MongoDB Atlas account. Please create an organization first." ); } const firstOrg = organizations.results[0]; if (!firstOrg?.id) { throw new Error( "The first organization found does not have an ID. Please check your Atlas account." ); } organizationId = firstOrg.id; assumedOrg = true; } catch { throw new Error( "Could not search for organizations in your MongoDB Atlas account, please provide an organization ID or create one first." ); } } const input = { name: projectName, orgId: organizationId, } as Group; const group = await this.session.apiClient.createGroup({ body: input, }); if (!group?.id) { throw new Error("Failed to create project"); } return { content: [ { type: "text", text: `Project "${projectName}" created successfully${assumedOrg ? ` (using organizationId ${organizationId}).` : ""}.`, }, ], }; } }

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