Skip to content

Commit 42aa95b

Browse files
authored
Merge pull request #544 from richardkmichael/accurate-cli-version
fix: hard-coded CLI inspector version
2 parents 92d1665 + 32ea112 commit 42aa95b

File tree

4 files changed

+31
-21
lines changed

4 files changed

+31
-21
lines changed

cli/src/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ type JsonValue =
3131
| JsonValue[]
3232
| { [key: string]: JsonValue };
3333

34+
import packageJson from "../package.json" with { type: "json" };
35+
3436
type Args = {
3537
target: string[];
3638
method?: string;
@@ -105,10 +107,12 @@ async function callMethod(args: Args): Promise<void> {
105107
args.headers,
106108
);
107109
const transport = createTransport(transportOptions);
108-
const client = new Client({
109-
name: "inspector-cli",
110-
version: "0.5.1",
111-
});
110+
111+
const [, name = packageJson.name] = packageJson.name.split("/");
112+
const version = packageJson.version;
113+
const clientIdentity = { name, version };
114+
115+
const client = new Client(clientIdentity);
112116

113117
try {
114118
await connect(client, transport);

client/src/lib/constants.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
import { InspectorConfig } from "./configurationTypes";
2+
import packageJson from "../../package.json";
3+
4+
// Client identity for MCP connections
5+
export const CLIENT_IDENTITY = (() => {
6+
const [, name = packageJson.name] = packageJson.name.split("/");
7+
const version = packageJson.version;
8+
return { name, version };
9+
})();
210

311
// OAuth-related session storage keys
412
export const SESSION_KEYS = {

client/src/lib/hooks/__tests__/useConnection.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { renderHook, act } from "@testing-library/react";
22
import { useConnection } from "../useConnection";
33
import { z } from "zod";
44
import { ClientRequest } from "@modelcontextprotocol/sdk/types.js";
5-
import { DEFAULT_INSPECTOR_CONFIG } from "../../constants";
5+
import { DEFAULT_INSPECTOR_CONFIG, CLIENT_IDENTITY } from "../../constants";
66
import {
77
SSEClientTransportOptions,
88
SseError,
@@ -251,8 +251,8 @@ describe("useConnection", () => {
251251

252252
expect(Client).toHaveBeenCalledWith(
253253
expect.objectContaining({
254-
name: "mcp-inspector",
255-
version: expect.any(String),
254+
name: CLIENT_IDENTITY.name,
255+
version: CLIENT_IDENTITY.version,
256256
}),
257257
expect.objectContaining({
258258
capabilities: expect.objectContaining({

client/src/lib/hooks/useConnection.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
3535
import { useEffect, useState } from "react";
3636
import { useToast } from "@/lib/hooks/useToast";
3737
import { z } from "zod";
38-
import { ConnectionStatus } from "../constants";
38+
import { ConnectionStatus, CLIENT_IDENTITY } from "../constants";
3939
import { Notification } from "../notificationTypes";
4040
import {
4141
auth,
@@ -47,7 +47,6 @@ import {
4747
saveClientInformationToSessionStorage,
4848
discoverScopes,
4949
} from "../auth";
50-
import packageJson from "../../../package.json";
5150
import {
5251
getMCPProxyAddress,
5352
getMCPServerRequestMaxTotalTimeout,
@@ -364,20 +363,19 @@ export function useConnection({
364363
};
365364

366365
const connect = async (_e?: unknown, retryCount: number = 0) => {
367-
const client = new Client<Request, Notification, Result>(
368-
{
369-
name: "mcp-inspector",
370-
version: packageJson.version,
371-
},
372-
{
373-
capabilities: {
374-
sampling: {},
375-
elicitation: {},
376-
roots: {
377-
listChanged: true,
378-
},
366+
const clientCapabilities = {
367+
capabilities: {
368+
sampling: {},
369+
elicitation: {},
370+
roots: {
371+
listChanged: true,
379372
},
380373
},
374+
};
375+
376+
const client = new Client<Request, Notification, Result>(
377+
CLIENT_IDENTITY,
378+
clientCapabilities,
381379
);
382380

383381
// Only check proxy health for proxy connections

0 commit comments

Comments
 (0)