@promptlayer/mcp-server 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/types.ts ADDED
@@ -0,0 +1,728 @@
1
+ /**
2
+ * TypeScript types and Zod schemas for PromptLayer API
3
+ * All schemas verified against OpenAPI spec at:
4
+ * https://github.com/magnivorg/prompt-layer-docs/blob/master/openapi.json
5
+ */
6
+
7
+ import { z } from "zod";
8
+
9
+
10
+ // ── Get Prompt Template (POST /prompt-templates/{identifier}) ────────────
11
+
12
+ export const GetPromptTemplateArgsSchema = z.object({
13
+ prompt_name: z
14
+ .string()
15
+ .describe("Prompt template name or ID"),
16
+ version: z
17
+ .number()
18
+ .int()
19
+ .min(1)
20
+ .optional()
21
+ .describe("Specific version number (defaults to latest)"),
22
+ workspace_id: z.number().int().optional().describe("Workspace ID"),
23
+ label: z
24
+ .string()
25
+ .optional()
26
+ .describe("Release label (e.g. 'prod'). Takes precedence over version."),
27
+ provider: z
28
+ .enum([
29
+ "openai", "anthropic", "amazon.bedrock", "cohere",
30
+ "google", "huggingface", "mistral", "openai.azure", "vertexai",
31
+ ])
32
+ .optional()
33
+ .describe("LLM provider to format llm_kwargs for. Overrides provider set in registry."),
34
+ input_variables: z
35
+ .record(z.string())
36
+ .optional()
37
+ .describe("Variables to fill template placeholders"),
38
+ metadata_filters: z
39
+ .record(z.string())
40
+ .optional()
41
+ .describe("Key-value filters for A/B release labels"),
42
+ model: z
43
+ .string()
44
+ .optional()
45
+ .describe("Model name for returning default parameters with llm_kwargs"),
46
+ model_parameter_overrides: z
47
+ .record(z.unknown())
48
+ .optional()
49
+ .describe("Model parameter overrides at runtime"),
50
+ api_key: z
51
+ .string()
52
+ .optional()
53
+ .describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
54
+ });
55
+
56
+ // ── Get Prompt Template Raw (GET /prompt-templates/{identifier}) ─────────
57
+
58
+ export const GetPromptTemplateRawArgsSchema = z.object({
59
+ identifier: z.string().describe("Prompt template name or ID"),
60
+ version: z.number().int().optional().describe("Version number. Mutually exclusive with label."),
61
+ label: z.string().optional().describe("Release label (e.g. 'prod'). Mutually exclusive with version."),
62
+ resolve_snippets: z.boolean().optional().describe("Expand snippets (default true). Set false to preserve raw @@@snippet@@@ refs."),
63
+ include_llm_kwargs: z.boolean().optional().describe("Include provider-specific LLM format (default false)."),
64
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
65
+ });
66
+
67
+ // ── List Prompt Templates (GET /prompt-templates) ────────────────────────
68
+
69
+ export const ListPromptTemplatesArgsSchema = z.object({
70
+ page: z.number().int().optional().describe("Page number"),
71
+ per_page: z.number().int().optional().describe("Items per page"),
72
+ label: z.string().optional().describe("Filter by release label"),
73
+ name: z.string().optional().describe("Filter by name (case-insensitive partial match)"),
74
+ status: z.enum(["active", "deleted", "all"]).optional().describe("Filter by status (default: 'active')"),
75
+ workspace_id: z.number().int().optional().describe("Workspace ID"),
76
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
77
+ });
78
+
79
+ // ── Publish Prompt Template (POST /rest/prompt-templates) ────────────────
80
+ // OpenAPI: body = { prompt_template: BasePromptTemplate, prompt_version: PromptVersion, release_labels? }
81
+
82
+ export const PublishPromptTemplateArgsSchema = z.object({
83
+ prompt_template: z.object({
84
+ prompt_name: z.string().describe("Name of the prompt template"),
85
+ tags: z.array(z.string()).optional().describe("Tags to associate"),
86
+ folder_id: z.number().int().optional().describe("Folder ID to publish into"),
87
+ workspace_id: z.number().int().optional().describe("Workspace ID"),
88
+ }).describe("Template metadata: prompt_name (required), tags, folder_id, workspace_id"),
89
+ prompt_version: z.object({
90
+ prompt_template: z.record(z.unknown()).describe("The template content in chat ({type:'chat', messages:[...]}) or completion format"),
91
+ commit_message: z.string().optional().describe("Commit message (max 72 chars)"),
92
+ metadata: z.record(z.unknown()).optional().describe("Metadata including model configuration"),
93
+ provider_base_url_name: z.string().optional().describe("Provider base URL name (max 255 chars)"),
94
+ provider_id: z.number().int().optional().describe("Provider ID"),
95
+ inference_client_name: z.string().optional().describe("Inference client name (max 255 chars)"),
96
+ }).describe("Version data: prompt_template content (required), commit_message, metadata"),
97
+ release_labels: z.array(z.string()).optional().describe("Release labels to assign (e.g. ['prod'])"),
98
+ snippet_overrides: z.record(z.string()).optional().describe("Snippet overrides: map snippet names to replacement content"),
99
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
100
+ });
101
+
102
+ // ── List Prompt Template Labels (GET /prompt-templates/{identifier}/labels)
103
+
104
+ export const ListPromptTemplateLabelsArgsSchema = z.object({
105
+ identifier: z.string().describe("Prompt template name or ID"),
106
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
107
+ });
108
+
109
+ // ── Create Prompt Label (POST /prompts/{prompt_id}/label) ────────────────
110
+ // OpenAPI: body = { prompt_version_number: int, name: str }
111
+
112
+ export const CreatePromptLabelArgsSchema = z.object({
113
+ prompt_id: z.number().int().describe("The prompt ID (path parameter)"),
114
+ prompt_version_number: z.number().int().optional().describe("The version number to attach the label to (provide this or prompt_version_id)"),
115
+ prompt_version_id: z.number().int().optional().describe("The version ID to attach the label to (provide this or prompt_version_number)"),
116
+ name: z.string().describe("The label name (e.g. 'prod', 'staging')"),
117
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
118
+ });
119
+
120
+ // ── Move Prompt Label (PATCH /prompt-labels/{prompt_label_id}) ──────────
121
+ // OpenAPI: body = { prompt_version_number: int }
122
+
123
+ export const MovePromptLabelArgsSchema = z.object({
124
+ prompt_label_id: z.number().int().describe("The prompt label ID to move"),
125
+ prompt_version_number: z.number().int().optional().describe("Target version number to move the label to (provide this or prompt_version_id)"),
126
+ prompt_version_id: z.number().int().optional().describe("Target version ID to move the label to (provide this or prompt_version_number)"),
127
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
128
+ });
129
+
130
+ // ── Delete Prompt Label (DELETE /prompt-labels/{prompt_label_id}) ────────
131
+
132
+ export const DeletePromptLabelArgsSchema = z.object({
133
+ prompt_label_id: z.number().int().describe("The prompt label ID to delete"),
134
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
135
+ });
136
+
137
+ // ── Get Snippet Usage (GET /prompt-templates/{identifier}/snippet-usage) ─
138
+
139
+ export const GetSnippetUsageArgsSchema = z.object({
140
+ identifier: z.string().describe("Prompt template name or ID"),
141
+ prompt_version_number: z.number().int().optional().describe("Filter by specific version number"),
142
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
143
+ });
144
+
145
+
146
+ // ── Log Request (POST /log-request) ──────────────────────────────────────
147
+ // NOTE: OpenAPI defines input/output as oneOf(ChatPrompt, CompletionPrompt).
148
+ // We use z.record(z.unknown()) because the MCP tool passes them through as-is;
149
+ // the PromptLayer server validates the discriminated union, not us.
150
+ // This is tracked as a known exception in scripts/diff-endpoints.ts.
151
+
152
+ export const LogRequestArgsSchema = z.object({
153
+ provider: z.string().describe("LLM provider (e.g. 'openai', 'anthropic')"),
154
+ model: z.string().describe("Model name (e.g. 'gpt-4o', 'claude-3-7-sonnet-20250219')"),
155
+ input: z.record(z.unknown()).describe("Input in Prompt Blueprint format: {type:'chat', messages:[{role, content:[{type:'text', text}]}]}"),
156
+ output: z.record(z.unknown()).describe("Output in Prompt Blueprint format: {type:'chat', messages:[{role:'assistant', content:[{type:'text', text}]}]}"),
157
+ request_start_time: z.string().describe("ISO 8601 datetime when request started"),
158
+ request_end_time: z.string().describe("ISO 8601 datetime when response received"),
159
+ parameters: z.record(z.unknown()).optional().describe("Model parameters (temperature, max_tokens, response_format, etc.)"),
160
+ tags: z.array(z.string()).optional().describe("Tags for categorizing the request"),
161
+ score_name: z.string().optional().describe("Score name (for named scores, e.g. 'relevance')"),
162
+ metadata: z.record(z.string()).optional().describe("Custom key-value metadata for search/filtering"),
163
+ prompt_name: z.string().optional().describe("Prompt template name to associate"),
164
+ prompt_id: z.number().int().optional().describe("Prompt template ID to associate"),
165
+ prompt_version_number: z.number().int().optional().describe("Prompt template version number"),
166
+ prompt_input_variables: z.record(z.unknown()).optional().describe("Variables used to format the prompt"),
167
+ input_tokens: z.number().int().optional().describe("Number of input tokens"),
168
+ output_tokens: z.number().int().optional().describe("Number of output tokens"),
169
+ price: z.number().optional().describe("Cost of the request"),
170
+ function_name: z.string().optional().describe("Name of the function called"),
171
+ score: z.number().int().optional().describe("Score between 0-100"),
172
+ api_type: z.string().optional().describe("API type for openai/azure (e.g. 'chat-completions', 'responses')"),
173
+ status: z.enum(["SUCCESS", "WARNING", "ERROR"]).optional().describe("Request status (default: SUCCESS)"),
174
+ error_type: z.enum([
175
+ "PROVIDER_TIMEOUT", "PROVIDER_QUOTA_LIMIT", "PROVIDER_RATE_LIMIT",
176
+ "PROVIDER_AUTH_ERROR", "PROVIDER_ERROR", "TEMPLATE_RENDER_ERROR",
177
+ "VARIABLE_MISSING_OR_EMPTY", "UNKNOWN_ERROR",
178
+ ]).optional().describe("Error type (only when status is ERROR or WARNING)"),
179
+ error_message: z.string().optional().describe("Error message (max 1024 chars)"),
180
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
181
+ });
182
+
183
+ // ── Create Spans Bulk (POST /spans-bulk) ─────────────────────────────────
184
+
185
+ export const CreateSpansBulkArgsSchema = z.object({
186
+ spans: z.array(z.record(z.unknown())).describe("Array of span objects (each with name, context, kind, start_time, end_time, status, attributes, resource; optional: parent_id, log_request)"),
187
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
188
+ });
189
+
190
+
191
+ // ── List Datasets (GET /api/public/v2/datasets) ──────────────────────────
192
+
193
+ export const ListDatasetsArgsSchema = z.object({
194
+ page: z.number().int().optional().describe("Page number (default: 1)"),
195
+ per_page: z.number().int().optional().describe("Items per page (default: 10)"),
196
+ name: z.string().optional().describe("Filter by dataset group name (case-insensitive partial match)"),
197
+ status: z.enum(["active", "deleted", "all"]).optional().describe("Filter by status (default: 'active')"),
198
+ dataset_group_id: z.number().int().optional().describe("Filter by dataset group ID"),
199
+ prompt_id: z.number().int().optional().describe("Filter by prompt ID"),
200
+ prompt_version_id: z.number().int().optional().describe("Filter by prompt version ID"),
201
+ prompt_label_id: z.number().int().optional().describe("Filter by prompt label ID"),
202
+ report_id: z.number().int().optional().describe("Filter by report ID"),
203
+ workspace_id: z.number().int().optional().describe("Filter by workspace ID"),
204
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
205
+ });
206
+
207
+ // ── Create Dataset Group (POST /api/public/v2/dataset-groups) ────────────
208
+
209
+ export const CreateDatasetGroupArgsSchema = z.object({
210
+ name: z.string().optional().describe("Dataset group name (unique within workspace). Auto-generated if omitted."),
211
+ workspace_id: z.number().int().optional().describe("Workspace ID"),
212
+ folder_id: z.number().int().optional().describe("Folder ID to place the dataset group into"),
213
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
214
+ });
215
+
216
+ // ── Create Dataset Version from File (POST /api/public/v2/dataset-versions/from-file)
217
+
218
+ export const CreateDatasetVersionFromFileArgsSchema = z.object({
219
+ dataset_group_id: z.number().int().describe("Dataset group ID"),
220
+ file_name: z.string().describe("File name with extension (e.g. 'data.csv' or 'data.json')"),
221
+ file_content_base64: z.string().describe("Base64-encoded file content"),
222
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
223
+ });
224
+
225
+ // ── Create Dataset Version from Filter Params (POST /api/public/v2/dataset-versions/from-filter-params)
226
+
227
+ export const CreateDatasetVersionFromFilterParamsArgsSchema = z.object({
228
+ dataset_group_id: z.number().int().describe("Dataset group ID"),
229
+ variables_to_parse: z.array(z.string()).optional().describe("Variables to extract from request logs"),
230
+ prompt_id: z.number().int().optional().describe("Filter by prompt template ID"),
231
+ prompt_version_id: z.number().int().optional().describe("Filter by prompt version ID"),
232
+ prompt_label_id: z.number().int().optional().describe("Filter by prompt label ID"),
233
+ workspace_id: z.number().int().optional().describe("Workspace ID"),
234
+ tags: z.array(z.string()).optional().describe("Filter by tags (simple tag filter)"),
235
+ metadata: z.record(z.string()).optional().describe("Simple metadata key-value filter"),
236
+ start_time: z.string().optional().describe("Start time filter (ISO 8601)"),
237
+ end_time: z.string().optional().describe("End time filter (ISO 8601)"),
238
+ id: z.number().int().optional().describe("Filter by specific request log ID"),
239
+ limit: z.number().int().optional().describe("Limit number of request logs to pull"),
240
+ tags_and: z.array(z.string()).optional().describe("Filter by tags (AND logic — all must match)"),
241
+ tags_or: z.array(z.string()).optional().describe("Filter by tags (OR logic — any can match)"),
242
+ metadata_and: z.array(z.object({ key: z.string(), value: z.string() })).optional().describe("Metadata filters with AND logic (all must match). Each item: {key, value}"),
243
+ metadata_or: z.array(z.object({ key: z.string(), value: z.string() })).optional().describe("Metadata filters with OR logic (any can match). Each item: {key, value}"),
244
+ scores: z.array(z.object({
245
+ name: z.string().describe("Score name"),
246
+ operator: z.enum([">", "<", ">=", "<=", "="]).describe("Comparison operator"),
247
+ value: z.number().int().describe("Score value to compare against"),
248
+ })).optional().describe("Filter by score criteria. Each item: {name, operator, value}"),
249
+ prompt_templates_include: z.array(z.object({
250
+ name: z.string().describe("Prompt template name"),
251
+ version_numbers: z.array(z.number().int()).optional().describe("Filter to specific version numbers"),
252
+ labels: z.array(z.string()).optional().describe("Filter to specific labels"),
253
+ })).optional().describe("Include request logs matching these prompt templates"),
254
+ prompt_templates_exclude: z.array(z.object({
255
+ name: z.string().describe("Prompt template name"),
256
+ version_numbers: z.array(z.number().int()).optional().describe("Filter to specific version numbers"),
257
+ labels: z.array(z.string()).optional().describe("Filter to specific labels"),
258
+ })).optional().describe("Exclude request logs matching these prompt templates"),
259
+ starred: z.boolean().optional().describe("Filter by starred status"),
260
+ status: z.array(z.enum(["SUCCESS", "WARNING", "ERROR"])).optional().describe("Filter by request log status"),
261
+ sort_by: z.enum([
262
+ "request_start_time", "input_tokens", "output_tokens", "price",
263
+ "score", "latency", "prompt_name", "status",
264
+ ]).optional().describe("Sort field"),
265
+ sort_order: z.enum(["asc", "desc"]).optional().describe("Sort direction"),
266
+ order_by_random: z.boolean().optional().describe("Random ordering (requires limit)"),
267
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
268
+ });
269
+
270
+
271
+ // ── List Evaluations (GET /api/public/v2/evaluations) ────────────────────
272
+
273
+ export const ListEvaluationsArgsSchema = z.object({
274
+ page: z.number().int().optional().describe("Page number (default: 1)"),
275
+ per_page: z.number().int().optional().describe("Items per page (default: 10)"),
276
+ name: z.string().optional().describe("Filter by name (case-insensitive partial match)"),
277
+ status: z.enum(["active", "deleted", "all"]).optional().describe("Filter by status (default: 'active')"),
278
+ workspace_id: z.number().int().optional().describe("Filter by workspace ID"),
279
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
280
+ });
281
+
282
+ // ── Create Evaluation Pipeline / Report (POST /reports) ──────────────────
283
+
284
+ export const CreateReportArgsSchema = z.object({
285
+ dataset_group_id: z.number().int().describe("Dataset group ID"),
286
+ name: z.string().optional().describe("Pipeline name (auto-generated if omitted)"),
287
+ folder_id: z.number().int().optional().describe("Folder ID for organization"),
288
+ dataset_version_number: z.number().int().optional().describe("Dataset version (uses latest if omitted)"),
289
+ columns: z.array(z.record(z.unknown())).optional().describe("Evaluation columns (each: column_type, name, configuration)"),
290
+ score_configuration: z.record(z.unknown()).optional().describe("Custom scoring logic configuration"),
291
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
292
+ });
293
+
294
+ // ── Run Evaluation (POST /reports/{report_id}/run) ───────────────────────
295
+
296
+ export const RunReportArgsSchema = z.object({
297
+ report_id: z.number().int().describe("Evaluation pipeline ID"),
298
+ name: z.string().describe("Name for this evaluation run"),
299
+ dataset_id: z.number().int().optional().describe("Override dataset ID"),
300
+ refresh_dataset: z.boolean().optional().describe("Refresh the dataset before running"),
301
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
302
+ });
303
+
304
+ // ── Get Evaluation (GET /reports/{report_id}) ────────────────────────────
305
+
306
+ export const GetReportArgsSchema = z.object({
307
+ report_id: z.number().int().describe("Evaluation pipeline ID"),
308
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
309
+ });
310
+
311
+ // ── Get Evaluation Score (GET /reports/{report_id}/score) ────────────────
312
+
313
+ export const GetReportScoreArgsSchema = z.object({
314
+ report_id: z.number().int().describe("Evaluation pipeline ID"),
315
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
316
+ });
317
+
318
+ // ── Configure Custom Scoring (PATCH /reports/{report_id}/score-card) ─────
319
+ // NOTE: This endpoint is in the PromptLayer reference docs but NOT in the
320
+ // OpenAPI spec. Tracked as a known exception in scripts/diff-endpoints.ts.
321
+ // See: https://docs.promptlayer.com/reference/update-report-score-card
322
+
323
+ export const UpdateReportScoreCardArgsSchema = z.object({
324
+ report_id: z.number().int().describe("Evaluation pipeline ID"),
325
+ column_names: z.array(z.string()).describe("Column names to include in score"),
326
+ code: z.string().optional().describe("Custom Python/JavaScript code for score calculation"),
327
+ code_language: z.enum(["PYTHON", "JAVASCRIPT"]).optional().describe("Code language (default: PYTHON)"),
328
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
329
+ });
330
+
331
+ // ── Delete Reports by Name (DELETE /reports/name/{report_name}) ──────────
332
+
333
+ export const DeleteReportsByNameArgsSchema = z.object({
334
+ report_name: z.string().describe("Name of reports to archive"),
335
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
336
+ });
337
+
338
+
339
+ // ── List Agents (GET /workflows) ─────────────────────────────────────────
340
+
341
+ export const ListWorkflowsArgsSchema = z.object({
342
+ page: z.number().int().optional().describe("Page number (default: 1)"),
343
+ per_page: z.number().int().optional().describe("Items per page (default: 30)"),
344
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
345
+ });
346
+
347
+ // ── Create Agent (POST /rest/workflows) ──────────────────────────────────
348
+
349
+ export const CreateWorkflowArgsSchema = z.object({
350
+ name: z.string().optional().describe("Name for a new agent. Cannot be used with workflow_id or workflow_name."),
351
+ workflow_id: z.number().int().optional().describe("Existing agent ID to create a new version for"),
352
+ workflow_name: z.string().optional().describe("Existing agent name to create a new version for"),
353
+ folder_id: z.number().int().optional().describe("Folder ID"),
354
+ commit_message: z.string().optional().describe("Version commit message"),
355
+ nodes: z.array(z.record(z.unknown())).describe("Node configs (each: name, node_type, configuration, is_output_node required; dependencies optional)"),
356
+ required_input_variables: z.record(z.string()).optional().describe("Input variable names to types, e.g. {user_query: 'string'}"),
357
+ edges: z.array(z.record(z.unknown())).optional().describe("Conditional connections between nodes"),
358
+ release_labels: z.array(z.string()).optional().describe("Release labels (e.g. ['production'])"),
359
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
360
+ });
361
+
362
+ // ── Update Agent / PATCH (PATCH /rest/workflows/{workflow_id_or_name}) ───
363
+
364
+ export const PatchWorkflowArgsSchema = z.object({
365
+ workflow_id_or_name: z.string().describe("Agent ID or name (path parameter)"),
366
+ base_version: z.number().int().optional().describe("Version to base changes on (defaults to latest)"),
367
+ commit_message: z.string().optional().describe("Version commit message"),
368
+ nodes: z.record(z.unknown()).optional().describe("Node updates keyed by name. Set value to null to remove a node."),
369
+ required_input_variables: z.record(z.string()).optional().describe("Replaces input variables entirely if provided"),
370
+ edges: z.array(z.record(z.unknown())).optional().describe("Replaces edges entirely if provided"),
371
+ release_labels: z.array(z.string()).optional().describe("Labels for the new version"),
372
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
373
+ });
374
+
375
+ // ── Run Agent (POST /workflows/{workflow_name}/run) ──────────────────────
376
+
377
+ export const RunWorkflowArgsSchema = z.object({
378
+ workflow_name: z.string().describe("Agent name (path parameter)"),
379
+ input_variables: z.record(z.unknown()).optional().describe("Input variables for the agent"),
380
+ workflow_version_number: z.number().int().optional().describe("Version number to run (defaults to latest)"),
381
+ workflow_label_name: z.string().optional().describe("Release label to run (e.g. 'prod')"),
382
+ metadata: z.record(z.string()).optional().describe("Metadata to attach to the execution"),
383
+ return_all_outputs: z.boolean().optional().describe("Return all node outputs (default: false, returns only final output)"),
384
+ // NOTE: callback_url is in the reference docs but not the OpenAPI spec.
385
+ // Tracked as a known exception in scripts/diff-endpoints.ts.
386
+ callback_url: z.string().optional().describe("Webhook URL for async results. Returns 202 immediately, POSTs results on completion."),
387
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
388
+ });
389
+
390
+ // ── Get Agent Version Execution Results (GET /workflow-version-execution-results)
391
+
392
+ export const GetWorkflowVersionExecutionResultsArgsSchema = z.object({
393
+ workflow_version_execution_id: z.number().int().describe("Execution ID to retrieve results for"),
394
+ return_all_outputs: z.boolean().optional().describe("Include all output nodes (default: false)"),
395
+ workflow_node_id: z.number().int().optional().describe("Filter results to a specific node by ID"),
396
+ workflow_node_name: z.string().optional().describe("Filter results to a specific node by name"),
397
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
398
+ });
399
+
400
+
401
+ // ── Get Agent (GET /workflows/{workflow_id_or_name}) ─────────────────────
402
+
403
+ export const GetWorkflowArgsSchema = z.object({
404
+ workflow_id_or_name: z.string().describe("Agent ID or name"),
405
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
406
+ });
407
+
408
+
409
+ export const CreateFolderArgsSchema = z.object({
410
+ name: z.string().describe("Folder name (unique within parent)"),
411
+ parent_id: z.number().int().optional().describe("Parent folder ID (root if omitted)"),
412
+ workspace_id: z.number().int().optional().describe("Workspace ID"),
413
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
414
+ });
415
+
416
+ // ── Edit Folder (PATCH /api/public/v2/folders/{folder_id}) ───────────────
417
+ // NOTE: Not yet in the OpenAPI spec. Added from backend source (PR #244).
418
+ // Tracked as a known exception in scripts/diff-endpoints.ts.
419
+
420
+ export const EditFolderArgsSchema = z.object({
421
+ folder_id: z.number().int().describe("Folder ID to rename"),
422
+ name: z.string().describe("New folder name (1-255 chars, unique within parent)"),
423
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
424
+ });
425
+
426
+ // ── Get Folder Entities (GET /api/public/v2/folders/entities) ────────────
427
+ // NOTE: Not yet in the OpenAPI spec. Added from backend source.
428
+ // Tracked as a known exception in scripts/diff-endpoints.ts.
429
+
430
+ const EntityTypeEnum = z.enum([
431
+ "FOLDER", "PROMPT", "SNIPPET", "WORKFLOW", "DATASET", "REPORT", "AB_TEST", "INPUT_VARIABLE_SET",
432
+ ]);
433
+
434
+ export const GetFolderEntitiesArgsSchema = z.object({
435
+ folder_id: z.number().int().optional().describe("Folder ID to list (root if omitted)"),
436
+ filter_type: z.union([EntityTypeEnum, z.array(EntityTypeEnum)]).optional().describe("Entity type(s) to include (default: all)"),
437
+ search_query: z.string().optional().describe("Search by name (case-insensitive partial match)"),
438
+ flatten: z.boolean().optional().describe("Flatten nested folder hierarchy (default: false)"),
439
+ include_metadata: z.boolean().optional().describe("Include entity metadata like latest_version_number (default: false)"),
440
+ workspace_id: z.number().int().optional().describe("Workspace ID"),
441
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
442
+ });
443
+
444
+ // ── Move Folder Entities (POST /api/public/v2/folders/entities) ──────────
445
+ // NOTE: Not yet in the OpenAPI spec. Added from backend source.
446
+ // Tracked as a known exception in scripts/diff-endpoints.ts.
447
+
448
+ export const MoveFolderEntitiesArgsSchema = z.object({
449
+ entities: z.array(z.object({
450
+ id: z.number().int().describe("Entity ID"),
451
+ type: EntityTypeEnum.describe("Entity type"),
452
+ })).describe("Entities to move"),
453
+ folder_id: z.number().int().optional().describe("Target folder ID (root if omitted)"),
454
+ workspace_id: z.number().int().optional().describe("Workspace ID"),
455
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
456
+ });
457
+
458
+ // ── Delete Folder Entities (DELETE /api/public/v2/folders/entities) ───────
459
+ // NOTE: Not yet in the OpenAPI spec. Added from backend source.
460
+ // Tracked as a known exception in scripts/diff-endpoints.ts.
461
+
462
+ export const DeleteFolderEntitiesArgsSchema = z.object({
463
+ entities: z.array(z.object({
464
+ id: z.number().int().describe("Entity ID"),
465
+ type: EntityTypeEnum.describe("Entity type"),
466
+ })).describe("Entities to delete"),
467
+ cascade: z.boolean().optional().describe("Delete folder contents recursively (default: false)"),
468
+ workspace_id: z.number().int().optional().describe("Workspace ID"),
469
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
470
+ });
471
+
472
+ // ── Resolve Folder ID (GET /api/public/v2/folders/resolve-id) ────────────
473
+ // NOTE: Not yet in the OpenAPI spec. Added from backend source.
474
+ // Tracked as a known exception in scripts/diff-endpoints.ts.
475
+
476
+ export const ResolveFolderIdArgsSchema = z.object({
477
+ path: z.string().describe("Folder path to resolve (e.g. 'foo/bar')"),
478
+ workspace_id: z.number().int().optional().describe("Workspace ID"),
479
+ api_key: z.string().optional().describe("PromptLayer API key (optional, defaults to PROMPTLAYER_API_KEY env var)"),
480
+ });
481
+
482
+
483
+ export type GetPromptTemplateParams = Omit<
484
+ z.infer<typeof GetPromptTemplateArgsSchema>,
485
+ "prompt_name" | "api_key"
486
+ >;
487
+ export type ListPromptTemplatesParams = Omit<
488
+ z.infer<typeof ListPromptTemplatesArgsSchema>,
489
+ "api_key"
490
+ >;
491
+
492
+
493
+ export const TOOL_DEFINITIONS = {
494
+ // ── Prompt Templates ────────────────────────────────────────────────
495
+ "get-prompt-template": {
496
+ name: "get-prompt-template",
497
+ description:
498
+ "Retrieve a fully rendered prompt ready to send to an LLM. Fills in input_variables, resolves " +
499
+ "snippets, and returns provider-formatted parameters. Use label (e.g. 'prod') or version number " +
500
+ "to pin a specific version; defaults to latest. " +
501
+ "WARNING: Snippets are baked into the output — @@@snippet@@@ references are lost. " +
502
+ "Do NOT use this for editing and re-publishing prompts. Use get-prompt-template-raw instead.",
503
+ inputSchema: GetPromptTemplateArgsSchema,
504
+ annotations: { readOnlyHint: true },
505
+ },
506
+ "get-prompt-template-raw": {
507
+ name: "get-prompt-template-raw",
508
+ description:
509
+ "Retrieve prompt template data for inspection or editing. Does not apply input variables. " +
510
+ "IMPORTANT: Set resolve_snippets=false to preserve @@@snippet_name@@@ references — " +
511
+ "this is required if you plan to edit and re-publish the prompt, otherwise snippet references " +
512
+ "will be lost. The response includes a 'snippets' array listing all referenced snippets. " +
513
+ "Set include_llm_kwargs=true to also get provider-specific parameters.",
514
+ inputSchema: GetPromptTemplateRawArgsSchema,
515
+ annotations: { readOnlyHint: true },
516
+ },
517
+ "list-prompt-templates": {
518
+ name: "list-prompt-templates",
519
+ description: "List all prompt templates in the workspace with pagination. Filter by name, release label, or status.",
520
+ inputSchema: ListPromptTemplatesArgsSchema,
521
+ annotations: { readOnlyHint: true },
522
+ },
523
+ "publish-prompt-template": {
524
+ name: "publish-prompt-template",
525
+ description:
526
+ "Create a new version of a prompt template. " +
527
+ "Body has two required objects: prompt_template (with prompt_name, tags, folder_id) and " +
528
+ "prompt_version (with prompt_template content in chat/completion format, commit_message, metadata). " +
529
+ "Optionally assign release_labels. " +
530
+ "IMPORTANT: If the prompt uses snippets, preserve @@@snippet_name@@@ markers in the content. " +
531
+ "Do not inline snippet text — this breaks snippet references.",
532
+ inputSchema: PublishPromptTemplateArgsSchema,
533
+ annotations: { readOnlyHint: false },
534
+ },
535
+ "list-prompt-template-labels": {
536
+ name: "list-prompt-template-labels",
537
+ description: "List all release labels assigned to a prompt template.",
538
+ inputSchema: ListPromptTemplateLabelsArgsSchema,
539
+ annotations: { readOnlyHint: true },
540
+ },
541
+ "create-prompt-label": {
542
+ name: "create-prompt-label",
543
+ description: "Attach a release label to a prompt template version. Requires prompt_id (path) and body with prompt_version_number and label name.",
544
+ inputSchema: CreatePromptLabelArgsSchema,
545
+ annotations: { readOnlyHint: false },
546
+ },
547
+ "move-prompt-label": {
548
+ name: "move-prompt-label",
549
+ description: "Move a release label to a different prompt version. Provide prompt_version_number to reassign the label.",
550
+ inputSchema: MovePromptLabelArgsSchema,
551
+ annotations: { readOnlyHint: false },
552
+ },
553
+ "delete-prompt-label": {
554
+ name: "delete-prompt-label",
555
+ description: "Delete a release label from a prompt template version.",
556
+ inputSchema: DeletePromptLabelArgsSchema,
557
+ annotations: { readOnlyHint: false },
558
+ },
559
+ "get-snippet-usage": {
560
+ name: "get-snippet-usage",
561
+ description: "Find all prompts that reference a given snippet. Returns prompt names, versions, and labels that use it.",
562
+ inputSchema: GetSnippetUsageArgsSchema,
563
+ annotations: { readOnlyHint: true },
564
+ },
565
+
566
+ // ── Tracking ────────────────────────────────────────────────────────
567
+ "log-request": {
568
+ name: "log-request",
569
+ description:
570
+ "Log an LLM request/response pair to PromptLayer. Input and output must be in Prompt Blueprint " +
571
+ "format: {type:'chat', messages:[{role, content:[{type:'text', text}]}]}. " +
572
+ "Supports structured outputs, tool calls, extended thinking, and error tracking.",
573
+ inputSchema: LogRequestArgsSchema,
574
+ annotations: { readOnlyHint: false },
575
+ },
576
+ "create-spans-bulk": {
577
+ name: "create-spans-bulk",
578
+ description: "Create OpenTelemetry-compatible spans in bulk for distributed tracing. Each span can optionally include a log_request.",
579
+ inputSchema: CreateSpansBulkArgsSchema,
580
+ annotations: { readOnlyHint: false },
581
+ },
582
+
583
+ // ── Datasets ────────────────────────────────────────────────────────
584
+ "list-datasets": {
585
+ name: "list-datasets",
586
+ description: "List datasets with pagination. Filter by name, status, dataset_group_id, prompt_id, report_id, etc.",
587
+ inputSchema: ListDatasetsArgsSchema,
588
+ annotations: { readOnlyHint: true },
589
+ },
590
+ "create-dataset-group": {
591
+ name: "create-dataset-group",
592
+ description: "Create a dataset group. An empty draft version (version_number=-1) is created automatically. Names must be unique per workspace.",
593
+ inputSchema: CreateDatasetGroupArgsSchema,
594
+ annotations: { readOnlyHint: false },
595
+ },
596
+ "create-dataset-version-from-file": {
597
+ name: "create-dataset-version-from-file",
598
+ description: "Create a dataset version by uploading base64-encoded CSV/JSON content. Processed asynchronously. Max 100MB.",
599
+ inputSchema: CreateDatasetVersionFromFileArgsSchema,
600
+ annotations: { readOnlyHint: false },
601
+ },
602
+ "create-dataset-version-from-filter-params": {
603
+ name: "create-dataset-version-from-filter-params",
604
+ description: "Create a dataset version from request log history using filter criteria. Populated asynchronously.",
605
+ inputSchema: CreateDatasetVersionFromFilterParamsArgsSchema,
606
+ annotations: { readOnlyHint: false },
607
+ },
608
+
609
+ // ── Evaluations ─────────────────────────────────────────────────────
610
+ "list-evaluations": {
611
+ name: "list-evaluations",
612
+ description: "List evaluation pipelines (called 'reports' in the API) with pagination. Filter by name, status, workspace_id.",
613
+ inputSchema: ListEvaluationsArgsSchema,
614
+ annotations: { readOnlyHint: true },
615
+ },
616
+ "create-report": {
617
+ name: "create-report",
618
+ description: "Create an evaluation pipeline (called 'report' in the API) linked to a dataset group. The recommended approach is to add LLM assertion columns that use a language model to score each row. For all available column types, search the PromptLayer docs or visit https://docs.promptlayer.com/features/evaluations/column-types.",
619
+ inputSchema: CreateReportArgsSchema,
620
+ annotations: { readOnlyHint: false },
621
+ },
622
+ "run-report": {
623
+ name: "run-report",
624
+ description: "Execute an evaluation pipeline. Runs all columns against the dataset and produces scores. Name is required.",
625
+ inputSchema: RunReportArgsSchema,
626
+ annotations: { readOnlyHint: false },
627
+ },
628
+ "get-report": {
629
+ name: "get-report",
630
+ description: "Get evaluation pipeline details including columns and configuration. Use get-report-score for the computed score.",
631
+ inputSchema: GetReportArgsSchema,
632
+ annotations: { readOnlyHint: true },
633
+ },
634
+ "get-report-score": {
635
+ name: "get-report-score",
636
+ description: "Get the computed score for an evaluation pipeline.",
637
+ inputSchema: GetReportScoreArgsSchema,
638
+ annotations: { readOnlyHint: true },
639
+ },
640
+ "update-report-score-card": {
641
+ name: "update-report-score-card",
642
+ description: "Configure custom scoring for an evaluation pipeline. Specify which column_names contribute to the score, with optional custom code.",
643
+ inputSchema: UpdateReportScoreCardArgsSchema,
644
+ annotations: { readOnlyHint: false },
645
+ },
646
+ "delete-reports-by-name": {
647
+ name: "delete-reports-by-name",
648
+ description: "Archive all evaluation pipelines matching the given name.",
649
+ inputSchema: DeleteReportsByNameArgsSchema,
650
+ annotations: { readOnlyHint: false },
651
+ },
652
+
653
+ // ── Agents / Workflows ──────────────────────────────────────────────
654
+ "list-workflows": {
655
+ name: "list-workflows",
656
+ description: "List all agents (called 'workflows' in the API) in the workspace with pagination.",
657
+ inputSchema: ListWorkflowsArgsSchema,
658
+ annotations: { readOnlyHint: true },
659
+ },
660
+ "create-workflow": {
661
+ name: "create-workflow",
662
+ description: "Create a new agent (called 'workflow' in the API) or a new version of an existing one. For new: use 'name'. For versioning: use workflow_id or workflow_name.",
663
+ inputSchema: CreateWorkflowArgsSchema,
664
+ annotations: { readOnlyHint: false },
665
+ },
666
+ "patch-workflow": {
667
+ name: "patch-workflow",
668
+ description: "Partially update an agent. Merges node changes into a new version. Set a node value to null to remove it.",
669
+ inputSchema: PatchWorkflowArgsSchema,
670
+ annotations: { readOnlyHint: false },
671
+ },
672
+ "run-workflow": {
673
+ name: "run-workflow",
674
+ description: "Execute an agent by name. Returns results synchronously, or returns immediately with an execution ID if callback_url is set for async webhook delivery.",
675
+ inputSchema: RunWorkflowArgsSchema,
676
+ annotations: { readOnlyHint: false },
677
+ },
678
+ "get-workflow-version-execution-results": {
679
+ name: "get-workflow-version-execution-results",
680
+ description: "Poll for agent execution results by execution ID. Returns results when complete, or indicates still running.",
681
+ inputSchema: GetWorkflowVersionExecutionResultsArgsSchema,
682
+ annotations: { readOnlyHint: true },
683
+ },
684
+ "get-workflow": {
685
+ name: "get-workflow",
686
+ description: "Get a single agent (called 'workflow' in the API) by ID or name. Returns the agent details and configuration.",
687
+ inputSchema: GetWorkflowArgsSchema,
688
+ annotations: { readOnlyHint: true },
689
+ },
690
+
691
+ // ── Folders ─────────────────────────────────────────────────────────
692
+ "create-folder": {
693
+ name: "create-folder",
694
+ description: "Create a folder for organizing resources. Nest with parent_id. Names unique within parent.",
695
+ inputSchema: CreateFolderArgsSchema,
696
+ annotations: { readOnlyHint: false },
697
+ },
698
+ "edit-folder": {
699
+ name: "edit-folder",
700
+ description: "Rename a folder. Name must be unique within the parent folder.",
701
+ inputSchema: EditFolderArgsSchema,
702
+ annotations: { readOnlyHint: false },
703
+ },
704
+ "get-folder-entities": {
705
+ name: "get-folder-entities",
706
+ description: "List entities (prompts, agents, datasets, evaluations, folders, etc.) in a folder. Returns root-level entities if folder_id is omitted. Use flatten=true to include all nested contents. Supports search and type filtering.",
707
+ inputSchema: GetFolderEntitiesArgsSchema,
708
+ annotations: { readOnlyHint: true },
709
+ },
710
+ "move-folder-entities": {
711
+ name: "move-folder-entities",
712
+ description: "Move entities (prompts, agents, datasets, evaluations, folders) into a target folder. Omit folder_id to move to workspace root.",
713
+ inputSchema: MoveFolderEntitiesArgsSchema,
714
+ annotations: { readOnlyHint: false },
715
+ },
716
+ "delete-folder-entities": {
717
+ name: "delete-folder-entities",
718
+ description: "Permanently delete entities (prompts, agents, datasets, evaluations, folders). WARNING: This is destructive and cannot be undone. Use cascade=true to recursively delete all folder contents.",
719
+ inputSchema: DeleteFolderEntitiesArgsSchema,
720
+ annotations: { readOnlyHint: false },
721
+ },
722
+ "resolve-folder-id": {
723
+ name: "resolve-folder-id",
724
+ description: "Resolve a folder path (e.g. 'foo/bar') to a folder ID.",
725
+ inputSchema: ResolveFolderIdArgsSchema,
726
+ annotations: { readOnlyHint: true },
727
+ },
728
+ } as const;