@langwatch/server 3.1.0-beta.5 → 3.1.0-beta.6

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.
Files changed (213) hide show
  1. package/langwatch/package.json +1 -1
  2. package/langwatch/pnpm-workspace.yaml +0 -1
  3. package/mcp-server/.env.example +2 -0
  4. package/mcp-server/.eslintrc.cjs +36 -0
  5. package/mcp-server/CHANGELOG.md +165 -0
  6. package/mcp-server/CONTRIBUTING.md +96 -0
  7. package/mcp-server/README.md +172 -0
  8. package/mcp-server/dist/archive-scenario-WJ2A7ETN.js +19 -0
  9. package/mcp-server/dist/archive-suite-4JOM4SSL.js +15 -0
  10. package/mcp-server/dist/assign-prompt-tag-GL7EAAF3.js +19 -0
  11. package/mcp-server/dist/chunk-2GT7IFWK.js +40 -0
  12. package/mcp-server/dist/chunk-2WPLXEKF.js +127 -0
  13. package/mcp-server/dist/chunk-4AUB2BIA.js +71 -0
  14. package/mcp-server/dist/chunk-BWWY5KEF.js +71 -0
  15. package/mcp-server/dist/chunk-CCWCIJJ3.js +22 -0
  16. package/mcp-server/dist/chunk-EGH5RPXM.js +25 -0
  17. package/mcp-server/dist/chunk-EUQDVOSU.js +39 -0
  18. package/mcp-server/dist/chunk-HYMIWO3U.js +44 -0
  19. package/mcp-server/dist/chunk-IE4M5OGE.js +42 -0
  20. package/mcp-server/dist/chunk-LUMEZEHL.js +48 -0
  21. package/mcp-server/dist/chunk-NUFPTHKU.js +9 -0
  22. package/mcp-server/dist/chunk-UDHJYT6P.js +1567 -0
  23. package/mcp-server/dist/chunk-WQG2DFHX.js +86 -0
  24. package/mcp-server/dist/chunk-WVI5CJ6S.js +21 -0
  25. package/mcp-server/dist/chunk-ZVS4UKN2.js +35 -0
  26. package/mcp-server/dist/chunk-ZXKLPC2E.js +27 -0
  27. package/mcp-server/dist/config.d.ts +17 -0
  28. package/mcp-server/dist/config.js +13 -0
  29. package/mcp-server/dist/create-agent-MBOOT3XK.js +23 -0
  30. package/mcp-server/dist/create-annotation-XMV6A7ED.js +24 -0
  31. package/mcp-server/dist/create-dashboard-VRKLFVZJ.js +18 -0
  32. package/mcp-server/dist/create-dataset-7HQPZCRE.js +22 -0
  33. package/mcp-server/dist/create-dataset-records-2NIVFYTV.js +22 -0
  34. package/mcp-server/dist/create-evaluator-WYFRFLRC.js +27 -0
  35. package/mcp-server/dist/create-mcp-server.d.ts +8 -0
  36. package/mcp-server/dist/create-mcp-server.js +8 -0
  37. package/mcp-server/dist/create-prompt-IEN7O6JT.js +39 -0
  38. package/mcp-server/dist/create-prompt-tag-CAEZ45VO.js +17 -0
  39. package/mcp-server/dist/create-scenario-6YHSMGLP.js +26 -0
  40. package/mcp-server/dist/create-suite-H5XOFDE5.js +38 -0
  41. package/mcp-server/dist/delete-agent-JKTNBWAA.js +18 -0
  42. package/mcp-server/dist/delete-annotation-ACMDV6QO.js +17 -0
  43. package/mcp-server/dist/delete-dashboard-VJSR7CRU.js +18 -0
  44. package/mcp-server/dist/delete-dataset-RTTTWP4D.js +20 -0
  45. package/mcp-server/dist/delete-dataset-records-KNQTIPQK.js +21 -0
  46. package/mcp-server/dist/delete-evaluator-7FVC5WM4.js +15 -0
  47. package/mcp-server/dist/delete-prompt-tag-ZMZUAGFW.js +17 -0
  48. package/mcp-server/dist/delete-workflow-EYQ3T4RQ.js +17 -0
  49. package/mcp-server/dist/discover-evaluator-schema-H23XCLNE.js +1402 -0
  50. package/mcp-server/dist/discover-scenario-schema-MEEEVND7.js +65 -0
  51. package/mcp-server/dist/discover-schema-3T52ORPB.js +446 -0
  52. package/mcp-server/dist/get-agent-E3QSTVKG.js +28 -0
  53. package/mcp-server/dist/get-analytics-2OHV763I.js +72 -0
  54. package/mcp-server/dist/get-dashboard-PC7JDHH6.js +29 -0
  55. package/mcp-server/dist/get-dataset-H5IK5FVU.js +48 -0
  56. package/mcp-server/dist/get-evaluator-UWVUPYTM.js +47 -0
  57. package/mcp-server/dist/get-prompt-WZUOLLQC.js +45 -0
  58. package/mcp-server/dist/get-scenario-Q6LCNUYN.js +33 -0
  59. package/mcp-server/dist/get-simulation-run-Z2XKO256.js +56 -0
  60. package/mcp-server/dist/get-suite-BXK5TN7P.js +44 -0
  61. package/mcp-server/dist/get-trace-4EJAYVBG.js +50 -0
  62. package/mcp-server/dist/get-workflow-O34QJLHD.js +25 -0
  63. package/mcp-server/dist/http-server-RSTXN4CN.js +224 -0
  64. package/mcp-server/dist/index.d.ts +2 -0
  65. package/mcp-server/dist/index.js +67774 -0
  66. package/mcp-server/dist/langwatch-api-annotations-ERBG27RF.js +17 -0
  67. package/mcp-server/dist/langwatch-api-dashboards-G6TR7VVO.js +17 -0
  68. package/mcp-server/dist/langwatch-api-monitors-WSXZLS2B.js +52 -0
  69. package/mcp-server/dist/langwatch-api-secrets-RR5DKG2X.js +40 -0
  70. package/mcp-server/dist/langwatch-api-triggers-2RTNSWQY.js +30 -0
  71. package/mcp-server/dist/langwatch-api-workflows-VJRIIDZ7.js +15 -0
  72. package/mcp-server/dist/list-agents-AW3P6FJV.js +32 -0
  73. package/mcp-server/dist/list-annotations-QNCGWPQ3.js +33 -0
  74. package/mcp-server/dist/list-dashboards-R7RK2IXL.js +32 -0
  75. package/mcp-server/dist/list-dataset-records-WVCSQP7P.js +39 -0
  76. package/mcp-server/dist/list-datasets-KEXRLDEU.js +60 -0
  77. package/mcp-server/dist/list-evaluators-7R2LB4JH.js +34 -0
  78. package/mcp-server/dist/list-model-providers-OBYJCKBX.js +35 -0
  79. package/mcp-server/dist/list-prompt-tags-6LY3ZPYI.js +23 -0
  80. package/mcp-server/dist/list-prompts-VWEZ4CDE.js +32 -0
  81. package/mcp-server/dist/list-scenarios-TXD4W2ZJ.js +40 -0
  82. package/mcp-server/dist/list-simulation-runs-RHPOLMFI.js +43 -0
  83. package/mcp-server/dist/list-suites-FSGBX27Z.js +42 -0
  84. package/mcp-server/dist/list-workflows-VRGEZ3EN.js +35 -0
  85. package/mcp-server/dist/rename-prompt-tag-VOJJLX4M.js +18 -0
  86. package/mcp-server/dist/run-agent-KTCC7TB7.js +36 -0
  87. package/mcp-server/dist/run-evaluation-2X3V3Q6L.js +64 -0
  88. package/mcp-server/dist/run-suite-BTMHGI2D.js +29 -0
  89. package/mcp-server/dist/run-workflow-IGAYGKJL.js +36 -0
  90. package/mcp-server/dist/search-traces-VYFUIMXH.js +72 -0
  91. package/mcp-server/dist/set-model-provider-W5IUI326.js +33 -0
  92. package/mcp-server/dist/update-agent-4BB7EYLR.js +20 -0
  93. package/mcp-server/dist/update-dataset-CXBKZ4W3.js +22 -0
  94. package/mcp-server/dist/update-dataset-record-HOHAMHXG.js +19 -0
  95. package/mcp-server/dist/update-evaluator-IVOR6FTR.js +24 -0
  96. package/mcp-server/dist/update-prompt-OWQAKE7K.js +24 -0
  97. package/mcp-server/dist/update-scenario-GDFVILPN.js +27 -0
  98. package/mcp-server/dist/update-suite-BXYUYSPT.js +39 -0
  99. package/mcp-server/package.json +79 -0
  100. package/mcp-server/pnpm-lock.yaml +6103 -0
  101. package/mcp-server/pnpm-workspace.yaml +2 -0
  102. package/mcp-server/pyproject.toml +17 -0
  103. package/mcp-server/src/__tests__/all-tools.integration.test.ts +1681 -0
  104. package/mcp-server/src/__tests__/config.unit.test.ts +169 -0
  105. package/mcp-server/src/__tests__/datasets.integration.test.ts +603 -0
  106. package/mcp-server/src/__tests__/datasets.unit.test.ts +240 -0
  107. package/mcp-server/src/__tests__/date-parsing.unit.test.ts +78 -0
  108. package/mcp-server/src/__tests__/discover-evaluator-schema.unit.test.ts +89 -0
  109. package/mcp-server/src/__tests__/discover-schema.unit.test.ts +118 -0
  110. package/mcp-server/src/__tests__/docker.integration.test.ts +234 -0
  111. package/mcp-server/src/__tests__/evaluator-tools.unit.test.ts +262 -0
  112. package/mcp-server/src/__tests__/http-transport.integration.test.ts +397 -0
  113. package/mcp-server/src/__tests__/integration.integration.test.ts +288 -0
  114. package/mcp-server/src/__tests__/langwatch-api.unit.test.ts +455 -0
  115. package/mcp-server/src/__tests__/model-provider-tools.unit.test.ts +190 -0
  116. package/mcp-server/src/__tests__/scenario-tools.integration.test.ts +286 -0
  117. package/mcp-server/src/__tests__/scenario-tools.unit.test.ts +185 -0
  118. package/mcp-server/src/__tests__/schemas.unit.test.ts +85 -0
  119. package/mcp-server/src/__tests__/tools.unit.test.ts +900 -0
  120. package/mcp-server/src/config.d.ts +15 -0
  121. package/mcp-server/src/config.ts +107 -0
  122. package/mcp-server/src/create-mcp-server.d.ts +6 -0
  123. package/mcp-server/src/create-mcp-server.ts +1799 -0
  124. package/mcp-server/src/http-server.ts +329 -0
  125. package/mcp-server/src/index.ts +46 -0
  126. package/mcp-server/src/langwatch-api-agents.ts +108 -0
  127. package/mcp-server/src/langwatch-api-annotations.ts +49 -0
  128. package/mcp-server/src/langwatch-api-dashboards.ts +48 -0
  129. package/mcp-server/src/langwatch-api-datasets.ts +191 -0
  130. package/mcp-server/src/langwatch-api-evaluators.ts +80 -0
  131. package/mcp-server/src/langwatch-api-model-providers.ts +41 -0
  132. package/mcp-server/src/langwatch-api-monitors.ts +82 -0
  133. package/mcp-server/src/langwatch-api-scenarios.ts +67 -0
  134. package/mcp-server/src/langwatch-api-secrets.ts +48 -0
  135. package/mcp-server/src/langwatch-api-simulation-runs.ts +51 -0
  136. package/mcp-server/src/langwatch-api-suites.ts +118 -0
  137. package/mcp-server/src/langwatch-api-triggers.ts +48 -0
  138. package/mcp-server/src/langwatch-api-workflows.ts +41 -0
  139. package/mcp-server/src/langwatch-api.ts +299 -0
  140. package/mcp-server/src/schemas/analytics-groups.ts +78 -0
  141. package/mcp-server/src/schemas/analytics-metrics.ts +179 -0
  142. package/mcp-server/src/schemas/create-dataset.ts +48 -0
  143. package/mcp-server/src/schemas/filter-fields.ts +119 -0
  144. package/mcp-server/src/schemas/index.ts +4 -0
  145. package/mcp-server/src/tools/archive-scenario.ts +19 -0
  146. package/mcp-server/src/tools/archive-suite.ts +12 -0
  147. package/mcp-server/src/tools/assign-prompt-tag.ts +16 -0
  148. package/mcp-server/src/tools/create-agent.ts +15 -0
  149. package/mcp-server/src/tools/create-annotation.ts +18 -0
  150. package/mcp-server/src/tools/create-dashboard.ts +7 -0
  151. package/mcp-server/src/tools/create-dataset-records.ts +23 -0
  152. package/mcp-server/src/tools/create-dataset.ts +22 -0
  153. package/mcp-server/src/tools/create-evaluator.ts +33 -0
  154. package/mcp-server/src/tools/create-prompt-tag.ts +12 -0
  155. package/mcp-server/src/tools/create-prompt.ts +58 -0
  156. package/mcp-server/src/tools/create-scenario.ts +30 -0
  157. package/mcp-server/src/tools/create-suite.ts +42 -0
  158. package/mcp-server/src/tools/delete-agent.ts +7 -0
  159. package/mcp-server/src/tools/delete-annotation.ts +7 -0
  160. package/mcp-server/src/tools/delete-dashboard.ts +7 -0
  161. package/mcp-server/src/tools/delete-dataset-records.ts +22 -0
  162. package/mcp-server/src/tools/delete-dataset.ts +20 -0
  163. package/mcp-server/src/tools/delete-evaluator.ts +12 -0
  164. package/mcp-server/src/tools/delete-prompt-tag.ts +12 -0
  165. package/mcp-server/src/tools/delete-workflow.ts +7 -0
  166. package/mcp-server/src/tools/discover-evaluator-schema.ts +143 -0
  167. package/mcp-server/src/tools/discover-scenario-schema.ts +71 -0
  168. package/mcp-server/src/tools/discover-schema.ts +106 -0
  169. package/mcp-server/src/tools/format-dataset-mutation.ts +25 -0
  170. package/mcp-server/src/tools/get-agent.ts +21 -0
  171. package/mcp-server/src/tools/get-analytics.ts +98 -0
  172. package/mcp-server/src/tools/get-dashboard.ts +22 -0
  173. package/mcp-server/src/tools/get-dataset.ts +63 -0
  174. package/mcp-server/src/tools/get-evaluator.ts +53 -0
  175. package/mcp-server/src/tools/get-prompt.ts +54 -0
  176. package/mcp-server/src/tools/get-scenario.ts +36 -0
  177. package/mcp-server/src/tools/get-simulation-run.ts +60 -0
  178. package/mcp-server/src/tools/get-suite.ts +47 -0
  179. package/mcp-server/src/tools/get-trace.ts +61 -0
  180. package/mcp-server/src/tools/get-workflow.ts +17 -0
  181. package/mcp-server/src/tools/list-agents.ts +27 -0
  182. package/mcp-server/src/tools/list-annotations.ts +33 -0
  183. package/mcp-server/src/tools/list-dashboards.ts +27 -0
  184. package/mcp-server/src/tools/list-dataset-records.ts +46 -0
  185. package/mcp-server/src/tools/list-datasets.ts +80 -0
  186. package/mcp-server/src/tools/list-evaluators.ts +37 -0
  187. package/mcp-server/src/tools/list-model-providers.ts +40 -0
  188. package/mcp-server/src/tools/list-prompt-tags.ts +21 -0
  189. package/mcp-server/src/tools/list-prompts.ts +34 -0
  190. package/mcp-server/src/tools/list-scenarios.ts +47 -0
  191. package/mcp-server/src/tools/list-simulation-runs.ts +49 -0
  192. package/mcp-server/src/tools/list-suites.ts +43 -0
  193. package/mcp-server/src/tools/list-workflows.ts +31 -0
  194. package/mcp-server/src/tools/rename-prompt-tag.ts +14 -0
  195. package/mcp-server/src/tools/run-agent.ts +36 -0
  196. package/mcp-server/src/tools/run-evaluation.ts +87 -0
  197. package/mcp-server/src/tools/run-suite.ts +28 -0
  198. package/mcp-server/src/tools/run-workflow.ts +36 -0
  199. package/mcp-server/src/tools/search-traces.ts +91 -0
  200. package/mcp-server/src/tools/set-model-provider.ts +46 -0
  201. package/mcp-server/src/tools/update-agent.ts +13 -0
  202. package/mcp-server/src/tools/update-dataset-record.ts +21 -0
  203. package/mcp-server/src/tools/update-dataset.ts +23 -0
  204. package/mcp-server/src/tools/update-evaluator.ts +30 -0
  205. package/mcp-server/src/tools/update-prompt.ts +31 -0
  206. package/mcp-server/src/tools/update-scenario.ts +32 -0
  207. package/mcp-server/src/tools/update-suite.ts +44 -0
  208. package/mcp-server/src/utils/date-parsing.ts +31 -0
  209. package/mcp-server/src/utils/escape-markdown.ts +12 -0
  210. package/mcp-server/tsconfig.json +27 -0
  211. package/mcp-server/uv.lock +2731 -0
  212. package/package.json +2 -1
  213. package/packages/server/dist/cli.cjs +1 -1
@@ -0,0 +1,43 @@
1
+ import { listSuites as apiListSuites } from "../langwatch-api-suites.js";
2
+
3
+ /**
4
+ * Handles the platform_list_suites MCP tool invocation.
5
+ */
6
+ export async function handleListSuites(params: {
7
+ format?: "digest" | "json";
8
+ }): Promise<string> {
9
+ const suites = await apiListSuites();
10
+
11
+ if (params.format === "json") {
12
+ return JSON.stringify(suites, null, 2);
13
+ }
14
+
15
+ if (!Array.isArray(suites) || suites.length === 0) {
16
+ return "No suites (run plans) found in this project.\n\n> Tip: Use `platform_create_suite` to create your first suite.";
17
+ }
18
+
19
+ const lines: string[] = [];
20
+ lines.push(`# Suites / Run Plans (${suites.length} total)\n`);
21
+
22
+ for (const s of suites) {
23
+ lines.push(`## ${s.name}`);
24
+ lines.push(`**ID**: ${s.id}`);
25
+ lines.push(`**Slug**: ${s.slug}`);
26
+ lines.push(`**Scenarios**: ${s.scenarioIds.length}`);
27
+ lines.push(`**Targets**: ${s.targets.length} (${s.targets.map((t) => `${t.type}:${t.referenceId}`).join(", ")})`);
28
+ lines.push(`**Repeat**: ${s.repeatCount}x`);
29
+ if (s.description) {
30
+ lines.push(`**Description**: ${s.description}`);
31
+ }
32
+ if (Array.isArray(s.labels) && s.labels.length > 0) {
33
+ lines.push(`**Labels**: ${s.labels.join(", ")}`);
34
+ }
35
+ lines.push("");
36
+ }
37
+
38
+ lines.push(
39
+ "> Use `platform_get_suite` with the ID to see full details, or `platform_run_suite` to trigger execution."
40
+ );
41
+
42
+ return lines.join("\n");
43
+ }
@@ -0,0 +1,31 @@
1
+ import { listWorkflows as apiListWorkflows } from "../langwatch-api-workflows.js";
2
+
3
+ export async function handleListWorkflows(): Promise<string> {
4
+ const workflows = await apiListWorkflows();
5
+
6
+ if (!Array.isArray(workflows) || workflows.length === 0) {
7
+ return "No workflows found in this project.";
8
+ }
9
+
10
+ const lines: string[] = [];
11
+ lines.push(`# Workflows (${workflows.length} total)\n`);
12
+
13
+ for (const w of workflows) {
14
+ const tags: string[] = [];
15
+ if (w.isEvaluator) tags.push("evaluator");
16
+ if (w.isComponent) tags.push("component");
17
+ const tagStr = tags.length > 0 ? ` [${tags.join(", ")}]` : "";
18
+
19
+ lines.push(`## ${w.name}${tagStr}`);
20
+ lines.push(`**ID**: ${w.id}`);
21
+ if (w.description) lines.push(`**Description**: ${w.description}`);
22
+ lines.push(`**Updated**: ${w.updatedAt}`);
23
+ lines.push("");
24
+ }
25
+
26
+ lines.push(
27
+ "> Use `platform_get_workflow` with the ID to see full workflow details.",
28
+ );
29
+
30
+ return lines.join("\n");
31
+ }
@@ -0,0 +1,14 @@
1
+ import { renamePromptTag as apiRenamePromptTag } from "../langwatch-api.js";
2
+
3
+ export async function handleRenamePromptTag(params: {
4
+ tag: string;
5
+ name: string;
6
+ }): Promise<string> {
7
+ await apiRenamePromptTag({ tag: params.tag, name: params.name });
8
+
9
+ const lines: string[] = [];
10
+ lines.push("Tag renamed successfully!\n");
11
+ lines.push(`**Old name**: ${params.tag}`);
12
+ lines.push(`**New name**: ${params.name}`);
13
+ return lines.join("\n");
14
+ }
@@ -0,0 +1,36 @@
1
+ import { runAgent as apiRunAgent } from "../langwatch-api-agents.js";
2
+
3
+ /**
4
+ * Handles the platform_run_agent MCP tool invocation.
5
+ */
6
+ export async function handleRunAgent(params: {
7
+ id: string;
8
+ input?: string;
9
+ }): Promise<string> {
10
+ let parsedInput: Record<string, unknown> = {};
11
+ if (params.input) {
12
+ try {
13
+ parsedInput = JSON.parse(params.input) as Record<string, unknown>;
14
+ } catch {
15
+ return "Error: `input` must be a valid JSON object.";
16
+ }
17
+ }
18
+
19
+ const { agentType, result } = await apiRunAgent(params.id, parsedInput);
20
+
21
+ const lines: string[] = [];
22
+ lines.push(`Agent executed successfully (type: ${agentType}).\n`);
23
+
24
+ if (typeof result === "object" && result !== null) {
25
+ const output = (result as Record<string, unknown>).output;
26
+ if (output !== undefined) {
27
+ lines.push("**Output:**");
28
+ lines.push(typeof output === "string" ? output : JSON.stringify(output, null, 2));
29
+ } else {
30
+ lines.push("**Result:**");
31
+ lines.push(JSON.stringify(result, null, 2));
32
+ }
33
+ }
34
+
35
+ return lines.join("\n");
36
+ }
@@ -0,0 +1,87 @@
1
+ import { makeRequest } from "../langwatch-api.js";
2
+
3
+ interface EvaluationRunResponse {
4
+ runId: string;
5
+ status: string;
6
+ total: number;
7
+ runUrl?: string;
8
+ }
9
+
10
+ interface EvaluationStatusResponse {
11
+ runId: string;
12
+ status: string;
13
+ progress: number;
14
+ total: number;
15
+ startedAt?: number;
16
+ finishedAt?: number;
17
+ summary?: {
18
+ totalCells?: number;
19
+ completedCells?: number;
20
+ failedCells?: number;
21
+ duration?: number;
22
+ runUrl?: string;
23
+ };
24
+ }
25
+
26
+ export async function handleRunEvaluation(params: {
27
+ slug: string;
28
+ }): Promise<string> {
29
+ const result = (await makeRequest(
30
+ "POST",
31
+ `/api/evaluations/v3/${encodeURIComponent(params.slug)}/run`,
32
+ )) as EvaluationRunResponse;
33
+
34
+ const lines: string[] = [];
35
+ lines.push(`Evaluation started!\n`);
36
+ lines.push(`**Run ID**: ${result.runId}`);
37
+ lines.push(`**Status**: ${result.status}`);
38
+ lines.push(`**Total cells**: ${result.total}`);
39
+ if (result.runUrl) lines.push(`**View at**: ${result.runUrl}`);
40
+ lines.push("");
41
+ lines.push(
42
+ `> Use \`platform_evaluation_status\` with run ID "${result.runId}" to check progress.`,
43
+ );
44
+
45
+ return lines.join("\n");
46
+ }
47
+
48
+ export async function handleEvaluationStatus(params: {
49
+ runId: string;
50
+ }): Promise<string> {
51
+ const status = (await makeRequest(
52
+ "GET",
53
+ `/api/evaluations/v3/runs/${encodeURIComponent(params.runId)}`,
54
+ )) as EvaluationStatusResponse;
55
+
56
+ const lines: string[] = [];
57
+ lines.push(`# Evaluation Run ${status.runId}\n`);
58
+ lines.push(`**Status**: ${status.status}`);
59
+ lines.push(`**Progress**: ${status.progress}/${status.total} cells`);
60
+
61
+ if (status.startedAt) {
62
+ lines.push(`**Started**: ${new Date(status.startedAt).toISOString()}`);
63
+ }
64
+ if (status.finishedAt) {
65
+ lines.push(`**Finished**: ${new Date(status.finishedAt).toISOString()}`);
66
+ }
67
+
68
+ if (status.summary) {
69
+ lines.push("\n## Summary\n");
70
+ if (status.summary.completedCells !== undefined) {
71
+ lines.push(`**Completed**: ${status.summary.completedCells}`);
72
+ }
73
+ if (status.summary.failedCells) {
74
+ lines.push(`**Failed**: ${status.summary.failedCells}`);
75
+ }
76
+ if (status.summary.duration) {
77
+ lines.push(
78
+ `**Duration**: ${(status.summary.duration / 1000).toFixed(1)}s`,
79
+ );
80
+ }
81
+ if (status.summary.runUrl) {
82
+ lines.push(`**View results**: ${status.summary.runUrl}`);
83
+ }
84
+ }
85
+
86
+ return lines.join("\n");
87
+ }
@@ -0,0 +1,28 @@
1
+ import { runSuite as apiRunSuite } from "../langwatch-api-suites.js";
2
+
3
+ /**
4
+ * Handles the platform_run_suite MCP tool invocation.
5
+ */
6
+ export async function handleRunSuite(params: {
7
+ id: string;
8
+ }): Promise<string> {
9
+ const result = await apiRunSuite(params.id);
10
+
11
+ const lines: string[] = [];
12
+ lines.push(`Suite run scheduled successfully.`);
13
+ lines.push("");
14
+ lines.push(`**Batch Run ID**: ${result.batchRunId}`);
15
+ lines.push(`**Jobs**: ${result.jobCount}`);
16
+ lines.push(`**Set ID**: ${result.setId}`);
17
+
18
+ if (result.skippedArchived.scenarios.length > 0) {
19
+ lines.push(`\n⚠️ Skipped archived scenarios: ${result.skippedArchived.scenarios.join(", ")}`);
20
+ }
21
+ if (result.skippedArchived.targets.length > 0) {
22
+ lines.push(`⚠️ Skipped archived targets: ${result.skippedArchived.targets.join(", ")}`);
23
+ }
24
+
25
+ lines.push("\nView results in the LangWatch dashboard under Simulations.");
26
+
27
+ return lines.join("\n");
28
+ }
@@ -0,0 +1,36 @@
1
+ import { runWorkflow as apiRunWorkflow } from "../langwatch-api-workflows.js";
2
+
3
+ /**
4
+ * Handles the platform_run_workflow MCP tool invocation.
5
+ */
6
+ export async function handleRunWorkflow(params: {
7
+ id: string;
8
+ input?: string;
9
+ }): Promise<string> {
10
+ let parsedInput: Record<string, unknown> = {};
11
+ if (params.input) {
12
+ try {
13
+ parsedInput = JSON.parse(params.input) as Record<string, unknown>;
14
+ } catch {
15
+ return "Error: `input` must be a valid JSON object.";
16
+ }
17
+ }
18
+
19
+ const result = await apiRunWorkflow(params.id, parsedInput);
20
+
21
+ const lines: string[] = [];
22
+ lines.push(`Workflow "${params.id}" executed successfully.\n`);
23
+
24
+ if (typeof result === "object" && result !== null) {
25
+ const output = (result as Record<string, unknown>).output;
26
+ if (output !== undefined) {
27
+ lines.push("**Output:**");
28
+ lines.push(typeof output === "string" ? output : JSON.stringify(output, null, 2));
29
+ } else {
30
+ lines.push("**Result:**");
31
+ lines.push(JSON.stringify(result, null, 2));
32
+ }
33
+ }
34
+
35
+ return lines.join("\n");
36
+ }
@@ -0,0 +1,91 @@
1
+ import { searchTraces as apiSearchTraces } from "../langwatch-api.js";
2
+ import { parseRelativeDate } from "../utils/date-parsing.js";
3
+
4
+ /**
5
+ * Handles the search_traces MCP tool invocation.
6
+ *
7
+ * Searches LangWatch traces with optional filters, text query, and date range.
8
+ * In digest mode (default), returns AI-readable formatted digests per trace.
9
+ * In json mode, returns the full raw JSON.
10
+ */
11
+ export async function handleSearchTraces(params: {
12
+ query?: string;
13
+ filters?: Record<string, string[]>;
14
+ startDate?: string;
15
+ endDate?: string;
16
+ pageSize?: number;
17
+ scrollId?: string;
18
+ format?: "digest" | "json";
19
+ }): Promise<string> {
20
+ const now = Date.now();
21
+ const startDate = params.startDate
22
+ ? parseRelativeDate(params.startDate)
23
+ : now - 86400000;
24
+ const endDate = params.endDate ? parseRelativeDate(params.endDate) : now;
25
+ const format = params.format ?? "digest";
26
+
27
+ const result = await apiSearchTraces({
28
+ query: params.query,
29
+ filters: params.filters,
30
+ startDate,
31
+ endDate,
32
+ pageSize: params.pageSize ?? 25,
33
+ scrollId: params.scrollId,
34
+ format,
35
+ });
36
+
37
+ const traces = result.traces ?? [];
38
+ if (traces.length === 0) {
39
+ return "No traces found matching your query.";
40
+ }
41
+
42
+ if (format === "json") {
43
+ return JSON.stringify(result, null, 2);
44
+ }
45
+
46
+ const lines: string[] = [];
47
+ lines.push(
48
+ `Found ${result.pagination?.totalHits ?? traces.length} traces:\n`
49
+ );
50
+
51
+ for (const trace of traces) {
52
+ lines.push(`### Trace: ${trace.trace_id}`);
53
+
54
+ if (trace.formatted_trace) {
55
+ lines.push(trace.formatted_trace);
56
+ } else {
57
+ const inputStr = trace.input?.value
58
+ ? String(trace.input.value)
59
+ : "N/A";
60
+ const outputStr = trace.output?.value
61
+ ? String(trace.output.value)
62
+ : "N/A";
63
+ lines.push(
64
+ `- **Input**: ${inputStr.slice(0, 100)}${inputStr.length > 100 ? "..." : ""}`
65
+ );
66
+ lines.push(
67
+ `- **Output**: ${outputStr.slice(0, 100)}${outputStr.length > 100 ? "..." : ""}`
68
+ );
69
+ }
70
+
71
+ if (trace.timestamps) {
72
+ lines.push(`- **Time**: ${trace.timestamps.started_at || "N/A"}`);
73
+ }
74
+ if (trace.error) {
75
+ lines.push(`- **Error**: ${JSON.stringify(trace.error)}`);
76
+ }
77
+ lines.push("");
78
+ }
79
+
80
+ if (result.pagination?.scrollId) {
81
+ lines.push(
82
+ `\n**More results available.** Use scrollId: "${result.pagination.scrollId}" to get next page.`
83
+ );
84
+ }
85
+
86
+ lines.push(
87
+ '\n> Tip: Use `get_trace` with a trace_id for full details. Use `search_traces` with `format: "json"` for raw data. Use `discover_schema` to see available filter fields.'
88
+ );
89
+
90
+ return lines.join("\n");
91
+ }
@@ -0,0 +1,46 @@
1
+ import { setModelProvider as apiSetModelProvider } from "../langwatch-api-model-providers.js";
2
+
3
+ /**
4
+ * Handles the platform_set_model_provider MCP tool invocation.
5
+ *
6
+ * Creates or updates a model provider configuration, including API keys.
7
+ * Returns confirmation with the updated provider status.
8
+ */
9
+ export async function handleSetModelProvider(params: {
10
+ provider: string;
11
+ enabled: boolean;
12
+ customKeys?: Record<string, unknown>;
13
+ defaultModel?: string;
14
+ }): Promise<string> {
15
+ const providers = await apiSetModelProvider(params);
16
+
17
+ const updated = providers[params.provider];
18
+
19
+ if (!updated) {
20
+ throw new Error(
21
+ `Model provider "${params.provider}" was not found in the response. The provider name may be invalid.`
22
+ );
23
+ }
24
+
25
+ const lines: string[] = [];
26
+ lines.push("Model provider updated successfully!\n");
27
+ lines.push(`**Provider**: ${params.provider}`);
28
+ lines.push(`**Status**: ${updated?.enabled ? "enabled" : "disabled"}`);
29
+
30
+ if (updated?.customKeys) {
31
+ const keyFields = Object.entries(updated.customKeys)
32
+ .map(([k, v]) => `${k}: ${v ? "set" : "not set"}`)
33
+ .join(", ");
34
+ lines.push(`**Keys**: ${keyFields}`);
35
+ }
36
+
37
+ if (params.defaultModel) {
38
+ // Show the normalized model name (with provider prefix)
39
+ const normalizedModel = params.defaultModel.includes("/")
40
+ ? params.defaultModel
41
+ : `${params.provider}/${params.defaultModel}`;
42
+ lines.push(`**Default Model**: ${normalizedModel}`);
43
+ }
44
+
45
+ return lines.join("\n");
46
+ }
@@ -0,0 +1,13 @@
1
+ import { updateAgent as apiUpdateAgent } from "../langwatch-api-agents.js";
2
+
3
+ export async function handleUpdateAgent(params: {
4
+ id: string;
5
+ name?: string;
6
+ type?: string;
7
+ config?: Record<string, unknown>;
8
+ }): Promise<string> {
9
+ const { id, ...data } = params;
10
+ const agent = await apiUpdateAgent({ id, ...data });
11
+
12
+ return `Agent updated successfully!\n\n**Name**: ${agent.name}\n**ID**: ${agent.id}\n**Type**: ${agent.type}`;
13
+ }
@@ -0,0 +1,21 @@
1
+ import { updateDatasetRecord as apiUpdateDatasetRecord } from "../langwatch-api-datasets.js";
2
+
3
+ /**
4
+ * Handles the platform_update_dataset_record MCP tool invocation.
5
+ *
6
+ * Updates a single record in a dataset and returns confirmation.
7
+ */
8
+ export async function handleUpdateDatasetRecord(params: {
9
+ slugOrId: string;
10
+ recordId: string;
11
+ entry: Record<string, unknown>;
12
+ }): Promise<string> {
13
+ const result = await apiUpdateDatasetRecord(params);
14
+
15
+ const lines: string[] = [];
16
+ lines.push("Record updated successfully!\n");
17
+ lines.push(`**Record ID**: ${result.id}`);
18
+ lines.push(`**Entry**: ${JSON.stringify(result.entry)}`);
19
+
20
+ return lines.join("\n");
21
+ }
@@ -0,0 +1,23 @@
1
+ import { updateDataset as apiUpdateDataset } from "../langwatch-api-datasets.js";
2
+ import type { DatasetColumnType } from "../langwatch-api-datasets.js";
3
+ import { formatDatasetMutationDetails } from "./format-dataset-mutation.js";
4
+
5
+ /**
6
+ * Handles the platform_update_dataset MCP tool invocation.
7
+ *
8
+ * Updates an existing dataset and returns a confirmation
9
+ * with the updated details.
10
+ */
11
+ export async function handleUpdateDataset(params: {
12
+ slugOrId: string;
13
+ name?: string;
14
+ columnTypes?: DatasetColumnType[];
15
+ }): Promise<string> {
16
+ const result = await apiUpdateDataset(params);
17
+
18
+ const lines: string[] = [];
19
+ lines.push("Dataset updated successfully!\n");
20
+ lines.push(...formatDatasetMutationDetails(result));
21
+
22
+ return lines.join("\n");
23
+ }
@@ -0,0 +1,30 @@
1
+ import {
2
+ updateEvaluator as apiUpdateEvaluator,
3
+ getEvaluatorType,
4
+ } from "../langwatch-api-evaluators.js";
5
+
6
+ /**
7
+ * Handles the platform_update_evaluator MCP tool invocation.
8
+ *
9
+ * Updates an existing evaluator and returns a confirmation
10
+ * with the updated details.
11
+ */
12
+ export async function handleUpdateEvaluator(params: {
13
+ evaluatorId: string;
14
+ name?: string;
15
+ config?: Record<string, unknown>;
16
+ }): Promise<string> {
17
+ const { evaluatorId, ...data } = params;
18
+ const result = await apiUpdateEvaluator({ id: evaluatorId, ...data });
19
+
20
+ const evaluatorType = getEvaluatorType(result);
21
+
22
+ const lines: string[] = [];
23
+ lines.push("Evaluator updated successfully!\n");
24
+ lines.push(`**ID**: ${result.id}`);
25
+ if (result.slug) lines.push(`**Slug**: ${result.slug}`);
26
+ lines.push(`**Name**: ${result.name}`);
27
+ if (evaluatorType) lines.push(`**Evaluator Type**: ${evaluatorType}`);
28
+
29
+ return lines.join("\n");
30
+ }
@@ -0,0 +1,31 @@
1
+ import { updatePrompt as apiUpdatePrompt } from "../langwatch-api.js";
2
+
3
+ /**
4
+ * Handles the platform_update_prompt MCP tool invocation.
5
+ *
6
+ * Updates an existing prompt via the PUT endpoint.
7
+ * Every update with a commitMessage creates a new version automatically.
8
+ */
9
+ export async function handleUpdatePrompt(params: {
10
+ idOrHandle: string;
11
+ messages?: Array<{ role: string; content: string }>;
12
+ model?: string;
13
+ commitMessage: string;
14
+ tags?: string[];
15
+ }): Promise<string> {
16
+ const { idOrHandle, ...data } = params;
17
+
18
+ const result = await apiUpdatePrompt(idOrHandle, data);
19
+
20
+ const lines: string[] = [];
21
+ lines.push("Prompt updated successfully!\n");
22
+ if (result.id) lines.push(`**ID**: ${result.id}`);
23
+ if (result.handle) lines.push(`**Handle**: ${result.handle}`);
24
+ if (result.latestVersionNumber != null)
25
+ lines.push(`**Version**: v${result.latestVersionNumber}`);
26
+ lines.push(`**Commit**: ${params.commitMessage}`);
27
+ if (params.tags && params.tags.length > 0)
28
+ lines.push(`**Tags**: ${params.tags.join(", ")}`);
29
+
30
+ return lines.join("\n");
31
+ }
@@ -0,0 +1,32 @@
1
+ import { updateScenario as apiUpdateScenario } from "../langwatch-api-scenarios.js";
2
+
3
+ /**
4
+ * Handles the platform_update_scenario MCP tool invocation.
5
+ *
6
+ * Updates an existing scenario and returns a confirmation
7
+ * with the updated details.
8
+ */
9
+ export async function handleUpdateScenario(params: {
10
+ scenarioId: string;
11
+ name?: string;
12
+ situation?: string;
13
+ criteria?: string[];
14
+ labels?: string[];
15
+ }): Promise<string> {
16
+ const { scenarioId, ...data } = params;
17
+ const result = await apiUpdateScenario({ id: scenarioId, ...data });
18
+
19
+ const lines: string[] = [];
20
+ lines.push("Scenario updated successfully!\n");
21
+ lines.push(`**ID**: ${result.id}`);
22
+ lines.push(`**Name**: ${result.name}`);
23
+ if (result.situation) lines.push(`**Situation**: ${result.situation}`);
24
+ if (Array.isArray(result.criteria) && result.criteria.length > 0) {
25
+ lines.push(`**Criteria**: ${result.criteria.length} criteria`);
26
+ }
27
+ if (Array.isArray(result.labels) && result.labels.length > 0) {
28
+ lines.push(`**Labels**: ${result.labels.join(", ")}`);
29
+ }
30
+
31
+ return lines.join("\n");
32
+ }
@@ -0,0 +1,44 @@
1
+ import { updateSuite as apiUpdateSuite } from "../langwatch-api-suites.js";
2
+ import type { SuiteTarget } from "../langwatch-api-suites.js";
3
+
4
+ /**
5
+ * Handles the platform_update_suite MCP tool invocation.
6
+ */
7
+ export async function handleUpdateSuite(params: {
8
+ id: string;
9
+ name?: string;
10
+ description?: string;
11
+ scenarioIds?: string[];
12
+ targets?: string;
13
+ repeatCount?: number;
14
+ labels?: string[];
15
+ }): Promise<string> {
16
+ let parsedTargets: SuiteTarget[] | undefined;
17
+ if (params.targets) {
18
+ try {
19
+ parsedTargets = JSON.parse(params.targets) as SuiteTarget[];
20
+ } catch {
21
+ return "Error: `targets` must be a valid JSON array.";
22
+ }
23
+ }
24
+
25
+ const suite = await apiUpdateSuite({
26
+ id: params.id,
27
+ name: params.name,
28
+ description: params.description,
29
+ scenarioIds: params.scenarioIds,
30
+ targets: parsedTargets,
31
+ repeatCount: params.repeatCount,
32
+ labels: params.labels,
33
+ });
34
+
35
+ return [
36
+ `Suite "${suite.name}" updated successfully.`,
37
+ "",
38
+ `**ID**: ${suite.id}`,
39
+ `**Slug**: ${suite.slug}`,
40
+ `**Scenarios**: ${suite.scenarioIds.length}`,
41
+ `**Targets**: ${suite.targets.length}`,
42
+ `**Repeat**: ${suite.repeatCount}x`,
43
+ ].join("\n");
44
+ }
@@ -0,0 +1,31 @@
1
+ const RELATIVE_UNITS: Record<string, number> = {
2
+ h: 3600000,
3
+ d: 86400000,
4
+ w: 604800000,
5
+ m: 2592000000,
6
+ };
7
+
8
+ /**
9
+ * Parses a date string that can be either a relative duration (e.g. "24h", "7d")
10
+ * or an ISO date string. Throws on invalid input rather than silently falling back.
11
+ *
12
+ * @returns epoch milliseconds
13
+ * @throws Error if the input is not a valid relative duration or parseable date string
14
+ */
15
+ export function parseRelativeDate(input: string): number {
16
+ if (input === "now") return Date.now();
17
+
18
+ const match = input.match(/^(\d+)(h|d|w|m)$/);
19
+ if (match) {
20
+ const [, amount, unit] = match;
21
+ return Date.now() - parseInt(amount!) * (RELATIVE_UNITS[unit!] ?? 86400000);
22
+ }
23
+
24
+ const parsed = Date.parse(input);
25
+ if (Number.isNaN(parsed)) {
26
+ throw new Error(
27
+ `Invalid date: "${input}". Use a relative duration (e.g. "24h", "7d", "4w") or an ISO date string.`
28
+ );
29
+ }
30
+ return parsed;
31
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Escapes characters that would break markdown table formatting.
3
+ *
4
+ * Replaces pipe characters (`|`) with `\|` and newlines with spaces
5
+ * so that values can be safely embedded in markdown tables and headers.
6
+ */
7
+ export function escapeMarkdown(value: string): string {
8
+ return value
9
+ .replace(/\\/g, "\\\\")
10
+ .replace(/\|/g, "\\|")
11
+ .replace(/\n/g, " ");
12
+ }