Depending upon whether it is being invoked from the npm package @modelcontextprotocol/inspector or @modelcontextprotocol/inspector-cli the location of package.json will either be in ../ or ../../
* In cli/src/index.ts - load package.json from the parent folder or parent's parent depending on file existence in parent. - move the load of package.json into callMethod function, which is the only place it is used, and is closer to where it is referenced.
This commit is contained in:
parent
6e27b5d530
commit
19a7d3752c
1 changed files with 10 additions and 2 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
import * as fs from "fs";
|
||||||
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
||||||
import { Command } from "commander";
|
import { Command } from "commander";
|
||||||
import {
|
import {
|
||||||
|
|
@ -31,8 +32,6 @@ type JsonValue =
|
||||||
| JsonValue[]
|
| JsonValue[]
|
||||||
| { [key: string]: JsonValue };
|
| { [key: string]: JsonValue };
|
||||||
|
|
||||||
import packageJson from "../../package.json" with { type: "json" };
|
|
||||||
|
|
||||||
type Args = {
|
type Args = {
|
||||||
target: string[];
|
target: string[];
|
||||||
method?: string;
|
method?: string;
|
||||||
|
|
@ -101,6 +100,15 @@ function createTransportOptions(
|
||||||
}
|
}
|
||||||
|
|
||||||
async function callMethod(args: Args): Promise<void> {
|
async function callMethod(args: Args): Promise<void> {
|
||||||
|
// Read package.json to get name and version for client identity
|
||||||
|
const pathA = "../package.json"; // We're in package @modelcontextprotocol/inspector-cli
|
||||||
|
const pathB = "../../package.json"; // We're in package @modelcontextprotocol/inspector
|
||||||
|
let packageJson: { name: string; version: string };
|
||||||
|
let packageJsonData = await import(fs.existsSync(pathA) ? pathA : pathB, {
|
||||||
|
with: { type: "json" },
|
||||||
|
});
|
||||||
|
packageJson = packageJsonData.default;
|
||||||
|
|
||||||
const transportOptions = createTransportOptions(
|
const transportOptions = createTransportOptions(
|
||||||
args.target,
|
args.target,
|
||||||
args.transport,
|
args.transport,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue