@mcpjam/inspector 1.0.18 → 1.0.19
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/client/index.html
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<link rel="icon" type="image/svg+xml" href="/mcp_jam.svg" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<title>MCPJam Inspector</title>
|
|
8
|
-
<script type="module" crossorigin src="/assets/index-
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-Bf9F3wwu.js"></script>
|
|
9
9
|
<link rel="stylesheet" crossorigin href="/assets/index-DkqfjygH.css">
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|
package/dist/server/index.js
CHANGED
|
@@ -172,43 +172,52 @@ var MCPClientManager = class {
|
|
|
172
172
|
getServerSummaries() {
|
|
173
173
|
return Array.from(this.clientStates.entries()).map(([serverId, state]) => ({
|
|
174
174
|
id: serverId,
|
|
175
|
-
status: this.
|
|
175
|
+
status: this.getConnectionStatusByAttemptingPing(serverId),
|
|
176
176
|
config: state.config
|
|
177
177
|
}));
|
|
178
178
|
}
|
|
179
|
-
|
|
180
|
-
|
|
179
|
+
getConnectionStatusByAttemptingPing(serverId) {
|
|
180
|
+
const state = this.clientStates.get(serverId);
|
|
181
|
+
if (state == null ? void 0 : state.promise) {
|
|
182
|
+
return "connecting";
|
|
183
|
+
}
|
|
184
|
+
const client = state == null ? void 0 : state.client;
|
|
185
|
+
if (!client) {
|
|
186
|
+
return "disconnected";
|
|
187
|
+
}
|
|
188
|
+
try {
|
|
189
|
+
client.ping();
|
|
190
|
+
return "connected";
|
|
191
|
+
} catch (error) {
|
|
192
|
+
return "disconnected";
|
|
193
|
+
}
|
|
181
194
|
}
|
|
182
195
|
getServerConfig(serverId) {
|
|
183
196
|
var _a2;
|
|
184
197
|
return (_a2 = this.clientStates.get(serverId)) == null ? void 0 : _a2.config;
|
|
185
198
|
}
|
|
186
199
|
async connectToServer(serverId, config) {
|
|
187
|
-
|
|
188
|
-
|
|
200
|
+
const timeout = this.getTimeout(config);
|
|
201
|
+
const existingState = this.clientStates.get(serverId);
|
|
202
|
+
if (existingState == null ? void 0 : existingState.client) {
|
|
189
203
|
throw new Error(`MCP server "${serverId}" is already connected.`);
|
|
190
204
|
}
|
|
191
|
-
const
|
|
192
|
-
const state = (_a2 = this.clientStates.get(serverId)) != null ? _a2 : {
|
|
205
|
+
const state = existingState != null ? existingState : {
|
|
193
206
|
config,
|
|
194
207
|
timeout
|
|
195
208
|
};
|
|
196
209
|
state.config = config;
|
|
197
210
|
state.timeout = timeout;
|
|
198
|
-
if (state.client) {
|
|
199
|
-
this.clientStates.set(serverId, state);
|
|
200
|
-
return state.client;
|
|
201
|
-
}
|
|
202
211
|
if (state.promise) {
|
|
203
212
|
this.clientStates.set(serverId, state);
|
|
204
213
|
return state.promise;
|
|
205
214
|
}
|
|
206
215
|
const connectionPromise = (async () => {
|
|
207
|
-
var
|
|
216
|
+
var _a2;
|
|
208
217
|
const client = new Client(
|
|
209
218
|
{
|
|
210
219
|
name: this.defaultClientName ? `${this.defaultClientName}` : serverId,
|
|
211
|
-
version: (
|
|
220
|
+
version: (_a2 = config.version) != null ? _a2 : this.defaultClientVersion
|
|
212
221
|
},
|
|
213
222
|
{
|
|
214
223
|
capabilities: this.buildCapabilities(config)
|
|
@@ -218,8 +227,8 @@ var MCPClientManager = class {
|
|
|
218
227
|
this.applyElicitationHandler(serverId, client);
|
|
219
228
|
if (config.onError) {
|
|
220
229
|
client.onerror = (error) => {
|
|
221
|
-
var
|
|
222
|
-
(
|
|
230
|
+
var _a22;
|
|
231
|
+
(_a22 = config.onError) == null ? void 0 : _a22.call(config, error);
|
|
223
232
|
};
|
|
224
233
|
}
|
|
225
234
|
client.onclose = () => {
|
|
@@ -247,10 +256,7 @@ var MCPClientManager = class {
|
|
|
247
256
|
this.clientStates.set(serverId, state);
|
|
248
257
|
return client;
|
|
249
258
|
})().catch((error) => {
|
|
250
|
-
|
|
251
|
-
state.client = void 0;
|
|
252
|
-
state.transport = void 0;
|
|
253
|
-
this.clientStates.set(serverId, state);
|
|
259
|
+
this.resetState(serverId);
|
|
254
260
|
throw error;
|
|
255
261
|
});
|
|
256
262
|
state.promise = connectionPromise;
|
|
@@ -258,6 +264,10 @@ var MCPClientManager = class {
|
|
|
258
264
|
return connectionPromise;
|
|
259
265
|
}
|
|
260
266
|
async disconnectServer(serverId) {
|
|
267
|
+
const connectionStatus = this.getConnectionStatusByAttemptingPing(serverId);
|
|
268
|
+
if (connectionStatus !== "connected") {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
261
271
|
const client = this.getClientById(serverId);
|
|
262
272
|
try {
|
|
263
273
|
await client.close();
|
|
@@ -1004,7 +1014,7 @@ servers.get("/status/:serverId", async (c) => {
|
|
|
1004
1014
|
try {
|
|
1005
1015
|
const serverId = c.req.param("serverId");
|
|
1006
1016
|
const mcpClientManager2 = c.mcpClientManager;
|
|
1007
|
-
const status = mcpClientManager2.
|
|
1017
|
+
const status = mcpClientManager2.getConnectionStatusByAttemptingPing(serverId);
|
|
1008
1018
|
return c.json({
|
|
1009
1019
|
success: true,
|
|
1010
1020
|
serverId,
|
|
@@ -1075,15 +1085,9 @@ servers.post("/reconnect", async (c) => {
|
|
|
1075
1085
|
normalizedConfig.url = new URL(urlValue.href);
|
|
1076
1086
|
}
|
|
1077
1087
|
}
|
|
1078
|
-
|
|
1079
|
-
const client = mcpClientManager2.getClient(serverId);
|
|
1080
|
-
if (client) {
|
|
1081
|
-
await mcpClientManager2.disconnectServer(serverId);
|
|
1082
|
-
}
|
|
1083
|
-
} catch {
|
|
1084
|
-
}
|
|
1088
|
+
await mcpClientManager2.disconnectServer(serverId);
|
|
1085
1089
|
await mcpClientManager2.connectToServer(serverId, normalizedConfig);
|
|
1086
|
-
const status = mcpClientManager2.
|
|
1090
|
+
const status = mcpClientManager2.getConnectionStatusByAttemptingPing(serverId);
|
|
1087
1091
|
const message = status === "connected" ? `Reconnected to server: ${serverId}` : `Server ${serverId} reconnected with status '${status}'`;
|
|
1088
1092
|
const success = status === "connected";
|
|
1089
1093
|
return c.json({
|
|
@@ -2442,10 +2446,6 @@ var handleAgentStepFinish = (streamingContext, text, toolCalls, toolResults, emi
|
|
|
2442
2446
|
streamingContext.lastEmittedToolCallId = currentToolCallId;
|
|
2443
2447
|
const toolName = call.name || call.toolName;
|
|
2444
2448
|
streamingContext.toolCallIdToName.set(currentToolCallId, toolName);
|
|
2445
|
-
if (!streamingContext.toolNameToCallIds.has(toolName)) {
|
|
2446
|
-
streamingContext.toolNameToCallIds.set(toolName, []);
|
|
2447
|
-
}
|
|
2448
|
-
streamingContext.toolNameToCallIds.get(toolName).push(currentToolCallId);
|
|
2449
2449
|
if (streamingContext.controller && streamingContext.encoder) {
|
|
2450
2450
|
sendSseEvent(
|
|
2451
2451
|
streamingContext.controller,
|
|
@@ -2587,10 +2587,6 @@ var createStreamingResponse = async (model, aiSdkTools, messages, streamingConte
|
|
|
2587
2587
|
const name = chunk.chunk.toolName || chunk.chunk.name;
|
|
2588
2588
|
const parameters = chunk.chunk.input ?? chunk.chunk.parameters ?? chunk.chunk.args ?? {};
|
|
2589
2589
|
streamingContext.toolCallIdToName.set(currentToolCallId, name);
|
|
2590
|
-
if (!streamingContext.toolNameToCallIds.has(name)) {
|
|
2591
|
-
streamingContext.toolNameToCallIds.set(name, []);
|
|
2592
|
-
}
|
|
2593
|
-
streamingContext.toolNameToCallIds.get(name).push(currentToolCallId);
|
|
2594
2590
|
iterationToolCalls.push({ name, params: parameters });
|
|
2595
2591
|
sendSseEvent(
|
|
2596
2592
|
streamingContext.controller,
|
|
@@ -2610,36 +2606,9 @@ var createStreamingResponse = async (model, aiSdkTools, messages, streamingConte
|
|
|
2610
2606
|
}
|
|
2611
2607
|
case "tool-result": {
|
|
2612
2608
|
const result = chunk.chunk.output ?? chunk.chunk.result ?? chunk.chunk.value;
|
|
2613
|
-
const
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
const queue = streamingContext.toolNameToCallIds.get(toolName);
|
|
2617
|
-
if (queue && queue.length > 0) {
|
|
2618
|
-
currentToolCallId = queue.shift();
|
|
2619
|
-
}
|
|
2620
|
-
}
|
|
2621
|
-
if (!currentToolCallId && streamingContext.lastEmittedToolCallId) {
|
|
2622
|
-
currentToolCallId = streamingContext.lastEmittedToolCallId;
|
|
2623
|
-
}
|
|
2624
|
-
if (!currentToolCallId) {
|
|
2625
|
-
currentToolCallId = `tc_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
2626
|
-
}
|
|
2627
|
-
if (toolName && streamingContext.toolNameToCallIds.has(toolName)) {
|
|
2628
|
-
const queue = streamingContext.toolNameToCallIds.get(toolName);
|
|
2629
|
-
const index = queue.indexOf(currentToolCallId);
|
|
2630
|
-
if (index !== -1) {
|
|
2631
|
-
queue.splice(index, 1);
|
|
2632
|
-
}
|
|
2633
|
-
}
|
|
2634
|
-
streamingContext.lastEmittedToolCallId = currentToolCallId;
|
|
2635
|
-
if (toolName) {
|
|
2636
|
-
streamingContext.toolCallIdToName.set(
|
|
2637
|
-
currentToolCallId,
|
|
2638
|
-
toolName
|
|
2639
|
-
);
|
|
2640
|
-
}
|
|
2641
|
-
const toolNameForLookup = toolName || streamingContext.toolCallIdToName.get(currentToolCallId);
|
|
2642
|
-
const serverId = toolNameForLookup ? extractServerId(toolNameForLookup) : void 0;
|
|
2609
|
+
const currentToolCallId = streamingContext.lastEmittedToolCallId ?? `tc_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
2610
|
+
const toolName = streamingContext.toolCallIdToName.get(currentToolCallId);
|
|
2611
|
+
const serverId = toolName ? extractServerId(toolName) : void 0;
|
|
2643
2612
|
iterationToolResults.push({ result });
|
|
2644
2613
|
sendSseEvent(
|
|
2645
2614
|
streamingContext.controller,
|
|
@@ -2711,21 +2680,10 @@ var createStreamingResponse = async (model, aiSdkTools, messages, streamingConte
|
|
|
2711
2680
|
messageHistory.push(...responseMessages);
|
|
2712
2681
|
for (const m of responseMessages) {
|
|
2713
2682
|
if (m.role === "tool") {
|
|
2683
|
+
const currentToolCallId = streamingContext.lastEmittedToolCallId != null ? streamingContext.lastEmittedToolCallId : `tc_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
2714
2684
|
const value = m.content;
|
|
2715
|
-
const toolName =
|
|
2716
|
-
|
|
2717
|
-
if (toolName && streamingContext.toolNameToCallIds.has(toolName)) {
|
|
2718
|
-
const queue = streamingContext.toolNameToCallIds.get(toolName);
|
|
2719
|
-
if (queue.length > 0) {
|
|
2720
|
-
currentToolCallId = queue.shift();
|
|
2721
|
-
} else {
|
|
2722
|
-
currentToolCallId = streamingContext.lastEmittedToolCallId ?? `tc_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
2723
|
-
}
|
|
2724
|
-
} else {
|
|
2725
|
-
currentToolCallId = streamingContext.lastEmittedToolCallId ?? `tc_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
2726
|
-
}
|
|
2727
|
-
const toolNameForLookup = toolName || streamingContext.toolCallIdToName.get(currentToolCallId);
|
|
2728
|
-
const serverId = toolNameForLookup ? extractServerId(toolNameForLookup) : void 0;
|
|
2685
|
+
const toolName = streamingContext.toolCallIdToName.get(currentToolCallId);
|
|
2686
|
+
const serverId = toolName ? extractServerId(toolName) : void 0;
|
|
2729
2687
|
iterationToolResults.push({ result: value });
|
|
2730
2688
|
sendSseEvent(streamingContext.controller, streamingContext.encoder, {
|
|
2731
2689
|
type: "tool_result",
|
|
@@ -2815,10 +2773,6 @@ var sendMessagesToBackend = async (messages, streamingContext, mcpClientManager2
|
|
|
2815
2773
|
const currentToolCallId = `tc_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
2816
2774
|
streamingContext.lastEmittedToolCallId = currentToolCallId;
|
|
2817
2775
|
streamingContext.toolCallIdToName.set(currentToolCallId, call.name);
|
|
2818
|
-
if (!streamingContext.toolNameToCallIds.has(call.name)) {
|
|
2819
|
-
streamingContext.toolNameToCallIds.set(call.name, []);
|
|
2820
|
-
}
|
|
2821
|
-
streamingContext.toolNameToCallIds.get(call.name).push(currentToolCallId);
|
|
2822
2776
|
sendSseEvent(streamingContext.controller, streamingContext.encoder, {
|
|
2823
2777
|
type: "tool_call",
|
|
2824
2778
|
toolCall: {
|
|
@@ -2831,18 +2785,7 @@ var sendMessagesToBackend = async (messages, streamingContext, mcpClientManager2
|
|
|
2831
2785
|
});
|
|
2832
2786
|
};
|
|
2833
2787
|
const emitToolResult = (result) => {
|
|
2834
|
-
const
|
|
2835
|
-
let currentToolCallId;
|
|
2836
|
-
if (toolName && streamingContext.toolNameToCallIds.has(toolName)) {
|
|
2837
|
-
const queue = streamingContext.toolNameToCallIds.get(toolName);
|
|
2838
|
-
if (queue.length > 0) {
|
|
2839
|
-
currentToolCallId = queue.shift();
|
|
2840
|
-
} else {
|
|
2841
|
-
currentToolCallId = streamingContext.lastEmittedToolCallId ?? `tc_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
2842
|
-
}
|
|
2843
|
-
} else {
|
|
2844
|
-
currentToolCallId = streamingContext.lastEmittedToolCallId ?? `tc_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
2845
|
-
}
|
|
2788
|
+
const currentToolCallId = streamingContext.lastEmittedToolCallId != null ? streamingContext.lastEmittedToolCallId : `tc_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
2846
2789
|
sendSseEvent(streamingContext.controller, streamingContext.encoder, {
|
|
2847
2790
|
type: "tool_result",
|
|
2848
2791
|
toolResult: {
|
|
@@ -2995,8 +2938,7 @@ chat.post("/", async (c) => {
|
|
|
2995
2938
|
toolCallId: 0,
|
|
2996
2939
|
lastEmittedToolCallId: null,
|
|
2997
2940
|
stepIndex: 0,
|
|
2998
|
-
toolCallIdToName: /* @__PURE__ */ new Map()
|
|
2999
|
-
toolNameToCallIds: /* @__PURE__ */ new Map()
|
|
2941
|
+
toolCallIdToName: /* @__PURE__ */ new Map()
|
|
3000
2942
|
};
|
|
3001
2943
|
mcpClientManager2.setElicitationCallback(async (request) => {
|
|
3002
2944
|
const elicitationRequest = {
|
|
@@ -9530,7 +9472,7 @@ function transformServerConfigsToEnvironment(serverIds, clientManager) {
|
|
|
9530
9472
|
if (!config) {
|
|
9531
9473
|
throw new Error(`Server '${serverId}' not found`);
|
|
9532
9474
|
}
|
|
9533
|
-
const status = clientManager.
|
|
9475
|
+
const status = clientManager.getConnectionStatusByAttemptingPing(serverId);
|
|
9534
9476
|
if (status !== "connected") {
|
|
9535
9477
|
throw new Error(
|
|
9536
9478
|
`Server '${serverId}' is not connected (status: ${status})`
|
|
@@ -9727,7 +9669,7 @@ function resolveServerIdsOrThrow(requestedIds, clientManager) {
|
|
|
9727
9669
|
async function collectToolsForServers(clientManager, serverIds) {
|
|
9728
9670
|
const perServerTools = await Promise.all(
|
|
9729
9671
|
serverIds.map(async (serverId) => {
|
|
9730
|
-
if (clientManager.
|
|
9672
|
+
if (clientManager.getConnectionStatusByAttemptingPing(serverId) !== "connected") {
|
|
9731
9673
|
return [];
|
|
9732
9674
|
}
|
|
9733
9675
|
try {
|