@mcp-ts/sdk 1.5.0 → 1.5.2

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.
Files changed (66) hide show
  1. package/dist/adapters/agui-adapter.d.mts +1 -1
  2. package/dist/adapters/agui-adapter.d.ts +1 -1
  3. package/dist/adapters/agui-adapter.js +43 -9
  4. package/dist/adapters/agui-adapter.js.map +1 -1
  5. package/dist/adapters/agui-adapter.mjs +43 -9
  6. package/dist/adapters/agui-adapter.mjs.map +1 -1
  7. package/dist/adapters/agui-middleware.d.mts +1 -1
  8. package/dist/adapters/agui-middleware.d.ts +1 -1
  9. package/dist/adapters/agui-middleware.js.map +1 -1
  10. package/dist/adapters/agui-middleware.mjs.map +1 -1
  11. package/dist/adapters/ai-adapter.d.mts +1 -1
  12. package/dist/adapters/ai-adapter.d.ts +1 -1
  13. package/dist/adapters/ai-adapter.js +42 -8
  14. package/dist/adapters/ai-adapter.js.map +1 -1
  15. package/dist/adapters/ai-adapter.mjs +42 -8
  16. package/dist/adapters/ai-adapter.mjs.map +1 -1
  17. package/dist/adapters/langchain-adapter.d.mts +1 -1
  18. package/dist/adapters/langchain-adapter.d.ts +1 -1
  19. package/dist/adapters/langchain-adapter.js +42 -8
  20. package/dist/adapters/langchain-adapter.js.map +1 -1
  21. package/dist/adapters/langchain-adapter.mjs +42 -8
  22. package/dist/adapters/langchain-adapter.mjs.map +1 -1
  23. package/dist/client/react.d.mts +91 -2
  24. package/dist/client/react.d.ts +91 -2
  25. package/dist/client/react.js +339 -3
  26. package/dist/client/react.js.map +1 -1
  27. package/dist/client/react.mjs +335 -4
  28. package/dist/client/react.mjs.map +1 -1
  29. package/dist/client/vue.d.mts +10 -0
  30. package/dist/client/vue.d.ts +10 -0
  31. package/dist/client/vue.js +28 -2
  32. package/dist/client/vue.js.map +1 -1
  33. package/dist/client/vue.mjs +28 -2
  34. package/dist/client/vue.mjs.map +1 -1
  35. package/dist/index.d.mts +1 -1
  36. package/dist/index.d.ts +1 -1
  37. package/dist/index.js +170 -37
  38. package/dist/index.js.map +1 -1
  39. package/dist/index.mjs +170 -37
  40. package/dist/index.mjs.map +1 -1
  41. package/dist/server/index.js +55 -11
  42. package/dist/server/index.js.map +1 -1
  43. package/dist/server/index.mjs +55 -11
  44. package/dist/server/index.mjs.map +1 -1
  45. package/dist/shared/index.d.mts +2 -2
  46. package/dist/shared/index.d.ts +2 -2
  47. package/dist/shared/index.js +115 -26
  48. package/dist/shared/index.js.map +1 -1
  49. package/dist/shared/index.mjs +115 -26
  50. package/dist/shared/index.mjs.map +1 -1
  51. package/dist/{tool-router-XnWVxPzv.d.mts → tool-router-DK0RJblO.d.mts} +3 -0
  52. package/dist/{tool-router-Bo8qZbsD.d.ts → tool-router-DsKhRmJm.d.ts} +3 -0
  53. package/package.json +1 -1
  54. package/src/adapters/agui-adapter.ts +7 -7
  55. package/src/adapters/ai-adapter.ts +5 -5
  56. package/src/adapters/langchain-adapter.ts +5 -5
  57. package/src/client/react/index.ts +14 -0
  58. package/src/client/react/oauth-popup.tsx +446 -0
  59. package/src/client/react/use-mcp.ts +84 -3
  60. package/src/client/vue/use-mcp.ts +80 -3
  61. package/src/server/handlers/sse-handler.ts +39 -0
  62. package/src/server/mcp/oauth-client.ts +32 -14
  63. package/src/shared/meta-tools.ts +62 -13
  64. package/src/shared/tool-index.ts +85 -12
  65. package/src/shared/tool-router.ts +8 -7
  66. package/supabase/migrations/20260421010000_add_session_cleanup_cron.sql +32 -0
@@ -2,8 +2,8 @@ export { D as Disposable, a as DisposableStore, E as Emitter, b as Event, M as M
2
2
  export { A as AuthenticationError, C as ConfigurationError, a as ConnectionError, I as InvalidStateError, M as McpError, N as NotConnectedError, R as RpcErrorCode, b as RpcErrorCodes, S as SessionNotFoundError, c as SessionValidationError, T as ToolExecutionError, U as UnauthorizedError, s as sanitizeServerLabel } from '../utils-0qmYrqoa.mjs';
3
3
  import { v as ToolInfo } from '../types-CfCoIsWI.mjs';
4
4
  export { C as CallToolParams, a as CallToolRequest, b as CallToolResponse, c as ConnectAuthRequiredResponse, d as ConnectErrorResponse, e as ConnectParams, f as ConnectRequest, g as ConnectResponse, h as ConnectResult, i as ConnectSuccessResponse, D as DisconnectParams, j as DisconnectResult, F as FinishAuthParams, k as FinishAuthResult, G as GetPromptParams, L as ListPromptsResult, l as ListResourcesResult, m as ListToolsResponse, n as ListToolsRpcResult, M as McpRpcMethod, o as McpRpcParams, p as McpRpcRequest, q as McpRpcResponse, R as ReadResourceParams, r as RestoreSessionResult, S as SessionInfo, s as SessionListResult, t as SessionParams, T as ToolClient, u as ToolClientProvider, w as TransportType, x as isCallToolSuccess, y as isConnectAuthRequired, z as isConnectError, A as isConnectSuccess, B as isListToolsSuccess } from '../types-CfCoIsWI.mjs';
5
- import { d as ToolRouter } from '../tool-router-XnWVxPzv.mjs';
6
- export { C as CompactTool, a as CompressionStats, E as EmbedFn, I as IndexedTool, S as SchemaCompressor, T as ToolGroupInfo, b as ToolIndex, c as ToolIndexOptions, e as ToolRouterClientInput, f as ToolRouterOptions, g as ToolRouterStrategy, h as ToolSummary } from '../tool-router-XnWVxPzv.mjs';
5
+ import { d as ToolRouter } from '../tool-router-DK0RJblO.mjs';
6
+ export { C as CompactTool, a as CompressionStats, E as EmbedFn, I as IndexedTool, S as SchemaCompressor, T as ToolGroupInfo, b as ToolIndex, c as ToolIndexOptions, e as ToolRouterClientInput, f as ToolRouterOptions, g as ToolRouterStrategy, h as ToolSummary } from '../tool-router-DK0RJblO.mjs';
7
7
  import { Tool, CallToolResult } from '@modelcontextprotocol/sdk/types.js';
8
8
 
9
9
  /**
@@ -2,8 +2,8 @@ export { D as Disposable, a as DisposableStore, E as Emitter, b as Event, M as M
2
2
  export { A as AuthenticationError, C as ConfigurationError, a as ConnectionError, I as InvalidStateError, M as McpError, N as NotConnectedError, R as RpcErrorCode, b as RpcErrorCodes, S as SessionNotFoundError, c as SessionValidationError, T as ToolExecutionError, U as UnauthorizedError, s as sanitizeServerLabel } from '../utils-0qmYrqoa.js';
3
3
  import { v as ToolInfo } from '../types-CfCoIsWI.js';
4
4
  export { C as CallToolParams, a as CallToolRequest, b as CallToolResponse, c as ConnectAuthRequiredResponse, d as ConnectErrorResponse, e as ConnectParams, f as ConnectRequest, g as ConnectResponse, h as ConnectResult, i as ConnectSuccessResponse, D as DisconnectParams, j as DisconnectResult, F as FinishAuthParams, k as FinishAuthResult, G as GetPromptParams, L as ListPromptsResult, l as ListResourcesResult, m as ListToolsResponse, n as ListToolsRpcResult, M as McpRpcMethod, o as McpRpcParams, p as McpRpcRequest, q as McpRpcResponse, R as ReadResourceParams, r as RestoreSessionResult, S as SessionInfo, s as SessionListResult, t as SessionParams, T as ToolClient, u as ToolClientProvider, w as TransportType, x as isCallToolSuccess, y as isConnectAuthRequired, z as isConnectError, A as isConnectSuccess, B as isListToolsSuccess } from '../types-CfCoIsWI.js';
5
- import { d as ToolRouter } from '../tool-router-Bo8qZbsD.js';
6
- export { C as CompactTool, a as CompressionStats, E as EmbedFn, I as IndexedTool, S as SchemaCompressor, T as ToolGroupInfo, b as ToolIndex, c as ToolIndexOptions, e as ToolRouterClientInput, f as ToolRouterOptions, g as ToolRouterStrategy, h as ToolSummary } from '../tool-router-Bo8qZbsD.js';
5
+ import { d as ToolRouter } from '../tool-router-DsKhRmJm.js';
6
+ export { C as CompactTool, a as CompressionStats, E as EmbedFn, I as IndexedTool, S as SchemaCompressor, T as ToolGroupInfo, b as ToolIndex, c as ToolIndexOptions, e as ToolRouterClientInput, f as ToolRouterOptions, g as ToolRouterStrategy, h as ToolSummary } from '../tool-router-DsKhRmJm.js';
7
7
  import { Tool, CallToolResult } from '@modelcontextprotocol/sdk/types.js';
8
8
 
9
9
  /**
@@ -279,6 +279,7 @@ var ToolIndex = class _ToolIndex {
279
279
  name: tool.name,
280
280
  description: tool.description ?? "",
281
281
  serverName: tool.serverName,
282
+ serverId: tool.serverId,
282
283
  sessionId: tool.sessionId,
283
284
  estimatedTokens
284
285
  });
@@ -341,12 +342,50 @@ var ToolIndex = class _ToolIndex {
341
342
  */
342
343
  async search(query, topK = 5) {
343
344
  if (this.tools.size === 0) return [];
344
- const queryLower = query.toLowerCase();
345
- const queryTokens = this.tokenize(queryLower);
345
+ const queryLower = query.toLowerCase().trim();
346
+ const exactMatches = [...this.toolSummaries.values()].filter(
347
+ (summary) => summary.name.toLowerCase() === queryLower
348
+ );
349
+ if (exactMatches.length > 0) {
350
+ return exactMatches.slice(0, topK);
351
+ }
352
+ if (queryLower.startsWith("mcp__") && queryLower.length > 5) {
353
+ const prefixMatches = [...this.toolSummaries.values()].filter((t) => t.name.toLowerCase().startsWith(queryLower)).slice(0, topK);
354
+ if (prefixMatches.length > 0) return prefixMatches;
355
+ }
356
+ const queryTermsRaw = queryLower.split(/\s+/).filter((t) => t.length > 0);
357
+ const requiredTerms = [];
358
+ const optionalTerms = [];
359
+ for (const term of queryTermsRaw) {
360
+ if (term.startsWith("+") && term.length > 1) {
361
+ requiredTerms.push(term.slice(1));
362
+ } else {
363
+ optionalTerms.push(term);
364
+ }
365
+ }
366
+ const allScoringTerms = requiredTerms.length > 0 ? [...requiredTerms, ...optionalTerms] : queryTermsRaw;
367
+ const normalizedQueryText = allScoringTerms.join(" ").trim();
368
+ const queryTokens = this.tokenize(allScoringTerms.join(" "));
369
+ const candidateKeys = /* @__PURE__ */ new Set();
370
+ for (const docKey of this.toolSummaries.keys()) {
371
+ if (requiredTerms.length > 0) {
372
+ const text = this.searchTexts.get(docKey) || "";
373
+ const summary = this.toolSummaries.get(docKey);
374
+ const nameLower = summary.name.toLowerCase();
375
+ const matchesAll = requiredTerms.every(
376
+ (term) => text.includes(term) || nameLower.includes(term)
377
+ );
378
+ if (!matchesAll) continue;
379
+ }
380
+ candidateKeys.add(docKey);
381
+ }
346
382
  const keywordScores = /* @__PURE__ */ new Map();
347
383
  const k1 = 1.2;
348
384
  const b = 0.75;
349
- for (const [docKey, docTf] of this.tfVectors) {
385
+ for (const docKey of candidateKeys) {
386
+ const docTf = this.tfVectors.get(docKey);
387
+ if (!docTf) continue;
388
+ const summary = this.toolSummaries.get(docKey);
350
389
  let score = 0;
351
390
  const docLen = this.docLengths.get(docKey) ?? 0;
352
391
  for (const tok of queryTokens) {
@@ -357,16 +396,31 @@ var ToolIndex = class _ToolIndex {
357
396
  const denominator = tfVal + k1 * (1 - b + b * (docLen / this.avgDocLength));
358
397
  score += idf * (numerator / denominator);
359
398
  }
360
- keywordScores.set(docKey, score);
399
+ const serverLower = (summary.serverName || summary.serverId || "").toLowerCase();
400
+ const toolLower = summary.name.toLowerCase();
401
+ for (const term of allScoringTerms) {
402
+ if (serverLower.includes(term)) {
403
+ score += 10;
404
+ }
405
+ if (toolLower.includes(term)) {
406
+ score += 5;
407
+ }
408
+ }
409
+ if (score > 0) {
410
+ keywordScores.set(docKey, score);
411
+ }
361
412
  }
362
413
  let embeddingScores = null;
363
414
  if (this.options.embedFn && this.embeddings.size > 0) {
364
415
  try {
365
- const [queryEmbedding] = await this.options.embedFn([queryLower]);
416
+ const [queryEmbedding] = await this.options.embedFn([normalizedQueryText]);
366
417
  if (queryEmbedding) {
367
418
  embeddingScores = /* @__PURE__ */ new Map();
368
- for (const [docKey, vec] of this.embeddings) {
369
- embeddingScores.set(docKey, this.cosineSimilarity(queryEmbedding, vec));
419
+ for (const docKey of candidateKeys) {
420
+ const vec = this.embeddings.get(docKey);
421
+ if (vec) {
422
+ embeddingScores.set(docKey, this.cosineSimilarity(queryEmbedding, vec));
423
+ }
370
424
  }
371
425
  }
372
426
  } catch {
@@ -374,7 +428,7 @@ var ToolIndex = class _ToolIndex {
374
428
  }
375
429
  const kw = this.options.keywordWeight;
376
430
  const finalScores = [];
377
- for (const docKey of this.toolSummaries.keys()) {
431
+ for (const docKey of candidateKeys) {
378
432
  const kwScore = keywordScores.get(docKey) ?? 0;
379
433
  const embScore = embeddingScores?.get(docKey) ?? 0;
380
434
  const score = embeddingScores ? kw * kwScore + (1 - kw) * embScore : kwScore;
@@ -432,7 +486,7 @@ var ToolIndex = class _ToolIndex {
432
486
  getTool(name, namespace) {
433
487
  const list = this.tools.get(name) ?? [];
434
488
  if (!namespace) return list;
435
- return list.filter((t) => t.sessionId === namespace || t.serverName === namespace);
489
+ return list.filter((t) => t.sessionId === namespace || t.serverId === namespace);
436
490
  }
437
491
  /** All indexed tool names. */
438
492
  getToolNames() {
@@ -492,7 +546,7 @@ var ToolIndex = class _ToolIndex {
492
546
  return parts.join(" ");
493
547
  }
494
548
  getDocumentKey(tool) {
495
- return `${tool.sessionId}::${tool.serverName}::${tool.name}`;
549
+ return `${tool.sessionId}::${tool.serverId}::${tool.name}`;
496
550
  }
497
551
  /** Simple whitespace + camelCase + snake_case tokenizer. */
498
552
  tokenize(text) {
@@ -578,13 +632,13 @@ var SchemaCompressor = class _SchemaCompressor {
578
632
  function createSearchToolDefinition() {
579
633
  return {
580
634
  name: "mcp_search_tool_bm25",
581
- description: 'Search the catalog of available tools using BM25 natural language ranking. Returns tool names, descriptions, and server info. Use this FIRST to find relevant tools before calling them. Example queries: "database query", "send email", "github pull request".',
635
+ description: 'Search the catalog of available tools. Returns tool names, descriptions, and server info. Use this FIRST to find relevant tools before calling them.\n\nQuery forms:\n- "select:Read,Edit,Grep" \u2014 fetch these exact tools by name\n- "notebook jupyter" \u2014 keyword search, up to limit best matches\n- "+slack send" \u2014 require "slack" in the name, rank by remaining terms',
582
636
  inputSchema: {
583
637
  type: "object",
584
638
  properties: {
585
639
  query: {
586
640
  type: "string",
587
- description: "Natural language description of the capability you need."
641
+ description: 'Query to find tools. Use "select:<tool_name>" for direct selection, or keywords to search. Prefix keywords with + to require them.'
588
642
  },
589
643
  limit: {
590
644
  type: "number",
@@ -626,9 +680,9 @@ function createGetSchemaToolDefinition() {
626
680
  type: "string",
627
681
  description: "The exact tool name returned by mcp_search_tool_bm25."
628
682
  },
629
- serverName: {
683
+ serverId: {
630
684
  type: "string",
631
- description: "Optional: The server name provided in mcp_search_tool_bm25. Required if multiple tools have the same name."
685
+ description: "Optional: The server ID provided in mcp_search_tool_bm25. Required if multiple tools have the same name."
632
686
  }
633
687
  },
634
688
  required: ["toolName"]
@@ -646,9 +700,9 @@ function createExecuteToolDefinition() {
646
700
  type: "string",
647
701
  description: "The exact tool name from mcp_search_tool_bm25 results."
648
702
  },
649
- serverName: {
703
+ serverId: {
650
704
  type: "string",
651
- description: "Optional: The server name provided in mcp_search_tool_bm25. Required if multiple tools have the same name."
705
+ description: "Optional: The server ID provided in mcp_search_tool_bm25. Required if multiple tools have the same name."
652
706
  },
653
707
  args: {
654
708
  type: "object",
@@ -678,9 +732,43 @@ async function executeMetaTool(toolName, args, router, callToolFn) {
678
732
  case "mcp_search_tool_bm25": {
679
733
  const query = String(args.query ?? "");
680
734
  const limit = Math.min(Number(args.limit) || 5, 20);
735
+ const selectMatch = query.match(/^select:(.+)$/i);
736
+ if (selectMatch) {
737
+ const requested = selectMatch[1].split(",").map((s) => s.trim()).filter(Boolean);
738
+ const found = [];
739
+ const errors = [];
740
+ for (const requestedToolName of requested) {
741
+ const { tool, error } = resolveToolSchema(requestedToolName);
742
+ if (error) {
743
+ const errorMsg = error.content[0]?.type === "text" ? error.content[0].text : "Unknown error";
744
+ errors.push(`- **${requestedToolName}**: ${errorMsg}`);
745
+ } else if (tool) {
746
+ found.push(tool);
747
+ } else {
748
+ errors.push(`- **${requestedToolName}**: Tool not found. Try searching with mcp_search_tool_bm25.`);
749
+ }
750
+ }
751
+ const lines = [];
752
+ if (found.length > 0) {
753
+ lines.push(...found.map(
754
+ (t, i) => `${i + 1}. **${t.name}** (server: ${t.serverName}, serverId: ${t.serverId})
755
+ ${t.description}`
756
+ ));
757
+ }
758
+ if (errors.length > 0) {
759
+ if (lines.length > 0) lines.push("");
760
+ lines.push("Errors resolving some tools:");
761
+ lines.push(...errors);
762
+ }
763
+ const text2 = lines.length > 0 ? lines.join("\n") : `No tools found matching select query: ${requested.join(", ")}`;
764
+ return {
765
+ content: [{ type: "text", text: text2 }],
766
+ isError: found.length === 0
767
+ };
768
+ }
681
769
  const results = await router.searchTools(query, limit);
682
770
  const text = results.length === 0 ? "No tools found matching your query. Try different keywords." : results.map(
683
- (t, i) => `${i + 1}. **${t.name}** (server: ${t.serverName})
771
+ (t, i) => `${i + 1}. **${t.name}** (server: ${t.serverName}, serverId: ${t.serverId})
684
772
  ${t.description}
685
773
  Estimated tokens: ${t.estimatedTokens}`
686
774
  ).join("\n");
@@ -694,7 +782,7 @@ async function executeMetaTool(toolName, args, router, callToolFn) {
694
782
  const limit = Math.min(Number(args.limit) || 5, 20);
695
783
  const results = await router.searchToolsRegex(pattern, limit);
696
784
  const text = results.length === 0 ? "No tools matched your regex pattern. Try a broader pattern." : results.map(
697
- (t, i) => `${i + 1}. **${t.name}** (server: ${t.serverName})
785
+ (t, i) => `${i + 1}. **${t.name}** (server: ${t.serverName}, serverId: ${t.serverId})
698
786
  ${t.description}
699
787
  Estimated tokens: ${t.estimatedTokens}`
700
788
  ).join("\n");
@@ -705,7 +793,7 @@ async function executeMetaTool(toolName, args, router, callToolFn) {
705
793
  }
706
794
  case "mcp_get_tool_schema": {
707
795
  const name = String(args.toolName ?? "");
708
- const namespace = String(args.serverName ?? "") || void 0;
796
+ const namespace = String(args.serverId ?? "") || void 0;
709
797
  const { tool, error } = resolveToolSchema(name, namespace);
710
798
  if (error) {
711
799
  return error;
@@ -733,7 +821,7 @@ async function executeMetaTool(toolName, args, router, callToolFn) {
733
821
  }
734
822
  case "mcp_execute_tool": {
735
823
  const targetToolName = String(args.toolName ?? "");
736
- const namespace = String(args.serverName ?? "") || void 0;
824
+ const namespace = String(args.serverId ?? "") || void 0;
737
825
  const toolArgs = args.args ?? {};
738
826
  if (!targetToolName) {
739
827
  return {
@@ -882,9 +970,9 @@ var ToolRouter = class {
882
970
  const matches = this.index.getTool(toolName, namespace);
883
971
  if (matches.length === 0) return void 0;
884
972
  if (matches.length > 1) {
885
- const servers = matches.map((m) => m.serverName).join(", ");
973
+ const servers = matches.map((m) => m.serverId).join(", ");
886
974
  throw new Error(
887
- `Tool "${toolName}" is provided by multiple servers: [${servers}]. Please specify the desired "serverName" as a namespace.`
975
+ `Tool "${toolName}" is provided by multiple servers: [${servers}]. Please specify the desired "serverId" as a namespace.`
888
976
  );
889
977
  }
890
978
  return matches[0];
@@ -995,6 +1083,7 @@ var ToolRouter = class {
995
1083
  for (const tool of tools) {
996
1084
  result.push({
997
1085
  ...tool,
1086
+ serverId,
998
1087
  serverName,
999
1088
  sessionId
1000
1089
  });
@@ -1028,16 +1117,16 @@ var ToolRouter = class {
1028
1117
  } else {
1029
1118
  const serverTools = /* @__PURE__ */ new Map();
1030
1119
  for (const tool of this.allTools) {
1031
- const group = tool.serverName;
1120
+ const group = tool.serverId;
1032
1121
  if (!serverTools.has(group)) {
1033
1122
  serverTools.set(group, []);
1034
1123
  }
1035
1124
  serverTools.get(group).push(tool.name);
1036
1125
  }
1037
- for (const [serverName, tools] of serverTools) {
1038
- this.groupsMap.set(serverName, {
1126
+ for (const [serverId, tools] of serverTools) {
1127
+ this.groupsMap.set(serverId, {
1039
1128
  tools,
1040
- active: this.activeGroups.size === 0 || this.activeGroups.has(serverName)
1129
+ active: this.activeGroups.size === 0 || this.activeGroups.has(serverId)
1041
1130
  });
1042
1131
  }
1043
1132
  }