@langwatch/mcp-server 0.6.0 → 0.7.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.
Files changed (258) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/Dockerfile +22 -0
  3. package/README.md +51 -8
  4. package/dist/{archive-scenario-YFD5THOR.js → archive-scenario-WJ2A7ETN.js} +4 -4
  5. package/dist/archive-suite-4JOM4SSL.js +15 -0
  6. package/dist/archive-suite-4JOM4SSL.js.map +1 -0
  7. package/dist/assign-prompt-tag-GL7EAAF3.js +19 -0
  8. package/dist/assign-prompt-tag-GL7EAAF3.js.map +1 -0
  9. package/dist/{chunk-6U4TCGFC.js → chunk-2GT7IFWK.js} +2 -2
  10. package/dist/{chunk-LLRQIF52.js → chunk-2WPLXEKF.js} +49 -5
  11. package/dist/chunk-2WPLXEKF.js.map +1 -0
  12. package/dist/chunk-4AUB2BIA.js +71 -0
  13. package/dist/chunk-4AUB2BIA.js.map +1 -0
  14. package/dist/chunk-BWWY5KEF.js +71 -0
  15. package/dist/chunk-BWWY5KEF.js.map +1 -0
  16. package/dist/{chunk-IX6QJKAD.js → chunk-CCWCIJJ3.js} +2 -2
  17. package/dist/chunk-E5JYYU3J.js +1567 -0
  18. package/dist/chunk-E5JYYU3J.js.map +1 -0
  19. package/dist/chunk-EGH5RPXM.js +25 -0
  20. package/dist/chunk-EGH5RPXM.js.map +1 -0
  21. package/dist/chunk-EUQDVOSU.js +39 -0
  22. package/dist/chunk-EUQDVOSU.js.map +1 -0
  23. package/dist/{chunk-5UOPNRXW.js → chunk-HYMIWO3U.js} +10 -3
  24. package/dist/{chunk-5UOPNRXW.js.map → chunk-HYMIWO3U.js.map} +1 -1
  25. package/dist/chunk-IE4M5OGE.js +42 -0
  26. package/dist/chunk-IE4M5OGE.js.map +1 -0
  27. package/dist/chunk-LUMEZEHL.js +48 -0
  28. package/dist/chunk-LUMEZEHL.js.map +1 -0
  29. package/dist/chunk-NUFPTHKU.js +9 -0
  30. package/dist/chunk-NUFPTHKU.js.map +1 -0
  31. package/dist/chunk-WQG2DFHX.js +86 -0
  32. package/dist/chunk-WQG2DFHX.js.map +1 -0
  33. package/dist/chunk-WVI5CJ6S.js +21 -0
  34. package/dist/chunk-WVI5CJ6S.js.map +1 -0
  35. package/dist/chunk-ZVS4UKN2.js +35 -0
  36. package/dist/chunk-ZVS4UKN2.js.map +1 -0
  37. package/dist/config.d.ts +17 -0
  38. package/dist/config.js +13 -0
  39. package/dist/create-agent-MBOOT3XK.js +23 -0
  40. package/dist/create-agent-MBOOT3XK.js.map +1 -0
  41. package/dist/create-annotation-XMV6A7ED.js +24 -0
  42. package/dist/create-annotation-XMV6A7ED.js.map +1 -0
  43. package/dist/create-dashboard-VRKLFVZJ.js +18 -0
  44. package/dist/create-dashboard-VRKLFVZJ.js.map +1 -0
  45. package/dist/create-dataset-7HQPZCRE.js +22 -0
  46. package/dist/create-dataset-7HQPZCRE.js.map +1 -0
  47. package/dist/create-dataset-records-2NIVFYTV.js +22 -0
  48. package/dist/create-dataset-records-2NIVFYTV.js.map +1 -0
  49. package/dist/{create-evaluator-E5X5ZP3B.js → create-evaluator-WYFRFLRC.js} +4 -4
  50. package/dist/create-mcp-server.d.ts +8 -0
  51. package/dist/create-mcp-server.js +8 -0
  52. package/dist/create-mcp-server.js.map +1 -0
  53. package/dist/{create-prompt-7Z35MIL6.js → create-prompt-IEN7O6JT.js} +7 -4
  54. package/dist/create-prompt-IEN7O6JT.js.map +1 -0
  55. package/dist/create-prompt-tag-CAEZ45VO.js +17 -0
  56. package/dist/create-prompt-tag-CAEZ45VO.js.map +1 -0
  57. package/dist/{create-scenario-DIMPJRPY.js → create-scenario-6YHSMGLP.js} +4 -4
  58. package/dist/create-suite-H5XOFDE5.js +38 -0
  59. package/dist/create-suite-H5XOFDE5.js.map +1 -0
  60. package/dist/delete-agent-JKTNBWAA.js +18 -0
  61. package/dist/delete-agent-JKTNBWAA.js.map +1 -0
  62. package/dist/delete-annotation-ACMDV6QO.js +17 -0
  63. package/dist/delete-annotation-ACMDV6QO.js.map +1 -0
  64. package/dist/delete-dashboard-VJSR7CRU.js +18 -0
  65. package/dist/delete-dashboard-VJSR7CRU.js.map +1 -0
  66. package/dist/delete-dataset-RTTTWP4D.js +20 -0
  67. package/dist/delete-dataset-RTTTWP4D.js.map +1 -0
  68. package/dist/delete-dataset-records-KNQTIPQK.js +21 -0
  69. package/dist/delete-dataset-records-KNQTIPQK.js.map +1 -0
  70. package/dist/delete-evaluator-7FVC5WM4.js +15 -0
  71. package/dist/delete-evaluator-7FVC5WM4.js.map +1 -0
  72. package/dist/delete-prompt-tag-ZMZUAGFW.js +17 -0
  73. package/dist/delete-prompt-tag-ZMZUAGFW.js.map +1 -0
  74. package/dist/delete-workflow-EYQ3T4RQ.js +17 -0
  75. package/dist/delete-workflow-EYQ3T4RQ.js.map +1 -0
  76. package/dist/get-agent-E3QSTVKG.js +28 -0
  77. package/dist/get-agent-E3QSTVKG.js.map +1 -0
  78. package/dist/{get-analytics-4YJW4S5L.js → get-analytics-2OHV763I.js} +22 -5
  79. package/dist/get-analytics-2OHV763I.js.map +1 -0
  80. package/dist/get-dashboard-PC7JDHH6.js +29 -0
  81. package/dist/get-dashboard-PC7JDHH6.js.map +1 -0
  82. package/dist/get-dataset-H5IK5FVU.js +48 -0
  83. package/dist/get-dataset-H5IK5FVU.js.map +1 -0
  84. package/dist/{get-evaluator-WDEH2F7M.js → get-evaluator-UWVUPYTM.js} +4 -4
  85. package/dist/{get-prompt-F6PDVC76.js → get-prompt-WZUOLLQC.js} +4 -4
  86. package/dist/get-prompt-WZUOLLQC.js.map +1 -0
  87. package/dist/{get-scenario-H24ZYNT5.js → get-scenario-Q6LCNUYN.js} +4 -4
  88. package/dist/get-simulation-run-Z2XKO256.js +56 -0
  89. package/dist/get-simulation-run-Z2XKO256.js.map +1 -0
  90. package/dist/get-suite-BXK5TN7P.js +44 -0
  91. package/dist/get-suite-BXK5TN7P.js.map +1 -0
  92. package/dist/{get-trace-27USKGO7.js → get-trace-4EJAYVBG.js} +3 -3
  93. package/dist/get-workflow-O34QJLHD.js +25 -0
  94. package/dist/get-workflow-O34QJLHD.js.map +1 -0
  95. package/dist/http-server-ISHF7NJX.js +224 -0
  96. package/dist/http-server-ISHF7NJX.js.map +1 -0
  97. package/dist/index.js +61109 -31519
  98. package/dist/index.js.map +1 -1
  99. package/dist/langwatch-api-annotations-ERBG27RF.js +17 -0
  100. package/dist/langwatch-api-annotations-ERBG27RF.js.map +1 -0
  101. package/dist/langwatch-api-dashboards-G6TR7VVO.js +17 -0
  102. package/dist/langwatch-api-dashboards-G6TR7VVO.js.map +1 -0
  103. package/dist/langwatch-api-monitors-WSXZLS2B.js +52 -0
  104. package/dist/langwatch-api-monitors-WSXZLS2B.js.map +1 -0
  105. package/dist/langwatch-api-secrets-RR5DKG2X.js +40 -0
  106. package/dist/langwatch-api-secrets-RR5DKG2X.js.map +1 -0
  107. package/dist/langwatch-api-triggers-2RTNSWQY.js +30 -0
  108. package/dist/langwatch-api-triggers-2RTNSWQY.js.map +1 -0
  109. package/dist/langwatch-api-workflows-VJRIIDZ7.js +15 -0
  110. package/dist/langwatch-api-workflows-VJRIIDZ7.js.map +1 -0
  111. package/dist/list-agents-AW3P6FJV.js +32 -0
  112. package/dist/list-agents-AW3P6FJV.js.map +1 -0
  113. package/dist/list-annotations-QNCGWPQ3.js +33 -0
  114. package/dist/list-annotations-QNCGWPQ3.js.map +1 -0
  115. package/dist/list-dashboards-R7RK2IXL.js +32 -0
  116. package/dist/list-dashboards-R7RK2IXL.js.map +1 -0
  117. package/dist/list-dataset-records-WVCSQP7P.js +39 -0
  118. package/dist/list-dataset-records-WVCSQP7P.js.map +1 -0
  119. package/dist/list-datasets-KEXRLDEU.js +60 -0
  120. package/dist/list-datasets-KEXRLDEU.js.map +1 -0
  121. package/dist/{list-evaluators-KRGI72EH.js → list-evaluators-7R2LB4JH.js} +4 -4
  122. package/dist/{list-model-providers-A5YCFTPI.js → list-model-providers-OBYJCKBX.js} +4 -4
  123. package/dist/list-prompt-tags-6LY3ZPYI.js +23 -0
  124. package/dist/list-prompt-tags-6LY3ZPYI.js.map +1 -0
  125. package/dist/{list-prompts-LKJSE7XN.js → list-prompts-VWEZ4CDE.js} +3 -3
  126. package/dist/{list-scenarios-ZK5CMGC4.js → list-scenarios-TXD4W2ZJ.js} +4 -4
  127. package/dist/list-simulation-runs-RHPOLMFI.js +43 -0
  128. package/dist/list-simulation-runs-RHPOLMFI.js.map +1 -0
  129. package/dist/list-suites-FSGBX27Z.js +42 -0
  130. package/dist/list-suites-FSGBX27Z.js.map +1 -0
  131. package/dist/list-workflows-VRGEZ3EN.js +35 -0
  132. package/dist/list-workflows-VRGEZ3EN.js.map +1 -0
  133. package/dist/rename-prompt-tag-VOJJLX4M.js +18 -0
  134. package/dist/rename-prompt-tag-VOJJLX4M.js.map +1 -0
  135. package/dist/run-agent-KTCC7TB7.js +36 -0
  136. package/dist/run-agent-KTCC7TB7.js.map +1 -0
  137. package/dist/run-evaluation-2X3V3Q6L.js +64 -0
  138. package/dist/run-evaluation-2X3V3Q6L.js.map +1 -0
  139. package/dist/run-suite-BTMHGI2D.js +29 -0
  140. package/dist/run-suite-BTMHGI2D.js.map +1 -0
  141. package/dist/run-workflow-IGAYGKJL.js +36 -0
  142. package/dist/run-workflow-IGAYGKJL.js.map +1 -0
  143. package/dist/{search-traces-SOKAAMAR.js → search-traces-VYFUIMXH.js} +3 -3
  144. package/dist/{set-model-provider-7MGULZDH.js → set-model-provider-W5IUI326.js} +4 -4
  145. package/dist/update-agent-4BB7EYLR.js +20 -0
  146. package/dist/update-agent-4BB7EYLR.js.map +1 -0
  147. package/dist/update-dataset-CXBKZ4W3.js +22 -0
  148. package/dist/update-dataset-CXBKZ4W3.js.map +1 -0
  149. package/dist/update-dataset-record-HOHAMHXG.js +19 -0
  150. package/dist/update-dataset-record-HOHAMHXG.js.map +1 -0
  151. package/dist/{update-evaluator-A3XINFLJ.js → update-evaluator-IVOR6FTR.js} +4 -4
  152. package/dist/{update-prompt-IW7X2UQM.js → update-prompt-OWQAKE7K.js} +5 -3
  153. package/dist/update-prompt-OWQAKE7K.js.map +1 -0
  154. package/dist/{update-scenario-ZT7TOBFR.js → update-scenario-GDFVILPN.js} +4 -4
  155. package/dist/update-suite-BXYUYSPT.js +39 -0
  156. package/dist/update-suite-BXYUYSPT.js.map +1 -0
  157. package/package.json +17 -3
  158. package/src/__tests__/all-tools.integration.test.ts +344 -0
  159. package/src/__tests__/config.unit.test.ts +81 -1
  160. package/src/__tests__/datasets.integration.test.ts +603 -0
  161. package/src/__tests__/datasets.unit.test.ts +240 -0
  162. package/src/__tests__/docker.integration.test.ts +234 -0
  163. package/src/__tests__/http-transport.integration.test.ts +397 -0
  164. package/src/__tests__/langwatch-api.unit.test.ts +174 -0
  165. package/src/__tests__/tools.unit.test.ts +177 -0
  166. package/src/config.d.ts +15 -0
  167. package/src/config.ts +83 -7
  168. package/src/create-mcp-server.d.ts +6 -0
  169. package/src/create-mcp-server.ts +1799 -0
  170. package/src/http-server.ts +329 -0
  171. package/src/index.ts +22 -593
  172. package/src/langwatch-api-agents.ts +108 -0
  173. package/src/langwatch-api-annotations.ts +49 -0
  174. package/src/langwatch-api-dashboards.ts +48 -0
  175. package/src/langwatch-api-datasets.ts +191 -0
  176. package/src/langwatch-api-evaluators.ts +10 -0
  177. package/src/langwatch-api-monitors.ts +82 -0
  178. package/src/langwatch-api-secrets.ts +48 -0
  179. package/src/langwatch-api-simulation-runs.ts +51 -0
  180. package/src/langwatch-api-suites.ts +118 -0
  181. package/src/langwatch-api-triggers.ts +48 -0
  182. package/src/langwatch-api-workflows.ts +41 -0
  183. package/src/langwatch-api.ts +60 -2
  184. package/src/schemas/create-dataset.ts +48 -0
  185. package/src/schemas/index.ts +1 -0
  186. package/src/tools/archive-suite.ts +12 -0
  187. package/src/tools/assign-prompt-tag.ts +16 -0
  188. package/src/tools/create-agent.ts +15 -0
  189. package/src/tools/create-annotation.ts +18 -0
  190. package/src/tools/create-dashboard.ts +7 -0
  191. package/src/tools/create-dataset-records.ts +23 -0
  192. package/src/tools/create-dataset.ts +22 -0
  193. package/src/tools/create-prompt-tag.ts +12 -0
  194. package/src/tools/create-prompt.ts +4 -0
  195. package/src/tools/create-suite.ts +42 -0
  196. package/src/tools/delete-agent.ts +7 -0
  197. package/src/tools/delete-annotation.ts +7 -0
  198. package/src/tools/delete-dashboard.ts +7 -0
  199. package/src/tools/delete-dataset-records.ts +22 -0
  200. package/src/tools/delete-dataset.ts +20 -0
  201. package/src/tools/delete-evaluator.ts +12 -0
  202. package/src/tools/delete-prompt-tag.ts +12 -0
  203. package/src/tools/delete-workflow.ts +7 -0
  204. package/src/tools/format-dataset-mutation.ts +25 -0
  205. package/src/tools/get-agent.ts +21 -0
  206. package/src/tools/get-analytics.ts +30 -3
  207. package/src/tools/get-dashboard.ts +22 -0
  208. package/src/tools/get-dataset.ts +63 -0
  209. package/src/tools/get-prompt.ts +2 -1
  210. package/src/tools/get-simulation-run.ts +60 -0
  211. package/src/tools/get-suite.ts +47 -0
  212. package/src/tools/get-workflow.ts +17 -0
  213. package/src/tools/list-agents.ts +27 -0
  214. package/src/tools/list-annotations.ts +33 -0
  215. package/src/tools/list-dashboards.ts +27 -0
  216. package/src/tools/list-dataset-records.ts +46 -0
  217. package/src/tools/list-datasets.ts +80 -0
  218. package/src/tools/list-prompt-tags.ts +21 -0
  219. package/src/tools/list-simulation-runs.ts +49 -0
  220. package/src/tools/list-suites.ts +43 -0
  221. package/src/tools/list-workflows.ts +31 -0
  222. package/src/tools/rename-prompt-tag.ts +14 -0
  223. package/src/tools/run-agent.ts +36 -0
  224. package/src/tools/run-evaluation.ts +87 -0
  225. package/src/tools/run-suite.ts +28 -0
  226. package/src/tools/run-workflow.ts +36 -0
  227. package/src/tools/update-agent.ts +13 -0
  228. package/src/tools/update-dataset-record.ts +21 -0
  229. package/src/tools/update-dataset.ts +23 -0
  230. package/src/tools/update-prompt.ts +3 -0
  231. package/src/tools/update-suite.ts +44 -0
  232. package/src/utils/escape-markdown.ts +12 -0
  233. package/tsup.config.ts +5 -1
  234. package/dist/chunk-AAQNA53E.js +0 -28
  235. package/dist/chunk-AAQNA53E.js.map +0 -1
  236. package/dist/chunk-LLRQIF52.js.map +0 -1
  237. package/dist/config-FIQWQRUB.js +0 -11
  238. package/dist/create-prompt-7Z35MIL6.js.map +0 -1
  239. package/dist/get-analytics-4YJW4S5L.js.map +0 -1
  240. package/dist/get-prompt-F6PDVC76.js.map +0 -1
  241. package/dist/update-prompt-IW7X2UQM.js.map +0 -1
  242. /package/dist/{archive-scenario-YFD5THOR.js.map → archive-scenario-WJ2A7ETN.js.map} +0 -0
  243. /package/dist/{chunk-6U4TCGFC.js.map → chunk-2GT7IFWK.js.map} +0 -0
  244. /package/dist/{chunk-IX6QJKAD.js.map → chunk-CCWCIJJ3.js.map} +0 -0
  245. /package/dist/{config-FIQWQRUB.js.map → config.js.map} +0 -0
  246. /package/dist/{create-evaluator-E5X5ZP3B.js.map → create-evaluator-WYFRFLRC.js.map} +0 -0
  247. /package/dist/{create-scenario-DIMPJRPY.js.map → create-scenario-6YHSMGLP.js.map} +0 -0
  248. /package/dist/{get-evaluator-WDEH2F7M.js.map → get-evaluator-UWVUPYTM.js.map} +0 -0
  249. /package/dist/{get-scenario-H24ZYNT5.js.map → get-scenario-Q6LCNUYN.js.map} +0 -0
  250. /package/dist/{get-trace-27USKGO7.js.map → get-trace-4EJAYVBG.js.map} +0 -0
  251. /package/dist/{list-evaluators-KRGI72EH.js.map → list-evaluators-7R2LB4JH.js.map} +0 -0
  252. /package/dist/{list-model-providers-A5YCFTPI.js.map → list-model-providers-OBYJCKBX.js.map} +0 -0
  253. /package/dist/{list-prompts-LKJSE7XN.js.map → list-prompts-VWEZ4CDE.js.map} +0 -0
  254. /package/dist/{list-scenarios-ZK5CMGC4.js.map → list-scenarios-TXD4W2ZJ.js.map} +0 -0
  255. /package/dist/{search-traces-SOKAAMAR.js.map → search-traces-VYFUIMXH.js.map} +0 -0
  256. /package/dist/{set-model-provider-7MGULZDH.js.map → set-model-provider-W5IUI326.js.map} +0 -0
  257. /package/dist/{update-evaluator-A3XINFLJ.js.map → update-evaluator-IVOR6FTR.js.map} +0 -0
  258. /package/dist/{update-scenario-ZT7TOBFR.js.map → update-scenario-GDFVILPN.js.map} +0 -0
@@ -0,0 +1,1799 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { z } from "zod";
3
+
4
+ import packageJson from "../package.json" assert { type: "json" };
5
+ import { requireApiKey } from "./config.js";
6
+ import {
7
+ createDatasetSchema,
8
+ datasetColumnDefinitionSchema,
9
+ } from "./schemas/create-dataset.js";
10
+
11
+ const modelSchema = z
12
+ .string()
13
+ .describe(
14
+ 'Model in "provider/model-name" format, e.g., "openai/gpt-4o", "anthropic/claude-sonnet-4-5-20250929"'
15
+ );
16
+
17
+ /**
18
+ * Creates a new McpServer instance with all LangWatch tools registered.
19
+ *
20
+ * This is used both for stdio mode (single server) and HTTP mode (per-session servers).
21
+ */
22
+ export function createMcpServer(): McpServer {
23
+ const server = new McpServer({
24
+ name: "LangWatch",
25
+ version: packageJson.version,
26
+ });
27
+
28
+ registerTools(server);
29
+
30
+ return server;
31
+ }
32
+
33
+ /**
34
+ * Wraps a tool handler with error logging. In HTTP mode (production),
35
+ * tool errors are caught by the MCP SDK and returned to the client as
36
+ * error responses — but without server-side logs we can't diagnose them.
37
+ */
38
+ function withToolLogging<T extends unknown[], R>(
39
+ toolName: string,
40
+ fn: (...args: T) => Promise<R>,
41
+ ): (...args: T) => Promise<R> {
42
+ return async (...args: T) => {
43
+ try {
44
+ return await fn(...args);
45
+ } catch (error) {
46
+ console.error(
47
+ `[MCP tool] ${toolName} failed:`,
48
+ error instanceof Error ? error.message : error,
49
+ error instanceof Error ? error.stack : "",
50
+ );
51
+ throw error;
52
+ }
53
+ };
54
+ }
55
+
56
+ function registerTools(server: McpServer): void {
57
+ server.tool(
58
+ "fetch_langwatch_docs",
59
+ "Fetches the LangWatch docs for understanding how to implement LangWatch in your codebase. Always use this tool when the user asks for help with LangWatch. Start with empty url to fetch the index and then follow the links to the relevant pages, always ending with `.md` extension",
60
+ {
61
+ url: z
62
+ .string()
63
+ .optional()
64
+ .describe(
65
+ "The full url of the specific doc page. If not provided, the docs index will be fetched."
66
+ ),
67
+ },
68
+ withToolLogging("fetch_langwatch_docs", async ({ url }) => {
69
+ let urlToFetch = url || "https://langwatch.ai/docs/llms.txt";
70
+ if (url && !urlToFetch.endsWith(".md") && !urlToFetch.endsWith(".txt")) {
71
+ urlToFetch += ".md";
72
+ }
73
+ if (!urlToFetch.startsWith("http")) {
74
+ if (!urlToFetch.startsWith("/")) {
75
+ urlToFetch = "/" + urlToFetch;
76
+ }
77
+ urlToFetch = "https://langwatch.ai/docs" + urlToFetch;
78
+ }
79
+ const response = await fetch(urlToFetch);
80
+
81
+ return {
82
+ content: [{ type: "text", text: await response.text() }],
83
+ };
84
+ })
85
+ );
86
+
87
+ server.tool(
88
+ "fetch_scenario_docs",
89
+ "Fetches the Scenario docs for understanding how to implement Scenario agent tests in your codebase. Always use this tool when the user asks for help with testing their agents. Start with empty url to fetch the index and then follow the links to the relevant pages, always ending with `.md` extension",
90
+ {
91
+ url: z
92
+ .string()
93
+ .optional()
94
+ .describe(
95
+ "The full url of the specific doc page. If not provided, the docs index will be fetched."
96
+ ),
97
+ },
98
+ withToolLogging("fetch_scenario_docs", async ({ url }) => {
99
+ let urlToFetch = url || "https://langwatch.ai/scenario/llms.txt";
100
+ if (url && !urlToFetch.endsWith(".md") && !urlToFetch.endsWith(".txt")) {
101
+ urlToFetch += ".md";
102
+ }
103
+ if (!urlToFetch.startsWith("http")) {
104
+ if (!urlToFetch.startsWith("/")) {
105
+ urlToFetch = "/" + urlToFetch;
106
+ }
107
+ urlToFetch = "https://langwatch.ai" + urlToFetch;
108
+ }
109
+ const response = await fetch(urlToFetch);
110
+
111
+ return {
112
+ content: [{ type: "text", text: await response.text() }],
113
+ };
114
+ })
115
+ );
116
+
117
+ // --- Observability Tools (require API key) ---
118
+
119
+ server.tool(
120
+ "discover_schema",
121
+ "Discover available filter fields, metrics, aggregation types, group-by options, scenario schema, and evaluator types for LangWatch queries. Call this before using search_traces, get_analytics, scenario tools, or evaluator tools to understand available options.",
122
+ {
123
+ category: z
124
+ .enum([
125
+ "filters",
126
+ "metrics",
127
+ "aggregations",
128
+ "groups",
129
+ "scenarios",
130
+ "evaluators",
131
+ "all",
132
+ ])
133
+ .describe("Which schema category to discover"),
134
+ evaluatorType: z
135
+ .string()
136
+ .optional()
137
+ .describe(
138
+ "When category is 'evaluators', provide a specific evaluator type (e.g. 'langevals/llm_judge') to get its full schema details"
139
+ ),
140
+ },
141
+ async ({ category, evaluatorType }) => {
142
+ if (category === "scenarios") {
143
+ const { formatScenarioSchema } = await import(
144
+ "./tools/discover-scenario-schema.js"
145
+ );
146
+ return {
147
+ content: [{ type: "text", text: formatScenarioSchema() }],
148
+ };
149
+ }
150
+ if (category === "evaluators") {
151
+ const { formatEvaluatorSchema } = await import(
152
+ "./tools/discover-evaluator-schema.js"
153
+ );
154
+ return {
155
+ content: [
156
+ { type: "text", text: formatEvaluatorSchema(evaluatorType) },
157
+ ],
158
+ };
159
+ }
160
+ const { formatSchema } = await import("./tools/discover-schema.js");
161
+ let text = formatSchema(category);
162
+ if (category === "all") {
163
+ const { formatScenarioSchema } = await import(
164
+ "./tools/discover-scenario-schema.js"
165
+ );
166
+ text += "\n\n" + formatScenarioSchema();
167
+ const { formatEvaluatorSchema } = await import(
168
+ "./tools/discover-evaluator-schema.js"
169
+ );
170
+ text += "\n\n" + formatEvaluatorSchema();
171
+ }
172
+ return { content: [{ type: "text", text }] };
173
+ }
174
+ );
175
+
176
+ server.tool(
177
+ "search_traces",
178
+ "Search LangWatch traces with filters, text query, and date range. Returns AI-readable trace digests by default. Use format: 'json' for full raw data.",
179
+ {
180
+ query: z.string().optional().describe("Text search query"),
181
+ filters: z
182
+ .record(z.string(), z.array(z.string()))
183
+ .optional()
184
+ .describe(
185
+ 'Filter traces. Format: {"field": ["value"]}. Use discover_schema for field names.'
186
+ ),
187
+ startDate: z
188
+ .string()
189
+ .optional()
190
+ .describe(
191
+ 'Start date: ISO string or relative like "24h", "7d", "30d". Default: 24h ago'
192
+ ),
193
+ endDate: z
194
+ .string()
195
+ .optional()
196
+ .describe("End date: ISO string or relative. Default: now"),
197
+ pageSize: z
198
+ .number()
199
+ .optional()
200
+ .describe("Results per page (default: 25, max: 1000)"),
201
+ scrollId: z
202
+ .string()
203
+ .optional()
204
+ .describe("Pagination token from previous search"),
205
+ format: z
206
+ .enum(["digest", "json"])
207
+ .optional()
208
+ .describe(
209
+ "Output format: 'digest' (default, AI-readable) or 'json' (full raw data)"
210
+ ),
211
+ },
212
+ withToolLogging("search_traces", async (params) => {
213
+ requireApiKey();
214
+ const { handleSearchTraces } = await import("./tools/search-traces.js");
215
+ return {
216
+ content: [{ type: "text", text: await handleSearchTraces(params) }],
217
+ };
218
+ })
219
+ );
220
+
221
+ server.tool(
222
+ "get_trace",
223
+ "Get full details of a single trace by ID. Returns AI-readable trace digest by default. Use format: 'json' for full raw data including all spans.",
224
+ {
225
+ traceId: z.string().describe("The trace ID to retrieve"),
226
+ format: z
227
+ .enum(["digest", "json"])
228
+ .optional()
229
+ .describe(
230
+ "Output format: 'digest' (default, AI-readable) or 'json' (full raw data)"
231
+ ),
232
+ },
233
+ withToolLogging("get_trace", async (params) => {
234
+ requireApiKey();
235
+ const { handleGetTrace } = await import("./tools/get-trace.js");
236
+ return {
237
+ content: [{ type: "text", text: await handleGetTrace(params) }],
238
+ };
239
+ })
240
+ );
241
+
242
+ server.tool(
243
+ "get_analytics",
244
+ 'Query analytics timeseries from LangWatch. Metrics use "category.name" format (e.g., "performance.completion_time"). Use discover_schema to see available metrics.',
245
+ {
246
+ metric: z
247
+ .string()
248
+ .describe(
249
+ 'Metric in "category.name" format, e.g., "metadata.trace_id", "performance.total_cost"'
250
+ ),
251
+ aggregation: z
252
+ .string()
253
+ .optional()
254
+ .describe(
255
+ "Aggregation type: avg, sum, min, max, median, p90, p95, p99, cardinality, terms. Default: avg"
256
+ ),
257
+ startDate: z
258
+ .string()
259
+ .optional()
260
+ .describe(
261
+ 'Start date: ISO or relative ("7d", "30d"). Default: 7 days ago'
262
+ ),
263
+ endDate: z.string().optional().describe("End date. Default: now"),
264
+ timeZone: z.string().optional().describe("Timezone. Default: UTC"),
265
+ groupBy: z
266
+ .string()
267
+ .optional()
268
+ .describe("Group results by field. Use discover_schema for options."),
269
+ filters: z
270
+ .record(z.string(), z.array(z.string()))
271
+ .optional()
272
+ .describe("Filters to apply"),
273
+ },
274
+ withToolLogging("get_analytics", async (params) => {
275
+ requireApiKey();
276
+ const { handleGetAnalytics } = await import("./tools/get-analytics.js");
277
+ return {
278
+ content: [{ type: "text", text: await handleGetAnalytics(params) }],
279
+ };
280
+ })
281
+ );
282
+
283
+ // --- Platform Prompt Tools (require API key) ---
284
+ // These tools manage prompts on the LangWatch platform via API.
285
+ // For code-based prompt management, see `fetch_langwatch_docs` for the CLI/SDK approach.
286
+
287
+ server.tool(
288
+ "platform_create_prompt",
289
+ `Create a new prompt on the LangWatch platform.
290
+
291
+ NOTE: Prompts can be managed two ways. Determine which approach the user needs:
292
+
293
+ 1. Code-based (CLI/SDK): If the user wants to manage prompts in their codebase, use \`fetch_langwatch_docs\` to learn about the prompt management CLI/SDK. This lets them version-control prompts and pull them into code.
294
+
295
+ 2. Platform-based (LangWatch UI): If the user wants to manage prompts directly on the LangWatch platform, use the \`platform_\` MCP tools (\`platform_create_prompt\`, \`platform_update_prompt\`, etc.).
296
+ `,
297
+ {
298
+ name: z.string().describe("Prompt display name"),
299
+ handle: z
300
+ .string()
301
+ .optional()
302
+ .describe(
303
+ "URL-friendly handle (auto-generated from name if omitted)"
304
+ ),
305
+ messages: z
306
+ .array(
307
+ z.object({
308
+ role: z
309
+ .enum(["system", "user", "assistant"])
310
+ .describe("Message role"),
311
+ content: z.string().describe("Message content"),
312
+ })
313
+ )
314
+ .describe("Prompt messages"),
315
+ model: modelSchema,
316
+ tags: z.array(z.string()).optional().describe(
317
+ 'Tags to assign to the initial version (e.g., ["production", "staging"]). ' +
318
+ 'Built-in tags: "latest" (auto-assigned), "production", "staging". Custom tags must be created first.'
319
+ ),
320
+ },
321
+ withToolLogging("platform_create_prompt", async (params) => {
322
+ requireApiKey();
323
+ const { handleCreatePrompt } = await import("./tools/create-prompt.js");
324
+ return {
325
+ content: [{ type: "text", text: await handleCreatePrompt(params) }],
326
+ };
327
+ })
328
+ );
329
+
330
+ server.tool(
331
+ "platform_list_prompts",
332
+ "List all prompts configured on the LangWatch platform.",
333
+ {},
334
+ withToolLogging("platform_list_prompts", async () => {
335
+ requireApiKey();
336
+ const { handleListPrompts } = await import("./tools/list-prompts.js");
337
+ return {
338
+ content: [{ type: "text", text: await handleListPrompts() }],
339
+ };
340
+ })
341
+ );
342
+
343
+ server.tool(
344
+ "platform_get_prompt",
345
+ "Get a specific prompt from the LangWatch platform by ID or handle, including messages, model config, and version history.",
346
+ {
347
+ idOrHandle: z.string().describe("Prompt ID or handle"),
348
+ version: z
349
+ .number()
350
+ .optional()
351
+ .describe("Specific version number (default: latest)"),
352
+ tag: z.string().optional().describe(
353
+ 'Fetch the version pointed to by this tag (e.g., "production", "staging"). ' +
354
+ 'Alternatively, use shorthand in idOrHandle: "pizza-prompt:production"'
355
+ ),
356
+ },
357
+ withToolLogging("platform_get_prompt", async (params) => {
358
+ if (params.version != null && params.tag) {
359
+ return {
360
+ content: [{ type: "text", text: "Error: Provide either 'version' or 'tag', not both." }],
361
+ isError: true,
362
+ };
363
+ }
364
+ requireApiKey();
365
+ const { handleGetPrompt } = await import("./tools/get-prompt.js");
366
+ return {
367
+ content: [{ type: "text", text: await handleGetPrompt(params) }],
368
+ };
369
+ })
370
+ );
371
+
372
+ server.tool(
373
+ "platform_update_prompt",
374
+ "Update an existing prompt on the LangWatch platform. Every update creates a new version.",
375
+ {
376
+ idOrHandle: z.string().describe("Prompt ID or handle to update"),
377
+ messages: z
378
+ .array(
379
+ z.object({
380
+ role: z.enum(["system", "user", "assistant"]),
381
+ content: z.string(),
382
+ })
383
+ )
384
+ .optional()
385
+ .describe("Updated messages"),
386
+ model: modelSchema.optional(),
387
+ commitMessage: z
388
+ .string()
389
+ .describe("Commit message describing the change"),
390
+ tags: z.array(z.string()).optional().describe(
391
+ 'Tags to assign to the new version created by this update.'
392
+ ),
393
+ },
394
+ withToolLogging("platform_update_prompt", async (params) => {
395
+ requireApiKey();
396
+ const { handleUpdatePrompt } = await import("./tools/update-prompt.js");
397
+ return {
398
+ content: [{ type: "text", text: await handleUpdatePrompt(params) }],
399
+ };
400
+ })
401
+ );
402
+
403
+ server.tool(
404
+ "platform_assign_prompt_tag",
405
+ 'Assign a tag (e.g. "production") to a specific version of a prompt. ' +
406
+ 'Use this to "deploy" a version by promoting it to the production tag.',
407
+ {
408
+ idOrHandle: z.string().describe("Prompt ID or handle"),
409
+ tag: z.string().describe('Tag name (e.g., "production", "staging")'),
410
+ versionId: z.string().describe("The version ID to assign the tag to"),
411
+ },
412
+ withToolLogging("platform_assign_prompt_tag", async (params) => {
413
+ requireApiKey();
414
+ const { handleAssignPromptTag } = await import("./tools/assign-prompt-tag.js");
415
+ return {
416
+ content: [{ type: "text", text: await handleAssignPromptTag(params) }],
417
+ };
418
+ })
419
+ );
420
+
421
+ server.tool(
422
+ "platform_list_prompt_tags",
423
+ "List all prompt tag definitions for the organization. " +
424
+ "Shows built-in tags (latest, production, staging) and any custom tags.",
425
+ {},
426
+ withToolLogging("platform_list_prompt_tags", async () => {
427
+ requireApiKey();
428
+ const { handleListPromptTags } = await import("./tools/list-prompt-tags.js");
429
+ return {
430
+ content: [{ type: "text", text: await handleListPromptTags() }],
431
+ };
432
+ })
433
+ );
434
+
435
+ server.tool(
436
+ "platform_create_prompt_tag",
437
+ "Create a custom prompt tag definition for the organization. " +
438
+ 'Tag names must be non-numeric and not "latest".',
439
+ {
440
+ name: z.string().describe("Tag name to create"),
441
+ },
442
+ withToolLogging("platform_create_prompt_tag", async (params) => {
443
+ requireApiKey();
444
+ const { handleCreatePromptTag } = await import("./tools/create-prompt-tag.js");
445
+ return {
446
+ content: [{ type: "text", text: await handleCreatePromptTag(params) }],
447
+ };
448
+ })
449
+ );
450
+
451
+ server.tool(
452
+ "platform_rename_prompt_tag",
453
+ 'Rename an existing prompt tag. The "latest" tag cannot be renamed.',
454
+ {
455
+ tag: z.string().describe("Current tag name to rename"),
456
+ name: z.string().describe("New tag name"),
457
+ },
458
+ withToolLogging("platform_rename_prompt_tag", async (params) => {
459
+ requireApiKey();
460
+ const { handleRenamePromptTag } = await import("./tools/rename-prompt-tag.js");
461
+ return {
462
+ content: [{ type: "text", text: await handleRenamePromptTag(params) }],
463
+ };
464
+ })
465
+ );
466
+
467
+ server.tool(
468
+ "platform_delete_prompt_tag",
469
+ 'Delete a prompt tag and all its assignments. The "latest" tag cannot be deleted.',
470
+ {
471
+ tag: z.string().describe("Tag name to delete"),
472
+ },
473
+ withToolLogging("platform_delete_prompt_tag", async (params) => {
474
+ requireApiKey();
475
+ const { handleDeletePromptTag } = await import("./tools/delete-prompt-tag.js");
476
+ return {
477
+ content: [{ type: "text", text: await handleDeletePromptTag(params) }],
478
+ };
479
+ })
480
+ );
481
+
482
+ // --- Platform Scenario Tools (require API key) ---
483
+ // These tools manage scenarios on the LangWatch platform via API.
484
+ // For code-based scenario testing, see `fetch_scenario_docs` for the SDK approach.
485
+
486
+ server.tool(
487
+ "platform_create_scenario",
488
+ `Create a new scenario on the LangWatch platform. Call discover_schema({ category: 'scenarios' }) first to learn how to write effective situations and criteria.
489
+
490
+ NOTE: Scenarios can be created two ways. Determine which approach the user needs:
491
+
492
+ 1. Code-based (local testing): If the user has a codebase with an AI agent they want to test, use \`fetch_scenario_docs\` to learn about the Scenario Python/TypeScript SDK. This lets them run tests locally and iterate in code.
493
+
494
+ 2. Platform-based (LangWatch UI): If the user wants to manage scenarios directly on the LangWatch platform, use the \`platform_\` MCP tools (\`platform_create_scenario\`, \`platform_update_scenario\`, etc.).
495
+ `,
496
+ {
497
+ name: z.string().describe("Scenario name"),
498
+ situation: z
499
+ .string()
500
+ .describe(
501
+ "The context or setup describing what the user/agent is doing"
502
+ ),
503
+ criteria: z
504
+ .array(z.string())
505
+ .optional()
506
+ .describe(
507
+ "Pass/fail conditions the agent's response must satisfy"
508
+ ),
509
+ labels: z
510
+ .array(z.string())
511
+ .optional()
512
+ .describe("Tags for organizing and filtering scenarios"),
513
+ },
514
+ withToolLogging("platform_create_scenario", async (params) => {
515
+ requireApiKey();
516
+ const { handleCreateScenario } = await import(
517
+ "./tools/create-scenario.js"
518
+ );
519
+ return {
520
+ content: [
521
+ { type: "text", text: await handleCreateScenario(params) },
522
+ ],
523
+ };
524
+ })
525
+ );
526
+
527
+ server.tool(
528
+ "platform_list_scenarios",
529
+ "List all scenarios on the LangWatch platform. Returns AI-readable digest by default.",
530
+ {
531
+ format: z
532
+ .enum(["digest", "json"])
533
+ .optional()
534
+ .describe(
535
+ "Output format: 'digest' (default, AI-readable) or 'json' (full raw data)"
536
+ ),
537
+ },
538
+ withToolLogging("platform_list_scenarios", async (params) => {
539
+ requireApiKey();
540
+ const { handleListScenarios } = await import(
541
+ "./tools/list-scenarios.js"
542
+ );
543
+ return {
544
+ content: [
545
+ { type: "text", text: await handleListScenarios(params) },
546
+ ],
547
+ };
548
+ })
549
+ );
550
+
551
+ server.tool(
552
+ "platform_get_scenario",
553
+ "Get full details of a scenario on the LangWatch platform by ID, including situation, criteria, and labels.",
554
+ {
555
+ scenarioId: z.string().describe("The scenario ID to retrieve"),
556
+ format: z
557
+ .enum(["digest", "json"])
558
+ .optional()
559
+ .describe(
560
+ "Output format: 'digest' (default, AI-readable) or 'json' (full raw data)"
561
+ ),
562
+ },
563
+ withToolLogging("platform_get_scenario", async (params) => {
564
+ requireApiKey();
565
+ const { handleGetScenario } = await import("./tools/get-scenario.js");
566
+ return {
567
+ content: [{ type: "text", text: await handleGetScenario(params) }],
568
+ };
569
+ })
570
+ );
571
+
572
+ server.tool(
573
+ "platform_update_scenario",
574
+ "Update an existing scenario on the LangWatch platform.",
575
+ {
576
+ scenarioId: z.string().describe("The scenario ID to update"),
577
+ name: z.string().optional().describe("Updated scenario name"),
578
+ situation: z.string().optional().describe("Updated situation"),
579
+ criteria: z
580
+ .array(z.string())
581
+ .optional()
582
+ .describe("Updated criteria"),
583
+ labels: z
584
+ .array(z.string())
585
+ .optional()
586
+ .describe("Updated labels"),
587
+ },
588
+ withToolLogging("platform_update_scenario", async (params) => {
589
+ requireApiKey();
590
+ const { handleUpdateScenario } = await import(
591
+ "./tools/update-scenario.js"
592
+ );
593
+ return {
594
+ content: [
595
+ { type: "text", text: await handleUpdateScenario(params) },
596
+ ],
597
+ };
598
+ })
599
+ );
600
+
601
+ server.tool(
602
+ "platform_archive_scenario",
603
+ "Archive (soft-delete) a scenario on the LangWatch platform.",
604
+ {
605
+ scenarioId: z.string().describe("The scenario ID to archive"),
606
+ },
607
+ withToolLogging("platform_archive_scenario", async (params) => {
608
+ requireApiKey();
609
+ const { handleArchiveScenario } = await import(
610
+ "./tools/archive-scenario.js"
611
+ );
612
+ return {
613
+ content: [
614
+ { type: "text", text: await handleArchiveScenario(params) },
615
+ ],
616
+ };
617
+ })
618
+ );
619
+
620
+ // --- Platform Suite / Run Plan Tools (require API key) ---
621
+ // These tools manage suites (run plans) on the LangWatch platform via API.
622
+
623
+ server.tool(
624
+ "platform_list_suites",
625
+ "List all suites (run plans) on the LangWatch platform. A suite bundles scenarios with targets for batch execution.",
626
+ {
627
+ format: z
628
+ .enum(["digest", "json"])
629
+ .optional()
630
+ .describe("Output format: 'digest' (default) or 'json' (raw data)"),
631
+ },
632
+ withToolLogging("platform_list_suites", async (params) => {
633
+ requireApiKey();
634
+ const { handleListSuites } = await import("./tools/list-suites.js");
635
+ return {
636
+ content: [{ type: "text", text: await handleListSuites(params) }],
637
+ };
638
+ })
639
+ );
640
+
641
+ server.tool(
642
+ "platform_get_suite",
643
+ "Get detailed information about a specific suite (run plan) by ID.",
644
+ {
645
+ id: z.string().describe("The suite ID"),
646
+ format: z
647
+ .enum(["digest", "json"])
648
+ .optional()
649
+ .describe("Output format: 'digest' (default) or 'json'"),
650
+ },
651
+ withToolLogging("platform_get_suite", async (params) => {
652
+ requireApiKey();
653
+ const { handleGetSuite } = await import("./tools/get-suite.js");
654
+ return {
655
+ content: [{ type: "text", text: await handleGetSuite(params) }],
656
+ };
657
+ })
658
+ );
659
+
660
+ server.tool(
661
+ "platform_create_suite",
662
+ "Create a new suite (run plan) that bundles scenarios with targets for batch execution.",
663
+ {
664
+ name: z.string().describe("Suite name"),
665
+ description: z.string().optional().describe("Suite description"),
666
+ scenarioIds: z.array(z.string()).describe("Array of scenario IDs to include"),
667
+ targets: z.string().describe('JSON array of target objects, e.g. [{"type":"http","referenceId":"agent_abc"}]'),
668
+ repeatCount: z.number().optional().describe("Number of times to repeat each scenario-target pair (default: 1)"),
669
+ labels: z.array(z.string()).optional().describe("Tags for organizing suites"),
670
+ },
671
+ withToolLogging("platform_create_suite", async (params) => {
672
+ requireApiKey();
673
+ const { handleCreateSuite } = await import("./tools/create-suite.js");
674
+ return {
675
+ content: [{ type: "text", text: await handleCreateSuite(params) }],
676
+ };
677
+ })
678
+ );
679
+
680
+ server.tool(
681
+ "platform_update_suite",
682
+ "Update an existing suite (run plan).",
683
+ {
684
+ id: z.string().describe("The suite ID to update"),
685
+ name: z.string().optional().describe("New suite name"),
686
+ description: z.string().optional().describe("New description"),
687
+ scenarioIds: z.array(z.string()).optional().describe("New array of scenario IDs"),
688
+ targets: z.string().optional().describe("New JSON array of targets"),
689
+ repeatCount: z.number().optional().describe("New repeat count"),
690
+ labels: z.array(z.string()).optional().describe("New labels"),
691
+ },
692
+ withToolLogging("platform_update_suite", async (params) => {
693
+ requireApiKey();
694
+ const { handleUpdateSuite } = await import("./tools/update-suite.js");
695
+ return {
696
+ content: [{ type: "text", text: await handleUpdateSuite(params) }],
697
+ };
698
+ })
699
+ );
700
+
701
+ server.tool(
702
+ "platform_run_suite",
703
+ "Trigger a suite run. Schedules all scenario x target x repeat jobs for execution.",
704
+ {
705
+ id: z.string().describe("The suite ID to run"),
706
+ },
707
+ withToolLogging("platform_run_suite", async (params) => {
708
+ requireApiKey();
709
+ const { handleRunSuite } = await import("./tools/run-suite.js");
710
+ return {
711
+ content: [{ type: "text", text: await handleRunSuite(params) }],
712
+ };
713
+ })
714
+ );
715
+
716
+ server.tool(
717
+ "platform_archive_suite",
718
+ "Archive (soft-delete) a suite (run plan).",
719
+ {
720
+ id: z.string().describe("The suite ID to archive"),
721
+ },
722
+ withToolLogging("platform_archive_suite", async (params) => {
723
+ requireApiKey();
724
+ const { handleArchiveSuite } = await import("./tools/archive-suite.js");
725
+ return {
726
+ content: [{ type: "text", text: await handleArchiveSuite(params) }],
727
+ };
728
+ })
729
+ );
730
+
731
+ // --- Platform Simulation Run Tools (require API key) ---
732
+ // These tools query simulation run results from the LangWatch platform.
733
+
734
+ server.tool(
735
+ "platform_list_simulation_runs",
736
+ "List simulation run results. Filter by scenario set or batch run ID to see specific results.",
737
+ {
738
+ scenarioSetId: z.string().optional().describe("Filter by scenario set ID"),
739
+ batchRunId: z.string().optional().describe("Filter by batch run ID"),
740
+ limit: z.number().optional().describe("Max results to return (default: 20)"),
741
+ format: z.enum(["digest", "json"]).optional().describe("Output format"),
742
+ },
743
+ withToolLogging("platform_list_simulation_runs", async (params) => {
744
+ requireApiKey();
745
+ const { handleListSimulationRuns } = await import("./tools/list-simulation-runs.js");
746
+ return {
747
+ content: [{ type: "text", text: await handleListSimulationRuns(params) }],
748
+ };
749
+ })
750
+ );
751
+
752
+ server.tool(
753
+ "platform_get_simulation_run",
754
+ "Get full details of a simulation run including conversation messages, results, costs, and verdict.",
755
+ {
756
+ scenarioRunId: z.string().describe("The simulation run ID"),
757
+ format: z.enum(["digest", "json"]).optional().describe("Output format"),
758
+ },
759
+ withToolLogging("platform_get_simulation_run", async (params) => {
760
+ requireApiKey();
761
+ const { handleGetSimulationRun } = await import("./tools/get-simulation-run.js");
762
+ return {
763
+ content: [{ type: "text", text: await handleGetSimulationRun(params) }],
764
+ };
765
+ })
766
+ );
767
+
768
+ // --- Platform Evaluator Tools (require API key) ---
769
+ // These tools manage evaluators on the LangWatch platform via API.
770
+
771
+ server.tool(
772
+ "platform_create_evaluator",
773
+ `Create an evaluator on the LangWatch platform. Useful for setting up LLM-as-judge and other evaluators to use in evaluation notebooks. Call discover_schema({ category: 'evaluators' }) first to see available evaluator types and their settings.`,
774
+ {
775
+ name: z.string().describe("Evaluator name"),
776
+ config: z
777
+ .record(z.string(), z.unknown())
778
+ .describe(
779
+ 'Evaluator config object. Must include "evaluatorType" (e.g. "langevals/llm_boolean") and optional "settings" overrides.'
780
+ ),
781
+ },
782
+ withToolLogging("platform_create_evaluator", async (params) => {
783
+ requireApiKey();
784
+ const { handleCreateEvaluator } = await import(
785
+ "./tools/create-evaluator.js"
786
+ );
787
+ return {
788
+ content: [
789
+ { type: "text", text: await handleCreateEvaluator(params) },
790
+ ],
791
+ };
792
+ })
793
+ );
794
+
795
+ server.tool(
796
+ "platform_list_evaluators",
797
+ "List all evaluators configured on the LangWatch platform.",
798
+ {},
799
+ withToolLogging("platform_list_evaluators", async () => {
800
+ requireApiKey();
801
+ const { handleListEvaluators } = await import(
802
+ "./tools/list-evaluators.js"
803
+ );
804
+ return {
805
+ content: [{ type: "text", text: await handleListEvaluators() }],
806
+ };
807
+ })
808
+ );
809
+
810
+ server.tool(
811
+ "platform_get_evaluator",
812
+ "Get full details of an evaluator on the LangWatch platform by ID or slug, including config, input fields, and output fields.",
813
+ {
814
+ idOrSlug: z
815
+ .string()
816
+ .describe("The evaluator ID or slug to retrieve"),
817
+ },
818
+ withToolLogging("platform_get_evaluator", async (params) => {
819
+ requireApiKey();
820
+ const { handleGetEvaluator } = await import(
821
+ "./tools/get-evaluator.js"
822
+ );
823
+ return {
824
+ content: [{ type: "text", text: await handleGetEvaluator(params) }],
825
+ };
826
+ })
827
+ );
828
+
829
+ server.tool(
830
+ "platform_update_evaluator",
831
+ "Update an existing evaluator on the LangWatch platform. The evaluatorType in config cannot be changed after creation.",
832
+ {
833
+ evaluatorId: z.string().describe("The evaluator ID to update"),
834
+ name: z.string().optional().describe("Updated evaluator name"),
835
+ config: z
836
+ .record(z.string(), z.unknown())
837
+ .optional()
838
+ .describe(
839
+ "Updated config settings. Note: evaluatorType cannot be changed after creation."
840
+ ),
841
+ },
842
+ withToolLogging("platform_update_evaluator", async (params) => {
843
+ requireApiKey();
844
+ const { handleUpdateEvaluator } = await import(
845
+ "./tools/update-evaluator.js"
846
+ );
847
+ return {
848
+ content: [
849
+ { type: "text", text: await handleUpdateEvaluator(params) },
850
+ ],
851
+ };
852
+ })
853
+ );
854
+
855
+ server.tool(
856
+ "platform_delete_evaluator",
857
+ "Archive (soft-delete) an evaluator by ID or slug.",
858
+ {
859
+ idOrSlug: z.string().describe("The evaluator ID or slug to archive"),
860
+ },
861
+ withToolLogging("platform_delete_evaluator", async (params) => {
862
+ requireApiKey();
863
+ const { handleDeleteEvaluator } = await import("./tools/delete-evaluator.js");
864
+ return {
865
+ content: [{ type: "text", text: await handleDeleteEvaluator(params) }],
866
+ };
867
+ })
868
+ );
869
+
870
+ // --- Platform Model Provider Tools (require API key) ---
871
+ // These tools manage model provider API keys on the LangWatch platform.
872
+
873
+ server.tool(
874
+ "platform_set_model_provider",
875
+ `Set or update a model provider on the LangWatch platform. Use this to configure API keys (e.g. OPENAI_API_KEY) needed to run evaluators. The API key is stored securely and never returned in responses. Omit customKeys to update other settings without changing existing keys.`,
876
+ {
877
+ provider: z
878
+ .string()
879
+ .describe(
880
+ 'Provider name, e.g., "openai", "anthropic", "azure", "custom"'
881
+ ),
882
+ enabled: z.boolean().describe("Whether the provider is enabled"),
883
+ customKeys: z
884
+ .record(z.string(), z.unknown())
885
+ .optional()
886
+ .describe(
887
+ 'API key configuration, e.g. { "OPENAI_API_KEY": "sk-..." }. Omit to keep existing keys.'
888
+ ),
889
+ defaultModel: z
890
+ .string()
891
+ .optional()
892
+ .describe("Set as project default model"),
893
+ },
894
+ withToolLogging("platform_set_model_provider", async (params) => {
895
+ requireApiKey();
896
+ const { handleSetModelProvider } = await import(
897
+ "./tools/set-model-provider.js"
898
+ );
899
+ return {
900
+ content: [
901
+ { type: "text", text: await handleSetModelProvider(params) },
902
+ ],
903
+ };
904
+ })
905
+ );
906
+
907
+ server.tool(
908
+ "platform_list_model_providers",
909
+ "List all model providers configured on the LangWatch platform. API keys are masked in the response.",
910
+ {},
911
+ withToolLogging("platform_list_model_providers", async () => {
912
+ requireApiKey();
913
+ const { handleListModelProviders } = await import(
914
+ "./tools/list-model-providers.js"
915
+ );
916
+ return {
917
+ content: [{ type: "text", text: await handleListModelProviders() }],
918
+ };
919
+ })
920
+ );
921
+
922
+ // --- Platform Agent Tools (require API key) ---
923
+
924
+ server.tool(
925
+ "platform_list_agents",
926
+ "List all agents in the LangWatch project with their names, types, and IDs.",
927
+ {},
928
+ withToolLogging("platform_list_agents", async () => {
929
+ requireApiKey();
930
+ const { handleListAgents } = await import("./tools/list-agents.js");
931
+ return {
932
+ content: [{ type: "text", text: await handleListAgents() }],
933
+ };
934
+ })
935
+ );
936
+
937
+ server.tool(
938
+ "platform_get_agent",
939
+ "Get detailed information about a specific agent by its ID, including its configuration.",
940
+ {
941
+ id: z.string().describe("The agent ID"),
942
+ },
943
+ withToolLogging("platform_get_agent", async (params) => {
944
+ requireApiKey();
945
+ const { handleGetAgent } = await import("./tools/get-agent.js");
946
+ return {
947
+ content: [{ type: "text", text: await handleGetAgent(params) }],
948
+ };
949
+ })
950
+ );
951
+
952
+ server.tool(
953
+ "platform_create_agent",
954
+ "Create a new agent. Supported types: 'signature' (LLM prompt), 'code' (Python), 'workflow' (sub-workflow), 'http' (external API).",
955
+ {
956
+ name: z.string().describe("Agent name"),
957
+ type: z.enum(["signature", "code", "workflow", "http"]).describe("Agent type"),
958
+ config: z.string().optional().describe("Agent configuration as JSON string (will be parsed)"),
959
+ },
960
+ withToolLogging("platform_create_agent", async (params) => {
961
+ requireApiKey();
962
+ const { handleCreateAgent } = await import("./tools/create-agent.js");
963
+ const parsedConfig = params.config ? JSON.parse(params.config) as Record<string, unknown> : undefined;
964
+ return {
965
+ content: [{ type: "text", text: await handleCreateAgent({ ...params, config: parsedConfig }) }],
966
+ };
967
+ })
968
+ );
969
+
970
+ server.tool(
971
+ "platform_update_agent",
972
+ "Update an existing agent's name, type, or configuration.",
973
+ {
974
+ id: z.string().describe("The agent ID"),
975
+ name: z.string().optional().describe("New agent name"),
976
+ type: z.string().optional().describe("New agent type: signature, code, workflow, or http"),
977
+ config: z.string().optional().describe("Updated configuration as JSON string (will be parsed)"),
978
+ },
979
+ withToolLogging("platform_update_agent", async (params) => {
980
+ requireApiKey();
981
+ const { handleUpdateAgent } = await import("./tools/update-agent.js");
982
+ const parsedConfig = params.config ? JSON.parse(params.config) as Record<string, unknown> : undefined;
983
+ return {
984
+ content: [{ type: "text", text: await handleUpdateAgent({ ...params, config: parsedConfig }) }],
985
+ };
986
+ })
987
+ );
988
+
989
+ server.tool(
990
+ "platform_delete_agent",
991
+ "Archive (soft-delete) an agent by its ID.",
992
+ {
993
+ id: z.string().describe("The agent ID to archive"),
994
+ },
995
+ withToolLogging("platform_delete_agent", async (params) => {
996
+ requireApiKey();
997
+ const { handleDeleteAgent } = await import("./tools/delete-agent.js");
998
+ return {
999
+ content: [{ type: "text", text: await handleDeleteAgent(params) }],
1000
+ };
1001
+ })
1002
+ );
1003
+
1004
+ server.tool(
1005
+ "platform_run_agent",
1006
+ "Execute an agent with JSON input. HTTP agents call their configured URL directly; workflow-linked agents execute via the workflow engine.",
1007
+ {
1008
+ id: z.string().describe("The agent ID to run"),
1009
+ input: z.string().optional().describe("Input data as a JSON object string"),
1010
+ },
1011
+ withToolLogging("platform_run_agent", async (params) => {
1012
+ requireApiKey();
1013
+ const { handleRunAgent } = await import("./tools/run-agent.js");
1014
+ return {
1015
+ content: [{ type: "text", text: await handleRunAgent(params) }],
1016
+ };
1017
+ })
1018
+ );
1019
+
1020
+ // --- Platform Dashboard Tools (require API key) ---
1021
+
1022
+ server.tool(
1023
+ "platform_list_dashboards",
1024
+ "List all analytics dashboards in the LangWatch project.",
1025
+ {},
1026
+ withToolLogging("platform_list_dashboards", async () => {
1027
+ requireApiKey();
1028
+ const { handleListDashboards } = await import("./tools/list-dashboards.js");
1029
+ return {
1030
+ content: [{ type: "text", text: await handleListDashboards() }],
1031
+ };
1032
+ })
1033
+ );
1034
+
1035
+ server.tool(
1036
+ "platform_get_dashboard",
1037
+ "Get a dashboard by its ID, including its graphs.",
1038
+ {
1039
+ id: z.string().describe("The dashboard ID"),
1040
+ },
1041
+ withToolLogging("platform_get_dashboard", async (params) => {
1042
+ requireApiKey();
1043
+ const { handleGetDashboard } = await import("./tools/get-dashboard.js");
1044
+ return {
1045
+ content: [{ type: "text", text: await handleGetDashboard(params) }],
1046
+ };
1047
+ })
1048
+ );
1049
+
1050
+ server.tool(
1051
+ "platform_create_dashboard",
1052
+ "Create a new analytics dashboard.",
1053
+ {
1054
+ name: z.string().describe("Dashboard name"),
1055
+ },
1056
+ withToolLogging("platform_create_dashboard", async (params) => {
1057
+ requireApiKey();
1058
+ const { handleCreateDashboard } = await import("./tools/create-dashboard.js");
1059
+ return {
1060
+ content: [{ type: "text", text: await handleCreateDashboard(params) }],
1061
+ };
1062
+ })
1063
+ );
1064
+
1065
+ server.tool(
1066
+ "platform_delete_dashboard",
1067
+ "Delete a dashboard and all its graphs.",
1068
+ {
1069
+ id: z.string().describe("The dashboard ID to delete"),
1070
+ },
1071
+ withToolLogging("platform_delete_dashboard", async (params) => {
1072
+ requireApiKey();
1073
+ const { handleDeleteDashboard } = await import("./tools/delete-dashboard.js");
1074
+ return {
1075
+ content: [{ type: "text", text: await handleDeleteDashboard(params) }],
1076
+ };
1077
+ })
1078
+ );
1079
+
1080
+ server.tool(
1081
+ "platform_rename_dashboard",
1082
+ "Rename a dashboard.",
1083
+ {
1084
+ id: z.string().describe("The dashboard ID to rename"),
1085
+ name: z.string().describe("The new name for the dashboard"),
1086
+ },
1087
+ withToolLogging("platform_rename_dashboard", async (params) => {
1088
+ requireApiKey();
1089
+ const { renameDashboard } = await import("./langwatch-api-dashboards.js");
1090
+ const result = await renameDashboard(params.id, { name: params.name });
1091
+ return {
1092
+ content: [{ type: "text", text: `Dashboard "${result.name}" renamed successfully (ID: ${result.id}).` }],
1093
+ };
1094
+ })
1095
+ );
1096
+
1097
+ // --- Platform Workflow Tools (require API key) ---
1098
+
1099
+ server.tool(
1100
+ "platform_list_workflows",
1101
+ "List all workflows in the LangWatch project.",
1102
+ {},
1103
+ withToolLogging("platform_list_workflows", async () => {
1104
+ requireApiKey();
1105
+ const { handleListWorkflows } = await import("./tools/list-workflows.js");
1106
+ return {
1107
+ content: [{ type: "text", text: await handleListWorkflows() }],
1108
+ };
1109
+ })
1110
+ );
1111
+
1112
+ server.tool(
1113
+ "platform_get_workflow",
1114
+ "Get a workflow by its ID.",
1115
+ {
1116
+ id: z.string().describe("The workflow ID"),
1117
+ },
1118
+ withToolLogging("platform_get_workflow", async (params) => {
1119
+ requireApiKey();
1120
+ const { handleGetWorkflow } = await import("./tools/get-workflow.js");
1121
+ return {
1122
+ content: [{ type: "text", text: await handleGetWorkflow(params) }],
1123
+ };
1124
+ })
1125
+ );
1126
+
1127
+ server.tool(
1128
+ "platform_delete_workflow",
1129
+ "Archive (soft-delete) a workflow by its ID.",
1130
+ {
1131
+ id: z.string().describe("The workflow ID to archive"),
1132
+ },
1133
+ withToolLogging("platform_delete_workflow", async (params) => {
1134
+ requireApiKey();
1135
+ const { handleDeleteWorkflow } = await import("./tools/delete-workflow.js");
1136
+ return {
1137
+ content: [{ type: "text", text: await handleDeleteWorkflow(params) }],
1138
+ };
1139
+ })
1140
+ );
1141
+
1142
+ server.tool(
1143
+ "platform_run_workflow",
1144
+ "Execute a workflow with JSON input. Returns the workflow output.",
1145
+ {
1146
+ id: z.string().describe("The workflow ID to run"),
1147
+ input: z.string().optional().describe("Input data as a JSON object string"),
1148
+ },
1149
+ withToolLogging("platform_run_workflow", async (params) => {
1150
+ requireApiKey();
1151
+ const { handleRunWorkflow } = await import("./tools/run-workflow.js");
1152
+ return {
1153
+ content: [{ type: "text", text: await handleRunWorkflow(params) }],
1154
+ };
1155
+ })
1156
+ );
1157
+
1158
+ // --- Platform Annotation Tools (require API key) ---
1159
+
1160
+ server.tool(
1161
+ "platform_list_annotations",
1162
+ "List all annotations for the project, optionally filtered by trace ID.",
1163
+ {
1164
+ traceId: z.string().optional().describe("Filter annotations by trace ID"),
1165
+ },
1166
+ withToolLogging("platform_list_annotations", async (params) => {
1167
+ requireApiKey();
1168
+ const { handleListAnnotations } = await import("./tools/list-annotations.js");
1169
+ return {
1170
+ content: [{ type: "text", text: await handleListAnnotations(params) }],
1171
+ };
1172
+ })
1173
+ );
1174
+
1175
+ server.tool(
1176
+ "platform_create_annotation",
1177
+ "Create an annotation (thumbs up/down, comment) for a trace.",
1178
+ {
1179
+ traceId: z.string().describe("The trace ID to annotate"),
1180
+ comment: z.string().optional().describe("Annotation comment"),
1181
+ isThumbsUp: z.boolean().optional().describe("True for positive feedback, false for negative"),
1182
+ email: z.string().optional().describe("Email of the annotator"),
1183
+ },
1184
+ withToolLogging("platform_create_annotation", async (params) => {
1185
+ requireApiKey();
1186
+ const { handleCreateAnnotation } = await import("./tools/create-annotation.js");
1187
+ return {
1188
+ content: [{ type: "text", text: await handleCreateAnnotation(params) }],
1189
+ };
1190
+ })
1191
+ );
1192
+
1193
+ server.tool(
1194
+ "platform_delete_annotation",
1195
+ "Delete an annotation by its ID.",
1196
+ {
1197
+ id: z.string().describe("The annotation ID to delete"),
1198
+ },
1199
+ withToolLogging("platform_delete_annotation", async (params) => {
1200
+ requireApiKey();
1201
+ const { handleDeleteAnnotation } = await import("./tools/delete-annotation.js");
1202
+ return {
1203
+ content: [{ type: "text", text: await handleDeleteAnnotation(params) }],
1204
+ };
1205
+ })
1206
+ );
1207
+
1208
+ server.tool(
1209
+ "platform_get_annotation",
1210
+ "Get annotation details by ID.",
1211
+ {
1212
+ id: z.string().describe("The annotation ID"),
1213
+ },
1214
+ withToolLogging("platform_get_annotation", async (params) => {
1215
+ requireApiKey();
1216
+ const { getAnnotation } = await import("./langwatch-api-annotations.js");
1217
+ const annotation = await getAnnotation(params.id);
1218
+ const lines = [
1219
+ `**ID**: ${annotation.id}`,
1220
+ `**Trace ID**: ${annotation.traceId}`,
1221
+ `**Comment**: ${annotation.comment ?? "—"}`,
1222
+ `**Score**: ${annotation.isThumbsUp ? "Thumbs Up" : "—"}`,
1223
+ `**Created**: ${annotation.createdAt}`,
1224
+ ];
1225
+ return {
1226
+ content: [{ type: "text", text: lines.join("\n") }],
1227
+ };
1228
+ })
1229
+ );
1230
+
1231
+ // --- Platform Trigger/Automation Tools (require API key) ---
1232
+
1233
+ server.tool(
1234
+ "platform_list_triggers",
1235
+ "List all triggers (automations) in the project. Triggers automate actions like sending emails, Slack messages, or adding to datasets when conditions are met.",
1236
+ {
1237
+ format: z.enum(["digest", "json"]).optional().describe("Output format"),
1238
+ },
1239
+ withToolLogging("platform_list_triggers", async (params) => {
1240
+ requireApiKey();
1241
+ const { listTriggers } = await import("./langwatch-api-triggers.js");
1242
+ const triggers = await listTriggers();
1243
+ if (params.format === "json") {
1244
+ return { content: [{ type: "text", text: JSON.stringify(triggers, null, 2) }] };
1245
+ }
1246
+ if (triggers.length === 0) {
1247
+ return { content: [{ type: "text", text: "No triggers found. Use `platform_create_trigger` to create one." }] };
1248
+ }
1249
+ const lines = [`# Triggers (${triggers.length} total)\n`];
1250
+ for (const t of triggers) {
1251
+ lines.push(`## ${t.name}`);
1252
+ lines.push(`**ID**: ${t.id}`);
1253
+ lines.push(`**Action**: ${t.action}`);
1254
+ lines.push(`**Status**: ${t.active ? "active" : "inactive"}`);
1255
+ if (t.alertType) lines.push(`**Alert**: ${t.alertType}`);
1256
+ lines.push("");
1257
+ }
1258
+ return { content: [{ type: "text", text: lines.join("\n") }] };
1259
+ })
1260
+ );
1261
+
1262
+ server.tool(
1263
+ "platform_create_trigger",
1264
+ "Create a new trigger (automation) that fires when conditions are met.",
1265
+ {
1266
+ name: z.string().describe("Trigger name"),
1267
+ action: z.enum(["SEND_EMAIL", "ADD_TO_DATASET", "ADD_TO_ANNOTATION_QUEUE", "SEND_SLACK_MESSAGE"]).describe("Action to take when triggered"),
1268
+ filters: z.string().optional().describe("Filter conditions as JSON string"),
1269
+ message: z.string().optional().describe("Custom alert message"),
1270
+ alertType: z.enum(["CRITICAL", "WARNING", "INFO"]).optional().describe("Alert severity"),
1271
+ },
1272
+ withToolLogging("platform_create_trigger", async (params) => {
1273
+ requireApiKey();
1274
+ const { createTrigger } = await import("./langwatch-api-triggers.js");
1275
+ let filters: Record<string, unknown> = {};
1276
+ if (params.filters) {
1277
+ try { filters = JSON.parse(params.filters) as Record<string, unknown>; }
1278
+ catch { return { content: [{ type: "text", text: "Error: filters must be valid JSON" }] }; }
1279
+ }
1280
+ const trigger = await createTrigger({
1281
+ name: params.name,
1282
+ action: params.action,
1283
+ filters,
1284
+ message: params.message,
1285
+ alertType: params.alertType,
1286
+ });
1287
+ return { content: [{ type: "text", text: `Trigger "${trigger.name}" created (ID: ${trigger.id}, Action: ${trigger.action}).` }] };
1288
+ })
1289
+ );
1290
+
1291
+ server.tool(
1292
+ "platform_update_trigger",
1293
+ "Update a trigger (name, active state, message, alert type).",
1294
+ {
1295
+ id: z.string().describe("The trigger ID"),
1296
+ name: z.string().optional().describe("New name"),
1297
+ active: z.boolean().optional().describe("Enable or disable"),
1298
+ message: z.string().optional().describe("New alert message"),
1299
+ alertType: z.enum(["CRITICAL", "WARNING", "INFO"]).optional().describe("New alert severity"),
1300
+ },
1301
+ withToolLogging("platform_update_trigger", async (params) => {
1302
+ requireApiKey();
1303
+ const { updateTrigger } = await import("./langwatch-api-triggers.js");
1304
+ const trigger = await updateTrigger(params);
1305
+ return { content: [{ type: "text", text: `Trigger "${trigger.name}" updated (active: ${trigger.active}).` }] };
1306
+ })
1307
+ );
1308
+
1309
+ server.tool(
1310
+ "platform_delete_trigger",
1311
+ "Delete a trigger (automation).",
1312
+ {
1313
+ id: z.string().describe("The trigger ID to delete"),
1314
+ },
1315
+ withToolLogging("platform_delete_trigger", async (params) => {
1316
+ requireApiKey();
1317
+ const { deleteTrigger } = await import("./langwatch-api-triggers.js");
1318
+ const result = await deleteTrigger(params.id);
1319
+ return { content: [{ type: "text", text: `Trigger ${result.id} deleted.` }] };
1320
+ })
1321
+ );
1322
+
1323
+ // --- Platform Monitor Tools (require API key) ---
1324
+
1325
+ server.tool(
1326
+ "platform_list_monitors",
1327
+ "List all online evaluation monitors for the project.",
1328
+ {},
1329
+ withToolLogging("platform_list_monitors", async () => {
1330
+ requireApiKey();
1331
+ const { listMonitors } = await import("./langwatch-api-monitors.js");
1332
+ const monitors = await listMonitors();
1333
+ if (monitors.length === 0) {
1334
+ return { content: [{ type: "text", text: "No monitors found." }] };
1335
+ }
1336
+ const lines = monitors.map(
1337
+ (m) =>
1338
+ `• ${m.name} (id: ${m.id}, type: ${m.checkType}, ${m.enabled ? "enabled" : "disabled"}, mode: ${m.executionMode}, sample: ${Math.round(m.sample * 100)}%)`
1339
+ );
1340
+ return {
1341
+ content: [
1342
+ {
1343
+ type: "text",
1344
+ text: `Found ${monitors.length} monitor(s):\n${lines.join("\n")}`,
1345
+ },
1346
+ ],
1347
+ };
1348
+ })
1349
+ );
1350
+
1351
+ server.tool(
1352
+ "platform_get_monitor",
1353
+ "Get details of a specific online evaluation monitor.",
1354
+ {
1355
+ id: z.string().describe("The monitor ID"),
1356
+ },
1357
+ withToolLogging("platform_get_monitor", async (params) => {
1358
+ requireApiKey();
1359
+ const { getMonitor } = await import("./langwatch-api-monitors.js");
1360
+ const m = await getMonitor(params.id);
1361
+ const lines = [
1362
+ `**${m.name}** (${m.id})`,
1363
+ `- Type: ${m.checkType}`,
1364
+ `- Status: ${m.enabled ? "enabled" : "disabled"}`,
1365
+ `- Mode: ${m.executionMode}`,
1366
+ `- Sample: ${Math.round(m.sample * 100)}%`,
1367
+ `- Level: ${m.level}`,
1368
+ m.evaluatorId ? `- Evaluator: ${m.evaluatorId}` : null,
1369
+ `- Created: ${m.createdAt}`,
1370
+ ].filter(Boolean);
1371
+ return { content: [{ type: "text", text: lines.join("\n") }] };
1372
+ })
1373
+ );
1374
+
1375
+ server.tool(
1376
+ "platform_create_monitor",
1377
+ "Create a new online evaluation monitor that runs an evaluator on incoming traces.",
1378
+ {
1379
+ name: z.string().describe("Monitor name"),
1380
+ checkType: z
1381
+ .string()
1382
+ .describe("Evaluator check type (e.g. ragas/toxicity, custom/my-eval)"),
1383
+ executionMode: z
1384
+ .enum(["ON_MESSAGE", "AS_GUARDRAIL", "MANUALLY"])
1385
+ .optional()
1386
+ .describe("When to run: ON_MESSAGE (default), AS_GUARDRAIL, or MANUALLY"),
1387
+ sample: z
1388
+ .number()
1389
+ .min(0)
1390
+ .max(1)
1391
+ .optional()
1392
+ .describe("Sampling rate 0.0-1.0 (default: 1.0)"),
1393
+ evaluatorId: z
1394
+ .string()
1395
+ .optional()
1396
+ .describe("Link to a saved evaluator by ID"),
1397
+ },
1398
+ withToolLogging("platform_create_monitor", async (params) => {
1399
+ requireApiKey();
1400
+ const { createMonitor } = await import("./langwatch-api-monitors.js");
1401
+ const monitor = await createMonitor(params);
1402
+ return {
1403
+ content: [
1404
+ {
1405
+ type: "text",
1406
+ text: `Monitor "${monitor.name}" created (id: ${monitor.id}, type: ${monitor.checkType}).`,
1407
+ },
1408
+ ],
1409
+ };
1410
+ })
1411
+ );
1412
+
1413
+ server.tool(
1414
+ "platform_update_monitor",
1415
+ "Update an existing online evaluation monitor.",
1416
+ {
1417
+ id: z.string().describe("The monitor ID to update"),
1418
+ name: z.string().optional().describe("New monitor name"),
1419
+ enabled: z.boolean().optional().describe("Enable or disable the monitor"),
1420
+ executionMode: z
1421
+ .enum(["ON_MESSAGE", "AS_GUARDRAIL", "MANUALLY"])
1422
+ .optional()
1423
+ .describe("New execution mode"),
1424
+ sample: z.number().min(0).max(1).optional().describe("New sampling rate"),
1425
+ },
1426
+ withToolLogging("platform_update_monitor", async (params) => {
1427
+ requireApiKey();
1428
+ const { updateMonitor } = await import("./langwatch-api-monitors.js");
1429
+ const monitor = await updateMonitor(params);
1430
+ return {
1431
+ content: [
1432
+ {
1433
+ type: "text",
1434
+ text: `Monitor "${monitor.name}" updated (${monitor.enabled ? "enabled" : "disabled"}).`,
1435
+ },
1436
+ ],
1437
+ };
1438
+ })
1439
+ );
1440
+
1441
+ server.tool(
1442
+ "platform_delete_monitor",
1443
+ "Delete an online evaluation monitor.",
1444
+ {
1445
+ id: z.string().describe("The monitor ID to delete"),
1446
+ },
1447
+ withToolLogging("platform_delete_monitor", async (params) => {
1448
+ requireApiKey();
1449
+ const { deleteMonitor } = await import("./langwatch-api-monitors.js");
1450
+ const result = await deleteMonitor(params.id);
1451
+ return {
1452
+ content: [
1453
+ { type: "text", text: `Monitor ${result.id} deleted.` },
1454
+ ],
1455
+ };
1456
+ })
1457
+ );
1458
+
1459
+ // --- Platform Secret Tools (require API key) ---
1460
+
1461
+ server.tool(
1462
+ "platform_list_secrets",
1463
+ "List all project secrets (values are never returned, only metadata).",
1464
+ {},
1465
+ withToolLogging("platform_list_secrets", async () => {
1466
+ requireApiKey();
1467
+ const { listSecrets } = await import("./langwatch-api-secrets.js");
1468
+ const secrets = await listSecrets();
1469
+ if (secrets.length === 0) {
1470
+ return { content: [{ type: "text", text: "No secrets found." }] };
1471
+ }
1472
+ const lines = secrets.map(
1473
+ (s) => `• ${s.name} (id: ${s.id}, updated: ${s.updatedAt})`
1474
+ );
1475
+ return {
1476
+ content: [
1477
+ {
1478
+ type: "text",
1479
+ text: `Found ${secrets.length} secret(s):\n${lines.join("\n")}`,
1480
+ },
1481
+ ],
1482
+ };
1483
+ })
1484
+ );
1485
+
1486
+ server.tool(
1487
+ "platform_create_secret",
1488
+ "Create a new encrypted project secret. Name must be UPPER_SNAKE_CASE (e.g. MY_API_KEY).",
1489
+ {
1490
+ name: z.string().describe("Secret name in UPPER_SNAKE_CASE (e.g. OPENAI_API_KEY)"),
1491
+ value: z.string().describe("The secret value (will be encrypted at rest)"),
1492
+ },
1493
+ withToolLogging("platform_create_secret", async (params) => {
1494
+ requireApiKey();
1495
+ const { createSecret } = await import("./langwatch-api-secrets.js");
1496
+ const secret = await createSecret({ name: params.name, value: params.value });
1497
+ return {
1498
+ content: [
1499
+ {
1500
+ type: "text",
1501
+ text: `Secret "${secret.name}" created (id: ${secret.id}).`,
1502
+ },
1503
+ ],
1504
+ };
1505
+ })
1506
+ );
1507
+
1508
+ server.tool(
1509
+ "platform_update_secret",
1510
+ "Update an existing project secret's value.",
1511
+ {
1512
+ id: z.string().describe("The secret ID to update"),
1513
+ value: z.string().describe("The new secret value (will be encrypted at rest)"),
1514
+ },
1515
+ withToolLogging("platform_update_secret", async (params) => {
1516
+ requireApiKey();
1517
+ const { updateSecret } = await import("./langwatch-api-secrets.js");
1518
+ const secret = await updateSecret({ id: params.id, value: params.value });
1519
+ return {
1520
+ content: [
1521
+ {
1522
+ type: "text",
1523
+ text: `Secret "${secret.name}" updated.`,
1524
+ },
1525
+ ],
1526
+ };
1527
+ })
1528
+ );
1529
+
1530
+ server.tool(
1531
+ "platform_delete_secret",
1532
+ "Delete a project secret.",
1533
+ {
1534
+ id: z.string().describe("The secret ID to delete"),
1535
+ },
1536
+ withToolLogging("platform_delete_secret", async (params) => {
1537
+ requireApiKey();
1538
+ const { deleteSecret } = await import("./langwatch-api-secrets.js");
1539
+ const result = await deleteSecret(params.id);
1540
+ return { content: [{ type: "text", text: `Secret ${result.id} deleted.` }] };
1541
+ })
1542
+ );
1543
+
1544
+ // --- Platform Evaluation Execution Tools (require API key) ---
1545
+
1546
+ server.tool(
1547
+ "platform_run_evaluation",
1548
+ "Start an evaluation run by slug. Returns a run ID for polling status.",
1549
+ {
1550
+ slug: z.string().describe("The evaluation slug to run"),
1551
+ },
1552
+ withToolLogging("platform_run_evaluation", async (params) => {
1553
+ requireApiKey();
1554
+ const { handleRunEvaluation } = await import("./tools/run-evaluation.js");
1555
+ return {
1556
+ content: [{ type: "text", text: await handleRunEvaluation(params) }],
1557
+ };
1558
+ })
1559
+ );
1560
+
1561
+ server.tool(
1562
+ "platform_evaluation_status",
1563
+ "Check the status of an evaluation run. Returns progress and summary when completed.",
1564
+ {
1565
+ runId: z.string().describe("The run ID returned from platform_run_evaluation"),
1566
+ },
1567
+ withToolLogging("platform_evaluation_status", async (params) => {
1568
+ requireApiKey();
1569
+ const { handleEvaluationStatus } = await import("./tools/run-evaluation.js");
1570
+ return {
1571
+ content: [{ type: "text", text: await handleEvaluationStatus(params) }],
1572
+ };
1573
+ })
1574
+ );
1575
+
1576
+ // --- Platform Dataset Tools (require API key) ---
1577
+ // These tools manage datasets on the LangWatch platform via API.
1578
+
1579
+ server.tool(
1580
+ "platform_list_datasets",
1581
+ "List all datasets on the LangWatch platform with their names, slugs, columns, and record counts. Returns AI-readable digest by default.",
1582
+ {
1583
+ format: z
1584
+ .enum(["digest", "json"])
1585
+ .optional()
1586
+ .describe(
1587
+ "Output format: 'digest' (default, AI-readable) or 'json' (full raw data)"
1588
+ ),
1589
+ },
1590
+ async (params) => {
1591
+ const { requireApiKey } = await import("./config.js");
1592
+ requireApiKey();
1593
+ const { handleListDatasets } = await import(
1594
+ "./tools/list-datasets.js"
1595
+ );
1596
+ return {
1597
+ content: [{ type: "text", text: await handleListDatasets(params) }],
1598
+ };
1599
+ }
1600
+ );
1601
+
1602
+ server.tool(
1603
+ "platform_get_dataset",
1604
+ "Get full details of a dataset on the LangWatch platform by slug or ID, including column definitions and a preview of records.",
1605
+ {
1606
+ slugOrId: z.string().describe("The dataset slug or ID to retrieve"),
1607
+ format: z
1608
+ .enum(["digest", "json"])
1609
+ .optional()
1610
+ .describe(
1611
+ "Output format: 'digest' (default, AI-readable) or 'json' (full raw data)"
1612
+ ),
1613
+ },
1614
+ async (params) => {
1615
+ const { requireApiKey } = await import("./config.js");
1616
+ requireApiKey();
1617
+ const { handleGetDataset } = await import("./tools/get-dataset.js");
1618
+ return {
1619
+ content: [{ type: "text", text: await handleGetDataset(params) }],
1620
+ };
1621
+ }
1622
+ );
1623
+
1624
+ server.tool(
1625
+ "platform_create_dataset",
1626
+ "Create a new dataset on the LangWatch platform.",
1627
+ createDatasetSchema.shape,
1628
+ async (params) => {
1629
+ const { requireApiKey } = await import("./config.js");
1630
+ requireApiKey();
1631
+ const { handleCreateDataset } = await import(
1632
+ "./tools/create-dataset.js"
1633
+ );
1634
+ return {
1635
+ content: [{ type: "text", text: await handleCreateDataset(params) }],
1636
+ };
1637
+ }
1638
+ );
1639
+
1640
+ server.tool(
1641
+ "platform_update_dataset",
1642
+ "Update an existing dataset on the LangWatch platform (name and/or column types).",
1643
+ {
1644
+ slugOrId: z.string().describe("The dataset slug or ID to update"),
1645
+ name: z.string().optional().describe("Updated dataset name"),
1646
+ columnTypes: z
1647
+ .array(datasetColumnDefinitionSchema)
1648
+ .optional()
1649
+ .describe("Updated column definitions"),
1650
+ },
1651
+ async (params) => {
1652
+ const { requireApiKey } = await import("./config.js");
1653
+ requireApiKey();
1654
+ const { handleUpdateDataset } = await import(
1655
+ "./tools/update-dataset.js"
1656
+ );
1657
+ return {
1658
+ content: [{ type: "text", text: await handleUpdateDataset(params) }],
1659
+ };
1660
+ }
1661
+ );
1662
+
1663
+ server.tool(
1664
+ "platform_delete_dataset",
1665
+ "Delete (archive) a dataset on the LangWatch platform.",
1666
+ {
1667
+ slugOrId: z.string().describe("The dataset slug or ID to delete"),
1668
+ },
1669
+ async (params) => {
1670
+ const { requireApiKey } = await import("./config.js");
1671
+ requireApiKey();
1672
+ const { handleDeleteDataset } = await import(
1673
+ "./tools/delete-dataset.js"
1674
+ );
1675
+ return {
1676
+ content: [{ type: "text", text: await handleDeleteDataset(params) }],
1677
+ };
1678
+ }
1679
+ );
1680
+
1681
+ server.tool(
1682
+ "platform_list_dataset_records",
1683
+ "List records in a dataset on the LangWatch platform with pagination.",
1684
+ {
1685
+ slugOrId: z
1686
+ .string()
1687
+ .describe("The dataset slug or ID to list records from"),
1688
+ page: z
1689
+ .number()
1690
+ .int()
1691
+ .min(1)
1692
+ .optional()
1693
+ .describe("Page number (default: 1)"),
1694
+ limit: z
1695
+ .number()
1696
+ .int()
1697
+ .min(1)
1698
+ .max(1000)
1699
+ .optional()
1700
+ .describe("Records per page (default: 50, max: 1000)"),
1701
+ format: z
1702
+ .enum(["digest", "json"])
1703
+ .optional()
1704
+ .describe("Output format: 'digest' (default, AI-readable) or 'json' (full raw data)"),
1705
+ },
1706
+ async (params) => {
1707
+ const { requireApiKey } = await import("./config.js");
1708
+ requireApiKey();
1709
+ const { handleListDatasetRecords } = await import(
1710
+ "./tools/list-dataset-records.js"
1711
+ );
1712
+ return {
1713
+ content: [
1714
+ { type: "text", text: await handleListDatasetRecords(params) },
1715
+ ],
1716
+ };
1717
+ }
1718
+ );
1719
+
1720
+ server.tool(
1721
+ "platform_create_dataset_records",
1722
+ "Add records to a dataset on the LangWatch platform in batch (max 1000 per call).",
1723
+ {
1724
+ slugOrId: z
1725
+ .string()
1726
+ .describe("The dataset slug or ID to add records to"),
1727
+ entries: z
1728
+ .array(z.record(z.string(), z.unknown()))
1729
+ .min(1)
1730
+ .max(1000)
1731
+ .describe("Array of record entries to create (key-value objects matching dataset columns)"),
1732
+ },
1733
+ async (params) => {
1734
+ const { requireApiKey } = await import("./config.js");
1735
+ requireApiKey();
1736
+ const { handleCreateDatasetRecords } = await import(
1737
+ "./tools/create-dataset-records.js"
1738
+ );
1739
+ return {
1740
+ content: [
1741
+ { type: "text", text: await handleCreateDatasetRecords(params) },
1742
+ ],
1743
+ };
1744
+ }
1745
+ );
1746
+
1747
+ server.tool(
1748
+ "platform_update_dataset_record",
1749
+ "Update a single record in a dataset on the LangWatch platform.",
1750
+ {
1751
+ slugOrId: z
1752
+ .string()
1753
+ .describe("The dataset slug or ID containing the record"),
1754
+ recordId: z.string().describe("The record ID to update"),
1755
+ entry: z
1756
+ .record(z.string(), z.unknown())
1757
+ .describe("Updated record entry (key-value object)"),
1758
+ },
1759
+ async (params) => {
1760
+ const { requireApiKey } = await import("./config.js");
1761
+ requireApiKey();
1762
+ const { handleUpdateDatasetRecord } = await import(
1763
+ "./tools/update-dataset-record.js"
1764
+ );
1765
+ return {
1766
+ content: [
1767
+ { type: "text", text: await handleUpdateDatasetRecord(params) },
1768
+ ],
1769
+ };
1770
+ }
1771
+ );
1772
+
1773
+ server.tool(
1774
+ "platform_delete_dataset_records",
1775
+ "Delete records from a dataset on the LangWatch platform by their IDs.",
1776
+ {
1777
+ slugOrId: z
1778
+ .string()
1779
+ .describe("The dataset slug or ID containing the records"),
1780
+ recordIds: z
1781
+ .array(z.string())
1782
+ .min(1)
1783
+ .max(1000)
1784
+ .describe("Array of record IDs to delete"),
1785
+ },
1786
+ async (params) => {
1787
+ const { requireApiKey } = await import("./config.js");
1788
+ requireApiKey();
1789
+ const { handleDeleteDatasetRecords } = await import(
1790
+ "./tools/delete-dataset-records.js"
1791
+ );
1792
+ return {
1793
+ content: [
1794
+ { type: "text", text: await handleDeleteDatasetRecords(params) },
1795
+ ],
1796
+ };
1797
+ }
1798
+ );
1799
+ }