@mcpjam/sdk 0.8.0 → 0.8.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.
- package/dist/index.d.mts +31 -159
- package/dist/index.d.ts +31 -159
- package/dist/index.js +70 -33
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +68 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
package/dist/index.mjs
CHANGED
|
@@ -3,10 +3,9 @@ import { StdioClientTransport, getDefaultEnvironment } from '@modelcontextprotoc
|
|
|
3
3
|
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
|
|
4
4
|
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
5
5
|
import { CallToolResultSchema, CreateTaskResultSchema, ResourceListChangedNotificationSchema, ResourceUpdatedNotificationSchema, PromptListChangedNotificationSchema, ElicitRequestSchema, ProgressNotificationSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
6
|
-
export { PromptListChangedNotificationSchema, ResourceListChangedNotificationSchema, ResourceUpdatedNotificationSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
7
6
|
import { DEFAULT_REQUEST_TIMEOUT_MSEC } from '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
8
7
|
import { z } from 'zod';
|
|
9
|
-
import {
|
|
8
|
+
import { generateText, stepCountIs, dynamicTool, jsonSchema, tool } from 'ai';
|
|
10
9
|
import { createAnthropic } from '@ai-sdk/anthropic';
|
|
11
10
|
import { createAzure } from '@ai-sdk/azure';
|
|
12
11
|
import { createDeepSeek } from '@ai-sdk/deepseek';
|
|
@@ -16,6 +15,7 @@ import { createOpenAI } from '@ai-sdk/openai';
|
|
|
16
15
|
import { createXai } from '@ai-sdk/xai';
|
|
17
16
|
import { createOpenRouter } from '@openrouter/ai-sdk-provider';
|
|
18
17
|
import { createOllama } from 'ollama-ai-provider-v2';
|
|
18
|
+
import { PostHog } from 'posthog-node';
|
|
19
19
|
|
|
20
20
|
// src/mcp-client-manager/MCPClientManager.ts
|
|
21
21
|
var DEFAULT_CLIENT_VERSION = "1.0.0";
|
|
@@ -551,6 +551,36 @@ function ensureJsonSchemaObject(schema) {
|
|
|
551
551
|
additionalProperties: false
|
|
552
552
|
};
|
|
553
553
|
}
|
|
554
|
+
function isMcpAppTool(toolMeta) {
|
|
555
|
+
if (!toolMeta) return false;
|
|
556
|
+
const nested = toolMeta.ui;
|
|
557
|
+
if (typeof nested?.resourceUri === "string") return true;
|
|
558
|
+
return typeof toolMeta["ui/resourceUri"] === "string";
|
|
559
|
+
}
|
|
560
|
+
function isChatGPTAppTool(toolMeta) {
|
|
561
|
+
if (!toolMeta) return false;
|
|
562
|
+
return typeof toolMeta["openai/outputTemplate"] === "string";
|
|
563
|
+
}
|
|
564
|
+
function scrubMetaFromToolResult(result) {
|
|
565
|
+
if (!result) return result;
|
|
566
|
+
const copy = { ...result };
|
|
567
|
+
if (copy._meta) {
|
|
568
|
+
delete copy._meta;
|
|
569
|
+
}
|
|
570
|
+
return copy;
|
|
571
|
+
}
|
|
572
|
+
function scrubStructuredContentFromToolResult(result) {
|
|
573
|
+
if (!result) return result;
|
|
574
|
+
const copy = { ...result };
|
|
575
|
+
if (copy.structuredContent) {
|
|
576
|
+
delete copy.structuredContent;
|
|
577
|
+
}
|
|
578
|
+
return copy;
|
|
579
|
+
}
|
|
580
|
+
function scrubMetaAndStructuredContentFromToolResult(result) {
|
|
581
|
+
if (!result) return result;
|
|
582
|
+
return scrubMetaFromToolResult(scrubStructuredContentFromToolResult(result));
|
|
583
|
+
}
|
|
554
584
|
async function convertMCPToolsToVercelTools(listToolsResult, {
|
|
555
585
|
schemas = "automatic",
|
|
556
586
|
callTool
|
|
@@ -558,18 +588,31 @@ async function convertMCPToolsToVercelTools(listToolsResult, {
|
|
|
558
588
|
const tools = {};
|
|
559
589
|
for (const toolDescription of listToolsResult.tools) {
|
|
560
590
|
const { name, description, inputSchema } = toolDescription;
|
|
591
|
+
const toolMeta = toolDescription._meta;
|
|
561
592
|
const execute = async (args, options) => {
|
|
562
|
-
options?.abortSignal?.throwIfAborted
|
|
593
|
+
options?.abortSignal?.throwIfAborted();
|
|
563
594
|
const result = await callTool({ name, args, options });
|
|
564
595
|
return CallToolResultSchema.parse(result);
|
|
565
596
|
};
|
|
597
|
+
const toModelOutput = isMcpAppTool(toolMeta) ? (opts) => {
|
|
598
|
+
const scrubbed = scrubMetaAndStructuredContentFromToolResult(
|
|
599
|
+
opts.output
|
|
600
|
+
);
|
|
601
|
+
return { type: "json", value: scrubbed };
|
|
602
|
+
} : isChatGPTAppTool(toolMeta) ? (opts) => {
|
|
603
|
+
const scrubbed = scrubStructuredContentFromToolResult(
|
|
604
|
+
opts.output
|
|
605
|
+
);
|
|
606
|
+
return { type: "json", value: scrubbed };
|
|
607
|
+
} : void 0;
|
|
566
608
|
let vercelTool;
|
|
567
609
|
if (schemas === "automatic") {
|
|
568
610
|
const normalizedInputSchema = ensureJsonSchemaObject(inputSchema);
|
|
569
611
|
vercelTool = dynamicTool({
|
|
570
612
|
description,
|
|
571
613
|
inputSchema: jsonSchema(normalizedInputSchema),
|
|
572
|
-
execute
|
|
614
|
+
execute,
|
|
615
|
+
...toModelOutput ? { toModelOutput } : {}
|
|
573
616
|
});
|
|
574
617
|
} else {
|
|
575
618
|
const overrides = schemas;
|
|
@@ -579,7 +622,8 @@ async function convertMCPToolsToVercelTools(listToolsResult, {
|
|
|
579
622
|
vercelTool = tool({
|
|
580
623
|
description,
|
|
581
624
|
inputSchema: overrides[name].inputSchema,
|
|
582
|
-
execute
|
|
625
|
+
execute,
|
|
626
|
+
...toModelOutput ? { toModelOutput } : {}
|
|
583
627
|
});
|
|
584
628
|
}
|
|
585
629
|
tools[name] = vercelTool;
|
|
@@ -1633,9 +1677,6 @@ function extractToolCalls(result) {
|
|
|
1633
1677
|
}
|
|
1634
1678
|
return toolCalls;
|
|
1635
1679
|
}
|
|
1636
|
-
function extractToolNames(result) {
|
|
1637
|
-
return extractToolCalls(result).map((tc) => tc.toolName);
|
|
1638
|
-
}
|
|
1639
1680
|
|
|
1640
1681
|
// src/PromptResult.ts
|
|
1641
1682
|
var PromptResult = class _PromptResult {
|
|
@@ -1956,9 +1997,9 @@ var TestAgent = class _TestAgent {
|
|
|
1956
1997
|
return instrumented;
|
|
1957
1998
|
}
|
|
1958
1999
|
/**
|
|
1959
|
-
* Build an array of
|
|
2000
|
+
* Build an array of ModelMessages from previous PromptResult(s) for multi-turn context.
|
|
1960
2001
|
* @param context - Single PromptResult or array of PromptResults to include as context
|
|
1961
|
-
* @returns Array of
|
|
2002
|
+
* @returns Array of ModelMessages representing the conversation history
|
|
1962
2003
|
*/
|
|
1963
2004
|
buildContextMessages(context) {
|
|
1964
2005
|
if (!context) {
|
|
@@ -2019,7 +2060,9 @@ var TestAgent = class _TestAgent {
|
|
|
2019
2060
|
// Use messages array for multi-turn, simple prompt for single-turn
|
|
2020
2061
|
...contextMessages.length > 0 ? { messages: [...contextMessages, userMessage] } : { prompt: message },
|
|
2021
2062
|
// Only include temperature if explicitly set (some models like reasoning models don't support it)
|
|
2022
|
-
...this.temperature !== void 0 && {
|
|
2063
|
+
...this.temperature !== void 0 && {
|
|
2064
|
+
temperature: this.temperature
|
|
2065
|
+
},
|
|
2023
2066
|
// Use stopWhen with stepCountIs for controlling max agentic steps
|
|
2024
2067
|
// AI SDK v6+ uses this instead of maxSteps
|
|
2025
2068
|
stopWhen: stepCountIs(this.maxSteps),
|
|
@@ -2331,6 +2374,12 @@ function calculateLatencyStats(values) {
|
|
|
2331
2374
|
count: values.length
|
|
2332
2375
|
};
|
|
2333
2376
|
}
|
|
2377
|
+
var posthog = new PostHog(
|
|
2378
|
+
"phc_dTOPniyUNU2kD8Jx8yHMXSqiZHM8I91uWopTMX6EBE9",
|
|
2379
|
+
{
|
|
2380
|
+
host: "https://us.i.posthog.com"
|
|
2381
|
+
}
|
|
2382
|
+
);
|
|
2334
2383
|
|
|
2335
2384
|
// src/EvalTest.ts
|
|
2336
2385
|
var Semaphore = class {
|
|
@@ -2385,6 +2434,13 @@ var EvalTest = class {
|
|
|
2385
2434
|
* Run this test with the given agent and options
|
|
2386
2435
|
*/
|
|
2387
2436
|
async run(agent, options) {
|
|
2437
|
+
posthog.capture({
|
|
2438
|
+
event: "eval_test_run_triggered",
|
|
2439
|
+
properties: {
|
|
2440
|
+
iterations: options.iterations,
|
|
2441
|
+
concurrency: options.concurrency ?? 5
|
|
2442
|
+
}
|
|
2443
|
+
});
|
|
2388
2444
|
const concurrency = options.concurrency ?? 5;
|
|
2389
2445
|
const retries = options.retries ?? 0;
|
|
2390
2446
|
const timeoutMs = options.timeoutMs ?? 3e4;
|
|
@@ -2791,6 +2847,6 @@ var EvalSuite = class {
|
|
|
2791
2847
|
}
|
|
2792
2848
|
};
|
|
2793
2849
|
|
|
2794
|
-
export { EvalSuite, EvalTest, MCPAuthError, MCPClientManager, MCPError, PROVIDER_PRESETS, PromptResult, TestAgent,
|
|
2850
|
+
export { EvalSuite, EvalTest, MCPAuthError, MCPClientManager, MCPError, PROVIDER_PRESETS, PromptResult, TestAgent, createCustomProvider, createModelFromString, isAuthError, isChatGPTAppTool, isMCPAuthError, isMcpAppTool, matchAnyToolCall, matchNoToolCalls, matchToolArgument, matchToolArgumentWith, matchToolCallCount, matchToolCallWithArgs, matchToolCallWithPartialArgs, matchToolCalls, matchToolCallsSubset, parseLLMString, parseModelIds, scrubMetaAndStructuredContentFromToolResult, scrubMetaFromToolResult };
|
|
2795
2851
|
//# sourceMappingURL=index.mjs.map
|
|
2796
2852
|
//# sourceMappingURL=index.mjs.map
|