@cityjson/cj-mcp 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
3
  import { existsSync } from "node:fs";
4
- import { dirname, resolve, join } from "node:path";
4
+ import { dirname, join, resolve } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
7
7
  import { z } from "zod";
@@ -9,17 +9,30 @@ import { readFile } from "node:fs/promises";
9
9
  const SERVER_NAME = "cityjson-spec-mcp-server";
10
10
  const SERVER_VERSION = "0.1.0";
11
11
  const DEFAULT_HTTP_PORT = 3e3;
12
- function findProjectRoot(startDir) {
13
- let current = startDir;
12
+ function findSpecsPath(packageDir) {
13
+ if (process.env.CITYJSON_SPECS_PATH) {
14
+ return process.env.CITYJSON_SPECS_PATH;
15
+ }
16
+ const packageRoot = dirname(packageDir);
17
+ const packageSpecsPath = join(packageRoot, "specs");
18
+ if (existsSync(packageSpecsPath)) {
19
+ return packageSpecsPath;
20
+ }
21
+ let current = packageDir;
14
22
  while (current !== "/" && !existsSync(resolve(current, "pnpm-workspace.yaml"))) {
15
23
  current = dirname(current);
16
24
  }
17
- return current;
25
+ if (current !== "/") {
26
+ const workspaceSpecsPath = join(current, "specs");
27
+ if (existsSync(workspaceSpecsPath)) {
28
+ return workspaceSpecsPath;
29
+ }
30
+ }
31
+ return packageSpecsPath;
18
32
  }
19
33
  function loadConfig() {
20
34
  const __dirname = dirname(fileURLToPath(import.meta.url));
21
- const projectRoot = findProjectRoot(__dirname);
22
- const specsPath = process.env.CITYJSON_SPECS_PATH || resolve(projectRoot, "specs");
35
+ const specsPath = findSpecsPath(__dirname);
23
36
  const transport = process.env.TRANSPORT || "stdio";
24
37
  const httpPort = process.env.PORT ? Number.parseInt(process.env.PORT, 10) : DEFAULT_HTTP_PORT;
25
38
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityjson/cj-mcp",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "MCP server for querying CityJSON specification chapters",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/src/config.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
  import { existsSync } from "node:fs";
6
- import { dirname, resolve } from "node:path";
6
+ import { dirname, join, resolve } from "node:path";
7
7
  import { fileURLToPath } from "node:url";
8
8
  import { DEFAULT_HTTP_PORT, SERVER_NAME, SERVER_VERSION } from "./constants.js";
9
9
 
@@ -16,14 +16,39 @@ export interface ServerConfig {
16
16
  }
17
17
 
18
18
  /**
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
20
23
  */
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;
23
40
  while (current !== "/" && !existsSync(resolve(current, "pnpm-workspace.yaml"))) {
24
41
  current = dirname(current);
25
42
  }
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;
27
52
  }
28
53
 
29
54
  /**
@@ -31,9 +56,7 @@ function findProjectRoot(startDir: string): string {
31
56
  */
32
57
  export function loadConfig(): ServerConfig {
33
58
  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);
37
60
  const transport = (process.env.TRANSPORT as "stdio" | "http") || "stdio";
38
61
  const httpPort = process.env.PORT ? Number.parseInt(process.env.PORT, 10) : DEFAULT_HTTP_PORT;
39
62