mcp-use 1.2.0-canary.0 → 1.2.0-canary.1
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/.tsbuildinfo +1 -1
- package/dist/{chunk-ZD4Q56ZQ.js → chunk-GKNOUQFQ.js} +36 -13
- package/dist/index.cjs +36 -13
- package/dist/index.js +1 -1
- package/dist/src/agents/mcp_agent.d.ts +12 -11
- package/dist/src/agents/mcp_agent.d.ts.map +1 -1
- package/dist/src/browser.cjs +36 -13
- package/dist/src/browser.js +1 -1
- package/package.json +3 -3
|
@@ -2100,7 +2100,7 @@ var MCPAgent = class {
|
|
|
2100
2100
|
const eventStream = agentExecutor.streamEvents(
|
|
2101
2101
|
{ messages: inputs },
|
|
2102
2102
|
{
|
|
2103
|
-
streamMode: "
|
|
2103
|
+
streamMode: "messages",
|
|
2104
2104
|
version: "v2",
|
|
2105
2105
|
callbacks: this.callbacks,
|
|
2106
2106
|
metadata: this.getMetadata(),
|
|
@@ -2119,8 +2119,20 @@ 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
|
+
logger.info("on_chat_model_stream", event.data.chunk);
|
|
2124
|
+
const chunk = event.data.chunk;
|
|
2125
|
+
if (chunk.content) {
|
|
2126
|
+
if (!finalResponse) {
|
|
2127
|
+
finalResponse = "";
|
|
2128
|
+
}
|
|
2129
|
+
const normalizedContent = this._normalizeOutput(chunk.content);
|
|
2130
|
+
finalResponse += normalizedContent;
|
|
2131
|
+
logger.debug(`\u{1F4DD} Accumulated response length: ${finalResponse.length}`);
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2122
2134
|
yield event;
|
|
2123
|
-
if (event.event === "on_chain_end" && event.data?.output) {
|
|
2135
|
+
if (event.event === "on_chain_end" && event.data?.output && !finalResponse) {
|
|
2124
2136
|
const output = event.data.output;
|
|
2125
2137
|
if (Array.isArray(output) && output.length > 0 && output[0]?.text) {
|
|
2126
2138
|
finalResponse = output[0].text;
|
|
@@ -2234,7 +2246,7 @@ var MCPAgent = class {
|
|
|
2234
2246
|
}
|
|
2235
2247
|
/**
|
|
2236
2248
|
* Attempt to create structured output from raw result with validation and retry logic.
|
|
2237
|
-
*
|
|
2249
|
+
*
|
|
2238
2250
|
* @param rawResult - The raw text result from the agent
|
|
2239
2251
|
* @param llm - LLM to use for structured output
|
|
2240
2252
|
* @param outputSchema - The Zod schema to validate against
|
|
@@ -2252,7 +2264,9 @@ var MCPAgent = class {
|
|
|
2252
2264
|
} else {
|
|
2253
2265
|
throw new Error("LLM is required for structured output");
|
|
2254
2266
|
}
|
|
2255
|
-
|
|
2267
|
+
const jsonSchema = zodToJsonSchema2(outputSchema);
|
|
2268
|
+
const { $schema, additionalProperties, ...cleanSchema } = jsonSchema;
|
|
2269
|
+
schemaDescription = JSON.stringify(cleanSchema, null, 2);
|
|
2256
2270
|
logger.info(`\u{1F504} Schema description: ${schemaDescription}`);
|
|
2257
2271
|
let textContent = "";
|
|
2258
2272
|
if (typeof rawResult === "string") {
|
|
@@ -2260,6 +2274,7 @@ var MCPAgent = class {
|
|
|
2260
2274
|
} else if (rawResult && typeof rawResult === "object") {
|
|
2261
2275
|
textContent = JSON.stringify(rawResult);
|
|
2262
2276
|
}
|
|
2277
|
+
logger.info("rawResult", rawResult);
|
|
2263
2278
|
if (!textContent) {
|
|
2264
2279
|
textContent = JSON.stringify(rawResult);
|
|
2265
2280
|
}
|
|
@@ -2270,28 +2285,34 @@ var MCPAgent = class {
|
|
|
2270
2285
|
let formatPrompt = `
|
|
2271
2286
|
Please format the following information according to the EXACT schema specified below.
|
|
2272
2287
|
You must use the exact field names and types as shown in the schema.
|
|
2273
|
-
|
|
2288
|
+
|
|
2274
2289
|
Required schema format:
|
|
2275
2290
|
${schemaDescription}
|
|
2276
|
-
|
|
2291
|
+
|
|
2277
2292
|
Content to extract from:
|
|
2278
2293
|
${textContent}
|
|
2279
|
-
|
|
2280
|
-
IMPORTANT:
|
|
2294
|
+
|
|
2295
|
+
IMPORTANT:
|
|
2281
2296
|
- Use ONLY the field names specified in the schema
|
|
2282
2297
|
- Match the data types exactly (string, number, boolean, array, etc.)
|
|
2283
2298
|
- Include ALL required fields
|
|
2284
2299
|
- Return valid JSON that matches the schema structure exactly
|
|
2300
|
+
- For missing data: use null for nullable fields, omit optional fields entirely
|
|
2301
|
+
- Do NOT use empty strings ("") or zero (0) as placeholders for missing data
|
|
2285
2302
|
`;
|
|
2286
2303
|
if (attempt > 1) {
|
|
2287
2304
|
formatPrompt += `
|
|
2288
|
-
|
|
2305
|
+
|
|
2289
2306
|
PREVIOUS ATTEMPT FAILED with error: ${lastError}
|
|
2290
2307
|
Please fix the issues mentioned above and ensure the output matches the schema exactly.
|
|
2291
2308
|
`;
|
|
2292
2309
|
}
|
|
2293
2310
|
try {
|
|
2294
2311
|
logger.info(`\u{1F504} Structured output attempt ${attempt} - using streaming approach`);
|
|
2312
|
+
const contentPreview = textContent.length > 300 ? `${textContent.slice(0, 300)}...` : textContent;
|
|
2313
|
+
logger.info(`\u{1F504} Content being formatted (${textContent.length} chars): ${contentPreview}`);
|
|
2314
|
+
logger.info(`\u{1F504} Full format prompt (${formatPrompt.length} chars):
|
|
2315
|
+
${formatPrompt}`);
|
|
2295
2316
|
const stream = await structuredLlm.stream(formatPrompt);
|
|
2296
2317
|
let structuredResult = null;
|
|
2297
2318
|
let chunkCount = 0;
|
|
@@ -2367,14 +2388,16 @@ var MCPAgent = class {
|
|
|
2367
2388
|
*/
|
|
2368
2389
|
_enhanceQueryWithSchema(query, outputSchema) {
|
|
2369
2390
|
try {
|
|
2370
|
-
const
|
|
2391
|
+
const jsonSchema = zodToJsonSchema2(outputSchema);
|
|
2392
|
+
const { $schema, additionalProperties, ...cleanSchema } = jsonSchema;
|
|
2393
|
+
const schemaDescription = JSON.stringify(cleanSchema, null, 2);
|
|
2371
2394
|
const enhancedQuery = `
|
|
2372
2395
|
${query}
|
|
2373
|
-
|
|
2396
|
+
|
|
2374
2397
|
IMPORTANT: Your response must include sufficient information to populate the following structured output:
|
|
2375
|
-
|
|
2398
|
+
|
|
2376
2399
|
${schemaDescription}
|
|
2377
|
-
|
|
2400
|
+
|
|
2378
2401
|
Make sure you gather ALL the required information during your task execution.
|
|
2379
2402
|
If any required information is missing, continue working to find it.
|
|
2380
2403
|
`;
|
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: "
|
|
2641
|
+
streamMode: "messages",
|
|
2642
2642
|
version: "v2",
|
|
2643
2643
|
callbacks: this.callbacks,
|
|
2644
2644
|
metadata: this.getMetadata(),
|
|
@@ -2657,8 +2657,20 @@ 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
|
+
logger.info("on_chat_model_stream", event.data.chunk);
|
|
2662
|
+
const chunk = event.data.chunk;
|
|
2663
|
+
if (chunk.content) {
|
|
2664
|
+
if (!finalResponse) {
|
|
2665
|
+
finalResponse = "";
|
|
2666
|
+
}
|
|
2667
|
+
const normalizedContent = this._normalizeOutput(chunk.content);
|
|
2668
|
+
finalResponse += normalizedContent;
|
|
2669
|
+
logger.debug(`\u{1F4DD} Accumulated response length: ${finalResponse.length}`);
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2660
2672
|
yield event;
|
|
2661
|
-
if (event.event === "on_chain_end" && event.data?.output) {
|
|
2673
|
+
if (event.event === "on_chain_end" && event.data?.output && !finalResponse) {
|
|
2662
2674
|
const output = event.data.output;
|
|
2663
2675
|
if (Array.isArray(output) && output.length > 0 && output[0]?.text) {
|
|
2664
2676
|
finalResponse = output[0].text;
|
|
@@ -2772,7 +2784,7 @@ var MCPAgent = class {
|
|
|
2772
2784
|
}
|
|
2773
2785
|
/**
|
|
2774
2786
|
* Attempt to create structured output from raw result with validation and retry logic.
|
|
2775
|
-
*
|
|
2787
|
+
*
|
|
2776
2788
|
* @param rawResult - The raw text result from the agent
|
|
2777
2789
|
* @param llm - LLM to use for structured output
|
|
2778
2790
|
* @param outputSchema - The Zod schema to validate against
|
|
@@ -2790,7 +2802,9 @@ var MCPAgent = class {
|
|
|
2790
2802
|
} else {
|
|
2791
2803
|
throw new Error("LLM is required for structured output");
|
|
2792
2804
|
}
|
|
2793
|
-
|
|
2805
|
+
const jsonSchema = (0, import_zod_to_json_schema2.zodToJsonSchema)(outputSchema);
|
|
2806
|
+
const { $schema, additionalProperties, ...cleanSchema } = jsonSchema;
|
|
2807
|
+
schemaDescription = JSON.stringify(cleanSchema, null, 2);
|
|
2794
2808
|
logger.info(`\u{1F504} Schema description: ${schemaDescription}`);
|
|
2795
2809
|
let textContent = "";
|
|
2796
2810
|
if (typeof rawResult === "string") {
|
|
@@ -2798,6 +2812,7 @@ var MCPAgent = class {
|
|
|
2798
2812
|
} else if (rawResult && typeof rawResult === "object") {
|
|
2799
2813
|
textContent = JSON.stringify(rawResult);
|
|
2800
2814
|
}
|
|
2815
|
+
logger.info("rawResult", rawResult);
|
|
2801
2816
|
if (!textContent) {
|
|
2802
2817
|
textContent = JSON.stringify(rawResult);
|
|
2803
2818
|
}
|
|
@@ -2808,28 +2823,34 @@ var MCPAgent = class {
|
|
|
2808
2823
|
let formatPrompt = `
|
|
2809
2824
|
Please format the following information according to the EXACT schema specified below.
|
|
2810
2825
|
You must use the exact field names and types as shown in the schema.
|
|
2811
|
-
|
|
2826
|
+
|
|
2812
2827
|
Required schema format:
|
|
2813
2828
|
${schemaDescription}
|
|
2814
|
-
|
|
2829
|
+
|
|
2815
2830
|
Content to extract from:
|
|
2816
2831
|
${textContent}
|
|
2817
|
-
|
|
2818
|
-
IMPORTANT:
|
|
2832
|
+
|
|
2833
|
+
IMPORTANT:
|
|
2819
2834
|
- Use ONLY the field names specified in the schema
|
|
2820
2835
|
- Match the data types exactly (string, number, boolean, array, etc.)
|
|
2821
2836
|
- Include ALL required fields
|
|
2822
2837
|
- Return valid JSON that matches the schema structure exactly
|
|
2838
|
+
- For missing data: use null for nullable fields, omit optional fields entirely
|
|
2839
|
+
- Do NOT use empty strings ("") or zero (0) as placeholders for missing data
|
|
2823
2840
|
`;
|
|
2824
2841
|
if (attempt > 1) {
|
|
2825
2842
|
formatPrompt += `
|
|
2826
|
-
|
|
2843
|
+
|
|
2827
2844
|
PREVIOUS ATTEMPT FAILED with error: ${lastError}
|
|
2828
2845
|
Please fix the issues mentioned above and ensure the output matches the schema exactly.
|
|
2829
2846
|
`;
|
|
2830
2847
|
}
|
|
2831
2848
|
try {
|
|
2832
2849
|
logger.info(`\u{1F504} Structured output attempt ${attempt} - using streaming approach`);
|
|
2850
|
+
const contentPreview = textContent.length > 300 ? `${textContent.slice(0, 300)}...` : textContent;
|
|
2851
|
+
logger.info(`\u{1F504} Content being formatted (${textContent.length} chars): ${contentPreview}`);
|
|
2852
|
+
logger.info(`\u{1F504} Full format prompt (${formatPrompt.length} chars):
|
|
2853
|
+
${formatPrompt}`);
|
|
2833
2854
|
const stream = await structuredLlm.stream(formatPrompt);
|
|
2834
2855
|
let structuredResult = null;
|
|
2835
2856
|
let chunkCount = 0;
|
|
@@ -2905,14 +2926,16 @@ var MCPAgent = class {
|
|
|
2905
2926
|
*/
|
|
2906
2927
|
_enhanceQueryWithSchema(query, outputSchema) {
|
|
2907
2928
|
try {
|
|
2908
|
-
const
|
|
2929
|
+
const jsonSchema = (0, import_zod_to_json_schema2.zodToJsonSchema)(outputSchema);
|
|
2930
|
+
const { $schema, additionalProperties, ...cleanSchema } = jsonSchema;
|
|
2931
|
+
const schemaDescription = JSON.stringify(cleanSchema, null, 2);
|
|
2909
2932
|
const enhancedQuery = `
|
|
2910
2933
|
${query}
|
|
2911
|
-
|
|
2934
|
+
|
|
2912
2935
|
IMPORTANT: Your response must include sufficient information to populate the following structured output:
|
|
2913
|
-
|
|
2936
|
+
|
|
2914
2937
|
${schemaDescription}
|
|
2915
|
-
|
|
2938
|
+
|
|
2916
2939
|
Make sure you gather ALL the required information during your task execution.
|
|
2917
2940
|
If any required information is missing, continue working to find it.
|
|
2918
2941
|
`;
|
package/dist/index.js
CHANGED
|
@@ -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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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?:
|
|
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,
|
|
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,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAA;AACzG,OAAO,KAAK,EACV,WAAW,EACZ,MAAM,0BAA0B,CAAA;AACjC,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAA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AAE,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;IA4P1C;;;;;;OAMG;YACW,wBAAwB;IA2JtC;;OAEG;IACH,OAAO,CAAC,yBAAyB;IAgCjC;;OAEG;IACH,OAAO,CAAC,uBAAuB;CAyBhC"}
|
package/dist/src/browser.cjs
CHANGED
|
@@ -3606,7 +3606,7 @@ var MCPAgent = class {
|
|
|
3606
3606
|
const eventStream = agentExecutor.streamEvents(
|
|
3607
3607
|
{ messages: inputs },
|
|
3608
3608
|
{
|
|
3609
|
-
streamMode: "
|
|
3609
|
+
streamMode: "messages",
|
|
3610
3610
|
version: "v2",
|
|
3611
3611
|
callbacks: this.callbacks,
|
|
3612
3612
|
metadata: this.getMetadata(),
|
|
@@ -3625,8 +3625,20 @@ 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
|
+
logger.info("on_chat_model_stream", event.data.chunk);
|
|
3630
|
+
const chunk = event.data.chunk;
|
|
3631
|
+
if (chunk.content) {
|
|
3632
|
+
if (!finalResponse) {
|
|
3633
|
+
finalResponse = "";
|
|
3634
|
+
}
|
|
3635
|
+
const normalizedContent = this._normalizeOutput(chunk.content);
|
|
3636
|
+
finalResponse += normalizedContent;
|
|
3637
|
+
logger.debug(`\u{1F4DD} Accumulated response length: ${finalResponse.length}`);
|
|
3638
|
+
}
|
|
3639
|
+
}
|
|
3628
3640
|
yield event;
|
|
3629
|
-
if (event.event === "on_chain_end" && event.data?.output) {
|
|
3641
|
+
if (event.event === "on_chain_end" && event.data?.output && !finalResponse) {
|
|
3630
3642
|
const output = event.data.output;
|
|
3631
3643
|
if (Array.isArray(output) && output.length > 0 && output[0]?.text) {
|
|
3632
3644
|
finalResponse = output[0].text;
|
|
@@ -3740,7 +3752,7 @@ var MCPAgent = class {
|
|
|
3740
3752
|
}
|
|
3741
3753
|
/**
|
|
3742
3754
|
* Attempt to create structured output from raw result with validation and retry logic.
|
|
3743
|
-
*
|
|
3755
|
+
*
|
|
3744
3756
|
* @param rawResult - The raw text result from the agent
|
|
3745
3757
|
* @param llm - LLM to use for structured output
|
|
3746
3758
|
* @param outputSchema - The Zod schema to validate against
|
|
@@ -3758,7 +3770,9 @@ var MCPAgent = class {
|
|
|
3758
3770
|
} else {
|
|
3759
3771
|
throw new Error("LLM is required for structured output");
|
|
3760
3772
|
}
|
|
3761
|
-
|
|
3773
|
+
const jsonSchema = (0, import_zod_to_json_schema2.zodToJsonSchema)(outputSchema);
|
|
3774
|
+
const { $schema, additionalProperties, ...cleanSchema } = jsonSchema;
|
|
3775
|
+
schemaDescription = JSON.stringify(cleanSchema, null, 2);
|
|
3762
3776
|
logger.info(`\u{1F504} Schema description: ${schemaDescription}`);
|
|
3763
3777
|
let textContent = "";
|
|
3764
3778
|
if (typeof rawResult === "string") {
|
|
@@ -3766,6 +3780,7 @@ var MCPAgent = class {
|
|
|
3766
3780
|
} else if (rawResult && typeof rawResult === "object") {
|
|
3767
3781
|
textContent = JSON.stringify(rawResult);
|
|
3768
3782
|
}
|
|
3783
|
+
logger.info("rawResult", rawResult);
|
|
3769
3784
|
if (!textContent) {
|
|
3770
3785
|
textContent = JSON.stringify(rawResult);
|
|
3771
3786
|
}
|
|
@@ -3776,28 +3791,34 @@ var MCPAgent = class {
|
|
|
3776
3791
|
let formatPrompt = `
|
|
3777
3792
|
Please format the following information according to the EXACT schema specified below.
|
|
3778
3793
|
You must use the exact field names and types as shown in the schema.
|
|
3779
|
-
|
|
3794
|
+
|
|
3780
3795
|
Required schema format:
|
|
3781
3796
|
${schemaDescription}
|
|
3782
|
-
|
|
3797
|
+
|
|
3783
3798
|
Content to extract from:
|
|
3784
3799
|
${textContent}
|
|
3785
|
-
|
|
3786
|
-
IMPORTANT:
|
|
3800
|
+
|
|
3801
|
+
IMPORTANT:
|
|
3787
3802
|
- Use ONLY the field names specified in the schema
|
|
3788
3803
|
- Match the data types exactly (string, number, boolean, array, etc.)
|
|
3789
3804
|
- Include ALL required fields
|
|
3790
3805
|
- Return valid JSON that matches the schema structure exactly
|
|
3806
|
+
- For missing data: use null for nullable fields, omit optional fields entirely
|
|
3807
|
+
- Do NOT use empty strings ("") or zero (0) as placeholders for missing data
|
|
3791
3808
|
`;
|
|
3792
3809
|
if (attempt > 1) {
|
|
3793
3810
|
formatPrompt += `
|
|
3794
|
-
|
|
3811
|
+
|
|
3795
3812
|
PREVIOUS ATTEMPT FAILED with error: ${lastError}
|
|
3796
3813
|
Please fix the issues mentioned above and ensure the output matches the schema exactly.
|
|
3797
3814
|
`;
|
|
3798
3815
|
}
|
|
3799
3816
|
try {
|
|
3800
3817
|
logger.info(`\u{1F504} Structured output attempt ${attempt} - using streaming approach`);
|
|
3818
|
+
const contentPreview = textContent.length > 300 ? `${textContent.slice(0, 300)}...` : textContent;
|
|
3819
|
+
logger.info(`\u{1F504} Content being formatted (${textContent.length} chars): ${contentPreview}`);
|
|
3820
|
+
logger.info(`\u{1F504} Full format prompt (${formatPrompt.length} chars):
|
|
3821
|
+
${formatPrompt}`);
|
|
3801
3822
|
const stream = await structuredLlm.stream(formatPrompt);
|
|
3802
3823
|
let structuredResult = null;
|
|
3803
3824
|
let chunkCount = 0;
|
|
@@ -3873,14 +3894,16 @@ var MCPAgent = class {
|
|
|
3873
3894
|
*/
|
|
3874
3895
|
_enhanceQueryWithSchema(query, outputSchema) {
|
|
3875
3896
|
try {
|
|
3876
|
-
const
|
|
3897
|
+
const jsonSchema = (0, import_zod_to_json_schema2.zodToJsonSchema)(outputSchema);
|
|
3898
|
+
const { $schema, additionalProperties, ...cleanSchema } = jsonSchema;
|
|
3899
|
+
const schemaDescription = JSON.stringify(cleanSchema, null, 2);
|
|
3877
3900
|
const enhancedQuery = `
|
|
3878
3901
|
${query}
|
|
3879
|
-
|
|
3902
|
+
|
|
3880
3903
|
IMPORTANT: Your response must include sufficient information to populate the following structured output:
|
|
3881
|
-
|
|
3904
|
+
|
|
3882
3905
|
${schemaDescription}
|
|
3883
|
-
|
|
3906
|
+
|
|
3884
3907
|
Make sure you gather ALL the required information during your task execution.
|
|
3885
3908
|
If any required information is missing, continue working to find it.
|
|
3886
3909
|
`;
|
package/dist/src/browser.js
CHANGED
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.
|
|
4
|
+
"version": "1.2.0-canary.1",
|
|
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.
|
|
65
|
-
"@mcp-use/inspector": "^0.4.9-canary.
|
|
64
|
+
"@mcp-use/cli": "^2.1.21-canary.2",
|
|
65
|
+
"@mcp-use/inspector": "^0.4.9-canary.2",
|
|
66
66
|
"cors": "^2.8.5",
|
|
67
67
|
"express": "^4.18.2",
|
|
68
68
|
"langfuse": "^3.38.6",
|