Skip to content

Commit 6db66d4

Browse files
committed
fix checks
1 parent 6dcf1fb commit 6db66d4

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

src/common/atlas/cluster.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ export function formatCluster(cluster: ClusterDescription20240805): Cluster {
5050
};
5151
});
5252

53-
const instanceSize = (regionConfigs.length <= 0 ? undefined : regionConfigs[0].instanceSize) || "UNKNOWN";
53+
const instanceSize =
54+
regionConfigs.length > 0 && regionConfigs[0]?.instanceSize ? regionConfigs[0].instanceSize : "UNKNOWN";
5455

5556
const clusterInstanceType = instanceSize == "M0" ? "FREE" : "DEDICATED";
5657

src/tools/atlas/create/createProject.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ export class CreateProjectTool extends AtlasToolBase {
2828
"No organizations were found in your MongoDB Atlas account. Please create an organization first."
2929
);
3030
}
31-
organizationId = organizations.results[0].id;
31+
const firstOrg = organizations.results[0];
32+
if (!firstOrg?.id) {
33+
throw new Error(
34+
"The first organization found does not have an ID. Please check your Atlas account."
35+
);
36+
}
37+
organizationId = firstOrg.id;
3238
assumedOrg = true;
3339
} catch {
3440
throw new Error(

src/tools/atlas/read/listProjects.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export class ListProjectsTool extends AtlasToolBase {
2121

2222
const orgs: Record<string, string> = orgData.results
2323
.map((org) => [org.id || "", org.name])
24-
.reduce((acc, [id, name]) => ({ ...acc, [id]: name }), {});
24+
.filter(([id]) => id)
25+
.reduce((acc, [id, name]) => ({ ...acc, [id as string]: name }), {});
2526

2627
const data = orgId
2728
? await this.session.apiClient.listOrganizationProjects({
@@ -41,7 +42,8 @@ export class ListProjectsTool extends AtlasToolBase {
4142
const rows = data.results
4243
.map((project) => {
4344
const createdAt = project.created ? new Date(project.created).toLocaleString() : "N/A";
44-
return `${project.name} | ${project.id} | ${orgs[project.orgId]} | ${project.orgId} | ${createdAt}`;
45+
const orgName = project.orgId && orgs[project.orgId] ? orgs[project.orgId] : "N/A";
46+
return `${project.name} | ${project.id} | ${orgName} | ${project.orgId} | ${createdAt}`;
4547
})
4648
.join("\n");
4749
const formattedProjects = `Project Name | Project ID | Organization Name | Organization ID | Created At

src/tools/tool.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ export abstract class ToolBase {
9393
this.update = (updates: { name?: string; description?: string; inputSchema?: AnyZodObject }) => {
9494
const tools = server["_registeredTools"] as { [toolName: string]: RegisteredTool };
9595
const existingTool = tools[this.name];
96+
if (!existingTool) {
97+
// Optionally, throw or log an error here
98+
return;
99+
}
96100
existingTool.annotations = this.annotations;
97101

98102
if (updates.name && updates.name !== this.name) {

tsconfig.build.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"outDir": "./dist",
88
"strict": true,
99
"strictNullChecks": true,
10+
"noUncheckedIndexedAccess": true,
1011
"esModuleInterop": true,
1112
"types": ["node"],
1213
"sourceMap": true,

0 commit comments

Comments
 (0)