@mcpjam/sdk 0.8.0 → 0.8.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/index.d.mts +31 -159
- package/dist/index.d.ts +31 -159
- package/dist/index.js +56 -33
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +54 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -552,6 +552,36 @@ function ensureJsonSchemaObject(schema) {
|
|
|
552
552
|
additionalProperties: false
|
|
553
553
|
};
|
|
554
554
|
}
|
|
555
|
+
function isMcpAppTool(toolMeta) {
|
|
556
|
+
if (!toolMeta) return false;
|
|
557
|
+
const nested = toolMeta.ui;
|
|
558
|
+
if (typeof nested?.resourceUri === "string") return true;
|
|
559
|
+
return typeof toolMeta["ui/resourceUri"] === "string";
|
|
560
|
+
}
|
|
561
|
+
function isChatGPTAppTool(toolMeta) {
|
|
562
|
+
if (!toolMeta) return false;
|
|
563
|
+
return typeof toolMeta["openai/outputTemplate"] === "string";
|
|
564
|
+
}
|
|
565
|
+
function scrubMetaFromToolResult(result) {
|
|
566
|
+
if (!result) return result;
|
|
567
|
+
const copy = { ...result };
|
|
568
|
+
if (copy._meta) {
|
|
569
|
+
delete copy._meta;
|
|
570
|
+
}
|
|
571
|
+
return copy;
|
|
572
|
+
}
|
|
573
|
+
function scrubStructuredContentFromToolResult(result) {
|
|
574
|
+
if (!result) return result;
|
|
575
|
+
const copy = { ...result };
|
|
576
|
+
if (copy.structuredContent) {
|
|
577
|
+
delete copy.structuredContent;
|
|
578
|
+
}
|
|
579
|
+
return copy;
|
|
580
|
+
}
|
|
581
|
+
function scrubMetaAndStructuredContentFromToolResult(result) {
|
|
582
|
+
if (!result) return result;
|
|
583
|
+
return scrubMetaFromToolResult(scrubStructuredContentFromToolResult(result));
|
|
584
|
+
}
|
|
555
585
|
async function convertMCPToolsToVercelTools(listToolsResult, {
|
|
556
586
|
schemas = "automatic",
|
|
557
587
|
callTool
|
|
@@ -559,18 +589,31 @@ async function convertMCPToolsToVercelTools(listToolsResult, {
|
|
|
559
589
|
const tools = {};
|
|
560
590
|
for (const toolDescription of listToolsResult.tools) {
|
|
561
591
|
const { name, description, inputSchema } = toolDescription;
|
|
592
|
+
const toolMeta = toolDescription._meta;
|
|
562
593
|
const execute = async (args, options) => {
|
|
563
|
-
options?.abortSignal?.throwIfAborted
|
|
594
|
+
options?.abortSignal?.throwIfAborted();
|
|
564
595
|
const result = await callTool({ name, args, options });
|
|
565
596
|
return types_js.CallToolResultSchema.parse(result);
|
|
566
597
|
};
|
|
598
|
+
const toModelOutput = isMcpAppTool(toolMeta) ? ((opts) => {
|
|
599
|
+
const scrubbed = scrubMetaAndStructuredContentFromToolResult(
|
|
600
|
+
opts.output
|
|
601
|
+
);
|
|
602
|
+
return { type: "json", value: scrubbed };
|
|
603
|
+
}) : isChatGPTAppTool(toolMeta) ? ((opts) => {
|
|
604
|
+
const scrubbed = scrubStructuredContentFromToolResult(
|
|
605
|
+
opts.output
|
|
606
|
+
);
|
|
607
|
+
return { type: "json", value: scrubbed };
|
|
608
|
+
}) : void 0;
|
|
567
609
|
let vercelTool;
|
|
568
610
|
if (schemas === "automatic") {
|
|
569
611
|
const normalizedInputSchema = ensureJsonSchemaObject(inputSchema);
|
|
570
612
|
vercelTool = ai.dynamicTool({
|
|
571
613
|
description,
|
|
572
614
|
inputSchema: ai.jsonSchema(normalizedInputSchema),
|
|
573
|
-
execute
|
|
615
|
+
execute,
|
|
616
|
+
...toModelOutput ? { toModelOutput } : {}
|
|
574
617
|
});
|
|
575
618
|
} else {
|
|
576
619
|
const overrides = schemas;
|
|
@@ -580,7 +623,8 @@ async function convertMCPToolsToVercelTools(listToolsResult, {
|
|
|
580
623
|
vercelTool = ai.tool({
|
|
581
624
|
description,
|
|
582
625
|
inputSchema: overrides[name].inputSchema,
|
|
583
|
-
execute
|
|
626
|
+
execute,
|
|
627
|
+
...toModelOutput ? { toModelOutput } : {}
|
|
584
628
|
});
|
|
585
629
|
}
|
|
586
630
|
tools[name] = vercelTool;
|
|
@@ -1634,9 +1678,6 @@ function extractToolCalls(result) {
|
|
|
1634
1678
|
}
|
|
1635
1679
|
return toolCalls;
|
|
1636
1680
|
}
|
|
1637
|
-
function extractToolNames(result) {
|
|
1638
|
-
return extractToolCalls(result).map((tc) => tc.toolName);
|
|
1639
|
-
}
|
|
1640
1681
|
|
|
1641
1682
|
// src/PromptResult.ts
|
|
1642
1683
|
var PromptResult = class _PromptResult {
|
|
@@ -1957,9 +1998,9 @@ var TestAgent = class _TestAgent {
|
|
|
1957
1998
|
return instrumented;
|
|
1958
1999
|
}
|
|
1959
2000
|
/**
|
|
1960
|
-
* Build an array of
|
|
2001
|
+
* Build an array of ModelMessages from previous PromptResult(s) for multi-turn context.
|
|
1961
2002
|
* @param context - Single PromptResult or array of PromptResults to include as context
|
|
1962
|
-
* @returns Array of
|
|
2003
|
+
* @returns Array of ModelMessages representing the conversation history
|
|
1963
2004
|
*/
|
|
1964
2005
|
buildContextMessages(context) {
|
|
1965
2006
|
if (!context) {
|
|
@@ -2020,7 +2061,9 @@ var TestAgent = class _TestAgent {
|
|
|
2020
2061
|
// Use messages array for multi-turn, simple prompt for single-turn
|
|
2021
2062
|
...contextMessages.length > 0 ? { messages: [...contextMessages, userMessage] } : { prompt: message },
|
|
2022
2063
|
// Only include temperature if explicitly set (some models like reasoning models don't support it)
|
|
2023
|
-
...this.temperature !== void 0 && {
|
|
2064
|
+
...this.temperature !== void 0 && {
|
|
2065
|
+
temperature: this.temperature
|
|
2066
|
+
},
|
|
2024
2067
|
// Use stopWhen with stepCountIs for controlling max agentic steps
|
|
2025
2068
|
// AI SDK v6+ uses this instead of maxSteps
|
|
2026
2069
|
stopWhen: ai.stepCountIs(this.maxSteps),
|
|
@@ -2792,18 +2835,6 @@ var EvalSuite = class {
|
|
|
2792
2835
|
}
|
|
2793
2836
|
};
|
|
2794
2837
|
|
|
2795
|
-
Object.defineProperty(exports, "PromptListChangedNotificationSchema", {
|
|
2796
|
-
enumerable: true,
|
|
2797
|
-
get: function () { return types_js.PromptListChangedNotificationSchema; }
|
|
2798
|
-
});
|
|
2799
|
-
Object.defineProperty(exports, "ResourceListChangedNotificationSchema", {
|
|
2800
|
-
enumerable: true,
|
|
2801
|
-
get: function () { return types_js.ResourceListChangedNotificationSchema; }
|
|
2802
|
-
});
|
|
2803
|
-
Object.defineProperty(exports, "ResourceUpdatedNotificationSchema", {
|
|
2804
|
-
enumerable: true,
|
|
2805
|
-
get: function () { return types_js.ResourceUpdatedNotificationSchema; }
|
|
2806
|
-
});
|
|
2807
2838
|
exports.EvalSuite = EvalSuite;
|
|
2808
2839
|
exports.EvalTest = EvalTest;
|
|
2809
2840
|
exports.MCPAuthError = MCPAuthError;
|
|
@@ -2812,19 +2843,12 @@ exports.MCPError = MCPError;
|
|
|
2812
2843
|
exports.PROVIDER_PRESETS = PROVIDER_PRESETS;
|
|
2813
2844
|
exports.PromptResult = PromptResult;
|
|
2814
2845
|
exports.TestAgent = TestAgent;
|
|
2815
|
-
exports.buildRequestInit = buildRequestInit;
|
|
2816
|
-
exports.calculateLatencyStats = calculateLatencyStats;
|
|
2817
|
-
exports.calculatePercentile = calculatePercentile;
|
|
2818
|
-
exports.convertMCPToolsToVercelTools = convertMCPToolsToVercelTools;
|
|
2819
2846
|
exports.createCustomProvider = createCustomProvider;
|
|
2820
2847
|
exports.createModelFromString = createModelFromString;
|
|
2821
|
-
exports.ensureJsonSchemaObject = ensureJsonSchemaObject;
|
|
2822
|
-
exports.extractToolCalls = extractToolCalls;
|
|
2823
|
-
exports.extractToolNames = extractToolNames;
|
|
2824
|
-
exports.formatError = formatError;
|
|
2825
2848
|
exports.isAuthError = isAuthError;
|
|
2849
|
+
exports.isChatGPTAppTool = isChatGPTAppTool;
|
|
2826
2850
|
exports.isMCPAuthError = isMCPAuthError;
|
|
2827
|
-
exports.
|
|
2851
|
+
exports.isMcpAppTool = isMcpAppTool;
|
|
2828
2852
|
exports.matchAnyToolCall = matchAnyToolCall;
|
|
2829
2853
|
exports.matchNoToolCalls = matchNoToolCalls;
|
|
2830
2854
|
exports.matchToolArgument = matchToolArgument;
|
|
@@ -2836,8 +2860,7 @@ exports.matchToolCalls = matchToolCalls;
|
|
|
2836
2860
|
exports.matchToolCallsSubset = matchToolCallsSubset;
|
|
2837
2861
|
exports.parseLLMString = parseLLMString;
|
|
2838
2862
|
exports.parseModelIds = parseModelIds;
|
|
2839
|
-
exports.
|
|
2840
|
-
exports.
|
|
2841
|
-
exports.supportsTasksList = supportsTasksList;
|
|
2863
|
+
exports.scrubMetaAndStructuredContentFromToolResult = scrubMetaAndStructuredContentFromToolResult;
|
|
2864
|
+
exports.scrubMetaFromToolResult = scrubMetaFromToolResult;
|
|
2842
2865
|
//# sourceMappingURL=index.js.map
|
|
2843
2866
|
//# sourceMappingURL=index.js.map
|