mcp-use 1.5.1-canary.1 → 1.5.1-canary.3

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.
@@ -592,6 +592,22 @@ var McpServer = class {
592
592
  }
593
593
  return `http://${this.serverHost}:${this.serverPort}`;
594
594
  }
595
+ /**
596
+ * Gets additional CSP URLs from environment variable
597
+ * Supports comma-separated list or single URL
598
+ * @returns Array of URLs to add to CSP resource_domains
599
+ */
600
+ getCSPUrls() {
601
+ const cspUrlsEnv = getEnv2("CSP_URLS");
602
+ if (!cspUrlsEnv) {
603
+ console.log("[CSP] No CSP_URLS environment variable found");
604
+ return [];
605
+ }
606
+ console.log("[CSP] Found CSP_URLS environment variable:", cspUrlsEnv);
607
+ const urls = cspUrlsEnv.split(",").map((url) => url.trim()).filter((url) => url.length > 0);
608
+ console.log("[CSP] Parsed CSP URLs:", urls);
609
+ return urls;
610
+ }
595
611
  /**
596
612
  * Define a static resource that can be accessed by clients
597
613
  *
@@ -763,11 +779,6 @@ var McpServer = class {
763
779
  */
764
780
  tool(toolDefinition) {
765
781
  const inputSchema = this.createParamsSchema(toolDefinition.inputs || []);
766
- const context = {
767
- sample: /* @__PURE__ */ __name(async (params, options) => {
768
- return await this.createMessage(params, options);
769
- }, "sample")
770
- };
771
782
  this.server.registerTool(
772
783
  toolDefinition.name,
773
784
  {
@@ -777,7 +788,98 @@ var McpServer = class {
777
788
  annotations: toolDefinition.annotations,
778
789
  _meta: toolDefinition._meta
779
790
  },
780
- async (params) => {
791
+ async (params, extra) => {
792
+ const progressToken = extra?._meta?.progressToken;
793
+ const context = {
794
+ /**
795
+ * Request sampling from the client's LLM with automatic progress notifications.
796
+ *
797
+ * Progress notifications are sent every 5 seconds (configurable) while waiting
798
+ * for the sampling response. This prevents client-side timeouts when
799
+ * resetTimeoutOnProgress is enabled.
800
+ *
801
+ * @param params - Sampling parameters (messages, model preferences, etc.)
802
+ * @param options - Optional configuration
803
+ * @param options.timeout - Timeout in milliseconds (default: no timeout / Infinity)
804
+ * @param options.progressIntervalMs - Interval between progress notifications (default: 5000ms)
805
+ * @param options.onProgress - Optional callback called each time progress is reported
806
+ * @returns The sampling result from the client's LLM
807
+ */
808
+ sample: /* @__PURE__ */ __name(async (sampleParams, options) => {
809
+ const {
810
+ timeout,
811
+ progressIntervalMs = 5e3,
812
+ onProgress
813
+ } = options ?? {};
814
+ let progressCount = 0;
815
+ let completed = false;
816
+ let progressInterval = null;
817
+ if (progressToken && extra?.sendNotification) {
818
+ progressInterval = setInterval(async () => {
819
+ if (completed) return;
820
+ progressCount++;
821
+ const progressData = {
822
+ progress: progressCount,
823
+ total: void 0,
824
+ message: `Waiting for LLM response... (${progressCount * Math.round(progressIntervalMs / 1e3)}s elapsed)`
825
+ };
826
+ if (onProgress) {
827
+ try {
828
+ onProgress(progressData);
829
+ } catch {
830
+ }
831
+ }
832
+ try {
833
+ await extra.sendNotification({
834
+ method: "notifications/progress",
835
+ params: {
836
+ progressToken,
837
+ progress: progressData.progress,
838
+ total: progressData.total,
839
+ message: progressData.message
840
+ }
841
+ });
842
+ } catch {
843
+ }
844
+ }, progressIntervalMs);
845
+ }
846
+ try {
847
+ const samplePromise = this.createMessage(sampleParams);
848
+ if (timeout && timeout !== Infinity) {
849
+ const timeoutPromise = new Promise((_, reject) => {
850
+ setTimeout(
851
+ () => reject(
852
+ new Error(`Sampling timed out after ${timeout}ms`)
853
+ ),
854
+ timeout
855
+ );
856
+ });
857
+ return await Promise.race([samplePromise, timeoutPromise]);
858
+ }
859
+ return await samplePromise;
860
+ } finally {
861
+ completed = true;
862
+ if (progressInterval) {
863
+ clearInterval(progressInterval);
864
+ }
865
+ }
866
+ }, "sample"),
867
+ /**
868
+ * Send a progress notification to the client.
869
+ * Only works if the client requested progress updates for this tool call.
870
+ */
871
+ reportProgress: progressToken && extra?.sendNotification ? async (progress, total, message) => {
872
+ await extra.sendNotification({
873
+ method: "notifications/progress",
874
+ params: {
875
+ progressToken,
876
+ progress,
877
+ total,
878
+ message
879
+ }
880
+ });
881
+ } : void 0
882
+ };
781
883
  if (toolDefinition.cb.length >= 2) {
782
884
  return await toolDefinition.cb(params, context);
783
885
  }
@@ -1639,6 +1741,8 @@ if (container && Component) {
1639
1741
  "https://*.oaiusercontent.com",
1640
1742
  // always also add the base url of the server
1641
1743
  ...this.getServerBaseUrl() ? [this.getServerBaseUrl()] : [],
1744
+ // add additional CSP URLs from environment variable
1745
+ ...this.getCSPUrls(),
1642
1746
  ...metadata.appsSdkMetadata?.["openai/widgetCSP"]?.resource_domains || []
1643
1747
  ]
1644
1748
  }
@@ -1816,6 +1920,8 @@ if (container && Component) {
1816
1920
  "https://*.openai.com",
1817
1921
  // always also add the base url of the server
1818
1922
  ...this.getServerBaseUrl() ? [this.getServerBaseUrl()] : [],
1923
+ // add additional CSP URLs from environment variable
1924
+ ...this.getCSPUrls(),
1819
1925
  ...metadata.appsSdkMetadata?.["openai/widgetCSP"]?.resource_domains || []
1820
1926
  ]
1821
1927
  }
@@ -1868,14 +1974,7 @@ if (container && Component) {
1868
1974
  if (this.mcpMounted) return;
1869
1975
  const { StreamableHTTPServerTransport } = await import("@modelcontextprotocol/sdk/server/streamableHttp.js");
1870
1976
  const idleTimeoutMs = this.config.sessionIdleTimeoutMs ?? 3e5;
1871
- const createNewTransport = /* @__PURE__ */ __name(async (closeOldSessionId) => {
1872
- if (closeOldSessionId && this.sessions.has(closeOldSessionId)) {
1873
- try {
1874
- this.sessions.get(closeOldSessionId).transport.close();
1875
- } catch (error) {
1876
- }
1877
- this.sessions.delete(closeOldSessionId);
1878
- }
1977
+ const getTransportConfig = /* @__PURE__ */ __name(() => {
1879
1978
  const isProduction = this.isProductionMode();
1880
1979
  let allowedOrigins = this.config.allowedOrigins;
1881
1980
  let enableDnsRebindingProtection = false;
@@ -1887,6 +1986,17 @@ if (container && Component) {
1887
1986
  allowedOrigins = void 0;
1888
1987
  enableDnsRebindingProtection = false;
1889
1988
  }
1989
+ return { allowedOrigins, enableDnsRebindingProtection };
1990
+ }, "getTransportConfig");
1991
+ const createNewTransport = /* @__PURE__ */ __name(async (closeOldSessionId) => {
1992
+ if (closeOldSessionId && this.sessions.has(closeOldSessionId)) {
1993
+ try {
1994
+ this.sessions.get(closeOldSessionId).transport.close();
1995
+ } catch (error) {
1996
+ }
1997
+ this.sessions.delete(closeOldSessionId);
1998
+ }
1999
+ const { allowedOrigins, enableDnsRebindingProtection } = getTransportConfig();
1890
2000
  const transport = new StreamableHTTPServerTransport({
1891
2001
  sessionIdGenerator: /* @__PURE__ */ __name(() => generateUUID(), "sessionIdGenerator"),
1892
2002
  enableJsonResponse: true,
@@ -1909,6 +2019,81 @@ if (container && Component) {
1909
2019
  await this.server.connect(transport);
1910
2020
  return transport;
1911
2021
  }, "createNewTransport");
2022
+ const createAndAutoInitializeTransport = /* @__PURE__ */ __name(async (oldSessionId) => {
2023
+ const { allowedOrigins, enableDnsRebindingProtection } = getTransportConfig();
2024
+ const transport = new StreamableHTTPServerTransport({
2025
+ sessionIdGenerator: /* @__PURE__ */ __name(() => oldSessionId, "sessionIdGenerator"),
2026
+ // Reuse old session ID!
2027
+ enableJsonResponse: true,
2028
+ allowedOrigins,
2029
+ enableDnsRebindingProtection,
2030
+ // We'll manually store the session, so don't rely on onsessioninitialized
2031
+ onsessionclosed: /* @__PURE__ */ __name((id) => {
2032
+ if (id) {
2033
+ this.sessions.delete(id);
2034
+ }
2035
+ }, "onsessionclosed")
2036
+ });
2037
+ await this.server.connect(transport);
2038
+ this.sessions.set(oldSessionId, {
2039
+ transport,
2040
+ lastAccessedAt: Date.now()
2041
+ });
2042
+ const initBody = {
2043
+ jsonrpc: "2.0",
2044
+ method: "initialize",
2045
+ params: {
2046
+ protocolVersion: "2024-11-05",
2047
+ capabilities: {},
2048
+ clientInfo: { name: "mcp-use-auto-reconnect", version: "1.0.0" }
2049
+ },
2050
+ id: "__auto_init__"
2051
+ };
2052
+ const syntheticHeaders = {
2053
+ "content-type": "application/json",
2054
+ accept: "application/json, text/event-stream"
2055
+ // SDK requires both!
2056
+ };
2057
+ const syntheticReq = {
2058
+ method: "POST",
2059
+ headers: syntheticHeaders,
2060
+ header: /* @__PURE__ */ __name((name) => syntheticHeaders[name.toLowerCase()], "header"),
2061
+ body: initBody
2062
+ };
2063
+ const syntheticRes = {
2064
+ statusCode: 200,
2065
+ setHeader: /* @__PURE__ */ __name(() => syntheticRes, "setHeader"),
2066
+ writeHead: /* @__PURE__ */ __name((code) => {
2067
+ syntheticRes.statusCode = code;
2068
+ return syntheticRes;
2069
+ }, "writeHead"),
2070
+ write: /* @__PURE__ */ __name(() => true, "write"),
2071
+ end: /* @__PURE__ */ __name(() => {
2072
+ }, "end"),
2073
+ on: /* @__PURE__ */ __name(() => syntheticRes, "on"),
2074
+ once: /* @__PURE__ */ __name(() => syntheticRes, "once"),
2075
+ removeListener: /* @__PURE__ */ __name(() => syntheticRes, "removeListener")
2076
+ };
2077
+ await new Promise((resolve) => {
2078
+ syntheticRes.end = () => {
2079
+ resolve();
2080
+ };
2081
+ transport.handleRequest(syntheticReq, syntheticRes, initBody);
2082
+ });
2083
+ if (syntheticRes.statusCode !== 200) {
2084
+ console.error(
2085
+ `[MCP] Auto-initialization failed with status ${syntheticRes.statusCode}`
2086
+ );
2087
+ this.sessions.delete(oldSessionId);
2088
+ throw new Error(
2089
+ `Auto-initialization failed: ${syntheticRes.statusCode}`
2090
+ );
2091
+ }
2092
+ console.log(
2093
+ `[MCP] Auto-initialized session ${oldSessionId} for seamless reconnection`
2094
+ );
2095
+ return transport;
2096
+ }, "createAndAutoInitializeTransport");
1912
2097
  const getOrCreateTransport = /* @__PURE__ */ __name(async (sessionId, isInit = false) => {
1913
2098
  if (isInit) {
1914
2099
  return await createNewTransport(sessionId);
@@ -1922,9 +2107,9 @@ if (container && Component) {
1922
2107
  const autoCreate = this.config.autoCreateSessionOnInvalidId ?? true;
1923
2108
  if (autoCreate) {
1924
2109
  console.warn(
1925
- `[MCP] Session ${sessionId} not found (expired or invalid), auto-creating new session for seamless reconnection`
2110
+ `[MCP] Session ${sessionId} not found (expired or invalid), auto-creating and initializing new session for seamless reconnection`
1926
2111
  );
1927
- return await createNewTransport(sessionId);
2112
+ return await createAndAutoInitializeTransport(sessionId);
1928
2113
  } else {
1929
2114
  return null;
1930
2115
  }
@@ -1,4 +1,79 @@
1
1
  import type { CreateMessageRequest, CreateMessageResult } from "@modelcontextprotocol/sdk/types.js";
2
+ /**
3
+ * Options for the sample() function in tool context.
4
+ */
5
+ export interface SampleOptions {
6
+ /**
7
+ * Timeout in milliseconds for the sampling request.
8
+ * Default: no timeout (Infinity) - waits indefinitely for the LLM response.
9
+ * Set this if you want to limit how long to wait for sampling.
10
+ */
11
+ timeout?: number;
12
+ /**
13
+ * Interval in milliseconds between progress notifications.
14
+ * Default: 5000 (5 seconds).
15
+ * Progress notifications are sent to the client to prevent timeout
16
+ * when the client has resetTimeoutOnProgress enabled.
17
+ */
18
+ progressIntervalMs?: number;
19
+ /**
20
+ * Optional callback called each time a progress notification is sent.
21
+ * Useful for logging or custom progress handling.
22
+ */
23
+ onProgress?: (progress: {
24
+ progress: number;
25
+ total?: number;
26
+ message: string;
27
+ }) => void;
28
+ }
29
+ /**
30
+ * Context object passed to tool callbacks.
31
+ * Provides access to sampling and progress reporting capabilities.
32
+ */
33
+ export interface ToolContext {
34
+ /**
35
+ * Request sampling from the client's LLM with automatic progress notifications.
36
+ *
37
+ * Progress notifications are sent every 5 seconds (configurable) while waiting
38
+ * for the sampling response. This prevents client-side timeouts when the client
39
+ * has `resetTimeoutOnProgress: true` enabled.
40
+ *
41
+ * By default, there is no timeout - the function waits indefinitely for the
42
+ * LLM response. Set `options.timeout` to limit the wait time.
43
+ *
44
+ * @param params - Sampling parameters (messages, model preferences, etc.)
45
+ * @param options - Optional configuration for timeout and progress
46
+ * @returns The sampling result from the client's LLM
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * // Basic usage - waits indefinitely with automatic progress notifications
51
+ * const result = await ctx.sample({
52
+ * messages: [{ role: 'user', content: { type: 'text', text: 'Hello' } }],
53
+ * });
54
+ *
55
+ * // With timeout and custom progress handling
56
+ * const result = await ctx.sample(
57
+ * { messages: [...] },
58
+ * {
59
+ * timeout: 120000, // 2 minute timeout
60
+ * progressIntervalMs: 3000, // Report progress every 3 seconds
61
+ * onProgress: ({ progress, message }) => console.log(message),
62
+ * }
63
+ * );
64
+ * ```
65
+ */
66
+ sample: (params: CreateMessageRequest["params"], options?: SampleOptions) => Promise<CreateMessageResult>;
67
+ /**
68
+ * Send a progress notification to the client.
69
+ * Only available if the client requested progress updates for this tool call.
70
+ *
71
+ * @param progress - Current progress value (should increase with each call)
72
+ * @param total - Total progress value if known
73
+ * @param message - Optional message describing current progress
74
+ */
75
+ reportProgress?: (progress: number, total?: number, message?: string) => Promise<void>;
76
+ }
2
77
  import type { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
3
78
  import { type Hono as HonoType } from "hono";
4
79
  import type { PromptDefinition, ResourceDefinition, ResourceTemplateDefinition, ServerConfig, ToolDefinition, UIResourceDefinition } from "./types/index.js";
@@ -33,6 +108,12 @@ export declare class McpServer {
33
108
  * @returns The complete base URL for the server
34
109
  */
35
110
  private getServerBaseUrl;
111
+ /**
112
+ * Gets additional CSP URLs from environment variable
113
+ * Supports comma-separated list or single URL
114
+ * @returns Array of URLs to add to CSP resource_domains
115
+ */
116
+ private getCSPUrls;
36
117
  /**
37
118
  * Define a static resource that can be accessed by clients
38
119
  *
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../../../src/server/mcp-server.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EAEpB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8CAA8C,CAAC;AACnF,OAAO,EAAsB,KAAK,IAAI,IAAI,QAAQ,EAAa,MAAM,MAAM,CAAC;AAkB5E,O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;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,IAAI,CAAC;IAkCxD;;;;;;;;;;;;;;;;;;;;;OAqBG;YACW,cAAc;IAwC5B;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,OAAO,CAAC,iBAAiB;IAoLzB;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,iBAAiB;IAWzB;;;;;;;;;;;;;;;;;;OAkBG;IACH,OAAO,CAAC,kBAAkB;IA+C1B;;;;;;;;;;;;;;;;;;OAkBG;IACH,OAAO,CAAC,sBAAsB;IAqC9B;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,qBAAqB;IAK7B;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,gBAAgB;CA4BzB;AAED,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,SAAS,EAAE,MAAM,QAAQ,CAAC,GAC7D,QAAQ,GAAG;IACT,UAAU,EAAE,CAAC,OAAO,CAAC,EAAE;QACrB,QAAQ,CAAC,EAAE,UAAU,GAAG,YAAY,GAAG,aAAa,CAAC;KACtD,KAAK,OAAO,CAAC,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;CACpD,CAAC;AAEJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,OAAO,CAAC,YAAY,CAAM,GACjC,iBAAiB,CAWnB"}
@@ -1,7 +1,12 @@
1
1
  import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
2
2
  import type { InputDefinition } from "./common.js";
3
3
  import type { ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
4
- export type ToolCallback = (params: Record<string, any>) => Promise<CallToolResult>;
4
+ import type { ToolContext } from "../mcp-server.js";
5
+ /**
6
+ * Callback function for tool execution.
7
+ * Can optionally receive a ToolContext as the second parameter for sampling support.
8
+ */
9
+ export type ToolCallback = (params: Record<string, any>, ctx?: ToolContext) => Promise<CallToolResult>;
5
10
  export interface ToolDefinition {
6
11
  /** Unique identifier for the tool */
7
12
  name: string;
@@ -11,7 +16,26 @@ export interface ToolDefinition {
11
16
  description?: string;
12
17
  /** Input parameter definitions */
13
18
  inputs?: InputDefinition[];
14
- /** Async callback function that executes the tool */
19
+ /**
20
+ * Async callback function that executes the tool.
21
+ * Receives tool parameters and optionally a ToolContext for sampling support.
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * // Simple tool without sampling
26
+ * cb: async ({ name }) => ({
27
+ * content: [{ type: 'text', text: `Hello, ${name}!` }]
28
+ * })
29
+ *
30
+ * // Tool with sampling support
31
+ * cb: async ({ text }, ctx) => {
32
+ * const result = await ctx.sample({
33
+ * messages: [{ role: 'user', content: { type: 'text', text } }]
34
+ * });
35
+ * return { content: result.content };
36
+ * }
37
+ * ```
38
+ */
15
39
  cb: ToolCallback;
16
40
  /** Tool annotations */
17
41
  annotations?: ToolAnnotations;
@@ -1 +1 @@
1
- {"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../../../src/server/types/tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAE1E,MAAM,MAAM,YAAY,GAAG,CACzB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KACxB,OAAO,CAAC,cAAc,CAAC,CAAC;AAE7B,MAAM,WAAW,cAAc;IAC7B,qCAAqC;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kCAAkC;IAClC,MAAM,CAAC,EAAE,eAAe,EAAE,CAAC;IAC3B,qDAAqD;IACrD,EAAE,EAAE,YAAY,CAAC;IACjB,uBAAuB;IACvB,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B,4BAA4B;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC"}
1
+ {"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../../../src/server/types/tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,CACzB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3B,GAAG,CAAC,EAAE,WAAW,KACd,OAAO,CAAC,cAAc,CAAC,CAAC;AAE7B,MAAM,WAAW,cAAc;IAC7B,qCAAqC;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kCAAkC;IAClC,MAAM,CAAC,EAAE,eAAe,EAAE,CAAC;IAC3B;;;;;;;;;;;;;;;;;;;OAmBG;IACH,EAAE,EAAE,YAAY,CAAC;IACjB,uBAAuB;IACvB,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B,4BAA4B;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mcp-use",
3
3
  "type": "module",
4
- "version": "1.5.1-canary.1",
4
+ "version": "1.5.1-canary.3",
5
5
  "description": "Opinionated MCP Framework for TypeScript (@modelcontextprotocol/sdk compatible) - Build MCP Agents and Clients + MCP Servers with support for MCP-UI.",
6
6
  "author": "mcp-use, Inc.",
7
7
  "license": "MIT",
@@ -115,8 +115,8 @@
115
115
  "ws": "^8.18.2",
116
116
  "zod": "^3.25.48",
117
117
  "zod-to-json-schema": "^3.24.6",
118
- "@mcp-use/cli": "2.3.1-canary.1",
119
- "@mcp-use/inspector": "0.7.1-canary.1"
118
+ "@mcp-use/cli": "2.3.1-canary.3",
119
+ "@mcp-use/inspector": "0.7.1-canary.3"
120
120
  },
121
121
  "optionalDependencies": {
122
122
  "@tailwindcss/vite": "^4.1.15",