mcp-use 1.2.0-canary.0 → 1.2.0-canary.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.
@@ -2100,7 +2100,7 @@ var MCPAgent = class {
2100
2100
  const eventStream = agentExecutor.streamEvents(
2101
2101
  { messages: inputs },
2102
2102
  {
2103
- streamMode: "updates",
2103
+ streamMode: "messages",
2104
2104
  version: "v2",
2105
2105
  callbacks: this.callbacks,
2106
2106
  metadata: this.getMetadata(),
@@ -2119,8 +2119,19 @@ var MCPAgent = class {
2119
2119
  if (event.event === "on_chat_model_stream" && event.data?.chunk?.content) {
2120
2120
  totalResponseLength += event.data.chunk.content.length;
2121
2121
  }
2122
+ if (event.event === "on_chat_model_stream" && event.data?.chunk) {
2123
+ const chunk = event.data.chunk;
2124
+ if (chunk.content) {
2125
+ if (!finalResponse) {
2126
+ finalResponse = "";
2127
+ }
2128
+ const normalizedContent = this._normalizeOutput(chunk.content);
2129
+ finalResponse += normalizedContent;
2130
+ logger.debug(`\u{1F4DD} Accumulated response length: ${finalResponse.length}`);
2131
+ }
2132
+ }
2122
2133
  yield event;
2123
- if (event.event === "on_chain_end" && event.data?.output) {
2134
+ if (event.event === "on_chain_end" && event.data?.output && !finalResponse) {
2124
2135
  const output = event.data.output;
2125
2136
  if (Array.isArray(output) && output.length > 0 && output[0]?.text) {
2126
2137
  finalResponse = output[0].text;
@@ -2234,13 +2245,13 @@ var MCPAgent = class {
2234
2245
  }
2235
2246
  /**
2236
2247
  * Attempt to create structured output from raw result with validation and retry logic.
2237
- *
2248
+ *
2238
2249
  * @param rawResult - The raw text result from the agent
2239
2250
  * @param llm - LLM to use for structured output
2240
2251
  * @param outputSchema - The Zod schema to validate against
2241
2252
  */
2242
2253
  async _attemptStructuredOutput(rawResult, llm, outputSchema) {
2243
- logger.info(`\u{1F504} Attempting structured output with schema: ${outputSchema}`);
2254
+ logger.info(`\u{1F504} Attempting structured output with schema: ${JSON.stringify(outputSchema, null, 2)}`);
2244
2255
  logger.info(`\u{1F504} Raw result: ${JSON.stringify(rawResult, null, 2)}`);
2245
2256
  let structuredLlm = null;
2246
2257
  let schemaDescription = "";
@@ -2252,7 +2263,9 @@ var MCPAgent = class {
2252
2263
  } else {
2253
2264
  throw new Error("LLM is required for structured output");
2254
2265
  }
2255
- schemaDescription = JSON.stringify(zodToJsonSchema2(outputSchema), null, 2);
2266
+ const jsonSchema = zodToJsonSchema2(outputSchema);
2267
+ const { $schema, additionalProperties, ...cleanSchema } = jsonSchema;
2268
+ schemaDescription = JSON.stringify(cleanSchema, null, 2);
2256
2269
  logger.info(`\u{1F504} Schema description: ${schemaDescription}`);
2257
2270
  let textContent = "";
2258
2271
  if (typeof rawResult === "string") {
@@ -2260,6 +2273,7 @@ var MCPAgent = class {
2260
2273
  } else if (rawResult && typeof rawResult === "object") {
2261
2274
  textContent = JSON.stringify(rawResult);
2262
2275
  }
2276
+ logger.info("rawResult", rawResult);
2263
2277
  if (!textContent) {
2264
2278
  textContent = JSON.stringify(rawResult);
2265
2279
  }
@@ -2270,28 +2284,34 @@ var MCPAgent = class {
2270
2284
  let formatPrompt = `
2271
2285
  Please format the following information according to the EXACT schema specified below.
2272
2286
  You must use the exact field names and types as shown in the schema.
2273
-
2287
+
2274
2288
  Required schema format:
2275
2289
  ${schemaDescription}
2276
-
2290
+
2277
2291
  Content to extract from:
2278
2292
  ${textContent}
2279
-
2280
- IMPORTANT:
2293
+
2294
+ IMPORTANT:
2281
2295
  - Use ONLY the field names specified in the schema
2282
2296
  - Match the data types exactly (string, number, boolean, array, etc.)
2283
2297
  - Include ALL required fields
2284
2298
  - Return valid JSON that matches the schema structure exactly
2299
+ - For missing data: use null for nullable fields, omit optional fields entirely
2300
+ - Do NOT use empty strings ("") or zero (0) as placeholders for missing data
2285
2301
  `;
2286
2302
  if (attempt > 1) {
2287
2303
  formatPrompt += `
2288
-
2304
+
2289
2305
  PREVIOUS ATTEMPT FAILED with error: ${lastError}
2290
2306
  Please fix the issues mentioned above and ensure the output matches the schema exactly.
2291
2307
  `;
2292
2308
  }
2293
2309
  try {
2294
2310
  logger.info(`\u{1F504} Structured output attempt ${attempt} - using streaming approach`);
2311
+ const contentPreview = textContent.length > 300 ? `${textContent.slice(0, 300)}...` : textContent;
2312
+ logger.info(`\u{1F504} Content being formatted (${textContent.length} chars): ${contentPreview}`);
2313
+ logger.info(`\u{1F504} Full format prompt (${formatPrompt.length} chars):
2314
+ ${formatPrompt}`);
2295
2315
  const stream = await structuredLlm.stream(formatPrompt);
2296
2316
  let structuredResult = null;
2297
2317
  let chunkCount = 0;
@@ -2367,14 +2387,16 @@ var MCPAgent = class {
2367
2387
  */
2368
2388
  _enhanceQueryWithSchema(query, outputSchema) {
2369
2389
  try {
2370
- const schemaDescription = JSON.stringify(zodToJsonSchema2(outputSchema), null, 2);
2390
+ const jsonSchema = zodToJsonSchema2(outputSchema);
2391
+ const { $schema, additionalProperties, ...cleanSchema } = jsonSchema;
2392
+ const schemaDescription = JSON.stringify(cleanSchema, null, 2);
2371
2393
  const enhancedQuery = `
2372
2394
  ${query}
2373
-
2395
+
2374
2396
  IMPORTANT: Your response must include sufficient information to populate the following structured output:
2375
-
2397
+
2376
2398
  ${schemaDescription}
2377
-
2399
+
2378
2400
  Make sure you gather ALL the required information during your task execution.
2379
2401
  If any required information is missing, continue working to find it.
2380
2402
  `;
package/dist/index.cjs CHANGED
@@ -2638,7 +2638,7 @@ var MCPAgent = class {
2638
2638
  const eventStream = agentExecutor.streamEvents(
2639
2639
  { messages: inputs },
2640
2640
  {
2641
- streamMode: "updates",
2641
+ streamMode: "messages",
2642
2642
  version: "v2",
2643
2643
  callbacks: this.callbacks,
2644
2644
  metadata: this.getMetadata(),
@@ -2657,8 +2657,19 @@ var MCPAgent = class {
2657
2657
  if (event.event === "on_chat_model_stream" && event.data?.chunk?.content) {
2658
2658
  totalResponseLength += event.data.chunk.content.length;
2659
2659
  }
2660
+ if (event.event === "on_chat_model_stream" && event.data?.chunk) {
2661
+ const chunk = event.data.chunk;
2662
+ if (chunk.content) {
2663
+ if (!finalResponse) {
2664
+ finalResponse = "";
2665
+ }
2666
+ const normalizedContent = this._normalizeOutput(chunk.content);
2667
+ finalResponse += normalizedContent;
2668
+ logger.debug(`\u{1F4DD} Accumulated response length: ${finalResponse.length}`);
2669
+ }
2670
+ }
2660
2671
  yield event;
2661
- if (event.event === "on_chain_end" && event.data?.output) {
2672
+ if (event.event === "on_chain_end" && event.data?.output && !finalResponse) {
2662
2673
  const output = event.data.output;
2663
2674
  if (Array.isArray(output) && output.length > 0 && output[0]?.text) {
2664
2675
  finalResponse = output[0].text;
@@ -2772,13 +2783,13 @@ var MCPAgent = class {
2772
2783
  }
2773
2784
  /**
2774
2785
  * Attempt to create structured output from raw result with validation and retry logic.
2775
- *
2786
+ *
2776
2787
  * @param rawResult - The raw text result from the agent
2777
2788
  * @param llm - LLM to use for structured output
2778
2789
  * @param outputSchema - The Zod schema to validate against
2779
2790
  */
2780
2791
  async _attemptStructuredOutput(rawResult, llm, outputSchema) {
2781
- logger.info(`\u{1F504} Attempting structured output with schema: ${outputSchema}`);
2792
+ logger.info(`\u{1F504} Attempting structured output with schema: ${JSON.stringify(outputSchema, null, 2)}`);
2782
2793
  logger.info(`\u{1F504} Raw result: ${JSON.stringify(rawResult, null, 2)}`);
2783
2794
  let structuredLlm = null;
2784
2795
  let schemaDescription = "";
@@ -2790,7 +2801,9 @@ var MCPAgent = class {
2790
2801
  } else {
2791
2802
  throw new Error("LLM is required for structured output");
2792
2803
  }
2793
- schemaDescription = JSON.stringify((0, import_zod_to_json_schema2.zodToJsonSchema)(outputSchema), null, 2);
2804
+ const jsonSchema = (0, import_zod_to_json_schema2.zodToJsonSchema)(outputSchema);
2805
+ const { $schema, additionalProperties, ...cleanSchema } = jsonSchema;
2806
+ schemaDescription = JSON.stringify(cleanSchema, null, 2);
2794
2807
  logger.info(`\u{1F504} Schema description: ${schemaDescription}`);
2795
2808
  let textContent = "";
2796
2809
  if (typeof rawResult === "string") {
@@ -2798,6 +2811,7 @@ var MCPAgent = class {
2798
2811
  } else if (rawResult && typeof rawResult === "object") {
2799
2812
  textContent = JSON.stringify(rawResult);
2800
2813
  }
2814
+ logger.info("rawResult", rawResult);
2801
2815
  if (!textContent) {
2802
2816
  textContent = JSON.stringify(rawResult);
2803
2817
  }
@@ -2808,28 +2822,34 @@ var MCPAgent = class {
2808
2822
  let formatPrompt = `
2809
2823
  Please format the following information according to the EXACT schema specified below.
2810
2824
  You must use the exact field names and types as shown in the schema.
2811
-
2825
+
2812
2826
  Required schema format:
2813
2827
  ${schemaDescription}
2814
-
2828
+
2815
2829
  Content to extract from:
2816
2830
  ${textContent}
2817
-
2818
- IMPORTANT:
2831
+
2832
+ IMPORTANT:
2819
2833
  - Use ONLY the field names specified in the schema
2820
2834
  - Match the data types exactly (string, number, boolean, array, etc.)
2821
2835
  - Include ALL required fields
2822
2836
  - Return valid JSON that matches the schema structure exactly
2837
+ - For missing data: use null for nullable fields, omit optional fields entirely
2838
+ - Do NOT use empty strings ("") or zero (0) as placeholders for missing data
2823
2839
  `;
2824
2840
  if (attempt > 1) {
2825
2841
  formatPrompt += `
2826
-
2842
+
2827
2843
  PREVIOUS ATTEMPT FAILED with error: ${lastError}
2828
2844
  Please fix the issues mentioned above and ensure the output matches the schema exactly.
2829
2845
  `;
2830
2846
  }
2831
2847
  try {
2832
2848
  logger.info(`\u{1F504} Structured output attempt ${attempt} - using streaming approach`);
2849
+ const contentPreview = textContent.length > 300 ? `${textContent.slice(0, 300)}...` : textContent;
2850
+ logger.info(`\u{1F504} Content being formatted (${textContent.length} chars): ${contentPreview}`);
2851
+ logger.info(`\u{1F504} Full format prompt (${formatPrompt.length} chars):
2852
+ ${formatPrompt}`);
2833
2853
  const stream = await structuredLlm.stream(formatPrompt);
2834
2854
  let structuredResult = null;
2835
2855
  let chunkCount = 0;
@@ -2905,14 +2925,16 @@ var MCPAgent = class {
2905
2925
  */
2906
2926
  _enhanceQueryWithSchema(query, outputSchema) {
2907
2927
  try {
2908
- const schemaDescription = JSON.stringify((0, import_zod_to_json_schema2.zodToJsonSchema)(outputSchema), null, 2);
2928
+ const jsonSchema = (0, import_zod_to_json_schema2.zodToJsonSchema)(outputSchema);
2929
+ const { $schema, additionalProperties, ...cleanSchema } = jsonSchema;
2930
+ const schemaDescription = JSON.stringify(cleanSchema, null, 2);
2909
2931
  const enhancedQuery = `
2910
2932
  ${query}
2911
-
2933
+
2912
2934
  IMPORTANT: Your response must include sufficient information to populate the following structured output:
2913
-
2935
+
2914
2936
  ${schemaDescription}
2915
-
2937
+
2916
2938
  Make sure you gather ALL the required information during your task execution.
2917
2939
  If any required information is missing, continue working to find it.
2918
2940
  `;
package/dist/index.js CHANGED
@@ -21,7 +21,7 @@ import {
21
21
  setTelemetrySource,
22
22
  streamEventsToAISDK,
23
23
  streamEventsToAISDKWithTools
24
- } from "./chunk-ZD4Q56ZQ.js";
24
+ } from "./chunk-IVB3GD5M.js";
25
25
  import {
26
26
  useMcp,
27
27
  useWidget,
@@ -1,16 +1,21 @@
1
1
  import type { BaseCallbackHandler } from '@langchain/core/callbacks/base';
2
- import type { BaseLanguageModelInterface } from '@langchain/core/language_models/base';
2
+ import type { BaseLanguageModelInterface, LanguageModelLike } from '@langchain/core/language_models/base';
3
3
  import type { BaseMessage } from '@langchain/core/messages';
4
4
  import type { StructuredToolInterface } from '@langchain/core/tools';
5
- import type { BaseCallbackConfig } from '@langchain/core/callbacks/manager';
6
5
  import type { StreamEvent } from '@langchain/core/tracers/log_stream';
7
6
  import type { ZodSchema } from 'zod';
8
7
  import type { MCPClient } from '../client.js';
9
8
  import type { BaseConnector } from '../connectors/base.js';
10
- export type StreamConfiguration = {
11
- streamMode?: "updates" | "messages" | "custom" | ("updates" | "messages" | "custom")[];
12
- configurable?: BaseCallbackConfig;
13
- };
9
+ import { SystemMessage } from 'langchain';
10
+ import { LangChainAdapter } from '../adapters/langchain_adapter.js';
11
+ import { ServerManager } from '../managers/server_manager.js';
12
+ import { ObservabilityManager } from '../observability/index.js';
13
+ /**
14
+ * Language model type that accepts any LangChain chat model.
15
+ * createAgent accepts a LanguageModelLike but ChatOpenAI, ChatAnthropic, etc. are still of type BaseLanguageModelInterface.
16
+ * Any is used to avoid TypeScript structural typing issues with protected properties until langchain fixes the issue.
17
+ */
18
+ export type LanguageModel = LanguageModelLike | BaseLanguageModelInterface | any;
14
19
  /**
15
20
  * Represents a single step in the agent's execution
16
21
  */
@@ -22,10 +27,6 @@ export interface AgentStep {
22
27
  };
23
28
  observation: string;
24
29
  }
25
- import { SystemMessage } from 'langchain';
26
- import { LangChainAdapter } from '../adapters/langchain_adapter.js';
27
- import { ServerManager } from '../managers/server_manager.js';
28
- import { ObservabilityManager } from '../observability/index.js';
29
30
  export declare class MCPAgent {
30
31
  private llm?;
31
32
  private client?;
@@ -60,7 +61,7 @@ export declare class MCPAgent {
60
61
  private isRemote;
61
62
  private remoteAgent;
62
63
  constructor(options: {
63
- llm?: BaseLanguageModelInterface;
64
+ llm?: LanguageModel;
64
65
  client?: MCPClient;
65
66
  connectors?: BaseConnector[];
66
67
  maxSteps?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"mcp_agent.d.ts","sourceRoot":"","sources":["../../../src/agents/mcp_agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAA;AACzE,OAAO,KAAK,EAAE,0BAA0B,EAAqB,MAAM,sCAAsC,CAAA;AACzG,OAAO,KAAK,EACV,WAAW,EACZ,MAAM,0BAA0B,CAAA;AACjC,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAA;AAC3E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAA;AACrE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AACpC,OAAO,KAAK,EAAE,S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AC;IAElB;;OAEG;IACU,GAAG,CAAC,CAAC,EAChB,KAAK,EAAE,MAAM,EACb,QAAQ,CAAC,EAAE,MAAM,EACjB,eAAe,CAAC,EAAE,OAAO,EACzB,eAAe,CAAC,EAAE,WAAW,EAAE,EAC/B,YAAY,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,GAC1B,OAAO,CAAC,CAAC,CAAC;IAwBC,MAAM,CAAC,CAAC,GAAG,MAAM,EAC7B,KAAK,EAAE,MAAM,EACb,QAAQ,CAAC,EAAE,MAAM,EACjB,eAAe,UAAO,EACtB,eAAe,CAAC,EAAE,WAAW,EAAE,EAC/B,YAAY,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,GAC1B,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,CAAC,EAAE,IAAI,CAAC;IAiT9C;;;OAGG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAWtB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAmCnC;;;OAGG;IACW,YAAY,CAAC,CAAC,GAAG,MAAM,EACnC,KAAK,EAAE,MAAM,EACb,QAAQ,CAAC,EAAE,MAAM,EACjB,eAAe,UAAO,EACtB,eAAe,CAAC,EAAE,WAAW,EAAE,EAC/B,YAAY,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,GAC1B,cAAc,CAAC,WAAW,EAAE,IAAI,EAAE,IAAI,CAAC;IA2P1C;;;;;;OAMG;YACW,wBAAwB;IA2JtC;;OAEG;IACH,OAAO,CAAC,yBAAyB;IAgCjC;;OAEG;IACH,OAAO,CAAC,uBAAuB;CAyBhC"}
@@ -3606,7 +3606,7 @@ var MCPAgent = class {
3606
3606
  const eventStream = agentExecutor.streamEvents(
3607
3607
  { messages: inputs },
3608
3608
  {
3609
- streamMode: "updates",
3609
+ streamMode: "messages",
3610
3610
  version: "v2",
3611
3611
  callbacks: this.callbacks,
3612
3612
  metadata: this.getMetadata(),
@@ -3625,8 +3625,19 @@ var MCPAgent = class {
3625
3625
  if (event.event === "on_chat_model_stream" && event.data?.chunk?.content) {
3626
3626
  totalResponseLength += event.data.chunk.content.length;
3627
3627
  }
3628
+ if (event.event === "on_chat_model_stream" && event.data?.chunk) {
3629
+ const chunk = event.data.chunk;
3630
+ if (chunk.content) {
3631
+ if (!finalResponse) {
3632
+ finalResponse = "";
3633
+ }
3634
+ const normalizedContent = this._normalizeOutput(chunk.content);
3635
+ finalResponse += normalizedContent;
3636
+ logger.debug(`\u{1F4DD} Accumulated response length: ${finalResponse.length}`);
3637
+ }
3638
+ }
3628
3639
  yield event;
3629
- if (event.event === "on_chain_end" && event.data?.output) {
3640
+ if (event.event === "on_chain_end" && event.data?.output && !finalResponse) {
3630
3641
  const output = event.data.output;
3631
3642
  if (Array.isArray(output) && output.length > 0 && output[0]?.text) {
3632
3643
  finalResponse = output[0].text;
@@ -3740,13 +3751,13 @@ var MCPAgent = class {
3740
3751
  }
3741
3752
  /**
3742
3753
  * Attempt to create structured output from raw result with validation and retry logic.
3743
- *
3754
+ *
3744
3755
  * @param rawResult - The raw text result from the agent
3745
3756
  * @param llm - LLM to use for structured output
3746
3757
  * @param outputSchema - The Zod schema to validate against
3747
3758
  */
3748
3759
  async _attemptStructuredOutput(rawResult, llm, outputSchema) {
3749
- logger.info(`\u{1F504} Attempting structured output with schema: ${outputSchema}`);
3760
+ logger.info(`\u{1F504} Attempting structured output with schema: ${JSON.stringify(outputSchema, null, 2)}`);
3750
3761
  logger.info(`\u{1F504} Raw result: ${JSON.stringify(rawResult, null, 2)}`);
3751
3762
  let structuredLlm = null;
3752
3763
  let schemaDescription = "";
@@ -3758,7 +3769,9 @@ var MCPAgent = class {
3758
3769
  } else {
3759
3770
  throw new Error("LLM is required for structured output");
3760
3771
  }
3761
- schemaDescription = JSON.stringify((0, import_zod_to_json_schema2.zodToJsonSchema)(outputSchema), null, 2);
3772
+ const jsonSchema = (0, import_zod_to_json_schema2.zodToJsonSchema)(outputSchema);
3773
+ const { $schema, additionalProperties, ...cleanSchema } = jsonSchema;
3774
+ schemaDescription = JSON.stringify(cleanSchema, null, 2);
3762
3775
  logger.info(`\u{1F504} Schema description: ${schemaDescription}`);
3763
3776
  let textContent = "";
3764
3777
  if (typeof rawResult === "string") {
@@ -3766,6 +3779,7 @@ var MCPAgent = class {
3766
3779
  } else if (rawResult && typeof rawResult === "object") {
3767
3780
  textContent = JSON.stringify(rawResult);
3768
3781
  }
3782
+ logger.info("rawResult", rawResult);
3769
3783
  if (!textContent) {
3770
3784
  textContent = JSON.stringify(rawResult);
3771
3785
  }
@@ -3776,28 +3790,34 @@ var MCPAgent = class {
3776
3790
  let formatPrompt = `
3777
3791
  Please format the following information according to the EXACT schema specified below.
3778
3792
  You must use the exact field names and types as shown in the schema.
3779
-
3793
+
3780
3794
  Required schema format:
3781
3795
  ${schemaDescription}
3782
-
3796
+
3783
3797
  Content to extract from:
3784
3798
  ${textContent}
3785
-
3786
- IMPORTANT:
3799
+
3800
+ IMPORTANT:
3787
3801
  - Use ONLY the field names specified in the schema
3788
3802
  - Match the data types exactly (string, number, boolean, array, etc.)
3789
3803
  - Include ALL required fields
3790
3804
  - Return valid JSON that matches the schema structure exactly
3805
+ - For missing data: use null for nullable fields, omit optional fields entirely
3806
+ - Do NOT use empty strings ("") or zero (0) as placeholders for missing data
3791
3807
  `;
3792
3808
  if (attempt > 1) {
3793
3809
  formatPrompt += `
3794
-
3810
+
3795
3811
  PREVIOUS ATTEMPT FAILED with error: ${lastError}
3796
3812
  Please fix the issues mentioned above and ensure the output matches the schema exactly.
3797
3813
  `;
3798
3814
  }
3799
3815
  try {
3800
3816
  logger.info(`\u{1F504} Structured output attempt ${attempt} - using streaming approach`);
3817
+ const contentPreview = textContent.length > 300 ? `${textContent.slice(0, 300)}...` : textContent;
3818
+ logger.info(`\u{1F504} Content being formatted (${textContent.length} chars): ${contentPreview}`);
3819
+ logger.info(`\u{1F504} Full format prompt (${formatPrompt.length} chars):
3820
+ ${formatPrompt}`);
3801
3821
  const stream = await structuredLlm.stream(formatPrompt);
3802
3822
  let structuredResult = null;
3803
3823
  let chunkCount = 0;
@@ -3873,14 +3893,16 @@ var MCPAgent = class {
3873
3893
  */
3874
3894
  _enhanceQueryWithSchema(query, outputSchema) {
3875
3895
  try {
3876
- const schemaDescription = JSON.stringify((0, import_zod_to_json_schema2.zodToJsonSchema)(outputSchema), null, 2);
3896
+ const jsonSchema = (0, import_zod_to_json_schema2.zodToJsonSchema)(outputSchema);
3897
+ const { $schema, additionalProperties, ...cleanSchema } = jsonSchema;
3898
+ const schemaDescription = JSON.stringify(cleanSchema, null, 2);
3877
3899
  const enhancedQuery = `
3878
3900
  ${query}
3879
-
3901
+
3880
3902
  IMPORTANT: Your response must include sufficient information to populate the following structured output:
3881
-
3903
+
3882
3904
  ${schemaDescription}
3883
-
3905
+
3884
3906
  Make sure you gather ALL the required information during your task execution.
3885
3907
  If any required information is missing, continue working to find it.
3886
3908
  `;
@@ -12,7 +12,7 @@ import {
12
12
  createReadableStreamFromGenerator,
13
13
  streamEventsToAISDK,
14
14
  streamEventsToAISDKWithTools
15
- } from "../chunk-ZD4Q56ZQ.js";
15
+ } from "../chunk-IVB3GD5M.js";
16
16
  import {
17
17
  BrowserOAuthClientProvider,
18
18
  onMcpAuthorization
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mcp-use",
3
3
  "type": "module",
4
- "version": "1.2.0-canary.0",
4
+ "version": "1.2.0-canary.2",
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",
@@ -61,8 +61,8 @@
61
61
  "peerDependencies": {
62
62
  "@langchain/anthropic": "^1.0.0",
63
63
  "@langchain/openai": "^1.0.0",
64
- "@mcp-use/cli": "^2.1.21-canary.0",
65
- "@mcp-use/inspector": "^0.4.9-canary.0",
64
+ "@mcp-use/cli": "^2.1.21-canary.3",
65
+ "@mcp-use/inspector": "^0.4.9-canary.3",
66
66
  "cors": "^2.8.5",
67
67
  "express": "^4.18.2",
68
68
  "langfuse": "^3.38.6",