Skip to content

Commit 69f1216

Browse files
authored
Merge pull request #839 from cliffhall/fix-cli-package.json-import
Fix cli package.json import
2 parents 901d10c + 19a7d37 commit 69f1216

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

cli/src/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env node
22

3+
import * as fs from "fs";
34
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
45
import { Command } from "commander";
56
import {
@@ -31,8 +32,6 @@ type JsonValue =
3132
| JsonValue[]
3233
| { [key: string]: JsonValue };
3334

34-
import packageJson from "../package.json" with { type: "json" };
35-
3635
type Args = {
3736
target: string[];
3837
method?: string;
@@ -101,6 +100,15 @@ function createTransportOptions(
101100
}
102101

103102
async function callMethod(args: Args): Promise<void> {
103+
// Read package.json to get name and version for client identity
104+
const pathA = "../package.json"; // We're in package @modelcontextprotocol/inspector-cli
105+
const pathB = "../../package.json"; // We're in package @modelcontextprotocol/inspector
106+
let packageJson: { name: string; version: string };
107+
let packageJsonData = await import(fs.existsSync(pathA) ? pathA : pathB, {
108+
with: { type: "json" },
109+
});
110+
packageJson = packageJsonData.default;
111+
104112
const transportOptions = createTransportOptions(
105113
args.target,
106114
args.transport,

0 commit comments

Comments
 (0)