@sanity/ailf 1.0.0 → 2.0.0
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/README.md +0 -1
- package/config/models.ts +15 -3
- package/dist/_vendor/ailf-core/config-helpers.d.ts +14 -17
- package/dist/_vendor/ailf-core/config-helpers.js +22 -2
- package/dist/_vendor/ailf-core/examples/index.d.ts +16 -0
- package/dist/_vendor/ailf-core/examples/index.js +25 -0
- package/dist/_vendor/ailf-core/index.d.ts +2 -2
- package/dist/_vendor/ailf-core/index.js +1 -1
- package/dist/_vendor/ailf-core/ports/context.d.ts +2 -0
- package/dist/_vendor/ailf-core/schemas/eval-config.d.ts +1 -0
- package/dist/_vendor/ailf-core/schemas/eval-config.js +10 -0
- package/dist/_vendor/ailf-core/schemas/pipeline-request.d.ts +1 -0
- package/dist/_vendor/ailf-core/schemas/pipeline-request.js +2 -0
- package/dist/_vendor/ailf-core/schemas/pipeline.d.ts +0 -2
- package/dist/_vendor/ailf-core/schemas/pipeline.js +0 -1
- package/dist/_vendor/ailf-core/types/generalized-task.d.ts +13 -0
- package/dist/_vendor/ailf-core/types/index.d.ts +1 -3
- package/dist/_vendor/ailf-core/types/plugin-registry.d.ts +78 -23
- package/dist/_vendor/ailf-core/types/plugin-registry.js +73 -20
- package/dist/adapters/config-sources/file-config-adapter.js +1 -0
- package/dist/adapters/config-sources/ts-config-loader.js +21 -13
- package/dist/adapters/task-sources/content-lake-task-source.js +17 -20
- package/dist/adapters/task-sources/index.d.ts +2 -2
- package/dist/adapters/task-sources/index.js +2 -2
- package/dist/adapters/task-sources/repo-schemas.d.ts +218 -16
- package/dist/adapters/task-sources/repo-schemas.js +227 -19
- package/dist/adapters/task-sources/repo-task-source.d.ts +14 -10
- package/dist/adapters/task-sources/repo-task-source.js +81 -122
- package/dist/adapters/task-sources/repo-validation.d.ts +36 -5
- package/dist/adapters/task-sources/repo-validation.js +126 -5
- package/dist/adapters/task-sources/task-file-loader.d.ts +2 -2
- package/dist/adapters/task-sources/task-file-loader.js +2 -2
- package/dist/commands/coverage-audit.js +3 -1
- package/dist/commands/init.d.ts +6 -4
- package/dist/commands/init.js +302 -23
- package/dist/commands/validate-tasks.d.ts +2 -2
- package/dist/commands/validate-tasks.js +26 -15
- package/dist/composition-root.d.ts +13 -1
- package/dist/composition-root.js +73 -41
- package/dist/index.d.ts +41 -0
- package/dist/index.js +48 -0
- package/dist/orchestration/build-step-sequence.js +4 -2
- package/dist/orchestration/steps/fetch-docs-step.js +2 -3
- package/dist/orchestration/steps/generate-configs-step.js +28 -12
- package/dist/pipeline/compiler/__tests__/agent-harness-handler.test.js +1 -1
- package/dist/pipeline/compiler/__tests__/knowledge-probe-handler.test.js +1 -1
- package/dist/pipeline/compiler/__tests__/literacy-handler.test.js +1 -1
- package/dist/pipeline/compiler/__tests__/mcp-server-handler.test.js +105 -68
- package/dist/pipeline/compiler/__tests__/scoring-and-presets.test.js +33 -100
- package/dist/pipeline/compiler/literacy-bridge.d.ts +1 -1
- package/dist/pipeline/compiler/literacy-bridge.js +1 -1
- package/dist/pipeline/compiler/mode-bases/agent-harness.d.ts +10 -0
- package/dist/pipeline/compiler/mode-bases/agent-harness.js +21 -0
- package/dist/pipeline/compiler/mode-bases/index.d.ts +4 -0
- package/dist/pipeline/compiler/mode-bases/index.js +4 -0
- package/dist/pipeline/compiler/mode-bases/knowledge-probe.d.ts +10 -0
- package/dist/pipeline/compiler/mode-bases/knowledge-probe.js +22 -0
- package/dist/pipeline/compiler/mode-bases/literacy.d.ts +12 -0
- package/dist/pipeline/compiler/mode-bases/literacy.js +78 -0
- package/dist/pipeline/compiler/mode-bases/mcp-server.d.ts +10 -0
- package/dist/pipeline/compiler/mode-bases/mcp-server.js +70 -0
- package/dist/pipeline/compiler/mode-handlers/agent-harness/assertions.d.ts +43 -0
- package/dist/pipeline/compiler/mode-handlers/agent-harness/assertions.js +187 -0
- package/dist/pipeline/compiler/mode-handlers/agent-harness/compiler.d.ts +19 -0
- package/dist/pipeline/compiler/mode-handlers/agent-harness/compiler.js +138 -0
- package/dist/pipeline/compiler/mode-handlers/agent-harness/index.d.ts +16 -0
- package/dist/pipeline/compiler/mode-handlers/agent-harness/index.js +43 -0
- package/dist/pipeline/compiler/mode-handlers/agent-harness/prompts.d.ts +9 -0
- package/dist/pipeline/compiler/mode-handlers/agent-harness/prompts.js +29 -0
- package/dist/pipeline/compiler/mode-handlers/agent-harness/sandbox.d.ts +12 -0
- package/dist/pipeline/compiler/mode-handlers/agent-harness/sandbox.js +82 -0
- package/dist/pipeline/compiler/mode-handlers/agent-harness/tool-presets.d.ts +4 -0
- package/dist/pipeline/compiler/mode-handlers/agent-harness/tool-presets.js +19 -0
- package/dist/pipeline/compiler/mode-handlers/{agent-harness-handler.d.ts → agent-harness/types.d.ts} +3 -24
- package/dist/pipeline/compiler/mode-handlers/agent-harness/types.js +4 -0
- package/dist/pipeline/compiler/mode-handlers/agent-harness/validation.d.ts +9 -0
- package/dist/pipeline/compiler/mode-handlers/agent-harness/validation.js +16 -0
- package/dist/pipeline/compiler/mode-handlers/index.d.ts +4 -5
- package/dist/pipeline/compiler/mode-handlers/index.js +4 -6
- package/dist/pipeline/compiler/mode-handlers/knowledge-probe/assertions.d.ts +16 -0
- package/dist/pipeline/compiler/mode-handlers/knowledge-probe/assertions.js +61 -0
- package/dist/pipeline/compiler/mode-handlers/knowledge-probe/compiler.d.ts +18 -0
- package/dist/pipeline/compiler/mode-handlers/knowledge-probe/compiler.js +112 -0
- package/dist/pipeline/compiler/mode-handlers/knowledge-probe/index.d.ts +26 -0
- package/dist/pipeline/compiler/mode-handlers/knowledge-probe/index.js +49 -0
- package/dist/pipeline/compiler/mode-handlers/knowledge-probe/prompts.d.ts +9 -0
- package/dist/pipeline/compiler/mode-handlers/knowledge-probe/prompts.js +28 -0
- package/dist/pipeline/compiler/mode-handlers/knowledge-probe/types.d.ts +44 -0
- package/dist/pipeline/compiler/mode-handlers/knowledge-probe/types.js +4 -0
- package/dist/pipeline/compiler/mode-handlers/knowledge-probe/validation.d.ts +9 -0
- package/dist/pipeline/compiler/mode-handlers/knowledge-probe/validation.js +24 -0
- package/dist/pipeline/compiler/mode-handlers/literacy/assertions.d.ts +18 -0
- package/dist/pipeline/compiler/mode-handlers/literacy/assertions.js +118 -0
- package/dist/pipeline/compiler/mode-handlers/literacy/compiler.d.ts +14 -0
- package/dist/pipeline/compiler/mode-handlers/literacy/compiler.js +105 -0
- package/dist/pipeline/compiler/mode-handlers/literacy/index.d.ts +11 -0
- package/dist/pipeline/compiler/mode-handlers/literacy/index.js +38 -0
- package/dist/pipeline/compiler/mode-handlers/literacy/prompts.d.ts +9 -0
- package/dist/pipeline/compiler/mode-handlers/literacy/prompts.js +74 -0
- package/dist/pipeline/compiler/mode-handlers/literacy/types.d.ts +41 -0
- package/dist/pipeline/compiler/mode-handlers/literacy/types.js +4 -0
- package/dist/pipeline/compiler/mode-handlers/literacy/validation.d.ts +12 -0
- package/dist/pipeline/compiler/mode-handlers/literacy/validation.js +28 -0
- package/dist/pipeline/compiler/mode-handlers/{mcp-assertions.d.ts → mcp-server/assertions.d.ts} +2 -10
- package/dist/pipeline/compiler/mode-handlers/{mcp-assertions.js → mcp-server/assertions.js} +63 -6
- package/dist/pipeline/compiler/mode-handlers/mcp-server/compiler.d.ts +19 -0
- package/dist/pipeline/compiler/mode-handlers/mcp-server/compiler.js +100 -0
- package/dist/pipeline/compiler/mode-handlers/mcp-server/index.d.ts +27 -0
- package/dist/pipeline/compiler/mode-handlers/mcp-server/index.js +54 -0
- package/dist/pipeline/compiler/mode-handlers/mcp-server/prompts.d.ts +8 -0
- package/dist/pipeline/compiler/mode-handlers/mcp-server/prompts.js +28 -0
- package/dist/pipeline/compiler/mode-handlers/mcp-server/provider-config.d.ts +28 -0
- package/dist/pipeline/compiler/mode-handlers/mcp-server/provider-config.js +104 -0
- package/dist/pipeline/compiler/mode-handlers/mcp-server/types.d.ts +37 -0
- package/dist/pipeline/compiler/mode-handlers/mcp-server/types.js +4 -0
- package/dist/pipeline/compiler/mode-handlers/mcp-server/validation.d.ts +9 -0
- package/dist/pipeline/compiler/mode-handlers/mcp-server/validation.js +43 -0
- package/dist/pipeline/compiler/mode-handlers/mcp-tool-provider/index.d.ts +33 -0
- package/dist/pipeline/compiler/mode-handlers/mcp-tool-provider/index.js +174 -0
- package/dist/pipeline/compiler/mode-handlers/mcp-tool-provider/mcp-connection.d.ts +19 -0
- package/dist/pipeline/compiler/mode-handlers/mcp-tool-provider/mcp-connection.js +95 -0
- package/dist/pipeline/compiler/mode-handlers/mcp-tool-provider/tool-loop-anthropic.d.ts +19 -0
- package/dist/pipeline/compiler/mode-handlers/mcp-tool-provider/tool-loop-anthropic.js +172 -0
- package/dist/pipeline/compiler/mode-handlers/mcp-tool-provider/tool-loop-openai.d.ts +14 -0
- package/dist/pipeline/compiler/mode-handlers/mcp-tool-provider/tool-loop-openai.js +16 -0
- package/dist/pipeline/compiler/mode-handlers/mcp-tool-provider/types.d.ts +93 -0
- package/dist/pipeline/compiler/mode-handlers/mcp-tool-provider/types.js +4 -0
- package/dist/pipeline/compiler/preset-loader.d.ts +22 -0
- package/dist/pipeline/compiler/preset-loader.js +99 -0
- package/dist/pipeline/compiler/presets/sanity-literacy.d.ts +6 -9
- package/dist/pipeline/compiler/presets/sanity-literacy.js +10 -156
- package/dist/pipeline/expand-tasks.d.ts +2 -2
- package/dist/pipeline/expand-tasks.js +2 -2
- package/dist/pipeline/generate-configs.js +1 -1
- package/dist/pipeline/map-request-to-config.js +1 -0
- package/dist/pipeline/mirror-repo-tasks.d.ts +7 -7
- package/dist/pipeline/mirror-repo-tasks.js +9 -9
- package/dist/pipeline/plan.js +1 -1
- package/package.json +11 -3
- package/dist/_vendor/ailf-tasks/cli.d.ts +0 -8
- package/dist/_vendor/ailf-tasks/cli.js +0 -61
- package/dist/_vendor/ailf-tasks/index.d.ts +0 -13
- package/dist/_vendor/ailf-tasks/index.js +0 -16
- package/dist/_vendor/ailf-tasks/parser.d.ts +0 -27
- package/dist/_vendor/ailf-tasks/parser.js +0 -73
- package/dist/_vendor/ailf-tasks/schemas.d.ts +0 -198
- package/dist/_vendor/ailf-tasks/schemas.js +0 -180
- package/dist/_vendor/ailf-tasks/validation.d.ts +0 -47
- package/dist/_vendor/ailf-tasks/validation.js +0 -162
- package/dist/pipeline/compiler/mode-handlers/agent-harness-handler.js +0 -485
- package/dist/pipeline/compiler/mode-handlers/knowledge-probe-handler.d.ts +0 -76
- package/dist/pipeline/compiler/mode-handlers/knowledge-probe-handler.js +0 -245
- package/dist/pipeline/compiler/mode-handlers/literacy-handler.d.ts +0 -89
- package/dist/pipeline/compiler/mode-handlers/literacy-handler.js +0 -379
- package/dist/pipeline/compiler/mode-handlers/mcp-server-handler.d.ts +0 -67
- package/dist/pipeline/compiler/mode-handlers/mcp-server-handler.js +0 -309
|
@@ -1,309 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCPServerModeHandler — compilation rules for `mcp-server` evaluation mode.
|
|
3
|
-
*
|
|
4
|
-
* This is the first non-literacy mode handler, proving the compiler
|
|
5
|
-
* architecture works end-to-end. It translates MCP server task definitions
|
|
6
|
-
* into Promptfoo configuration with:
|
|
7
|
-
*
|
|
8
|
-
* - An MCP provider that wraps the server under test
|
|
9
|
-
* - Tool-call assertions compiled to Promptfoo `javascript` assertions
|
|
10
|
-
* - Server lifecycle management via Promptfoo provider hooks
|
|
11
|
-
* - Multi-turn conversation support via Promptfoo's `steps` syntax
|
|
12
|
-
*
|
|
13
|
-
* Promptfoo supports MCP servers as providers natively:
|
|
14
|
-
* ```yaml
|
|
15
|
-
* providers:
|
|
16
|
-
* - id: mcp:./my-server
|
|
17
|
-
* config:
|
|
18
|
-
* command: node
|
|
19
|
-
* args: [./dist/server.js]
|
|
20
|
-
* env: { API_KEY: "..." }
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* This handler assembles that config from AILF's `MCPServerTaskDefinition`.
|
|
24
|
-
*
|
|
25
|
-
* @see docs/exec-plans/architecture-overhaul/phase-3-mcp-server-mode.md
|
|
26
|
-
* @see packages/core/src/types/eval-mode-config.ts — MCPServerModeConfig
|
|
27
|
-
* @see packages/core/src/types/generalized-task.ts — MCPServerTaskDefinition
|
|
28
|
-
*/
|
|
29
|
-
import { buildMCPAssertions, } from "./mcp-assertions.js";
|
|
30
|
-
// ---------------------------------------------------------------------------
|
|
31
|
-
// Canonical MCP server prompt templates
|
|
32
|
-
// ---------------------------------------------------------------------------
|
|
33
|
-
// Handler-owned prompts for MCP server evaluations. Instructs the model to
|
|
34
|
-
// interact with MCP tools rather than writing standalone code.
|
|
35
|
-
export const MCP_PROMPT_TEMPLATES = {
|
|
36
|
-
"mcp-server": {
|
|
37
|
-
id: "mcp-server",
|
|
38
|
-
label: "MCP Server Tool Use",
|
|
39
|
-
template: `You are an AI assistant with access to an MCP (Model Context Protocol) server that provides tools for interacting with a Sanity content backend.
|
|
40
|
-
|
|
41
|
-
## Task
|
|
42
|
-
{{task}}
|
|
43
|
-
|
|
44
|
-
## Instructions
|
|
45
|
-
|
|
46
|
-
1. Use the available MCP tools to complete the task
|
|
47
|
-
2. Call tools with the correct parameters as described in their schemas
|
|
48
|
-
3. Interpret tool responses and use the results to accomplish the goal
|
|
49
|
-
4. If a tool returns an error, explain the issue clearly
|
|
50
|
-
5. Prefer using specific tools over broad queries when possible
|
|
51
|
-
|
|
52
|
-
Complete the task using the MCP tools provided:
|
|
53
|
-
`,
|
|
54
|
-
variables: ["task"],
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* Validate that an MCP task definition has all required fields.
|
|
59
|
-
*/
|
|
60
|
-
export function validateMCPTask(task) {
|
|
61
|
-
const errors = [];
|
|
62
|
-
if (!task.id) {
|
|
63
|
-
errors.push({ field: "id", message: "Task ID is required" });
|
|
64
|
-
}
|
|
65
|
-
if (!task.title) {
|
|
66
|
-
errors.push({ field: "title", message: "Task title is required" });
|
|
67
|
-
}
|
|
68
|
-
if (task.serverConfig) {
|
|
69
|
-
const { transport, command, url } = task.serverConfig;
|
|
70
|
-
if (transport === "stdio" && !command) {
|
|
71
|
-
errors.push({
|
|
72
|
-
field: "serverConfig.command",
|
|
73
|
-
message: "Server command is required for stdio transport (e.g., 'node dist/server.js')",
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
if ((transport === "sse" || transport === "streamable-http") && !url) {
|
|
77
|
-
errors.push({
|
|
78
|
-
field: "serverConfig.url",
|
|
79
|
-
message: `Server URL is required for ${transport} transport`,
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
// Assertions should reference MCP-compatible types
|
|
84
|
-
if (task.assertions) {
|
|
85
|
-
for (const assertion of task.assertions) {
|
|
86
|
-
if (assertion.type === "tool-called" &&
|
|
87
|
-
!("value" in assertion && assertion.value)) {
|
|
88
|
-
errors.push({
|
|
89
|
-
field: "assertions",
|
|
90
|
-
message: 'tool-called assertion requires a "value" specifying the tool name',
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return errors;
|
|
96
|
-
}
|
|
97
|
-
// ---------------------------------------------------------------------------
|
|
98
|
-
// Compilation
|
|
99
|
-
// ---------------------------------------------------------------------------
|
|
100
|
-
/**
|
|
101
|
-
* Compile an MCP server task definition into Promptfoo configuration.
|
|
102
|
-
*
|
|
103
|
-
* This is the core of the MCP mode handler. It produces:
|
|
104
|
-
* 1. A provider config pointing to the MCP server
|
|
105
|
-
* 2. Test cases with tool-call assertions
|
|
106
|
-
* 3. Appropriate prompts for the evaluation
|
|
107
|
-
*/
|
|
108
|
-
export function compileMCPTask(task, options) {
|
|
109
|
-
const warnings = [];
|
|
110
|
-
// Validate
|
|
111
|
-
const validationErrors = validateMCPTask(task);
|
|
112
|
-
if (validationErrors.length > 0) {
|
|
113
|
-
for (const err of validationErrors) {
|
|
114
|
-
warnings.push(`MCP task "${task.id}": ${err.field} — ${err.message}`);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
// Build provider
|
|
118
|
-
const providers = buildMCPProvider(task, warnings);
|
|
119
|
-
// Build prompts
|
|
120
|
-
const prompts = buildMCPPrompts(task);
|
|
121
|
-
// Build test cases
|
|
122
|
-
const tests = buildMCPTestCases(task, options, warnings);
|
|
123
|
-
return { providers, tests, prompts, warnings };
|
|
124
|
-
}
|
|
125
|
-
// ---------------------------------------------------------------------------
|
|
126
|
-
// Provider assembly
|
|
127
|
-
// ---------------------------------------------------------------------------
|
|
128
|
-
/**
|
|
129
|
-
* Build a Promptfoo-native MCP provider config.
|
|
130
|
-
*
|
|
131
|
-
* Promptfoo supports MCP servers natively via `id: "mcp"` with a
|
|
132
|
-
* structured config. See: https://www.promptfoo.dev/docs/providers/mcp/
|
|
133
|
-
*
|
|
134
|
-
* Key config shape:
|
|
135
|
-
* { enabled: true, server: { url?, command?, args?, name?, auth?, headers? },
|
|
136
|
-
* tools?, exclude_tools?, timeout?, debug? }
|
|
137
|
-
*/
|
|
138
|
-
function buildMCPProvider(task, warnings) {
|
|
139
|
-
const config = task.serverConfig;
|
|
140
|
-
if (!config) {
|
|
141
|
-
warnings.push(`MCP task "${task.id}": no serverConfig — using placeholder provider. ` +
|
|
142
|
-
"Set serverConfig.command or serverConfig.url to point to your MCP server.");
|
|
143
|
-
return [
|
|
144
|
-
{
|
|
145
|
-
id: "mcp",
|
|
146
|
-
label: `MCP Server: ${task.title}`,
|
|
147
|
-
config: { enabled: true, server: { name: task.id } },
|
|
148
|
-
},
|
|
149
|
-
];
|
|
150
|
-
}
|
|
151
|
-
// Build the server sub-config (Promptfoo's native format)
|
|
152
|
-
const server = { name: task.id };
|
|
153
|
-
if (config.transport === "stdio") {
|
|
154
|
-
// Promptfoo expects command + args as separate fields
|
|
155
|
-
const parts = config.command?.split(/\s+/) ?? [];
|
|
156
|
-
server.command = parts[0] ?? "node";
|
|
157
|
-
if (parts.length > 1) {
|
|
158
|
-
server.args = parts.slice(1);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
162
|
-
// sse or streamable-http — use URL-based connection
|
|
163
|
-
server.url = config.url;
|
|
164
|
-
}
|
|
165
|
-
// Auth config (Promptfoo supports bearer, basic, api_key, oauth)
|
|
166
|
-
if (config.auth) {
|
|
167
|
-
server.auth = config.auth;
|
|
168
|
-
}
|
|
169
|
-
else if (config.env) {
|
|
170
|
-
// Backward compat: if env has a token-like variable, convert to
|
|
171
|
-
// bearer auth using Promptfoo's {{env.VAR}} template syntax
|
|
172
|
-
const tokenKey = Object.keys(config.env).find((k) => /token|auth|key/i.test(k));
|
|
173
|
-
if (tokenKey) {
|
|
174
|
-
const val = config.env[tokenKey];
|
|
175
|
-
// Convert $env(VAR) syntax to Promptfoo's {{env.VAR}} syntax
|
|
176
|
-
let envVar = val;
|
|
177
|
-
if (val.startsWith("$env(") && val.endsWith(")")) {
|
|
178
|
-
envVar = val.slice(5, -1); // $env(VAR_NAME) → VAR_NAME
|
|
179
|
-
}
|
|
180
|
-
// Validate extracted env var name is non-empty and valid
|
|
181
|
-
if (!envVar || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(envVar)) {
|
|
182
|
-
warnings.push(`MCP task: env var name "${envVar}" from "${val}" is not a valid ` +
|
|
183
|
-
"identifier — skipping auth config");
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
server.auth = {
|
|
187
|
-
type: "bearer",
|
|
188
|
-
token: `{{env.${envVar}}}`,
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
// Custom headers (if any non-auth env vars remain)
|
|
194
|
-
if (config.env) {
|
|
195
|
-
const headers = {};
|
|
196
|
-
for (const [key, val] of Object.entries(config.env)) {
|
|
197
|
-
if (/header[_.]?/i.test(key)) {
|
|
198
|
-
headers[key.replace(/^header[_.]?/i, "")] = val;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
if (Object.keys(headers).length > 0) {
|
|
202
|
-
server.headers = headers;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
// Build top-level provider config
|
|
206
|
-
const providerConfig = {
|
|
207
|
-
enabled: true,
|
|
208
|
-
server,
|
|
209
|
-
};
|
|
210
|
-
// Tool filtering — map AILF capabilities to Promptfoo tools
|
|
211
|
-
if (task.capabilities && task.capabilities.length > 0) {
|
|
212
|
-
providerConfig.tools = task.capabilities;
|
|
213
|
-
}
|
|
214
|
-
// Timeout
|
|
215
|
-
if (config.startupTimeoutMs) {
|
|
216
|
-
providerConfig.timeout = config.startupTimeoutMs;
|
|
217
|
-
}
|
|
218
|
-
return [
|
|
219
|
-
{
|
|
220
|
-
id: "mcp",
|
|
221
|
-
label: `MCP Server: ${task.title}`,
|
|
222
|
-
config: providerConfig,
|
|
223
|
-
},
|
|
224
|
-
];
|
|
225
|
-
}
|
|
226
|
-
// ---------------------------------------------------------------------------
|
|
227
|
-
// Prompt assembly
|
|
228
|
-
// ---------------------------------------------------------------------------
|
|
229
|
-
function buildMCPPrompts(task) {
|
|
230
|
-
// MCP mode uses a single prompt — the task description
|
|
231
|
-
const promptText = task.prompt?.text ??
|
|
232
|
-
task.prompt?.vars?.task ??
|
|
233
|
-
task.description ??
|
|
234
|
-
`Test MCP server: ${task.title}`;
|
|
235
|
-
return [
|
|
236
|
-
{
|
|
237
|
-
id: "mcp-test",
|
|
238
|
-
label: `MCP: ${task.title}`,
|
|
239
|
-
raw: String(promptText),
|
|
240
|
-
},
|
|
241
|
-
];
|
|
242
|
-
}
|
|
243
|
-
// ---------------------------------------------------------------------------
|
|
244
|
-
// Test case assembly
|
|
245
|
-
// ---------------------------------------------------------------------------
|
|
246
|
-
function buildMCPTestCases(task, options, warnings) {
|
|
247
|
-
const tests = [];
|
|
248
|
-
// Build assertion context
|
|
249
|
-
const assertionContext = {
|
|
250
|
-
capabilities: task.capabilities ?? [],
|
|
251
|
-
graderProvider: options?.graderProvider,
|
|
252
|
-
taskId: task.id,
|
|
253
|
-
};
|
|
254
|
-
// Compile assertions
|
|
255
|
-
// Cast GeneralizedAssertionDefinition[] → AssertionInput[] (structurally compatible)
|
|
256
|
-
const assertions = [];
|
|
257
|
-
if (task.assertions) {
|
|
258
|
-
const rawAssertions = task.assertions;
|
|
259
|
-
const { assertions: mapped, warnings: assertionWarnings } = buildMCPAssertions(rawAssertions, assertionContext);
|
|
260
|
-
assertions.push(...mapped);
|
|
261
|
-
warnings.push(...assertionWarnings);
|
|
262
|
-
}
|
|
263
|
-
// Build test case vars
|
|
264
|
-
const vars = {
|
|
265
|
-
task: task.prompt?.vars?.task ?? task.description ?? `Test: ${task.title}`,
|
|
266
|
-
...(task.prompt?.vars ?? {}),
|
|
267
|
-
};
|
|
268
|
-
// Primary test case
|
|
269
|
-
tests.push({
|
|
270
|
-
description: `${task.id} — ${task.title}`,
|
|
271
|
-
vars,
|
|
272
|
-
...(assertions.length > 0 ? { assert: assertions } : {}),
|
|
273
|
-
});
|
|
274
|
-
// Multi-turn test cases
|
|
275
|
-
if (task.multiTurn?.turns && task.multiTurn.turns.length > 0) {
|
|
276
|
-
tests.push({
|
|
277
|
-
description: `${task.id} — ${task.title} [multi-turn]`,
|
|
278
|
-
vars: {
|
|
279
|
-
...vars,
|
|
280
|
-
__multiTurn: task.multiTurn.turns,
|
|
281
|
-
},
|
|
282
|
-
...(assertions.length > 0 ? { assert: assertions } : {}),
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
return tests;
|
|
286
|
-
}
|
|
287
|
-
// ---------------------------------------------------------------------------
|
|
288
|
-
// ModeHandler adapter
|
|
289
|
-
// ---------------------------------------------------------------------------
|
|
290
|
-
/** ModeHandler-conformant export for the mcp-server evaluation mode. */
|
|
291
|
-
export const handler = {
|
|
292
|
-
getPrompts() {
|
|
293
|
-
return MCP_PROMPT_TEMPLATES;
|
|
294
|
-
},
|
|
295
|
-
compileTask(task, ctx) {
|
|
296
|
-
if (!("mode" in task) || task.mode !== "mcp-server") {
|
|
297
|
-
throw new Error(`MCP server handler received task with mode "${task.mode ?? "undefined"}" — expected "mcp-server"`);
|
|
298
|
-
}
|
|
299
|
-
const result = compileMCPTask(task, {
|
|
300
|
-
graderProvider: ctx.graderProvider,
|
|
301
|
-
});
|
|
302
|
-
return {
|
|
303
|
-
providers: result.providers,
|
|
304
|
-
tests: result.tests,
|
|
305
|
-
prompts: result.prompts,
|
|
306
|
-
warnings: result.warnings,
|
|
307
|
-
};
|
|
308
|
-
},
|
|
309
|
-
};
|