@langwatch/server 3.1.0-beta.5 → 3.1.0-beta.7
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/langwatch/package.json +1 -1
- package/langwatch/pnpm-workspace.yaml +0 -1
- package/mcp-server/.env.example +2 -0
- package/mcp-server/.eslintrc.cjs +36 -0
- package/mcp-server/CHANGELOG.md +165 -0
- package/mcp-server/CONTRIBUTING.md +96 -0
- package/mcp-server/README.md +172 -0
- package/mcp-server/dist/archive-scenario-WJ2A7ETN.js +19 -0
- package/mcp-server/dist/archive-suite-4JOM4SSL.js +15 -0
- package/mcp-server/dist/assign-prompt-tag-GL7EAAF3.js +19 -0
- package/mcp-server/dist/chunk-2GT7IFWK.js +40 -0
- package/mcp-server/dist/chunk-2WPLXEKF.js +127 -0
- package/mcp-server/dist/chunk-4AUB2BIA.js +71 -0
- package/mcp-server/dist/chunk-BWWY5KEF.js +71 -0
- package/mcp-server/dist/chunk-CCWCIJJ3.js +22 -0
- package/mcp-server/dist/chunk-EGH5RPXM.js +25 -0
- package/mcp-server/dist/chunk-EUQDVOSU.js +39 -0
- package/mcp-server/dist/chunk-HYMIWO3U.js +44 -0
- package/mcp-server/dist/chunk-IE4M5OGE.js +42 -0
- package/mcp-server/dist/chunk-LUMEZEHL.js +48 -0
- package/mcp-server/dist/chunk-NUFPTHKU.js +9 -0
- package/mcp-server/dist/chunk-UDHJYT6P.js +1567 -0
- package/mcp-server/dist/chunk-WQG2DFHX.js +86 -0
- package/mcp-server/dist/chunk-WVI5CJ6S.js +21 -0
- package/mcp-server/dist/chunk-ZVS4UKN2.js +35 -0
- package/mcp-server/dist/chunk-ZXKLPC2E.js +27 -0
- package/mcp-server/dist/config.d.ts +17 -0
- package/mcp-server/dist/config.js +13 -0
- package/mcp-server/dist/create-agent-MBOOT3XK.js +23 -0
- package/mcp-server/dist/create-annotation-XMV6A7ED.js +24 -0
- package/mcp-server/dist/create-dashboard-VRKLFVZJ.js +18 -0
- package/mcp-server/dist/create-dataset-7HQPZCRE.js +22 -0
- package/mcp-server/dist/create-dataset-records-2NIVFYTV.js +22 -0
- package/mcp-server/dist/create-evaluator-WYFRFLRC.js +27 -0
- package/mcp-server/dist/create-mcp-server.d.ts +8 -0
- package/mcp-server/dist/create-mcp-server.js +8 -0
- package/mcp-server/dist/create-prompt-IEN7O6JT.js +39 -0
- package/mcp-server/dist/create-prompt-tag-CAEZ45VO.js +17 -0
- package/mcp-server/dist/create-scenario-6YHSMGLP.js +26 -0
- package/mcp-server/dist/create-suite-H5XOFDE5.js +38 -0
- package/mcp-server/dist/delete-agent-JKTNBWAA.js +18 -0
- package/mcp-server/dist/delete-annotation-ACMDV6QO.js +17 -0
- package/mcp-server/dist/delete-dashboard-VJSR7CRU.js +18 -0
- package/mcp-server/dist/delete-dataset-RTTTWP4D.js +20 -0
- package/mcp-server/dist/delete-dataset-records-KNQTIPQK.js +21 -0
- package/mcp-server/dist/delete-evaluator-7FVC5WM4.js +15 -0
- package/mcp-server/dist/delete-prompt-tag-ZMZUAGFW.js +17 -0
- package/mcp-server/dist/delete-workflow-EYQ3T4RQ.js +17 -0
- package/mcp-server/dist/discover-evaluator-schema-H23XCLNE.js +1402 -0
- package/mcp-server/dist/discover-scenario-schema-MEEEVND7.js +65 -0
- package/mcp-server/dist/discover-schema-3T52ORPB.js +446 -0
- package/mcp-server/dist/get-agent-E3QSTVKG.js +28 -0
- package/mcp-server/dist/get-analytics-2OHV763I.js +72 -0
- package/mcp-server/dist/get-dashboard-PC7JDHH6.js +29 -0
- package/mcp-server/dist/get-dataset-H5IK5FVU.js +48 -0
- package/mcp-server/dist/get-evaluator-UWVUPYTM.js +47 -0
- package/mcp-server/dist/get-prompt-WZUOLLQC.js +45 -0
- package/mcp-server/dist/get-scenario-Q6LCNUYN.js +33 -0
- package/mcp-server/dist/get-simulation-run-Z2XKO256.js +56 -0
- package/mcp-server/dist/get-suite-BXK5TN7P.js +44 -0
- package/mcp-server/dist/get-trace-4EJAYVBG.js +50 -0
- package/mcp-server/dist/get-workflow-O34QJLHD.js +25 -0
- package/mcp-server/dist/http-server-RSTXN4CN.js +224 -0
- package/mcp-server/dist/index.d.ts +2 -0
- package/mcp-server/dist/index.js +67774 -0
- package/mcp-server/dist/langwatch-api-annotations-ERBG27RF.js +17 -0
- package/mcp-server/dist/langwatch-api-dashboards-G6TR7VVO.js +17 -0
- package/mcp-server/dist/langwatch-api-monitors-WSXZLS2B.js +52 -0
- package/mcp-server/dist/langwatch-api-secrets-RR5DKG2X.js +40 -0
- package/mcp-server/dist/langwatch-api-triggers-2RTNSWQY.js +30 -0
- package/mcp-server/dist/langwatch-api-workflows-VJRIIDZ7.js +15 -0
- package/mcp-server/dist/list-agents-AW3P6FJV.js +32 -0
- package/mcp-server/dist/list-annotations-QNCGWPQ3.js +33 -0
- package/mcp-server/dist/list-dashboards-R7RK2IXL.js +32 -0
- package/mcp-server/dist/list-dataset-records-WVCSQP7P.js +39 -0
- package/mcp-server/dist/list-datasets-KEXRLDEU.js +60 -0
- package/mcp-server/dist/list-evaluators-7R2LB4JH.js +34 -0
- package/mcp-server/dist/list-model-providers-OBYJCKBX.js +35 -0
- package/mcp-server/dist/list-prompt-tags-6LY3ZPYI.js +23 -0
- package/mcp-server/dist/list-prompts-VWEZ4CDE.js +32 -0
- package/mcp-server/dist/list-scenarios-TXD4W2ZJ.js +40 -0
- package/mcp-server/dist/list-simulation-runs-RHPOLMFI.js +43 -0
- package/mcp-server/dist/list-suites-FSGBX27Z.js +42 -0
- package/mcp-server/dist/list-workflows-VRGEZ3EN.js +35 -0
- package/mcp-server/dist/rename-prompt-tag-VOJJLX4M.js +18 -0
- package/mcp-server/dist/run-agent-KTCC7TB7.js +36 -0
- package/mcp-server/dist/run-evaluation-2X3V3Q6L.js +64 -0
- package/mcp-server/dist/run-suite-BTMHGI2D.js +29 -0
- package/mcp-server/dist/run-workflow-IGAYGKJL.js +36 -0
- package/mcp-server/dist/search-traces-VYFUIMXH.js +72 -0
- package/mcp-server/dist/set-model-provider-W5IUI326.js +33 -0
- package/mcp-server/dist/update-agent-4BB7EYLR.js +20 -0
- package/mcp-server/dist/update-dataset-CXBKZ4W3.js +22 -0
- package/mcp-server/dist/update-dataset-record-HOHAMHXG.js +19 -0
- package/mcp-server/dist/update-evaluator-IVOR6FTR.js +24 -0
- package/mcp-server/dist/update-prompt-OWQAKE7K.js +24 -0
- package/mcp-server/dist/update-scenario-GDFVILPN.js +27 -0
- package/mcp-server/dist/update-suite-BXYUYSPT.js +39 -0
- package/mcp-server/package.json +79 -0
- package/mcp-server/pnpm-lock.yaml +6103 -0
- package/mcp-server/pnpm-workspace.yaml +2 -0
- package/mcp-server/pyproject.toml +17 -0
- package/mcp-server/src/__tests__/all-tools.integration.test.ts +1681 -0
- package/mcp-server/src/__tests__/config.unit.test.ts +169 -0
- package/mcp-server/src/__tests__/datasets.integration.test.ts +603 -0
- package/mcp-server/src/__tests__/datasets.unit.test.ts +240 -0
- package/mcp-server/src/__tests__/date-parsing.unit.test.ts +78 -0
- package/mcp-server/src/__tests__/discover-evaluator-schema.unit.test.ts +89 -0
- package/mcp-server/src/__tests__/discover-schema.unit.test.ts +118 -0
- package/mcp-server/src/__tests__/docker.integration.test.ts +234 -0
- package/mcp-server/src/__tests__/evaluator-tools.unit.test.ts +262 -0
- package/mcp-server/src/__tests__/http-transport.integration.test.ts +397 -0
- package/mcp-server/src/__tests__/integration.integration.test.ts +288 -0
- package/mcp-server/src/__tests__/langwatch-api.unit.test.ts +455 -0
- package/mcp-server/src/__tests__/model-provider-tools.unit.test.ts +190 -0
- package/mcp-server/src/__tests__/scenario-tools.integration.test.ts +286 -0
- package/mcp-server/src/__tests__/scenario-tools.unit.test.ts +185 -0
- package/mcp-server/src/__tests__/schemas.unit.test.ts +85 -0
- package/mcp-server/src/__tests__/tools.unit.test.ts +900 -0
- package/mcp-server/src/config.d.ts +15 -0
- package/mcp-server/src/config.ts +107 -0
- package/mcp-server/src/create-mcp-server.d.ts +6 -0
- package/mcp-server/src/create-mcp-server.ts +1799 -0
- package/mcp-server/src/http-server.ts +329 -0
- package/mcp-server/src/index.ts +46 -0
- package/mcp-server/src/langwatch-api-agents.ts +108 -0
- package/mcp-server/src/langwatch-api-annotations.ts +49 -0
- package/mcp-server/src/langwatch-api-dashboards.ts +48 -0
- package/mcp-server/src/langwatch-api-datasets.ts +191 -0
- package/mcp-server/src/langwatch-api-evaluators.ts +80 -0
- package/mcp-server/src/langwatch-api-model-providers.ts +41 -0
- package/mcp-server/src/langwatch-api-monitors.ts +82 -0
- package/mcp-server/src/langwatch-api-scenarios.ts +67 -0
- package/mcp-server/src/langwatch-api-secrets.ts +48 -0
- package/mcp-server/src/langwatch-api-simulation-runs.ts +51 -0
- package/mcp-server/src/langwatch-api-suites.ts +118 -0
- package/mcp-server/src/langwatch-api-triggers.ts +48 -0
- package/mcp-server/src/langwatch-api-workflows.ts +41 -0
- package/mcp-server/src/langwatch-api.ts +299 -0
- package/mcp-server/src/schemas/analytics-groups.ts +78 -0
- package/mcp-server/src/schemas/analytics-metrics.ts +179 -0
- package/mcp-server/src/schemas/create-dataset.ts +48 -0
- package/mcp-server/src/schemas/filter-fields.ts +119 -0
- package/mcp-server/src/schemas/index.ts +4 -0
- package/mcp-server/src/tools/archive-scenario.ts +19 -0
- package/mcp-server/src/tools/archive-suite.ts +12 -0
- package/mcp-server/src/tools/assign-prompt-tag.ts +16 -0
- package/mcp-server/src/tools/create-agent.ts +15 -0
- package/mcp-server/src/tools/create-annotation.ts +18 -0
- package/mcp-server/src/tools/create-dashboard.ts +7 -0
- package/mcp-server/src/tools/create-dataset-records.ts +23 -0
- package/mcp-server/src/tools/create-dataset.ts +22 -0
- package/mcp-server/src/tools/create-evaluator.ts +33 -0
- package/mcp-server/src/tools/create-prompt-tag.ts +12 -0
- package/mcp-server/src/tools/create-prompt.ts +58 -0
- package/mcp-server/src/tools/create-scenario.ts +30 -0
- package/mcp-server/src/tools/create-suite.ts +42 -0
- package/mcp-server/src/tools/delete-agent.ts +7 -0
- package/mcp-server/src/tools/delete-annotation.ts +7 -0
- package/mcp-server/src/tools/delete-dashboard.ts +7 -0
- package/mcp-server/src/tools/delete-dataset-records.ts +22 -0
- package/mcp-server/src/tools/delete-dataset.ts +20 -0
- package/mcp-server/src/tools/delete-evaluator.ts +12 -0
- package/mcp-server/src/tools/delete-prompt-tag.ts +12 -0
- package/mcp-server/src/tools/delete-workflow.ts +7 -0
- package/mcp-server/src/tools/discover-evaluator-schema.ts +143 -0
- package/mcp-server/src/tools/discover-scenario-schema.ts +71 -0
- package/mcp-server/src/tools/discover-schema.ts +106 -0
- package/mcp-server/src/tools/format-dataset-mutation.ts +25 -0
- package/mcp-server/src/tools/get-agent.ts +21 -0
- package/mcp-server/src/tools/get-analytics.ts +98 -0
- package/mcp-server/src/tools/get-dashboard.ts +22 -0
- package/mcp-server/src/tools/get-dataset.ts +63 -0
- package/mcp-server/src/tools/get-evaluator.ts +53 -0
- package/mcp-server/src/tools/get-prompt.ts +54 -0
- package/mcp-server/src/tools/get-scenario.ts +36 -0
- package/mcp-server/src/tools/get-simulation-run.ts +60 -0
- package/mcp-server/src/tools/get-suite.ts +47 -0
- package/mcp-server/src/tools/get-trace.ts +61 -0
- package/mcp-server/src/tools/get-workflow.ts +17 -0
- package/mcp-server/src/tools/list-agents.ts +27 -0
- package/mcp-server/src/tools/list-annotations.ts +33 -0
- package/mcp-server/src/tools/list-dashboards.ts +27 -0
- package/mcp-server/src/tools/list-dataset-records.ts +46 -0
- package/mcp-server/src/tools/list-datasets.ts +80 -0
- package/mcp-server/src/tools/list-evaluators.ts +37 -0
- package/mcp-server/src/tools/list-model-providers.ts +40 -0
- package/mcp-server/src/tools/list-prompt-tags.ts +21 -0
- package/mcp-server/src/tools/list-prompts.ts +34 -0
- package/mcp-server/src/tools/list-scenarios.ts +47 -0
- package/mcp-server/src/tools/list-simulation-runs.ts +49 -0
- package/mcp-server/src/tools/list-suites.ts +43 -0
- package/mcp-server/src/tools/list-workflows.ts +31 -0
- package/mcp-server/src/tools/rename-prompt-tag.ts +14 -0
- package/mcp-server/src/tools/run-agent.ts +36 -0
- package/mcp-server/src/tools/run-evaluation.ts +87 -0
- package/mcp-server/src/tools/run-suite.ts +28 -0
- package/mcp-server/src/tools/run-workflow.ts +36 -0
- package/mcp-server/src/tools/search-traces.ts +91 -0
- package/mcp-server/src/tools/set-model-provider.ts +46 -0
- package/mcp-server/src/tools/update-agent.ts +13 -0
- package/mcp-server/src/tools/update-dataset-record.ts +21 -0
- package/mcp-server/src/tools/update-dataset.ts +23 -0
- package/mcp-server/src/tools/update-evaluator.ts +30 -0
- package/mcp-server/src/tools/update-prompt.ts +31 -0
- package/mcp-server/src/tools/update-scenario.ts +32 -0
- package/mcp-server/src/tools/update-suite.ts +44 -0
- package/mcp-server/src/utils/date-parsing.ts +31 -0
- package/mcp-server/src/utils/escape-markdown.ts +12 -0
- package/mcp-server/tsconfig.json +27 -0
- package/mcp-server/uv.lock +2731 -0
- package/package.json +2 -1
- package/packages/server/dist/cli.cjs +6 -2
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { AVAILABLE_EVALUATORS } from "../../../langevals/ts-integration/evaluators.generated.js";
|
|
2
|
+
import type { EvaluatorDefinition, EvaluatorTypes } from "../../../langevals/ts-integration/evaluators.generated.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Formats evaluator schema information for the discover_schema tool.
|
|
6
|
+
*
|
|
7
|
+
* Two levels of detail:
|
|
8
|
+
* - Overview (no evaluatorType): compact list of all evaluator types
|
|
9
|
+
* - Detail (with evaluatorType): full schema for one evaluator type
|
|
10
|
+
*/
|
|
11
|
+
export function formatEvaluatorSchema(evaluatorType?: string): string {
|
|
12
|
+
if (evaluatorType) {
|
|
13
|
+
return formatEvaluatorDetail(evaluatorType);
|
|
14
|
+
}
|
|
15
|
+
return formatEvaluatorOverview();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Returns a compact overview of all available evaluator types.
|
|
20
|
+
* Shows type, name, category, and a one-line description.
|
|
21
|
+
*/
|
|
22
|
+
function formatEvaluatorOverview(): string {
|
|
23
|
+
const lines: string[] = [];
|
|
24
|
+
lines.push("# Available Evaluator Types\n");
|
|
25
|
+
|
|
26
|
+
const byCategory = new Map<string, { type: string; name: string; description: string }[]>();
|
|
27
|
+
|
|
28
|
+
for (const [type, def] of Object.entries(AVAILABLE_EVALUATORS)) {
|
|
29
|
+
const evalDef = def as EvaluatorDefinition<EvaluatorTypes>;
|
|
30
|
+
const oneLine = extractFirstLine(evalDef.description);
|
|
31
|
+
const entry = { type, name: evalDef.name, description: oneLine };
|
|
32
|
+
|
|
33
|
+
const list = byCategory.get(evalDef.category) ?? [];
|
|
34
|
+
list.push(entry);
|
|
35
|
+
byCategory.set(evalDef.category, list);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
for (const [category, entries] of byCategory) {
|
|
39
|
+
lines.push(`## ${category}\n`);
|
|
40
|
+
for (const entry of entries) {
|
|
41
|
+
lines.push(`- **${entry.type}** (${entry.name}): ${entry.description}`);
|
|
42
|
+
}
|
|
43
|
+
lines.push("");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
lines.push(
|
|
47
|
+
"> Use `discover_schema({ category: 'evaluators', evaluatorType: '<type>' })` for full details on a specific evaluator type.",
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
return lines.join("\n");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Returns the full schema for a specific evaluator type.
|
|
55
|
+
* Includes settings with descriptions and defaults, required/optional fields, env vars, and result fields.
|
|
56
|
+
*/
|
|
57
|
+
function formatEvaluatorDetail(evaluatorType: string): string {
|
|
58
|
+
const def = AVAILABLE_EVALUATORS[evaluatorType as EvaluatorTypes] as
|
|
59
|
+
| EvaluatorDefinition<EvaluatorTypes>
|
|
60
|
+
| undefined;
|
|
61
|
+
|
|
62
|
+
if (!def) {
|
|
63
|
+
return `Unknown evaluator type: "${evaluatorType}". Use \`discover_schema({ category: 'evaluators' })\` to see all available types.`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const lines: string[] = [];
|
|
67
|
+
lines.push(`# ${def.name} (\`${evaluatorType}\`)\n`);
|
|
68
|
+
lines.push(`**Category**: ${def.category}`);
|
|
69
|
+
lines.push(`**Is Guardrail**: ${def.isGuardrail ? "Yes" : "No"}`);
|
|
70
|
+
if (def.docsUrl) {
|
|
71
|
+
lines.push(`**Docs**: ${def.docsUrl}`);
|
|
72
|
+
}
|
|
73
|
+
lines.push("");
|
|
74
|
+
lines.push(`## Description\n`);
|
|
75
|
+
lines.push(def.description.trim());
|
|
76
|
+
|
|
77
|
+
// Required and optional fields
|
|
78
|
+
lines.push("\n## Fields\n");
|
|
79
|
+
if (def.requiredFields.length > 0) {
|
|
80
|
+
lines.push(`**Required**: ${def.requiredFields.join(", ")}`);
|
|
81
|
+
} else {
|
|
82
|
+
lines.push("**Required**: none");
|
|
83
|
+
}
|
|
84
|
+
if (def.optionalFields.length > 0) {
|
|
85
|
+
lines.push(`**Optional**: ${def.optionalFields.join(", ")}`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Settings
|
|
89
|
+
const settingsEntries = Object.entries(def.settings);
|
|
90
|
+
if (settingsEntries.length > 0) {
|
|
91
|
+
lines.push("\n## Settings\n");
|
|
92
|
+
for (const [key, setting] of settingsEntries) {
|
|
93
|
+
const s = setting as { description?: string; default: unknown };
|
|
94
|
+
const defaultStr = JSON.stringify(s.default);
|
|
95
|
+
const desc = s.description ? ` - ${s.description}` : "";
|
|
96
|
+
lines.push(`- **${key}**${desc}`);
|
|
97
|
+
lines.push(` Default: \`${defaultStr}\``);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Env vars
|
|
102
|
+
if (def.envVars.length > 0) {
|
|
103
|
+
lines.push("\n## Required Environment Variables\n");
|
|
104
|
+
for (const envVar of def.envVars) {
|
|
105
|
+
lines.push(`- \`${envVar}\``);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Result fields
|
|
110
|
+
const resultEntries = Object.entries(def.result);
|
|
111
|
+
if (resultEntries.length > 0) {
|
|
112
|
+
lines.push("\n## Result Fields\n");
|
|
113
|
+
for (const [key, value] of resultEntries) {
|
|
114
|
+
const v = value as { description: string };
|
|
115
|
+
lines.push(`- **${key}**: ${v.description}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
lines.push("\n## Usage Example\n");
|
|
120
|
+
lines.push("```json");
|
|
121
|
+
lines.push(JSON.stringify({
|
|
122
|
+
evaluatorType: evaluatorType,
|
|
123
|
+
settings: Object.fromEntries(
|
|
124
|
+
settingsEntries.map(([key, setting]) => [key, (setting as { default: unknown }).default]),
|
|
125
|
+
),
|
|
126
|
+
}, null, 2));
|
|
127
|
+
lines.push("```");
|
|
128
|
+
|
|
129
|
+
return lines.join("\n");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Extracts the first meaningful line from a multi-line description.
|
|
134
|
+
*/
|
|
135
|
+
function extractFirstLine(description: string): string {
|
|
136
|
+
const trimmed = description.trim();
|
|
137
|
+
const firstLine = trimmed.split("\n")[0]?.trim() ?? trimmed;
|
|
138
|
+
// Limit to a reasonable length
|
|
139
|
+
if (firstLine.length > 120) {
|
|
140
|
+
return firstLine.slice(0, 117) + "...";
|
|
141
|
+
}
|
|
142
|
+
return firstLine;
|
|
143
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a human-readable description of the scenario schema,
|
|
3
|
+
* including field descriptions, authoring guidance, and examples.
|
|
4
|
+
*/
|
|
5
|
+
export function formatScenarioSchema(): string {
|
|
6
|
+
const lines: string[] = [];
|
|
7
|
+
|
|
8
|
+
lines.push("# Scenario Schema\n");
|
|
9
|
+
|
|
10
|
+
lines.push("## Fields\n");
|
|
11
|
+
lines.push(
|
|
12
|
+
'- **name** (required): A short, descriptive name (e.g., "billing dispute resolution", "password reset with 2FA unavailable")',
|
|
13
|
+
);
|
|
14
|
+
lines.push(
|
|
15
|
+
"- **situation** (required): The context that guides the user simulator — who the user is, what they want, and any constraints (see Writing a Good Situation below)",
|
|
16
|
+
);
|
|
17
|
+
lines.push(
|
|
18
|
+
"- **criteria** (array of strings): Pass/fail conditions a judge evaluates the agent against (see Writing Good Criteria below)",
|
|
19
|
+
);
|
|
20
|
+
lines.push(
|
|
21
|
+
'- **labels** (array of strings): Tags for organizing scenarios (e.g., "auth", "happy-path", "edge-case")',
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
lines.push("\n## Writing a Good Situation\n");
|
|
25
|
+
lines.push(
|
|
26
|
+
"The situation drives the user simulator. Include these elements:",
|
|
27
|
+
);
|
|
28
|
+
lines.push("- **Persona**: Who is the user? (e.g., a stressed small business owner, a confused teenager)");
|
|
29
|
+
lines.push("- **Emotional state**: How are they feeling? (e.g., frustrated, anxious, impatient)");
|
|
30
|
+
lines.push("- **Background/Context**: What happened before this conversation?");
|
|
31
|
+
lines.push("- **Intent**: What do they want to accomplish?");
|
|
32
|
+
lines.push("- **Constraints**: What limitations do they have? (e.g., no phone for 2FA, unfamiliar with technical terms)");
|
|
33
|
+
lines.push("\nExample:");
|
|
34
|
+
lines.push("```");
|
|
35
|
+
lines.push("User is a small business owner stressed about tax deadline.");
|
|
36
|
+
lines.push("They need help categorizing expenses but aren't familiar with");
|
|
37
|
+
lines.push("accounting terms. They appreciate patient explanations and examples.");
|
|
38
|
+
lines.push("They have a spreadsheet of transactions but aren't sure which");
|
|
39
|
+
lines.push("categories apply to their consulting business.");
|
|
40
|
+
lines.push("```");
|
|
41
|
+
|
|
42
|
+
lines.push("\n## Writing Good Criteria\n");
|
|
43
|
+
lines.push("Criteria are what the judge uses to pass or fail the agent. Each criterion should be:");
|
|
44
|
+
lines.push("- **Specific and testable** — not vague like \"responds helpfully\"");
|
|
45
|
+
lines.push("- **Behavioral** — describes what the agent should *do*, not how it works internally");
|
|
46
|
+
lines.push("- **Independent** — each criterion checks one thing");
|
|
47
|
+
lines.push("\nGood criteria patterns:");
|
|
48
|
+
lines.push("- **Information gathering**: \"Agent asks for the user's account number before proceeding\"");
|
|
49
|
+
lines.push("- **Safety/guardrails**: \"Agent does not reveal internal system details or error stack traces\"");
|
|
50
|
+
lines.push("- **Clarification**: \"Agent asks clarifying questions before taking irreversible action\"");
|
|
51
|
+
lines.push("- **Tone**: \"Agent maintains a professional and empathetic tone throughout\"");
|
|
52
|
+
lines.push("- **Completeness**: \"Agent confirms the user understands the solution before ending\"");
|
|
53
|
+
lines.push("- **Domain-specific**: \"Agent recommends releasing a wild frog rather than keeping it as a pet\"");
|
|
54
|
+
lines.push("\nAvoid vague criteria like:");
|
|
55
|
+
lines.push('- "Responds correctly" — correct how?');
|
|
56
|
+
lines.push('- "Is helpful" — helpful in what way?');
|
|
57
|
+
lines.push('- "Works well" — not testable');
|
|
58
|
+
|
|
59
|
+
lines.push("\n## Target Types\n");
|
|
60
|
+
lines.push("Scenarios can target different execution backends:");
|
|
61
|
+
lines.push("- **prompt**: Test a prompt template with variable substitution");
|
|
62
|
+
lines.push("- **http**: Test an HTTP endpoint (e.g., a deployed agent API)");
|
|
63
|
+
lines.push("- **code**: Test a code function directly");
|
|
64
|
+
|
|
65
|
+
lines.push("\n## Tips\n");
|
|
66
|
+
lines.push("- Start simple, then layer complexity (add constraints, edge cases)");
|
|
67
|
+
lines.push("- Test edge cases: user changes their mind, gives ambiguous input, makes mistakes");
|
|
68
|
+
lines.push("- Use `fetch_scenario_docs` for the full authoring guide and advanced patterns");
|
|
69
|
+
|
|
70
|
+
return lines.join("\n");
|
|
71
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { filterFields } from "../schemas/filter-fields.js";
|
|
2
|
+
import { analyticsMetrics } from "../schemas/analytics-metrics.js";
|
|
3
|
+
import { analyticsGroups } from "../schemas/analytics-groups.js";
|
|
4
|
+
|
|
5
|
+
export type Category =
|
|
6
|
+
| "filters"
|
|
7
|
+
| "metrics"
|
|
8
|
+
| "aggregations"
|
|
9
|
+
| "groups"
|
|
10
|
+
| "all";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Formats the LangWatch analytics schema into human-readable markdown.
|
|
14
|
+
*
|
|
15
|
+
* Returns documentation for the requested category of schema elements
|
|
16
|
+
* (filter fields, metrics, aggregation types, or group-by options).
|
|
17
|
+
*/
|
|
18
|
+
export function formatSchema(category: Category): string {
|
|
19
|
+
const sections: string[] = [];
|
|
20
|
+
|
|
21
|
+
if (category === "filters" || category === "all") {
|
|
22
|
+
sections.push(formatFilters());
|
|
23
|
+
}
|
|
24
|
+
if (category === "metrics" || category === "all") {
|
|
25
|
+
sections.push(formatMetrics());
|
|
26
|
+
}
|
|
27
|
+
if (category === "aggregations" || category === "all") {
|
|
28
|
+
sections.push(formatAggregations());
|
|
29
|
+
}
|
|
30
|
+
if (category === "groups" || category === "all") {
|
|
31
|
+
sections.push(formatGroups());
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return sections.join("\n\n");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function formatFilters(): string {
|
|
38
|
+
const lines = ["## Available Filter Fields", ""];
|
|
39
|
+
lines.push(
|
|
40
|
+
"Use these in the `filters` parameter of `search_traces` and `get_analytics`."
|
|
41
|
+
);
|
|
42
|
+
lines.push('Format: `{ "field_name": ["value1", "value2"] }`');
|
|
43
|
+
lines.push("");
|
|
44
|
+
for (const f of filterFields) {
|
|
45
|
+
lines.push(
|
|
46
|
+
`- **${f.field}**: ${f.description}${f.example ? ` (e.g., \`${f.example}\`)` : ""}`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
return lines.join("\n");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function formatMetrics(): string {
|
|
53
|
+
const lines = ["## Available Metrics", ""];
|
|
54
|
+
lines.push(
|
|
55
|
+
"Use these in `get_analytics` as `metric` parameter in `category.name` format."
|
|
56
|
+
);
|
|
57
|
+
lines.push("");
|
|
58
|
+
|
|
59
|
+
const byCategory = new Map<string, typeof analyticsMetrics>();
|
|
60
|
+
for (const m of analyticsMetrics) {
|
|
61
|
+
const list = byCategory.get(m.category) || [];
|
|
62
|
+
list.push(m);
|
|
63
|
+
byCategory.set(m.category, list);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
for (const [cat, metrics] of byCategory) {
|
|
67
|
+
lines.push(`### ${cat}`);
|
|
68
|
+
for (const m of metrics) {
|
|
69
|
+
lines.push(`- **${cat}.${m.name}** (${m.label}): ${m.description}`);
|
|
70
|
+
lines.push(` Aggregations: ${m.allowedAggregations.join(", ")}`);
|
|
71
|
+
}
|
|
72
|
+
lines.push("");
|
|
73
|
+
}
|
|
74
|
+
return lines.join("\n");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function formatAggregations(): string {
|
|
78
|
+
return [
|
|
79
|
+
"## Available Aggregation Types",
|
|
80
|
+
"",
|
|
81
|
+
"- **cardinality**: Count unique values",
|
|
82
|
+
"- **terms**: Distribution/breakdown of values",
|
|
83
|
+
"- **avg**: Average",
|
|
84
|
+
"- **sum**: Sum total",
|
|
85
|
+
"- **min**: Minimum",
|
|
86
|
+
"- **max**: Maximum",
|
|
87
|
+
"- **median**: 50th percentile",
|
|
88
|
+
"- **p90**: 90th percentile",
|
|
89
|
+
"- **p95**: 95th percentile",
|
|
90
|
+
"- **p99**: 99th percentile",
|
|
91
|
+
"",
|
|
92
|
+
"Note: Not all aggregations are available for all metrics. Check the metric's allowed aggregations.",
|
|
93
|
+
].join("\n");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function formatGroups(): string {
|
|
97
|
+
const lines = ["## Available Group-By Options", ""];
|
|
98
|
+
lines.push(
|
|
99
|
+
"Use these in the `groupBy` parameter of `get_analytics`."
|
|
100
|
+
);
|
|
101
|
+
lines.push("");
|
|
102
|
+
for (const g of analyticsGroups) {
|
|
103
|
+
lines.push(`- **${g.name}** (${g.label}): ${g.description}`);
|
|
104
|
+
}
|
|
105
|
+
return lines.join("\n");
|
|
106
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { DatasetMutationResponse } from "../langwatch-api-datasets.js";
|
|
2
|
+
import { escapeMarkdown } from "../utils/escape-markdown.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Formats the common detail lines for a dataset mutation response
|
|
6
|
+
* (name, slug, id, and column types).
|
|
7
|
+
*
|
|
8
|
+
* Used by both create-dataset and update-dataset handlers to avoid
|
|
9
|
+
* duplicating the formatting logic.
|
|
10
|
+
*/
|
|
11
|
+
export function formatDatasetMutationDetails(
|
|
12
|
+
result: DatasetMutationResponse,
|
|
13
|
+
): string[] {
|
|
14
|
+
const lines: string[] = [];
|
|
15
|
+
lines.push(`**Name**: ${escapeMarkdown(result.name)}`);
|
|
16
|
+
lines.push(`**Slug**: ${escapeMarkdown(result.slug)}`);
|
|
17
|
+
lines.push(`**ID**: ${escapeMarkdown(result.id)}`);
|
|
18
|
+
if (Array.isArray(result.columnTypes) && result.columnTypes.length > 0) {
|
|
19
|
+
const colNames = result.columnTypes
|
|
20
|
+
.map((c) => `${escapeMarkdown(c.name)} (${escapeMarkdown(c.type)})`)
|
|
21
|
+
.join(", ");
|
|
22
|
+
lines.push(`**Columns**: ${colNames}`);
|
|
23
|
+
}
|
|
24
|
+
return lines;
|
|
25
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getAgent as apiGetAgent } from "../langwatch-api-agents.js";
|
|
2
|
+
|
|
3
|
+
export async function handleGetAgent(params: { id: string }): Promise<string> {
|
|
4
|
+
const agent = await apiGetAgent(params.id);
|
|
5
|
+
|
|
6
|
+
const lines: string[] = [];
|
|
7
|
+
lines.push(`# ${agent.name}\n`);
|
|
8
|
+
lines.push(`**ID**: ${agent.id}`);
|
|
9
|
+
lines.push(`**Type**: ${agent.type}`);
|
|
10
|
+
lines.push(`**Created**: ${agent.createdAt}`);
|
|
11
|
+
lines.push(`**Updated**: ${agent.updatedAt}`);
|
|
12
|
+
|
|
13
|
+
if (agent.config && Object.keys(agent.config).length > 0) {
|
|
14
|
+
lines.push("\n## Config\n");
|
|
15
|
+
lines.push("```json");
|
|
16
|
+
lines.push(JSON.stringify(agent.config, null, 2));
|
|
17
|
+
lines.push("```");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return lines.join("\n");
|
|
21
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { AnalyticsBucket } from "../langwatch-api.js";
|
|
2
|
+
import { getAnalyticsTimeseries as apiGetAnalytics } from "../langwatch-api.js";
|
|
3
|
+
import { parseRelativeDate } from "../utils/date-parsing.js";
|
|
4
|
+
|
|
5
|
+
type GroupedData = Record<string, Record<string, number>>;
|
|
6
|
+
|
|
7
|
+
function getGroupedData(
|
|
8
|
+
bucket: AnalyticsBucket,
|
|
9
|
+
groupBy: string,
|
|
10
|
+
): GroupedData | undefined {
|
|
11
|
+
const data = bucket[groupBy];
|
|
12
|
+
if (typeof data === "object" && data !== null && !Array.isArray(data)) {
|
|
13
|
+
return data as GroupedData;
|
|
14
|
+
}
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Handles the get_analytics MCP tool invocation.
|
|
20
|
+
*
|
|
21
|
+
* Queries analytics timeseries from LangWatch and formats the results
|
|
22
|
+
* as an AI-readable markdown table.
|
|
23
|
+
*/
|
|
24
|
+
export async function handleGetAnalytics(params: {
|
|
25
|
+
metric: string;
|
|
26
|
+
aggregation?: string;
|
|
27
|
+
startDate?: string;
|
|
28
|
+
endDate?: string;
|
|
29
|
+
timeZone?: string;
|
|
30
|
+
groupBy?: string;
|
|
31
|
+
filters?: Record<string, string[]>;
|
|
32
|
+
}): Promise<string> {
|
|
33
|
+
const now = Date.now();
|
|
34
|
+
const startDate = params.startDate
|
|
35
|
+
? parseRelativeDate(params.startDate)
|
|
36
|
+
: now - 7 * 86400000;
|
|
37
|
+
const endDate = params.endDate ? parseRelativeDate(params.endDate) : now;
|
|
38
|
+
|
|
39
|
+
// Parse metric format "category.name"
|
|
40
|
+
const [category, name] = params.metric.includes(".")
|
|
41
|
+
? params.metric.split(".", 2)
|
|
42
|
+
: ["metadata", params.metric];
|
|
43
|
+
const metricKey = `${category}.${name}`;
|
|
44
|
+
const aggregation = params.aggregation ?? "avg";
|
|
45
|
+
|
|
46
|
+
const result = await apiGetAnalytics({
|
|
47
|
+
series: [{ metric: metricKey, aggregation }],
|
|
48
|
+
startDate,
|
|
49
|
+
endDate,
|
|
50
|
+
timeZone: params.timeZone ?? "UTC",
|
|
51
|
+
groupBy: params.groupBy,
|
|
52
|
+
filters: params.filters,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const lines: string[] = [];
|
|
56
|
+
lines.push(`# Analytics: ${metricKey} (${aggregation})\n`);
|
|
57
|
+
lines.push(
|
|
58
|
+
`Period: ${new Date(startDate).toISOString().split("T")[0]} to ${new Date(endDate).toISOString().split("T")[0]}`
|
|
59
|
+
);
|
|
60
|
+
if (params.groupBy) lines.push(`Grouped by: ${params.groupBy}`);
|
|
61
|
+
lines.push("");
|
|
62
|
+
|
|
63
|
+
const currentPeriod = result.currentPeriod ?? [];
|
|
64
|
+
if (currentPeriod.length === 0) {
|
|
65
|
+
lines.push("No data available for this period.");
|
|
66
|
+
} else if (
|
|
67
|
+
params.groupBy &&
|
|
68
|
+
currentPeriod.some((b) => getGroupedData(b, params.groupBy!) !== undefined)
|
|
69
|
+
) {
|
|
70
|
+
lines.push("| Date | Group | Value |");
|
|
71
|
+
lines.push("|------|-------|-------|");
|
|
72
|
+
for (const bucket of currentPeriod) {
|
|
73
|
+
const groups = getGroupedData(bucket, params.groupBy);
|
|
74
|
+
if (!groups) continue;
|
|
75
|
+
for (const [groupKey, metrics] of Object.entries(groups)) {
|
|
76
|
+
const value =
|
|
77
|
+
Object.values(metrics).find((v) => typeof v === "number") ?? "N/A";
|
|
78
|
+
lines.push(`| ${bucket.date} | ${groupKey} | ${value} |`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
} else {
|
|
82
|
+
lines.push("| Date | Value |");
|
|
83
|
+
lines.push("|------|-------|");
|
|
84
|
+
for (const bucket of currentPeriod) {
|
|
85
|
+
const value =
|
|
86
|
+
Object.entries(bucket).find(
|
|
87
|
+
([k]) => k !== "date" && typeof bucket[k] === "number"
|
|
88
|
+
)?.[1] ?? "N/A";
|
|
89
|
+
lines.push(`| ${bucket.date} | ${value} |`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
lines.push(
|
|
94
|
+
"\n> Tip: Use `discover_schema` to see all available metrics and aggregation types."
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
return lines.join("\n");
|
|
98
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { getDashboard as apiGetDashboard } from "../langwatch-api-dashboards.js";
|
|
2
|
+
|
|
3
|
+
export async function handleGetDashboard(params: { id: string }): Promise<string> {
|
|
4
|
+
const dashboard = await apiGetDashboard(params.id);
|
|
5
|
+
|
|
6
|
+
const lines: string[] = [];
|
|
7
|
+
lines.push(`# ${dashboard.name}\n`);
|
|
8
|
+
lines.push(`**ID**: ${dashboard.id}`);
|
|
9
|
+
lines.push(`**Order**: ${dashboard.order}`);
|
|
10
|
+
lines.push(`**Graphs**: ${Array.isArray(dashboard.graphs) ? dashboard.graphs.length : 0}`);
|
|
11
|
+
lines.push(`**Created**: ${dashboard.createdAt}`);
|
|
12
|
+
lines.push(`**Updated**: ${dashboard.updatedAt}`);
|
|
13
|
+
|
|
14
|
+
if (Array.isArray(dashboard.graphs) && dashboard.graphs.length > 0) {
|
|
15
|
+
lines.push("\n## Graphs\n");
|
|
16
|
+
lines.push("```json");
|
|
17
|
+
lines.push(JSON.stringify(dashboard.graphs, null, 2));
|
|
18
|
+
lines.push("```");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return lines.join("\n");
|
|
22
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getDataset as apiGetDataset,
|
|
3
|
+
type DatasetDetailResponse,
|
|
4
|
+
} from "../langwatch-api-datasets.js";
|
|
5
|
+
import { escapeMarkdown } from "../utils/escape-markdown.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Formats a dataset detail response into AI-readable markdown.
|
|
9
|
+
*
|
|
10
|
+
* Exported for unit testing.
|
|
11
|
+
*/
|
|
12
|
+
export function formatDatasetResponse(
|
|
13
|
+
dataset: DatasetDetailResponse,
|
|
14
|
+
): string {
|
|
15
|
+
const lines: string[] = [];
|
|
16
|
+
lines.push(`# Dataset: ${escapeMarkdown(dataset.name)}\n`);
|
|
17
|
+
lines.push(`**Slug**: ${escapeMarkdown(dataset.slug)}`);
|
|
18
|
+
lines.push(`**ID**: ${escapeMarkdown(dataset.id)}`);
|
|
19
|
+
|
|
20
|
+
// Column table
|
|
21
|
+
if (
|
|
22
|
+
Array.isArray(dataset.columnTypes) &&
|
|
23
|
+
dataset.columnTypes.length > 0
|
|
24
|
+
) {
|
|
25
|
+
lines.push("\n## Columns\n");
|
|
26
|
+
lines.push("| Name | Type |");
|
|
27
|
+
lines.push("|------|------|");
|
|
28
|
+
for (const col of dataset.columnTypes) {
|
|
29
|
+
lines.push(`| ${escapeMarkdown(col.name)} | ${escapeMarkdown(col.type)} |`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Record preview
|
|
34
|
+
if (Array.isArray(dataset.data) && dataset.data.length > 0) {
|
|
35
|
+
lines.push(`\n## Records (${dataset.data.length} shown)\n`);
|
|
36
|
+
for (const record of dataset.data) {
|
|
37
|
+
lines.push(`**${escapeMarkdown(record.id)}**: ${escapeMarkdown(JSON.stringify(record.entry))}`);
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
lines.push("\nNo records in this dataset.");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return lines.join("\n");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Handles the platform_get_dataset MCP tool invocation.
|
|
48
|
+
*
|
|
49
|
+
* Retrieves a specific dataset by slug or ID and formats it as
|
|
50
|
+
* AI-readable markdown or raw JSON.
|
|
51
|
+
*/
|
|
52
|
+
export async function handleGetDataset(params: {
|
|
53
|
+
slugOrId: string;
|
|
54
|
+
format?: "digest" | "json";
|
|
55
|
+
}): Promise<string> {
|
|
56
|
+
const dataset = await apiGetDataset(params.slugOrId);
|
|
57
|
+
|
|
58
|
+
if (params.format === "json") {
|
|
59
|
+
return JSON.stringify(dataset, null, 2);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return formatDatasetResponse(dataset);
|
|
63
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getEvaluator as apiGetEvaluator,
|
|
3
|
+
getEvaluatorType,
|
|
4
|
+
} from "../langwatch-api-evaluators.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Handles the platform_get_evaluator MCP tool invocation.
|
|
8
|
+
*
|
|
9
|
+
* Retrieves a specific evaluator by ID or slug and formats it as
|
|
10
|
+
* AI-readable markdown.
|
|
11
|
+
*/
|
|
12
|
+
export async function handleGetEvaluator(params: {
|
|
13
|
+
idOrSlug: string;
|
|
14
|
+
}): Promise<string> {
|
|
15
|
+
const evaluator = await apiGetEvaluator(params.idOrSlug);
|
|
16
|
+
|
|
17
|
+
const evaluatorType = getEvaluatorType(evaluator);
|
|
18
|
+
|
|
19
|
+
const lines: string[] = [];
|
|
20
|
+
lines.push(`# Evaluator: ${evaluator.name}\n`);
|
|
21
|
+
lines.push(`**ID**: ${evaluator.id}`);
|
|
22
|
+
if (evaluator.slug) lines.push(`**Slug**: ${evaluator.slug}`);
|
|
23
|
+
lines.push(`**Kind**: ${evaluator.type}`);
|
|
24
|
+
if (evaluatorType) lines.push(`**Evaluator Type**: ${evaluatorType}`);
|
|
25
|
+
|
|
26
|
+
if (evaluator.config) {
|
|
27
|
+
lines.push("\n## Config");
|
|
28
|
+
lines.push("```json");
|
|
29
|
+
lines.push(JSON.stringify(evaluator.config, null, 2));
|
|
30
|
+
lines.push("```");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (Array.isArray(evaluator.fields) && evaluator.fields.length > 0) {
|
|
34
|
+
lines.push("\n## Input Fields");
|
|
35
|
+
for (const field of evaluator.fields) {
|
|
36
|
+
const opt = field.optional ? " (optional)" : "";
|
|
37
|
+
lines.push(`- **${field.identifier}** (${field.type})${opt}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (Array.isArray(evaluator.outputFields) && evaluator.outputFields.length > 0) {
|
|
42
|
+
lines.push("\n## Output Fields");
|
|
43
|
+
for (const field of evaluator.outputFields) {
|
|
44
|
+
lines.push(`- **${field.identifier}** (${field.type})`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (evaluator.workflowName) {
|
|
49
|
+
lines.push(`\n**Workflow**: ${evaluator.workflowName}`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return lines.join("\n");
|
|
53
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { getPrompt as apiGetPrompt } from "../langwatch-api.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Handles the platform_get_prompt MCP tool invocation.
|
|
5
|
+
*
|
|
6
|
+
* Retrieves a specific prompt by ID or handle and formats it as
|
|
7
|
+
* AI-readable markdown, including messages, model config, and version history.
|
|
8
|
+
*/
|
|
9
|
+
export async function handleGetPrompt(params: {
|
|
10
|
+
idOrHandle: string;
|
|
11
|
+
version?: number;
|
|
12
|
+
tag?: string;
|
|
13
|
+
}): Promise<string> {
|
|
14
|
+
const prompt = await apiGetPrompt(params.idOrHandle, { version: params.version, tag: params.tag });
|
|
15
|
+
|
|
16
|
+
const lines: string[] = [];
|
|
17
|
+
lines.push(
|
|
18
|
+
`# Prompt: ${prompt.name || prompt.handle || prompt.id}\n`
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
if (prompt.handle) lines.push(`**Handle**: ${prompt.handle}`);
|
|
22
|
+
if (prompt.id) lines.push(`**ID**: ${prompt.id}`);
|
|
23
|
+
if (prompt.latestVersionNumber != null)
|
|
24
|
+
lines.push(`**Latest Version**: v${prompt.latestVersionNumber}`);
|
|
25
|
+
|
|
26
|
+
// Show model config
|
|
27
|
+
const version = prompt.versions?.[0] ?? prompt;
|
|
28
|
+
if (version.model) lines.push(`**Model**: ${version.model}`);
|
|
29
|
+
|
|
30
|
+
// Show messages
|
|
31
|
+
const messages = version.messages || prompt.prompt || [];
|
|
32
|
+
if (Array.isArray(messages) && messages.length > 0) {
|
|
33
|
+
lines.push("\n## Messages");
|
|
34
|
+
for (const msg of messages) {
|
|
35
|
+
lines.push(`\n### ${msg.role}`);
|
|
36
|
+
lines.push(msg.content);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Show version history
|
|
41
|
+
if (prompt.versions && prompt.versions.length > 0) {
|
|
42
|
+
lines.push("\n## Version History");
|
|
43
|
+
for (const v of prompt.versions.slice(0, 10)) {
|
|
44
|
+
const versionNum = v.version ?? "?";
|
|
45
|
+
const commitMsg = v.commitMessage || "No message";
|
|
46
|
+
lines.push(`- **v${versionNum}**: ${commitMsg}`);
|
|
47
|
+
}
|
|
48
|
+
if (prompt.versions.length > 10) {
|
|
49
|
+
lines.push(`... and ${prompt.versions.length - 10} more versions`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return lines.join("\n");
|
|
54
|
+
}
|