atlas-list-projects
Retrieve a list of MongoDB Atlas projects to manage and organize your database resources. Filter by organization ID or view all projects for comprehensive oversight.
Instructions
List MongoDB Atlas projects
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| orgId | No | Atlas organization ID to filter projects. If not provided, projects for all orgs are returned. |
Implementation Reference
- Implements the core logic of the 'atlas-list-projects' tool: fetches organizations, retrieves projects (filtered by orgId if provided), formats and returns the list of projects with details like name, id, orgId, orgName, and created date.
protected async execute({ orgId }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> { const orgData = await this.session.apiClient.listOrgs(); if (!orgData?.results?.length) { return { content: [{ type: "text", text: "No organizations found in your MongoDB Atlas account." }], }; } const orgs: Record<string, string> = orgData.results .filter((org) => org.id) // eslint-disable-next-line @typescript-eslint/no-non-null-assertion .reduce((acc, org) => ({ ...acc, [org.id!]: org.name }), {}); const data = orgId ? await this.session.apiClient.getOrgGroups({ params: { path: { orgId, }, }, }) : await this.session.apiClient.listGroups(); if (!data?.results?.length) { return { content: [{ type: "text", text: `No projects found in organization ${orgId}.` }], }; } const serializedProjects = JSON.stringify( data.results.map((project) => ({ name: project.name, id: project.id, orgId: project.orgId, orgName: orgs[project.orgId] ?? "N/A", created: project.created ? new Date(project.created).toLocaleString() : "N/A", })), null, 2 ); return { content: formatUntrustedData(`Found ${data.results.length} projects`, serializedProjects), }; } - Defines the input schema for the tool, with an optional 'orgId' parameter for filtering projects by organization.
protected argsShape = { orgId: AtlasArgs.organizationId() .describe("Atlas organization ID to filter projects. If not provided, projects for all orgs are returned.") .optional(), }; - src/tools/atlas/read/listProjects.ts:8-9 (registration)Declares the ListProjectsTool class with the tool name 'atlas-list-projects', which is used during registration in the MCP server via generic tool registration in src/server.ts.
export class ListProjectsTool extends AtlasToolBase { public name = "atlas-list-projects"; - src/tools/atlas/tools.ts:2-2 (registration)Re-exports ListProjectsTool for inclusion in the atlas tools module, which is then aggregated into AllTools for server registration.
export { ListProjectsTool } from "./read/listProjects.js"; - src/tools/index.ts:7-11 (registration)Aggregates all tools including AtlasTools (which includes ListProjectsTool) into AllTools array, used by the server for instantiating and registering all tools.
export const AllTools: ToolClass[] = Object.values({ ...MongoDbTools, ...AtlasTools, ...AtlasLocalTools, });