Skip to content

Commit 4fa5d6a

Browse files
committed
feat: add org in atlas-list-projects
1 parent 55618a6 commit 4fa5d6a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/tools/atlas/listProjects.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ export class ListProjectsTool extends AtlasToolBase {
1313
};
1414

1515
protected async execute({ orgId }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
16+
const orgData = await this.session.apiClient.listOrganizations();
17+
18+
if (!orgData?.results?.length) {
19+
throw new Error("No organizations found in your MongoDB Atlas account.");
20+
}
21+
22+
const orgs: Record<string, string> = orgData.results.map((org) => [org.id || "", org.name]).reduce((acc, [id, name]) => ({ ...acc, [id]: name }), {});
23+
1624
const data = orgId
1725
? await this.session.apiClient.listOrganizationProjects({
1826
params: {
@@ -31,11 +39,11 @@ export class ListProjectsTool extends AtlasToolBase {
3139
const rows = data.results
3240
.map((project) => {
3341
const createdAt = project.created ? new Date(project.created).toLocaleString() : "N/A";
34-
return `${project.name} | ${project.id} | ${createdAt}`;
42+
return `${project.name} | ${project.id} | ${orgs[project.orgId]} | ${project.orgId} | ${createdAt}`;
3543
})
3644
.join("\n");
37-
const formattedProjects = `Project Name | Project ID | Created At
38-
----------------| ----------------| ----------------
45+
const formattedProjects = `Project Name | Project ID | Organization Name | Organization ID | Created At
46+
----------------| ----------------| ----------------| ----------------| ----------------
3947
${rows}`;
4048
return {
4149
content: [{ type: "text", text: formattedProjects }],

0 commit comments

Comments
 (0)