Skip to content

feat: add org in atlas-list-projects #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/tools/atlas/listProjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ export class ListProjectsTool extends AtlasToolBase {
};

protected async execute({ orgId }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
const orgData = await this.session.apiClient.listOrganizations();

if (!orgData?.results?.length) {
throw new Error("No organizations found in your MongoDB Atlas account.");
}

const orgs: Record<string, string> = orgData.results
.map((org) => [org.id || "", org.name])
.reduce((acc, [id, name]) => ({ ...acc, [id]: name }), {});

const data = orgId
? await this.session.apiClient.listOrganizationProjects({
params: {
Expand All @@ -31,11 +41,11 @@ export class ListProjectsTool extends AtlasToolBase {
const rows = data.results
.map((project) => {
const createdAt = project.created ? new Date(project.created).toLocaleString() : "N/A";
return `${project.name} | ${project.id} | ${createdAt}`;
return `${project.name} | ${project.id} | ${orgs[project.orgId]} | ${project.orgId} | ${createdAt}`;
})
.join("\n");
const formattedProjects = `Project Name | Project ID | Created At
----------------| ----------------| ----------------
const formattedProjects = `Project Name | Project ID | Organization Name | Organization ID | Created At
----------------| ----------------| ----------------| ----------------| ----------------
${rows}`;
return {
content: [{ type: "text", text: formattedProjects }],
Expand Down
Loading