@mcpjam/inspector 1.0.17 → 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.
@@ -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.resolveConnectionStatus(state),
175
+ status: this.getConnectionStatusByAttemptingPing(serverId),
176
176
  config: state.config
177
177
  }));
178
178
  }
179
- getConnectionStatus(serverId) {
180
- return this.resolveConnectionStatus(this.clientStates.get(serverId));
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
- var _a2;
188
- if (this.clientStates.has(serverId)) {
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 timeout = this.getTimeout(config);
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 _a22;
216
+ var _a2;
208
217
  const client = new Client(
209
218
  {
210
219
  name: this.defaultClientName ? `${this.defaultClientName}` : serverId,
211
- version: (_a22 = config.version) != null ? _a22 : this.defaultClientVersion
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 _a3;
222
- (_a3 = config.onError) == null ? void 0 : _a3.call(config, error);
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
- state.promise = void 0;
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.getConnectionStatus(serverId);
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
- try {
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.getConnectionStatus(serverId);
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 toolName = chunk.chunk.toolName || chunk.chunk.name || null;
2614
- let currentToolCallId = chunk.chunk.toolCallId || void 0;
2615
- if (!currentToolCallId && toolName) {
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 = m.toolName || m.name;
2716
- let currentToolCallId;
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 toolName = result.toolName;
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 = {
@@ -3218,7 +3160,7 @@ import { MCPClient } from "@mastra/mcp";
3218
3160
  import { streamText as streamText2 } from "ai";
3219
3161
 
3220
3162
  // ../node_modules/convex/dist/esm/index.js
3221
- var version = "1.27.3";
3163
+ var version = "1.28.0";
3222
3164
 
3223
3165
  // ../node_modules/convex/dist/esm/values/base64.js
3224
3166
  var lookup = [];
@@ -3849,7 +3791,7 @@ function createApi(pathParts = []) {
3849
3791
  }
3850
3792
  var anyApi = createApi();
3851
3793
 
3852
- // ../node_modules/convex/dist/esm/browser/long.js
3794
+ // ../node_modules/convex/dist/esm/vendor/long.js
3853
3795
  var __defProp4 = Object.defineProperty;
3854
3796
  var __defNormalProp3 = (obj, key, value) => key in obj ? __defProp4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3855
3797
  var __publicField3 = (obj, key, value) => __defNormalProp3(obj, typeof key !== "symbol" ? key + "" : key, value);
@@ -3926,7 +3868,7 @@ var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
3926
3868
  var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;
3927
3869
  var MAX_UNSIGNED_VALUE = new Long(4294967295 | 0, 4294967295 | 0);
3928
3870
 
3929
- // ../node_modules/jwt-decode/build/esm/index.js
3871
+ // ../node_modules/convex/dist/esm/vendor/jwt-decode/index.js
3930
3872
  var InvalidTokenError = class extends Error {
3931
3873
  };
3932
3874
  InvalidTokenError.prototype.name = "InvalidTokenError";
@@ -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.getConnectionStatus(serverId);
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.getConnectionStatus(serverId) !== "connected") {
9672
+ if (clientManager.getConnectionStatusByAttemptingPing(serverId) !== "connected") {
9731
9673
  return [];
9732
9674
  }
9733
9675
  try {