Skip to content

Commit 8ced988

Browse files
committed
refactor: copilot review feedback
1 parent 4bb5c19 commit 8ced988

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
"@types/express": "^5.0.3",
9898
"@types/node": "^24.5.2",
9999
"@types/proper-lockfile": "^4.1.4",
100-
"@types/react": "^18.0.0",
100+
"@types/react": "^18.3.0",
101101
"@types/react-dom": "^19.2.3",
102102
"@types/semver": "^7.7.0",
103103
"@types/yargs-parser": "^21.0.3",
@@ -152,8 +152,8 @@
152152
"node-machine-id": "1.1.12",
153153
"oauth4webapi": "^3.8.0",
154154
"openapi-fetch": "^0.15.0",
155-
"react": "^18.0.0",
156-
"react-dom": "^18.0.0",
155+
"react": "^18.3.0",
156+
"react-dom": "^18.3.0",
157157
"ts-levenshtein": "^1.0.7",
158158
"voyage-ai-provider": "^2.0.0",
159159
"zod": "^3.25.76"

src/ui/build/mount.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ const components: Record<string, React.ComponentType> = {};
1818
for (const [path, module] of Object.entries(componentModules)) {
1919
const match = path.match(/\.\.\/components\/([^/]+)\/index\.ts$/);
2020
if (match) {
21-
const componentName = match[1]!;
21+
const componentName = match[1];
22+
if (!componentName) continue;
2223
// The component should be exported with the same name as the folder
2324
const Component = module[componentName];
2425
if (Component) {

src/ui/registry/registry.ts

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,39 @@
11
import { readFileSync, existsSync } from "fs";
22
import { join, dirname } from "path";
3+
import { fileURLToPath } from "url";
34
import { uiMap } from "./uiMap.js";
45

6+
/**
7+
* Get the directory of the current module, works in both ESM and CJS.
8+
*/
9+
function getCurrentDir(): string {
10+
if (typeof __dirname !== "undefined") {
11+
return __dirname;
12+
}
13+
return dirname(fileURLToPath(import.meta.url));
14+
}
15+
16+
/**
17+
* Find the package root by looking for package.json walking up from the current directory.
18+
*/
19+
function findPackageRoot(startDir: string): string {
20+
let dir = startDir;
21+
while (dir !== dirname(dir)) {
22+
if (existsSync(join(dir, "package.json"))) {
23+
return dir;
24+
}
25+
dir = dirname(dir);
26+
}
27+
return process.cwd();
28+
}
29+
530
/**
631
* Get the default UI dist path by finding the package root.
732
*/
833
function getDefaultUIDistPath(): string {
9-
try {
10-
// eslint-disable-next-line @typescript-eslint/no-require-imports
11-
const packageJsonPath = require.resolve("mongodb-mcp-server/package.json");
12-
const packageRoot = dirname(packageJsonPath);
13-
return join(packageRoot, "dist", "ui");
14-
} catch {
15-
return join(process.cwd(), "dist", "ui");
16-
}
34+
const currentDir = getCurrentDir();
35+
const packageRoot = findPackageRoot(currentDir);
36+
return join(packageRoot, "dist", "ui");
1737
}
1838

1939
/**

0 commit comments

Comments
 (0)