Skip to content

Commit af779e1

Browse files
authored
feat: add org in atlas-list-projects (#120)
1 parent c2980a6 commit af779e1

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/tools/atlas/listProjects.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ 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
23+
.map((org) => [org.id || "", org.name])
24+
.reduce((acc, [id, name]) => ({ ...acc, [id]: name }), {});
25+
1626
const data = orgId
1727
? await this.session.apiClient.listOrganizationProjects({
1828
params: {
@@ -31,11 +41,11 @@ export class ListProjectsTool extends AtlasToolBase {
3141
const rows = data.results
3242
.map((project) => {
3343
const createdAt = project.created ? new Date(project.created).toLocaleString() : "N/A";
34-
return `${project.name} | ${project.id} | ${createdAt}`;
44+
return `${project.name} | ${project.id} | ${orgs[project.orgId]} | ${project.orgId} | ${createdAt}`;
3545
})
3646
.join("\n");
37-
const formattedProjects = `Project Name | Project ID | Created At
38-
----------------| ----------------| ----------------
47+
const formattedProjects = `Project Name | Project ID | Organization Name | Organization ID | Created At
48+
----------------| ----------------| ----------------| ----------------| ----------------
3949
${rows}`;
4050
return {
4151
content: [{ type: "text", text: formattedProjects }],

0 commit comments

Comments
 (0)