Skip to content

Commit 01b9b77

Browse files
committed
feat: Implement robust specs directory discovery and bump package version.
1 parent 48560c9 commit 01b9b77

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

packages/mcp-server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cityjson/cj-mcp",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "MCP server for querying CityJSON specification chapters",
55
"type": "module",
66
"main": "dist/index.js",

packages/mcp-server/src/config.ts

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
import { existsSync } from "node:fs";
6-
import { dirname, resolve } from "node:path";
6+
import { dirname, join, resolve } from "node:path";
77
import { fileURLToPath } from "node:url";
88
import { DEFAULT_HTTP_PORT, SERVER_NAME, SERVER_VERSION } from "./constants.js";
99

@@ -16,24 +16,47 @@ export interface ServerConfig {
1616
}
1717

1818
/**
19-
* Find project root by looking for pnpm-workspace.yaml
19+
* Find specs directory by checking multiple locations:
20+
* 1. Environment variable CITYJSON_SPECS_PATH
21+
* 2. Relative to package (for npm install): <package>/specs
22+
* 3. Relative to workspace root (for development): <workspace>/specs
2023
*/
21-
function findProjectRoot(startDir: string): string {
22-
let current = startDir;
24+
function findSpecsPath(packageDir: string): string {
25+
// Check environment variable first
26+
if (process.env.CITYJSON_SPECS_PATH) {
27+
return process.env.CITYJSON_SPECS_PATH;
28+
}
29+
30+
// Check relative to package (npm install case)
31+
// dist/index.js -> package root -> specs
32+
const packageRoot = dirname(packageDir);
33+
const packageSpecsPath = join(packageRoot, "specs");
34+
if (existsSync(packageSpecsPath)) {
35+
return packageSpecsPath;
36+
}
37+
38+
// Check relative to workspace root (development case)
39+
let current = packageDir;
2340
while (current !== "/" && !existsSync(resolve(current, "pnpm-workspace.yaml"))) {
2441
current = dirname(current);
2542
}
26-
return current;
43+
if (current !== "/") {
44+
const workspaceSpecsPath = join(current, "specs");
45+
if (existsSync(workspaceSpecsPath)) {
46+
return workspaceSpecsPath;
47+
}
48+
}
49+
50+
// Fallback to package relative path
51+
return packageSpecsPath;
2752
}
2853

2954
/**
3055
* Load configuration from environment variables
3156
*/
3257
export function loadConfig(): ServerConfig {
3358
const __dirname = dirname(fileURLToPath(import.meta.url));
34-
const projectRoot = findProjectRoot(__dirname);
35-
36-
const specsPath = process.env.CITYJSON_SPECS_PATH || resolve(projectRoot, "specs");
59+
const specsPath = findSpecsPath(__dirname);
3760
const transport = (process.env.TRANSPORT as "stdio" | "http") || "stdio";
3861
const httpPort = process.env.PORT ? Number.parseInt(process.env.PORT, 10) : DEFAULT_HTTP_PORT;
3962

0 commit comments

Comments
 (0)