portkey-admin-mcp 0.16.4 → 0.16.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ENDPOINTS.md +29 -29
- package/README.md +136 -129
- package/build/index.js +525 -262
- package/build/server.js +555 -232
- package/docs/DISTRIBUTION.md +72 -26
- package/docs/VERCEL_DEPLOYMENT.md +4 -3
- package/package.json +7 -7
package/build/index.js
CHANGED
|
@@ -3,6 +3,120 @@
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
import { serveStdio } from "@modelcontextprotocol/server/stdio";
|
|
5
5
|
|
|
6
|
+
// src/lib/fetch.ts
|
|
7
|
+
var FetchError = class extends Error {
|
|
8
|
+
constructor(message, status, response) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.status = status;
|
|
11
|
+
this.response = response;
|
|
12
|
+
this.name = "FetchError";
|
|
13
|
+
}
|
|
14
|
+
status;
|
|
15
|
+
response;
|
|
16
|
+
};
|
|
17
|
+
var DEFAULT_MAX_UPSTREAM_BODY_BYTES = 8 * 1024 * 1024;
|
|
18
|
+
var DEFAULT_MAX_TOOL_RESULT_BYTES = 4 * 1024 * 1024;
|
|
19
|
+
var MAX_CONFIGURABLE_BYTES = 1024 * 1024 * 1024;
|
|
20
|
+
var MAX_UPSTREAM_BODY_BYTES_ENV = "PORTKEY_MAX_UPSTREAM_BODY_BYTES";
|
|
21
|
+
var MAX_TOOL_RESULT_BYTES_ENV = "PORTKEY_MAX_TOOL_RESULT_BYTES";
|
|
22
|
+
function resolveByteLimit(envName, fallback) {
|
|
23
|
+
const raw = process.env[envName]?.trim();
|
|
24
|
+
if (!raw) return fallback;
|
|
25
|
+
const parsed = /^\d+$/.test(raw) ? Number(raw) : Number.NaN;
|
|
26
|
+
if (!Number.isSafeInteger(parsed) || parsed < 1 || parsed > MAX_CONFIGURABLE_BYTES) {
|
|
27
|
+
throw new Error(
|
|
28
|
+
`Invalid ${envName} value: ${raw}. Must be a positive integer number of bytes (1-${MAX_CONFIGURABLE_BYTES})`
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
return parsed;
|
|
32
|
+
}
|
|
33
|
+
function getMaxUpstreamBodyBytes() {
|
|
34
|
+
return resolveByteLimit(
|
|
35
|
+
MAX_UPSTREAM_BODY_BYTES_ENV,
|
|
36
|
+
DEFAULT_MAX_UPSTREAM_BODY_BYTES
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
function getMaxToolResultBytes() {
|
|
40
|
+
return resolveByteLimit(
|
|
41
|
+
MAX_TOOL_RESULT_BYTES_ENV,
|
|
42
|
+
DEFAULT_MAX_TOOL_RESULT_BYTES
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
function assertByteLimitsConfigured() {
|
|
46
|
+
getMaxUpstreamBodyBytes();
|
|
47
|
+
getMaxToolResultBytes();
|
|
48
|
+
}
|
|
49
|
+
var ResponseBodyTooLargeError = class extends Error {
|
|
50
|
+
constructor(limit) {
|
|
51
|
+
super(`Response body is larger than the ${limit}-byte limit`);
|
|
52
|
+
this.limit = limit;
|
|
53
|
+
this.name = "ResponseBodyTooLargeError";
|
|
54
|
+
}
|
|
55
|
+
limit;
|
|
56
|
+
};
|
|
57
|
+
async function readBoundedText(response, maxBytes) {
|
|
58
|
+
if (!response.body) return "";
|
|
59
|
+
const reader = response.body.getReader();
|
|
60
|
+
const chunks = [];
|
|
61
|
+
let received = 0;
|
|
62
|
+
try {
|
|
63
|
+
for (; ; ) {
|
|
64
|
+
const { done, value } = await reader.read();
|
|
65
|
+
if (done) break;
|
|
66
|
+
received += value.byteLength;
|
|
67
|
+
if (received > maxBytes) {
|
|
68
|
+
await reader.cancel().catch(() => void 0);
|
|
69
|
+
throw new ResponseBodyTooLargeError(maxBytes);
|
|
70
|
+
}
|
|
71
|
+
chunks.push(value);
|
|
72
|
+
}
|
|
73
|
+
} finally {
|
|
74
|
+
reader.releaseLock();
|
|
75
|
+
}
|
|
76
|
+
return new TextDecoder().decode(Buffer.concat(chunks));
|
|
77
|
+
}
|
|
78
|
+
async function readBoundedJson(response, maxBytes) {
|
|
79
|
+
return JSON.parse(await readBoundedText(response, maxBytes));
|
|
80
|
+
}
|
|
81
|
+
async function fetchWithTimeout(url, options = {}) {
|
|
82
|
+
const { timeout = 3e4, ...fetchOptions } = options;
|
|
83
|
+
return fetch(url, {
|
|
84
|
+
...fetchOptions,
|
|
85
|
+
signal: AbortSignal.timeout(timeout)
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function buildQueryString(params) {
|
|
89
|
+
if (!params) return "";
|
|
90
|
+
const entries = Object.entries(params).flatMap(([key, value]) => {
|
|
91
|
+
if (value === void 0 || value === null) return [];
|
|
92
|
+
if (Array.isArray(value)) {
|
|
93
|
+
return value.map((item) => [key, String(item)]);
|
|
94
|
+
}
|
|
95
|
+
return [[key, String(value)]];
|
|
96
|
+
});
|
|
97
|
+
if (entries.length === 0) return "";
|
|
98
|
+
return `?${new URLSearchParams(entries).toString()}`;
|
|
99
|
+
}
|
|
100
|
+
async function parseErrorResponse(response, maxBytes = DEFAULT_MAX_UPSTREAM_BODY_BYTES) {
|
|
101
|
+
try {
|
|
102
|
+
const body = await readBoundedJson(response, maxBytes);
|
|
103
|
+
const err = body.error ?? body.data ?? body ?? {};
|
|
104
|
+
const code = err?.errorCode ?? err?.code;
|
|
105
|
+
return {
|
|
106
|
+
status_code: body?.status_code ?? response.status,
|
|
107
|
+
message: err?.message ?? `HTTP error! status: ${response.status}${code ? ` (${code})` : ""}`,
|
|
108
|
+
slug: err?.slug,
|
|
109
|
+
code,
|
|
110
|
+
type: err?.type
|
|
111
|
+
};
|
|
112
|
+
} catch (error) {
|
|
113
|
+
return {
|
|
114
|
+
status_code: response.status,
|
|
115
|
+
message: error instanceof ResponseBodyTooLargeError ? `HTTP error! status: ${response.status} (error body over the ${maxBytes}-byte limit)` : `HTTP error! status: ${response.status}`
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
6
120
|
// src/lib/logger.ts
|
|
7
121
|
var LOG_LEVELS = {
|
|
8
122
|
debug: 0,
|
|
@@ -186,56 +300,6 @@ var CreateAccessPolicyResponseSchema = z.object({
|
|
|
186
300
|
// src/services/base.service.ts
|
|
187
301
|
import crypto from "node:crypto";
|
|
188
302
|
|
|
189
|
-
// src/lib/fetch.ts
|
|
190
|
-
var FetchError = class extends Error {
|
|
191
|
-
constructor(message, status, response) {
|
|
192
|
-
super(message);
|
|
193
|
-
this.status = status;
|
|
194
|
-
this.response = response;
|
|
195
|
-
this.name = "FetchError";
|
|
196
|
-
}
|
|
197
|
-
status;
|
|
198
|
-
response;
|
|
199
|
-
};
|
|
200
|
-
async function fetchWithTimeout(url, options = {}) {
|
|
201
|
-
const { timeout = 3e4, ...fetchOptions } = options;
|
|
202
|
-
return fetch(url, {
|
|
203
|
-
...fetchOptions,
|
|
204
|
-
signal: AbortSignal.timeout(timeout)
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
function buildQueryString(params) {
|
|
208
|
-
if (!params) return "";
|
|
209
|
-
const entries = Object.entries(params).flatMap(([key, value]) => {
|
|
210
|
-
if (value === void 0 || value === null) return [];
|
|
211
|
-
if (Array.isArray(value)) {
|
|
212
|
-
return value.map((item) => [key, String(item)]);
|
|
213
|
-
}
|
|
214
|
-
return [[key, String(value)]];
|
|
215
|
-
});
|
|
216
|
-
if (entries.length === 0) return "";
|
|
217
|
-
return `?${new URLSearchParams(entries).toString()}`;
|
|
218
|
-
}
|
|
219
|
-
async function parseErrorResponse(response) {
|
|
220
|
-
try {
|
|
221
|
-
const body = await response.json();
|
|
222
|
-
const err = body.error ?? body.data ?? body ?? {};
|
|
223
|
-
const code = err?.errorCode ?? err?.code;
|
|
224
|
-
return {
|
|
225
|
-
status_code: body?.status_code ?? response.status,
|
|
226
|
-
message: err?.message ?? `HTTP error! status: ${response.status}${code ? ` (${code})` : ""}`,
|
|
227
|
-
slug: err?.slug,
|
|
228
|
-
code,
|
|
229
|
-
type: err?.type
|
|
230
|
-
};
|
|
231
|
-
} catch {
|
|
232
|
-
return {
|
|
233
|
-
status_code: response.status,
|
|
234
|
-
message: `HTTP error! status: ${response.status}`
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
303
|
// src/lib/path-segment.ts
|
|
240
304
|
function isDotPathSegment(value) {
|
|
241
305
|
let decoded = value;
|
|
@@ -450,6 +514,7 @@ var BaseService = class {
|
|
|
450
514
|
paramKeys: options.params ? Object.keys(options.params) : []
|
|
451
515
|
}
|
|
452
516
|
});
|
|
517
|
+
const maxBodyBytes = getMaxUpstreamBodyBytes();
|
|
453
518
|
try {
|
|
454
519
|
const response = await fetchWithTimeout(url, {
|
|
455
520
|
method,
|
|
@@ -460,7 +525,7 @@ var BaseService = class {
|
|
|
460
525
|
});
|
|
461
526
|
const duration_ms = Date.now() - startTime;
|
|
462
527
|
if (!response.ok) {
|
|
463
|
-
const apiError = await parseErrorResponse(response);
|
|
528
|
+
const apiError = await parseErrorResponse(response, maxBodyBytes);
|
|
464
529
|
Logger.error("HTTP request failed", {
|
|
465
530
|
requestId,
|
|
466
531
|
method,
|
|
@@ -481,7 +546,16 @@ var BaseService = class {
|
|
|
481
546
|
if (options.allowNoContent && response.status === 204) {
|
|
482
547
|
return NO_CONTENT;
|
|
483
548
|
}
|
|
484
|
-
|
|
549
|
+
try {
|
|
550
|
+
return await readBoundedJson(response, maxBodyBytes);
|
|
551
|
+
} catch (error) {
|
|
552
|
+
if (error instanceof ResponseBodyTooLargeError) {
|
|
553
|
+
throw new Error(
|
|
554
|
+
`Portkey ${method} ${path} returned a response larger than ${maxBodyBytes} bytes (${MAX_UPSTREAM_BODY_BYTES_ENV}). Narrow the request with filters or a smaller page_size, or raise the limit.`
|
|
555
|
+
);
|
|
556
|
+
}
|
|
557
|
+
throw error;
|
|
558
|
+
}
|
|
485
559
|
} catch (error) {
|
|
486
560
|
const duration_ms = Date.now() - startTime;
|
|
487
561
|
if (!(error instanceof FetchError)) {
|
|
@@ -557,9 +631,9 @@ var BaseService = class {
|
|
|
557
631
|
})
|
|
558
632
|
);
|
|
559
633
|
}
|
|
560
|
-
async put(path, body) {
|
|
634
|
+
async put(path, body, params) {
|
|
561
635
|
return this.rejectNoContent(
|
|
562
|
-
await this.executeRequest("PUT", path, { body })
|
|
636
|
+
await this.executeRequest("PUT", path, { body, params })
|
|
563
637
|
);
|
|
564
638
|
}
|
|
565
639
|
/**
|
|
@@ -631,7 +705,7 @@ var AnalyticsService = class extends BaseService {
|
|
|
631
705
|
* Helper method to build query params from analytics parameters
|
|
632
706
|
*/
|
|
633
707
|
buildAnalyticsParams(params) {
|
|
634
|
-
|
|
708
|
+
return {
|
|
635
709
|
time_of_generation_min: params.time_of_generation_min,
|
|
636
710
|
time_of_generation_max: params.time_of_generation_max,
|
|
637
711
|
total_units_min: params.total_units_min,
|
|
@@ -648,7 +722,7 @@ var AnalyticsService = class extends BaseService {
|
|
|
648
722
|
virtual_keys: params.virtual_keys,
|
|
649
723
|
configs: params.configs,
|
|
650
724
|
workspace_slug: params.workspace_slug,
|
|
651
|
-
include_all_workspaces: params.include_all_workspaces
|
|
725
|
+
include_all_workspaces: params.include_all_workspaces,
|
|
652
726
|
exclude_workspace_slugs: params.exclude_workspace_slugs,
|
|
653
727
|
api_key_ids: params.api_key_ids,
|
|
654
728
|
metadata: params.metadata,
|
|
@@ -656,21 +730,14 @@ var AnalyticsService = class extends BaseService {
|
|
|
656
730
|
deployment_id: params.deployment_id,
|
|
657
731
|
trace_id: params.trace_id,
|
|
658
732
|
span_id: params.span_id,
|
|
659
|
-
prompt_slug: params.prompt_slug
|
|
733
|
+
prompt_slug: params.prompt_slug,
|
|
734
|
+
current_page: params.current_page,
|
|
735
|
+
page_size: params.page_size,
|
|
736
|
+
order_by: params.order_by,
|
|
737
|
+
order_by_type: params.order_by_type,
|
|
738
|
+
columns: params.columns,
|
|
739
|
+
include_total: params.include_total
|
|
660
740
|
};
|
|
661
|
-
if ("current_page" in params) {
|
|
662
|
-
baseParams.current_page = params.current_page;
|
|
663
|
-
}
|
|
664
|
-
if ("page_size" in params) {
|
|
665
|
-
baseParams.page_size = params.page_size;
|
|
666
|
-
}
|
|
667
|
-
if ("order_by" in params) baseParams.order_by = params.order_by;
|
|
668
|
-
if ("order_by_type" in params)
|
|
669
|
-
baseParams.order_by_type = params.order_by_type;
|
|
670
|
-
if ("columns" in params) baseParams.columns = params.columns;
|
|
671
|
-
if ("include_total" in params)
|
|
672
|
-
baseParams.include_total = params.include_total;
|
|
673
|
-
return baseParams;
|
|
674
741
|
}
|
|
675
742
|
// ==================== Cost Analytics ====================
|
|
676
743
|
async getCostAnalytics(params) {
|
|
@@ -1582,9 +1649,10 @@ var McpIntegrationsService = class extends BaseService {
|
|
|
1582
1649
|
`/mcp-integrations/${this.encodePathSegment(id)}/metadata`
|
|
1583
1650
|
);
|
|
1584
1651
|
}
|
|
1585
|
-
async listMcpIntegrationCapabilities(id) {
|
|
1652
|
+
async listMcpIntegrationCapabilities(id, params) {
|
|
1586
1653
|
return this.get(
|
|
1587
|
-
`/mcp-integrations/${this.encodePathSegment(id)}/capabilities
|
|
1654
|
+
`/mcp-integrations/${this.encodePathSegment(id)}/capabilities`,
|
|
1655
|
+
{ type: params?.type }
|
|
1588
1656
|
);
|
|
1589
1657
|
}
|
|
1590
1658
|
async updateMcpIntegrationCapabilities(id, data) {
|
|
@@ -1628,6 +1696,8 @@ var McpServersService = class extends BaseService {
|
|
|
1628
1696
|
current_page: params?.current_page,
|
|
1629
1697
|
page_size: params?.page_size,
|
|
1630
1698
|
workspace_id: params?.workspace_id,
|
|
1699
|
+
id: params?.id,
|
|
1700
|
+
search: params?.search,
|
|
1631
1701
|
tags: params?.tags === void 0 ? void 0 : JSON.stringify(params.tags)
|
|
1632
1702
|
});
|
|
1633
1703
|
}
|
|
@@ -1656,7 +1726,8 @@ var McpServersService = class extends BaseService {
|
|
|
1656
1726
|
`/mcp-servers/${this.encodePathSegment(id)}/capabilities`,
|
|
1657
1727
|
{
|
|
1658
1728
|
current_page: params?.current_page,
|
|
1659
|
-
page_size: params?.page_size
|
|
1729
|
+
page_size: params?.page_size,
|
|
1730
|
+
type: params?.type
|
|
1660
1731
|
}
|
|
1661
1732
|
);
|
|
1662
1733
|
}
|
|
@@ -1672,7 +1743,8 @@ var McpServersService = class extends BaseService {
|
|
|
1672
1743
|
`/mcp-servers/${this.encodePathSegment(id)}/user-access`,
|
|
1673
1744
|
{
|
|
1674
1745
|
current_page: params?.current_page,
|
|
1675
|
-
page_size: params?.page_size
|
|
1746
|
+
page_size: params?.page_size,
|
|
1747
|
+
search: params?.search
|
|
1676
1748
|
}
|
|
1677
1749
|
);
|
|
1678
1750
|
}
|
|
@@ -1735,6 +1807,7 @@ var PartialsService = class extends BaseService {
|
|
|
1735
1807
|
|
|
1736
1808
|
// src/services/prompts.service.ts
|
|
1737
1809
|
import { isDeepStrictEqual } from "node:util";
|
|
1810
|
+
var PROMOTE_INCOMPLETE_SOURCE_MESSAGE = "Cannot promote prompt: source version needs a string, a model (model, ai_model_id or finetune_id) and a virtual_key (or a virtual_key override)";
|
|
1738
1811
|
var PromptsService = class extends BaseService {
|
|
1739
1812
|
async createPrompt(data) {
|
|
1740
1813
|
const { is_raw_template, ...rest } = data;
|
|
@@ -1771,6 +1844,8 @@ var PromptsService = class extends BaseService {
|
|
|
1771
1844
|
string: raw.string ?? "",
|
|
1772
1845
|
parameters: raw.parameters ?? {},
|
|
1773
1846
|
model: raw.model,
|
|
1847
|
+
ai_model_id: raw.ai_model_id,
|
|
1848
|
+
finetune_id: raw.finetune_id,
|
|
1774
1849
|
virtual_key: raw.virtual_key,
|
|
1775
1850
|
functions: raw.functions ?? void 0,
|
|
1776
1851
|
tools: raw.tools ?? void 0,
|
|
@@ -1782,12 +1857,14 @@ var PromptsService = class extends BaseService {
|
|
|
1782
1857
|
object: "prompt"
|
|
1783
1858
|
};
|
|
1784
1859
|
}
|
|
1785
|
-
async updatePrompt(promptId, data) {
|
|
1860
|
+
async updatePrompt(promptId, data, options = {}) {
|
|
1786
1861
|
const { template_metadata, is_raw_template, ...rest } = data;
|
|
1787
1862
|
const body = {
|
|
1788
1863
|
...rest,
|
|
1789
|
-
//
|
|
1790
|
-
|
|
1864
|
+
// Partial updates backfill missing version fields from the latest
|
|
1865
|
+
// version. Callers that send a complete version turn this off so absent
|
|
1866
|
+
// fields are cleared instead of inherited.
|
|
1867
|
+
patch: options.patch ?? true
|
|
1791
1868
|
};
|
|
1792
1869
|
if (template_metadata !== void 0) {
|
|
1793
1870
|
body.prompt_metadata = template_metadata;
|
|
@@ -2014,24 +2091,40 @@ var PromptsService = class extends BaseService {
|
|
|
2014
2091
|
data.target_collection_id
|
|
2015
2092
|
);
|
|
2016
2093
|
if (existingTarget) {
|
|
2017
|
-
const
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2094
|
+
const virtualKey2 = data.virtual_key || sourceVersion.virtual_key;
|
|
2095
|
+
if (!sourceVersion.string || !(sourceVersion.model || sourceVersion.ai_model_id || sourceVersion.finetune_id) || !virtualKey2) {
|
|
2096
|
+
throw new Error(PROMOTE_INCOMPLETE_SOURCE_MESSAGE);
|
|
2097
|
+
}
|
|
2098
|
+
const updateResult = await this.updatePrompt(
|
|
2099
|
+
existingTarget.id,
|
|
2100
|
+
{
|
|
2101
|
+
string: sourceVersion.string,
|
|
2102
|
+
parameters: sourceVersion.parameters ?? {},
|
|
2103
|
+
...sourceVersion.model && { model: sourceVersion.model },
|
|
2104
|
+
...sourceVersion.ai_model_id && {
|
|
2105
|
+
ai_model_id: sourceVersion.ai_model_id
|
|
2106
|
+
},
|
|
2107
|
+
...sourceVersion.finetune_id && {
|
|
2108
|
+
finetune_id: sourceVersion.finetune_id
|
|
2109
|
+
},
|
|
2110
|
+
virtual_key: virtualKey2,
|
|
2111
|
+
functions: sourceVersion.functions ?? [],
|
|
2112
|
+
tools: sourceVersion.tools ?? [],
|
|
2113
|
+
...sourceVersion.tool_choice !== void 0 && {
|
|
2114
|
+
tool_choice: sourceVersion.tool_choice
|
|
2115
|
+
},
|
|
2116
|
+
is_raw_template: sourceVersion.is_raw_template ?? false,
|
|
2117
|
+
version_description: `Promoted from ${sourcePrompt.slug} v${sourceVersion.version_number}`,
|
|
2118
|
+
template_metadata: {
|
|
2119
|
+
...sourceVersion.template_metadata,
|
|
2120
|
+
env: data.target_env,
|
|
2121
|
+
promoted_from: sourcePrompt.slug,
|
|
2122
|
+
promoted_from_version: sourceVersion.version_number.toString(),
|
|
2123
|
+
promoted_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
2124
|
+
}
|
|
2125
|
+
},
|
|
2126
|
+
{ patch: false }
|
|
2127
|
+
);
|
|
2035
2128
|
return {
|
|
2036
2129
|
source_prompt_id: data.source_prompt_id,
|
|
2037
2130
|
source_version_id: sourceVersion.id,
|
|
@@ -2047,13 +2140,22 @@ var PromptsService = class extends BaseService {
|
|
|
2047
2140
|
"Cannot promote prompt: source version has no virtual_key and none was provided"
|
|
2048
2141
|
);
|
|
2049
2142
|
}
|
|
2143
|
+
if (!(sourceVersion.model || sourceVersion.ai_model_id || sourceVersion.finetune_id)) {
|
|
2144
|
+
throw new Error(PROMOTE_INCOMPLETE_SOURCE_MESSAGE);
|
|
2145
|
+
}
|
|
2050
2146
|
const createResult = await this.createPrompt({
|
|
2051
2147
|
name: targetName,
|
|
2052
2148
|
collection_id: data.target_collection_id,
|
|
2053
2149
|
string: sourceVersion.string,
|
|
2054
2150
|
parameters: sourceVersion.parameters,
|
|
2055
2151
|
virtual_key: virtualKey,
|
|
2056
|
-
model: sourceVersion.model,
|
|
2152
|
+
...sourceVersion.model && { model: sourceVersion.model },
|
|
2153
|
+
...sourceVersion.ai_model_id && {
|
|
2154
|
+
ai_model_id: sourceVersion.ai_model_id
|
|
2155
|
+
},
|
|
2156
|
+
...sourceVersion.finetune_id && {
|
|
2157
|
+
finetune_id: sourceVersion.finetune_id
|
|
2158
|
+
},
|
|
2057
2159
|
functions: sourceVersion.functions,
|
|
2058
2160
|
tools: sourceVersion.tools,
|
|
2059
2161
|
tool_choice: sourceVersion.tool_choice,
|
|
@@ -2115,12 +2217,17 @@ var ProvidersService = class extends BaseService {
|
|
|
2115
2217
|
});
|
|
2116
2218
|
}
|
|
2117
2219
|
async updateProvider(slug, data, workspaceId) {
|
|
2118
|
-
|
|
2119
|
-
|
|
2220
|
+
return this.put(
|
|
2221
|
+
`/providers/${this.encodePathSegment(slug)}`,
|
|
2222
|
+
data,
|
|
2223
|
+
{ workspace_id: workspaceId || void 0 }
|
|
2224
|
+
);
|
|
2120
2225
|
}
|
|
2121
2226
|
async deleteProvider(slug, workspaceId) {
|
|
2122
|
-
const
|
|
2123
|
-
|
|
2227
|
+
const result = await this.delete(
|
|
2228
|
+
`/providers/${this.encodePathSegment(slug)}`,
|
|
2229
|
+
{ workspace_id: workspaceId || void 0 }
|
|
2230
|
+
);
|
|
2124
2231
|
return isNoContent(result) ? {} : result;
|
|
2125
2232
|
}
|
|
2126
2233
|
};
|
|
@@ -2347,7 +2454,7 @@ function getSharedServiceCacheKey(apiKey) {
|
|
|
2347
2454
|
const keyDigest = createHmac("sha256", SERVICE_CACHE_HMAC_KEY).update(apiKey).digest("hex");
|
|
2348
2455
|
return JSON.stringify({
|
|
2349
2456
|
apiKey: keyDigest,
|
|
2350
|
-
baseUrl: process.env.PORTKEY_BASE_URL
|
|
2457
|
+
baseUrl: process.env.PORTKEY_BASE_URL ?? DEFAULT_BASE_URL
|
|
2351
2458
|
});
|
|
2352
2459
|
}
|
|
2353
2460
|
var sharedPortkeyServices = /* @__PURE__ */ new Map();
|
|
@@ -2377,8 +2484,7 @@ var PortkeyService = class {
|
|
|
2377
2484
|
health;
|
|
2378
2485
|
constructor(apiKey) {
|
|
2379
2486
|
const resolvedApiKey = resolvePortkeyApiKey(apiKey);
|
|
2380
|
-
const resolvedBaseUrl = process.env.PORTKEY_BASE_URL ??
|
|
2381
|
-
validateUrl(resolvedBaseUrl);
|
|
2487
|
+
const resolvedBaseUrl = process.env.PORTKEY_BASE_URL ?? DEFAULT_BASE_URL;
|
|
2382
2488
|
this.accessPolicies = new AccessPoliciesService(
|
|
2383
2489
|
resolvedApiKey,
|
|
2384
2490
|
resolvedBaseUrl
|
|
@@ -2452,8 +2558,8 @@ var SecretReferenceListItemSchema = z3.object({
|
|
|
2452
2558
|
slug: z3.string(),
|
|
2453
2559
|
manager_type: SecretManagerTypeSchema,
|
|
2454
2560
|
status: z3.literal("ACTIVE"),
|
|
2455
|
-
created_at: z3.iso.datetime(),
|
|
2456
|
-
last_updated_at: z3.iso.datetime(),
|
|
2561
|
+
created_at: z3.iso.datetime({ offset: true }),
|
|
2562
|
+
last_updated_at: z3.iso.datetime({ offset: true }),
|
|
2457
2563
|
object: z3.literal("secret-reference")
|
|
2458
2564
|
});
|
|
2459
2565
|
var ListSecretReferencesResponseSchema = z3.object({
|
|
@@ -2796,7 +2902,7 @@ var GENERIC_GRAPH_ANALYTICS_TOOLS = [
|
|
|
2796
2902
|
},
|
|
2797
2903
|
{
|
|
2798
2904
|
name: "get_user_requests_analytics",
|
|
2799
|
-
description: "Get per-user request-count time-series data with counts grouped by user. Use this to find heavy users and traffic concentration; use get_users_analytics for aggregate
|
|
2905
|
+
description: "Get per-user request-count time-series data with counts grouped by user. Use this to find heavy users and traffic concentration; use get_users_analytics for aggregate unique-user trends instead.",
|
|
2800
2906
|
method: (analytics, params) => analytics.getUserRequestsAnalytics(params)
|
|
2801
2907
|
},
|
|
2802
2908
|
{
|
|
@@ -2856,57 +2962,27 @@ function normalizeMetadataFilter(value) {
|
|
|
2856
2962
|
}
|
|
2857
2963
|
return void 0;
|
|
2858
2964
|
}
|
|
2965
|
+
var ANALYTICS_PARAM_ALIASES = [
|
|
2966
|
+
["status_codes", "status_code", normalizeCommaSeparatedParam],
|
|
2967
|
+
["virtual_key_slugs", "virtual_keys", normalizeCommaSeparatedParam],
|
|
2968
|
+
["config_slugs", "configs", normalizeCommaSeparatedParam],
|
|
2969
|
+
["api_key_ids", "api_key_ids", normalizeCommaSeparatedParam],
|
|
2970
|
+
["metadata_filter", "metadata", normalizeMetadataFilter],
|
|
2971
|
+
["provider_models", "ai_org_model", normalizeCommaSeparatedParam],
|
|
2972
|
+
["deployment_ids", "deployment_id", normalizeCommaSeparatedParam],
|
|
2973
|
+
["trace_ids", "trace_id", normalizeCommaSeparatedParam],
|
|
2974
|
+
["span_ids", "span_id", normalizeCommaSeparatedParam]
|
|
2975
|
+
];
|
|
2859
2976
|
function normalizeAnalyticsParams(params) {
|
|
2860
|
-
const {
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
config_slugs,
|
|
2864
|
-
api_key_ids,
|
|
2865
|
-
trace_ids,
|
|
2866
|
-
span_ids,
|
|
2867
|
-
provider_models,
|
|
2868
|
-
deployment_ids,
|
|
2869
|
-
metadata_filter,
|
|
2870
|
-
...legacyParams
|
|
2871
|
-
} = params;
|
|
2872
|
-
const normalizedParams = {
|
|
2873
|
-
...legacyParams
|
|
2874
|
-
};
|
|
2875
|
-
const statusCode = normalizeCommaSeparatedParam(status_codes) ?? normalizeCommaSeparatedParam(legacyParams.status_code);
|
|
2876
|
-
if (statusCode !== void 0) {
|
|
2877
|
-
normalizedParams.status_code = statusCode;
|
|
2878
|
-
}
|
|
2879
|
-
const virtualKeys = normalizeCommaSeparatedParam(virtual_key_slugs) ?? normalizeCommaSeparatedParam(legacyParams.virtual_keys);
|
|
2880
|
-
if (virtualKeys !== void 0) {
|
|
2881
|
-
normalizedParams.virtual_keys = virtualKeys;
|
|
2882
|
-
}
|
|
2883
|
-
const configs = normalizeCommaSeparatedParam(config_slugs) ?? normalizeCommaSeparatedParam(legacyParams.configs);
|
|
2884
|
-
if (configs !== void 0) {
|
|
2885
|
-
normalizedParams.configs = configs;
|
|
2886
|
-
}
|
|
2887
|
-
const apiKeyIds = normalizeCommaSeparatedParam(api_key_ids) ?? normalizeCommaSeparatedParam(legacyParams.api_key_ids);
|
|
2888
|
-
if (apiKeyIds !== void 0) {
|
|
2889
|
-
normalizedParams.api_key_ids = apiKeyIds;
|
|
2890
|
-
}
|
|
2891
|
-
const metadata = normalizeMetadataFilter(metadata_filter) ?? normalizeMetadataFilter(legacyParams.metadata);
|
|
2892
|
-
if (metadata !== void 0) {
|
|
2893
|
-
normalizedParams.metadata = metadata;
|
|
2894
|
-
}
|
|
2895
|
-
const providerModels = normalizeCommaSeparatedParam(provider_models) ?? normalizeCommaSeparatedParam(legacyParams.ai_org_model);
|
|
2896
|
-
if (providerModels !== void 0) {
|
|
2897
|
-
normalizedParams.ai_org_model = providerModels;
|
|
2898
|
-
}
|
|
2899
|
-
const deploymentId = normalizeCommaSeparatedParam(deployment_ids) ?? normalizeCommaSeparatedParam(legacyParams.deployment_id);
|
|
2900
|
-
if (deploymentId !== void 0) {
|
|
2901
|
-
normalizedParams.deployment_id = deploymentId;
|
|
2902
|
-
}
|
|
2903
|
-
const traceId = normalizeCommaSeparatedParam(trace_ids) ?? normalizeCommaSeparatedParam(legacyParams.trace_id);
|
|
2904
|
-
if (traceId !== void 0) {
|
|
2905
|
-
normalizedParams.trace_id = traceId;
|
|
2977
|
+
const normalizedParams = { ...params };
|
|
2978
|
+
for (const [alias] of ANALYTICS_PARAM_ALIASES) {
|
|
2979
|
+
delete normalizedParams[alias];
|
|
2906
2980
|
}
|
|
2907
|
-
const
|
|
2908
|
-
|
|
2909
|
-
|
|
2981
|
+
for (const [alias, legacy, normalize] of ANALYTICS_PARAM_ALIASES) {
|
|
2982
|
+
const value = normalize(params[alias]) ?? normalize(params[legacy]);
|
|
2983
|
+
if (value !== void 0) {
|
|
2984
|
+
normalizedParams[legacy] = value;
|
|
2985
|
+
}
|
|
2910
2986
|
}
|
|
2911
2987
|
return normalizedParams;
|
|
2912
2988
|
}
|
|
@@ -2968,7 +3044,7 @@ function registerAnalyticsTools(server, service) {
|
|
|
2968
3044
|
server.registerTool(
|
|
2969
3045
|
"get_token_analytics",
|
|
2970
3046
|
{
|
|
2971
|
-
description: "Get token-usage time-series data with summary.
|
|
3047
|
+
description: "Get token-usage time-series data with summary.total and summary.avg (average tokens per request), and per-bucket total and avg. Portkey doesn't split prompt and completion tokens in this graph. Use this for consumption trends; use get_cost_analytics when you need spend instead of token volume.",
|
|
2972
3048
|
inputSchema: baseAnalyticsSchema
|
|
2973
3049
|
},
|
|
2974
3050
|
async (params) => {
|
|
@@ -2978,15 +3054,13 @@ function registerAnalyticsTools(server, service) {
|
|
|
2978
3054
|
const dataPoints = analytics.data_points.map((point) => ({
|
|
2979
3055
|
timestamp: point.timestamp,
|
|
2980
3056
|
total: point.total,
|
|
2981
|
-
|
|
2982
|
-
completion: point.completion
|
|
3057
|
+
avg: point.avg
|
|
2983
3058
|
}));
|
|
2984
3059
|
return jsonResult(
|
|
2985
3060
|
formatGraphAnalytics(
|
|
2986
3061
|
{
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
completion_tokens: analytics.summary.completion
|
|
3062
|
+
total: analytics.summary.total,
|
|
3063
|
+
avg: analytics.summary.avg
|
|
2990
3064
|
},
|
|
2991
3065
|
dataPoints
|
|
2992
3066
|
)
|
|
@@ -3100,7 +3174,7 @@ function registerAnalyticsTools(server, service) {
|
|
|
3100
3174
|
server.registerTool(
|
|
3101
3175
|
"get_cache_hit_rate",
|
|
3102
3176
|
{
|
|
3103
|
-
description: "Get cache-effectiveness time-series data with summary.hit_rate
|
|
3177
|
+
description: "Get cache-effectiveness time-series data with summary.hit_rate and summary.total_hits, and per-bucket simple_hits, semantic_hits, rate, and cumulative simple and semantic cache savings. Use this to measure cache effectiveness; use get_cache_hit_latency for speed rather than hit/miss ratio.",
|
|
3104
3178
|
inputSchema: baseAnalyticsSchema
|
|
3105
3179
|
},
|
|
3106
3180
|
async (params) => {
|
|
@@ -3109,16 +3183,17 @@ function registerAnalyticsTools(server, service) {
|
|
|
3109
3183
|
);
|
|
3110
3184
|
const dataPoints = analytics.data_points.map((point) => ({
|
|
3111
3185
|
timestamp: point.timestamp,
|
|
3186
|
+
simple_hits: point.simple_hits,
|
|
3187
|
+
semantic_hits: point.semantic_hits,
|
|
3112
3188
|
rate: point.rate,
|
|
3113
|
-
|
|
3114
|
-
|
|
3189
|
+
cumulative_simple_cache_savings: point.cumulative_simple_cache_savings,
|
|
3190
|
+
cumulative_semantic_cache_savings: point.cumulative_semantic_cache_savings
|
|
3115
3191
|
}));
|
|
3116
3192
|
return jsonResult(
|
|
3117
3193
|
formatGraphAnalytics(
|
|
3118
3194
|
{
|
|
3119
3195
|
hit_rate: analytics.summary.rate,
|
|
3120
|
-
total_hits: analytics.summary.
|
|
3121
|
-
total_misses: analytics.summary.total_misses
|
|
3196
|
+
total_hits: analytics.summary.total
|
|
3122
3197
|
},
|
|
3123
3198
|
dataPoints
|
|
3124
3199
|
)
|
|
@@ -3142,7 +3217,7 @@ function registerAnalyticsTools(server, service) {
|
|
|
3142
3217
|
server.registerTool(
|
|
3143
3218
|
"get_users_analytics",
|
|
3144
3219
|
{
|
|
3145
|
-
description: "Get user
|
|
3220
|
+
description: "Get unique-user time-series data with summary.total and per-bucket total unique users. Use this for adoption trends; use get_user_requests_analytics for per-user traffic or get_analytics_group_users for per-user cost and token detail.",
|
|
3146
3221
|
inputSchema: baseAnalyticsSchema
|
|
3147
3222
|
},
|
|
3148
3223
|
async (params) => {
|
|
@@ -3151,14 +3226,12 @@ function registerAnalyticsTools(server, service) {
|
|
|
3151
3226
|
);
|
|
3152
3227
|
const dataPoints = analytics.data_points.map((point) => ({
|
|
3153
3228
|
timestamp: point.timestamp,
|
|
3154
|
-
|
|
3155
|
-
new_users: point.new_users
|
|
3229
|
+
total: point.total
|
|
3156
3230
|
}));
|
|
3157
3231
|
return jsonResult(
|
|
3158
3232
|
formatGraphAnalytics(
|
|
3159
3233
|
{
|
|
3160
|
-
|
|
3161
|
-
total_new_users: analytics.summary.total_new_users
|
|
3234
|
+
total: analytics.summary.total
|
|
3162
3235
|
},
|
|
3163
3236
|
dataPoints
|
|
3164
3237
|
)
|
|
@@ -3181,7 +3254,7 @@ function registerAnalyticsTools(server, service) {
|
|
|
3181
3254
|
server.registerTool(
|
|
3182
3255
|
"get_analytics_group_users",
|
|
3183
3256
|
{
|
|
3184
|
-
description: "Get a paginated per-user breakdown with total_groups, group_count, and a users array containing request count, cost, and token usage. Use this for billing, audits, or top-consumer analysis; use get_users_analytics for aggregate
|
|
3257
|
+
description: "Get a paginated per-user breakdown with total_groups, group_count, and a users array containing request count, cost, and token usage. Use this for billing, audits, or top-consumer analysis; use get_users_analytics for aggregate unique-user trends.",
|
|
3185
3258
|
inputSchema: paginatedAnalyticsSchema
|
|
3186
3259
|
},
|
|
3187
3260
|
async (params) => {
|
|
@@ -3675,7 +3748,6 @@ function registerConfigsTools(server, service) {
|
|
|
3675
3748
|
inputSchema: CONFIGS_TOOL_SCHEMAS.updateConfig,
|
|
3676
3749
|
annotations: {
|
|
3677
3750
|
readOnlyHint: false,
|
|
3678
|
-
destructiveHint: false,
|
|
3679
3751
|
idempotentHint: false,
|
|
3680
3752
|
openWorldHint: false
|
|
3681
3753
|
}
|
|
@@ -4120,7 +4192,6 @@ function registerGuardrailsTools(server, service) {
|
|
|
4120
4192
|
annotations: {
|
|
4121
4193
|
title: "Update Organisation Guardrail Defaults",
|
|
4122
4194
|
readOnlyHint: false,
|
|
4123
|
-
destructiveHint: false,
|
|
4124
4195
|
idempotentHint: true,
|
|
4125
4196
|
openWorldHint: true
|
|
4126
4197
|
}
|
|
@@ -4389,31 +4460,68 @@ import { z as z15 } from "zod";
|
|
|
4389
4460
|
|
|
4390
4461
|
// src/lib/limits.ts
|
|
4391
4462
|
var PERIODIC_RESET_DEFAULT = "monthly";
|
|
4463
|
+
function hasUsageLimitInput(params) {
|
|
4464
|
+
return params.credit_limit !== void 0 || params.alert_threshold !== void 0 || params.type !== void 0 || params.periodic_reset !== void 0;
|
|
4465
|
+
}
|
|
4466
|
+
function copyDefinedUsageLimitFields(params, limits) {
|
|
4467
|
+
if (params.type !== void 0) {
|
|
4468
|
+
limits.type = params.type;
|
|
4469
|
+
}
|
|
4470
|
+
if (params.periodic_reset !== void 0) {
|
|
4471
|
+
limits.periodic_reset = params.periodic_reset;
|
|
4472
|
+
}
|
|
4473
|
+
if (params.credit_limit !== void 0) {
|
|
4474
|
+
limits.credit_limit = params.credit_limit;
|
|
4475
|
+
}
|
|
4476
|
+
if (params.alert_threshold !== void 0) {
|
|
4477
|
+
limits.alert_threshold = params.alert_threshold;
|
|
4478
|
+
}
|
|
4479
|
+
return limits;
|
|
4480
|
+
}
|
|
4392
4481
|
function buildUsageLimits(params) {
|
|
4393
|
-
if (params
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4482
|
+
if (!hasUsageLimitInput(params)) {
|
|
4483
|
+
return void 0;
|
|
4484
|
+
}
|
|
4485
|
+
return copyDefinedUsageLimitFields(params, {
|
|
4486
|
+
type: "cost",
|
|
4487
|
+
periodic_reset: PERIODIC_RESET_DEFAULT
|
|
4488
|
+
});
|
|
4489
|
+
}
|
|
4490
|
+
function buildUsageLimitsUpdate(params) {
|
|
4491
|
+
if (!hasUsageLimitInput(params)) {
|
|
4492
|
+
return void 0;
|
|
4493
|
+
}
|
|
4494
|
+
return copyDefinedUsageLimitFields(params, {});
|
|
4495
|
+
}
|
|
4496
|
+
async function mergeUsageLimitsUpdate(supplied, readExisting) {
|
|
4497
|
+
if (supplied === void 0) {
|
|
4498
|
+
return void 0;
|
|
4499
|
+
}
|
|
4500
|
+
const existing = await readExisting();
|
|
4501
|
+
const base = existing ? {} : { type: "cost", periodic_reset: PERIODIC_RESET_DEFAULT };
|
|
4502
|
+
if (existing) {
|
|
4503
|
+
for (const key of [
|
|
4504
|
+
"type",
|
|
4505
|
+
"credit_limit",
|
|
4506
|
+
"alert_threshold",
|
|
4507
|
+
"periodic_reset",
|
|
4508
|
+
"periodic_reset_days"
|
|
4509
|
+
]) {
|
|
4510
|
+
if (existing[key] !== void 0) {
|
|
4511
|
+
Object.assign(base, { [key]: existing[key] });
|
|
4512
|
+
}
|
|
4400
4513
|
}
|
|
4401
|
-
if (
|
|
4402
|
-
|
|
4514
|
+
if (supplied.periodic_reset !== void 0) {
|
|
4515
|
+
delete base.periodic_reset_days;
|
|
4516
|
+
} else if (base.periodic_reset_days !== void 0 && base.periodic_reset_days !== null) {
|
|
4517
|
+
delete base.periodic_reset;
|
|
4403
4518
|
}
|
|
4404
|
-
return limits;
|
|
4405
4519
|
}
|
|
4406
|
-
return
|
|
4520
|
+
return { ...base, ...supplied };
|
|
4407
4521
|
}
|
|
4408
4522
|
function buildRateLimitsRpm(rpmValue) {
|
|
4409
4523
|
if (rpmValue !== void 0) {
|
|
4410
|
-
return
|
|
4411
|
-
{
|
|
4412
|
-
type: "requests",
|
|
4413
|
-
unit: "rpm",
|
|
4414
|
-
value: rpmValue
|
|
4415
|
-
}
|
|
4416
|
-
];
|
|
4524
|
+
return buildRateLimits({ value: rpmValue, unit: "rpm" });
|
|
4417
4525
|
}
|
|
4418
4526
|
return void 0;
|
|
4419
4527
|
}
|
|
@@ -5167,7 +5275,9 @@ var KEYS_TOOL_SCHEMAS = {
|
|
|
5167
5275
|
alert_threshold: z16.coerce.number().min(0).max(100).optional().describe("New alert threshold percentage (0-100)"),
|
|
5168
5276
|
rate_limit_rpm: z16.coerce.number().positive().optional().describe("New rate limit in requests per minute"),
|
|
5169
5277
|
rate_limits: z16.array(apiKeyRateLimitSchema).nullable().optional().describe("Replacement request or token rate limits, or null to clear"),
|
|
5170
|
-
reset_usage: z16.
|
|
5278
|
+
reset_usage: z16.boolean().optional().describe(
|
|
5279
|
+
"Set to true to reset current usage; an exhausted key returns to active"
|
|
5280
|
+
),
|
|
5171
5281
|
default_config_id: z16.string().optional().describe("New default configuration ID"),
|
|
5172
5282
|
default_metadata: z16.record(z16.string(), z16.string()).optional().describe("New default metadata key-value pairs"),
|
|
5173
5283
|
default_allow_config_override: z16.boolean().optional().describe("Whether callers may override the key's default config"),
|
|
@@ -5214,6 +5324,7 @@ var createApiKeySchema = z16.object(KEYS_TOOL_SCHEMAS.createApiKey).superRefine(
|
|
|
5214
5324
|
});
|
|
5215
5325
|
function formatKeyUsageLimits(limits) {
|
|
5216
5326
|
return limits ? {
|
|
5327
|
+
type: limits.type,
|
|
5217
5328
|
credit_limit: limits.credit_limit,
|
|
5218
5329
|
alert_threshold: limits.alert_threshold,
|
|
5219
5330
|
periodic_reset: limits.periodic_reset
|
|
@@ -5359,18 +5470,22 @@ function registerKeysTools(server, service) {
|
|
|
5359
5470
|
server.registerTool(
|
|
5360
5471
|
"update_virtual_key",
|
|
5361
5472
|
{
|
|
5362
|
-
description: "Update a virtual key's name, secret, note, or limits. Rotating the key takes effect immediately, and limit changes apply to downstream prompts and configs using this slug. Returns success when Portkey accepts the update.",
|
|
5473
|
+
description: "Update a virtual key's name, secret, note, or limits. Rotating the key takes effect immediately, and limit changes apply to downstream prompts and configs using this slug. Returns success when Portkey accepts the update. Limit updates read the current limits and write them back, and Portkey has no conditional writes, so concurrent limit updates to the same resource can overwrite each other. Serialize them.",
|
|
5363
5474
|
inputSchema: KEYS_TOOL_SCHEMAS.updateVirtualKey
|
|
5364
5475
|
},
|
|
5365
5476
|
async (params) => {
|
|
5477
|
+
const usageLimits = await mergeUsageLimitsUpdate(
|
|
5478
|
+
buildUsageLimitsUpdate({
|
|
5479
|
+
credit_limit: params.credit_limit,
|
|
5480
|
+
alert_threshold: params.alert_threshold
|
|
5481
|
+
}),
|
|
5482
|
+
async () => (await service.keys.getVirtualKey(params.slug)).usage_limits
|
|
5483
|
+
);
|
|
5366
5484
|
const result = await service.keys.updateVirtualKey(params.slug, {
|
|
5367
5485
|
name: params.name,
|
|
5368
5486
|
key: params.key,
|
|
5369
5487
|
note: params.note,
|
|
5370
|
-
usage_limits:
|
|
5371
|
-
credit_limit: params.credit_limit,
|
|
5372
|
-
alert_threshold: params.alert_threshold
|
|
5373
|
-
}),
|
|
5488
|
+
usage_limits: usageLimits,
|
|
5374
5489
|
rate_limits: buildRateLimitsRpm(params.rate_limit_rpm),
|
|
5375
5490
|
deploymentConfig: params.deployment_configurations?.map(
|
|
5376
5491
|
(configuration) => ({
|
|
@@ -5479,18 +5594,22 @@ function registerKeysTools(server, service) {
|
|
|
5479
5594
|
server.registerTool(
|
|
5480
5595
|
"update_api_key",
|
|
5481
5596
|
{
|
|
5482
|
-
description: "Update an API key's name, description, scopes, defaults, or limits, unlike delete_api_key which revokes it or create_api_key which issues a new one. Changes take effect immediately for downstream callers, type and sub-type stay fixed after creation, and the call returns success without rotating the secret.",
|
|
5597
|
+
description: "Update an API key's name, description, scopes, defaults, or limits, unlike delete_api_key which revokes it or create_api_key which issues a new one. Changes take effect immediately for downstream callers, type and sub-type stay fixed after creation, and the call returns success without rotating the secret. Limit updates read the current limits and write them back, and Portkey has no conditional writes, so concurrent limit updates to the same resource can overwrite each other. Serialize them.",
|
|
5483
5598
|
inputSchema: KEYS_TOOL_SCHEMAS.updateApiKey
|
|
5484
5599
|
},
|
|
5485
5600
|
async (params) => {
|
|
5601
|
+
const usageLimits = await mergeUsageLimitsUpdate(
|
|
5602
|
+
buildUsageLimitsUpdate({
|
|
5603
|
+
credit_limit: params.credit_limit,
|
|
5604
|
+
alert_threshold: params.alert_threshold
|
|
5605
|
+
}),
|
|
5606
|
+
async () => (await service.keys.getApiKey(params.id)).usage_limits
|
|
5607
|
+
);
|
|
5486
5608
|
const result = await service.keys.updateApiKey(params.id, {
|
|
5487
5609
|
name: params.name,
|
|
5488
5610
|
description: params.description,
|
|
5489
5611
|
scopes: params.scopes,
|
|
5490
|
-
usage_limits:
|
|
5491
|
-
credit_limit: params.credit_limit,
|
|
5492
|
-
alert_threshold: params.alert_threshold
|
|
5493
|
-
}),
|
|
5612
|
+
usage_limits: usageLimits,
|
|
5494
5613
|
rate_limits: params.rate_limits === void 0 ? buildRateLimitsRpm(params.rate_limit_rpm) : params.rate_limits,
|
|
5495
5614
|
...params.reset_usage !== void 0 ? { reset_usage: params.reset_usage } : {},
|
|
5496
5615
|
defaults: params.default_config_id !== void 0 || params.default_metadata !== void 0 || params.default_allow_config_override !== void 0 ? {
|
|
@@ -6364,7 +6483,10 @@ var MCP_INTEGRATIONS_TOOL_SCHEMAS = {
|
|
|
6364
6483
|
"Additional documented or forward-compatible configuration fields. For headers auth, configurations.custom_headers is a string-to-string header map."
|
|
6365
6484
|
),
|
|
6366
6485
|
workspace_id: z20.string().optional().describe(
|
|
6367
|
-
"Workspace ID
|
|
6486
|
+
"Workspace ID; set it to create the integration at workspace level. With an organisation admin key, give this or organisation_id."
|
|
6487
|
+
),
|
|
6488
|
+
organisation_id: z20.string().optional().describe(
|
|
6489
|
+
"Organisation ID; required with an organisation admin API key when workspace_id is omitted"
|
|
6368
6490
|
),
|
|
6369
6491
|
secret_mappings: mcpSecretMappingsSchema.optional().describe(
|
|
6370
6492
|
"Runtime Secret Reference mappings; every configurations.<field> target must be unique"
|
|
@@ -6402,7 +6524,8 @@ var MCP_INTEGRATIONS_TOOL_SCHEMAS = {
|
|
|
6402
6524
|
id: z20.string().describe("The MCP integration ID or slug")
|
|
6403
6525
|
},
|
|
6404
6526
|
listMcpIntegrationCapabilities: {
|
|
6405
|
-
id: z20.string().describe("The MCP integration ID or slug")
|
|
6527
|
+
id: z20.string().describe("The MCP integration ID or slug"),
|
|
6528
|
+
type: z20.enum(["tool", "prompt", "resource", "resource_template"]).optional().describe("Only return capabilities of this type")
|
|
6406
6529
|
},
|
|
6407
6530
|
updateMcpIntegrationCapabilities: {
|
|
6408
6531
|
id: z20.string().describe("The MCP integration ID or slug"),
|
|
@@ -6424,7 +6547,15 @@ var MCP_INTEGRATIONS_TOOL_SCHEMAS = {
|
|
|
6424
6547
|
id: z20.string().describe("Workspace ID"),
|
|
6425
6548
|
enabled: z20.boolean().describe("Whether workspace has access")
|
|
6426
6549
|
})
|
|
6427
|
-
).
|
|
6550
|
+
).describe(
|
|
6551
|
+
"Array of workspace access updates; may be empty when only changing global_workspace_access"
|
|
6552
|
+
),
|
|
6553
|
+
global_workspace_access: z20.object({
|
|
6554
|
+
enabled: z20.boolean().describe("Whether every workspace gets access by default")
|
|
6555
|
+
}).optional().describe("Organisation-wide workspace access default"),
|
|
6556
|
+
override_existing_workspace_access: z20.boolean().optional().describe(
|
|
6557
|
+
"When true, global_workspace_access replaces existing per-workspace settings"
|
|
6558
|
+
)
|
|
6428
6559
|
}
|
|
6429
6560
|
};
|
|
6430
6561
|
var createMcpIntegrationSchema = z20.object(MCP_INTEGRATIONS_TOOL_SCHEMAS.createMcpIntegration).superRefine((value, ctx) => {
|
|
@@ -6627,7 +6758,12 @@ function registerMcpIntegrationsTools(server, service) {
|
|
|
6627
6758
|
inputSchema: MCP_INTEGRATIONS_TOOL_SCHEMAS.listMcpIntegrationCapabilities
|
|
6628
6759
|
},
|
|
6629
6760
|
async (params) => {
|
|
6630
|
-
const result = await service.mcpIntegrations.listMcpIntegrationCapabilities(
|
|
6761
|
+
const result = await service.mcpIntegrations.listMcpIntegrationCapabilities(
|
|
6762
|
+
params.id,
|
|
6763
|
+
{
|
|
6764
|
+
type: params.type
|
|
6765
|
+
}
|
|
6766
|
+
);
|
|
6631
6767
|
return jsonResult({
|
|
6632
6768
|
total: result.total,
|
|
6633
6769
|
capabilities: result.data
|
|
@@ -6641,7 +6777,6 @@ function registerMcpIntegrationsTools(server, service) {
|
|
|
6641
6777
|
inputSchema: MCP_INTEGRATIONS_TOOL_SCHEMAS.updateMcpIntegrationCapabilities,
|
|
6642
6778
|
annotations: {
|
|
6643
6779
|
readOnlyHint: false,
|
|
6644
|
-
destructiveHint: false,
|
|
6645
6780
|
idempotentHint: true,
|
|
6646
6781
|
openWorldHint: false
|
|
6647
6782
|
}
|
|
@@ -6683,14 +6818,17 @@ function registerMcpIntegrationsTools(server, service) {
|
|
|
6683
6818
|
inputSchema: MCP_INTEGRATIONS_TOOL_SCHEMAS.updateMcpIntegrationWorkspaces,
|
|
6684
6819
|
annotations: {
|
|
6685
6820
|
readOnlyHint: false,
|
|
6686
|
-
destructiveHint: false,
|
|
6687
6821
|
idempotentHint: true,
|
|
6688
6822
|
openWorldHint: false
|
|
6689
6823
|
}
|
|
6690
6824
|
},
|
|
6691
6825
|
async (params) => {
|
|
6692
6826
|
await service.mcpIntegrations.updateMcpIntegrationWorkspaces(params.id, {
|
|
6693
|
-
workspaces: params.workspaces
|
|
6827
|
+
workspaces: params.workspaces,
|
|
6828
|
+
...params.global_workspace_access !== void 0 ? { global_workspace_access: params.global_workspace_access } : {},
|
|
6829
|
+
...params.override_existing_workspace_access !== void 0 ? {
|
|
6830
|
+
override_existing_workspace_access: params.override_existing_workspace_access
|
|
6831
|
+
} : {}
|
|
6694
6832
|
});
|
|
6695
6833
|
return jsonResult({
|
|
6696
6834
|
message: `Successfully updated workspace access for MCP integration "${params.id}"`,
|
|
@@ -6707,7 +6845,9 @@ var MCP_SERVERS_TOOL_SCHEMAS = {
|
|
|
6707
6845
|
tags: resourceTagsSchema.optional().describe("Match resources carrying all supplied tags"),
|
|
6708
6846
|
current_page: CurrentPageSchema,
|
|
6709
6847
|
page_size: PageSizeSchema.describe("Number of results per page (max 100)"),
|
|
6710
|
-
workspace_id: z21.string().optional().describe("Filter by workspace ID")
|
|
6848
|
+
workspace_id: z21.string().optional().describe("Filter by workspace ID"),
|
|
6849
|
+
id: z21.string().optional().describe("Filter by MCP server ID, or several IDs separated by commas"),
|
|
6850
|
+
search: z21.string().max(255).optional().describe("Search MCP servers (up to 255 characters)")
|
|
6711
6851
|
},
|
|
6712
6852
|
createMcpServer: {
|
|
6713
6853
|
tags: resourceTagsSchema.nullable().optional().describe(
|
|
@@ -6716,7 +6856,10 @@ var MCP_SERVERS_TOOL_SCHEMAS = {
|
|
|
6716
6856
|
name: z21.string().describe("Display name for the MCP server"),
|
|
6717
6857
|
mcp_integration_id: z21.string().describe("ID or slug of the MCP integration this server belongs to"),
|
|
6718
6858
|
slug: z21.string().optional().describe("Custom slug. Auto-generated if omitted"),
|
|
6719
|
-
description: z21.string().optional().describe("Description of the MCP server")
|
|
6859
|
+
description: z21.string().optional().describe("Description of the MCP server"),
|
|
6860
|
+
workspace_id: z21.string().optional().describe(
|
|
6861
|
+
"Workspace ID or slug; required with an organisation admin API key"
|
|
6862
|
+
)
|
|
6720
6863
|
},
|
|
6721
6864
|
getMcpServer: {
|
|
6722
6865
|
id: z21.string().describe("The MCP server ID or slug to retrieve")
|
|
@@ -6738,7 +6881,8 @@ var MCP_SERVERS_TOOL_SCHEMAS = {
|
|
|
6738
6881
|
listMcpServerCapabilities: {
|
|
6739
6882
|
id: z21.string().describe("The MCP server ID or slug"),
|
|
6740
6883
|
current_page: CurrentPageSchema,
|
|
6741
|
-
page_size: PageSizeSchema.describe("Number of results per page (max 100)")
|
|
6884
|
+
page_size: PageSizeSchema.describe("Number of results per page (max 100)"),
|
|
6885
|
+
type: z21.enum(["tool", "prompt", "resource", "resource_template"]).optional().describe("Only return capabilities of this type")
|
|
6742
6886
|
},
|
|
6743
6887
|
updateMcpServerCapabilities: {
|
|
6744
6888
|
id: z21.string().describe("The MCP server ID or slug"),
|
|
@@ -6753,7 +6897,8 @@ var MCP_SERVERS_TOOL_SCHEMAS = {
|
|
|
6753
6897
|
listMcpServerUserAccess: {
|
|
6754
6898
|
id: z21.string().describe("The MCP server ID or slug"),
|
|
6755
6899
|
current_page: CurrentPageSchema,
|
|
6756
|
-
page_size: PageSizeSchema.describe("Number of results per page (max 100)")
|
|
6900
|
+
page_size: PageSizeSchema.describe("Number of results per page (max 100)"),
|
|
6901
|
+
search: z21.string().optional().describe("Search by user name or email")
|
|
6757
6902
|
},
|
|
6758
6903
|
updateMcpServerUserAccess: {
|
|
6759
6904
|
id: z21.string().describe("The MCP server ID or slug"),
|
|
@@ -6762,7 +6907,10 @@ var MCP_SERVERS_TOOL_SCHEMAS = {
|
|
|
6762
6907
|
user_id: z21.string().describe("User ID"),
|
|
6763
6908
|
enabled: z21.boolean().describe("Whether user has access")
|
|
6764
6909
|
})
|
|
6765
|
-
).min(1).describe("Array of user access updates")
|
|
6910
|
+
).min(1).optional().describe("Array of user access updates"),
|
|
6911
|
+
default_user_access: z21.enum(["allow", "deny"]).optional().describe(
|
|
6912
|
+
"Server default for users without an explicit override. Provide this, users, or both"
|
|
6913
|
+
)
|
|
6766
6914
|
},
|
|
6767
6915
|
listMcpServerConnections: {
|
|
6768
6916
|
id: z21.string().describe("MCP server ID or slug whose connections to list"),
|
|
@@ -6789,6 +6937,13 @@ var MCP_SERVERS_TOOL_SCHEMAS = {
|
|
|
6789
6937
|
)
|
|
6790
6938
|
}
|
|
6791
6939
|
};
|
|
6940
|
+
var updateMcpServerUserAccessSchema = z21.object(MCP_SERVERS_TOOL_SCHEMAS.updateMcpServerUserAccess).refine(
|
|
6941
|
+
(value) => value.users !== void 0 || value.default_user_access !== void 0,
|
|
6942
|
+
{
|
|
6943
|
+
message: "Provide users, default_user_access, or both",
|
|
6944
|
+
path: ["users"]
|
|
6945
|
+
}
|
|
6946
|
+
);
|
|
6792
6947
|
function formatMcpServer(server) {
|
|
6793
6948
|
return {
|
|
6794
6949
|
id: server.id,
|
|
@@ -6969,7 +7124,8 @@ function registerMcpServersTools(server, service) {
|
|
|
6969
7124
|
params.id,
|
|
6970
7125
|
{
|
|
6971
7126
|
current_page: params.current_page,
|
|
6972
|
-
page_size: params.page_size
|
|
7127
|
+
page_size: params.page_size,
|
|
7128
|
+
type: params.type
|
|
6973
7129
|
}
|
|
6974
7130
|
);
|
|
6975
7131
|
return jsonResult({
|
|
@@ -7006,7 +7162,8 @@ function registerMcpServersTools(server, service) {
|
|
|
7006
7162
|
params.id,
|
|
7007
7163
|
{
|
|
7008
7164
|
current_page: params.current_page,
|
|
7009
|
-
page_size: params.page_size
|
|
7165
|
+
page_size: params.page_size,
|
|
7166
|
+
search: params.search
|
|
7010
7167
|
}
|
|
7011
7168
|
);
|
|
7012
7169
|
return jsonResult({
|
|
@@ -7020,12 +7177,14 @@ function registerMcpServersTools(server, service) {
|
|
|
7020
7177
|
server.registerTool(
|
|
7021
7178
|
"update_mcp_server_user_access",
|
|
7022
7179
|
{
|
|
7023
|
-
description: "Grant or revoke individual user access to an MCP server. Changes take effect immediately and override the default access setting for the selected users; use list_mcp_server_user_access first if you need the current state.",
|
|
7180
|
+
description: "Grant or revoke individual user access to an MCP server, and/or set the server default (default_user_access) for users without an override. Changes take effect immediately and override the default access setting for the selected users; use list_mcp_server_user_access first if you need the current state.",
|
|
7024
7181
|
inputSchema: MCP_SERVERS_TOOL_SCHEMAS.updateMcpServerUserAccess
|
|
7025
7182
|
},
|
|
7026
|
-
async (
|
|
7183
|
+
async (rawParams) => {
|
|
7184
|
+
const params = updateMcpServerUserAccessSchema.parse(rawParams);
|
|
7027
7185
|
await service.mcpServers.updateMcpServerUserAccess(params.id, {
|
|
7028
|
-
user_access: params.users
|
|
7186
|
+
...params.users !== void 0 ? { user_access: params.users } : {},
|
|
7187
|
+
...params.default_user_access !== void 0 ? { default_user_access: params.default_user_access } : {}
|
|
7029
7188
|
});
|
|
7030
7189
|
return jsonResult({
|
|
7031
7190
|
message: `Successfully updated user access for MCP server "${params.id}"`,
|
|
@@ -7724,7 +7883,7 @@ function registerPromptsTools(server, service) {
|
|
|
7724
7883
|
server.registerTool(
|
|
7725
7884
|
"run_prompt_completion",
|
|
7726
7885
|
{
|
|
7727
|
-
description: "Execute a prompt against the configured model and return the completion. This makes a billable model call, so use render_prompt first when you want to check the template and validate_completion_metadata when billing fields are uncertain.",
|
|
7886
|
+
description: "Execute a prompt against the configured model and return the completion text, plus any tool_calls or function_call the model requested (returned as data, never executed). This makes a billable model call, so use render_prompt first when you want to check the template and validate_completion_metadata when billing fields are uncertain.",
|
|
7728
7887
|
inputSchema: PROMPTS_TOOL_SCHEMAS.runPromptCompletion
|
|
7729
7888
|
},
|
|
7730
7889
|
async (params) => {
|
|
@@ -7742,6 +7901,9 @@ function registerPromptsTools(server, service) {
|
|
|
7742
7901
|
id: result.id,
|
|
7743
7902
|
model: result.model,
|
|
7744
7903
|
response: choice?.message?.content ?? null,
|
|
7904
|
+
// Returned as data only. The server never executes a tool call.
|
|
7905
|
+
...choice?.message?.tool_calls?.length ? { tool_calls: choice.message.tool_calls } : {},
|
|
7906
|
+
...choice?.message?.function_call ? { function_call: choice.message.function_call } : {},
|
|
7745
7907
|
finish_reason: choice?.finish_reason ?? null,
|
|
7746
7908
|
usage: result.usage ? {
|
|
7747
7909
|
prompt_tokens: result.usage.prompt_tokens,
|
|
@@ -7924,14 +8086,16 @@ var PROVIDERS_TOOL_SCHEMAS = {
|
|
|
7924
8086
|
credit_limit: z24.coerce.number().positive().optional().describe("New credit limit for usage"),
|
|
7925
8087
|
alert_threshold: z24.coerce.number().min(0).max(100).optional().describe("New alert threshold percentage (0-100)"),
|
|
7926
8088
|
usage_limit_type: z24.enum(["cost", "tokens"]).optional().describe(
|
|
7927
|
-
"
|
|
8089
|
+
"Usage limit type: 'cost' or 'tokens'. If omitted, preserves the existing type; defaults to 'cost' when no limits exist."
|
|
7928
8090
|
),
|
|
7929
8091
|
periodic_reset: z24.enum(["monthly", "weekly"]).optional().describe(
|
|
7930
|
-
"
|
|
8092
|
+
"Reset period: 'monthly' or 'weekly'. If omitted, preserves the existing cadence, including custom reset days; defaults to 'monthly' when no limits exist."
|
|
8093
|
+
),
|
|
8094
|
+
rate_limit_value: z24.coerce.number().positive().optional().describe(
|
|
8095
|
+
"New rate limit value. Must be provided together with rate_limit_unit."
|
|
7931
8096
|
),
|
|
7932
|
-
rate_limit_value: z24.coerce.number().positive().optional().describe("New rate limit value"),
|
|
7933
8097
|
rate_limit_unit: z24.enum(["rpm", "rph", "rpd"]).optional().describe(
|
|
7934
|
-
"Rate limit unit: 'rpm' (requests per minute), 'rph' (requests per hour), or 'rpd' (requests per day)"
|
|
8098
|
+
"Rate limit unit: 'rpm' (requests per minute), 'rph' (requests per hour), or 'rpd' (requests per day). Must be provided together with rate_limit_value."
|
|
7935
8099
|
),
|
|
7936
8100
|
expires_at: z24.string().optional().describe("New expiration date in ISO 8601 format"),
|
|
7937
8101
|
reset_usage: z24.boolean().optional().describe("Set to true to reset accumulated usage metrics")
|
|
@@ -7941,6 +8105,18 @@ var PROVIDERS_TOOL_SCHEMAS = {
|
|
|
7941
8105
|
workspace_id: z24.string().optional().describe("Workspace ID - required when using organization admin keys")
|
|
7942
8106
|
}
|
|
7943
8107
|
};
|
|
8108
|
+
var RATE_LIMIT_PAIR_MESSAGE = "rate_limit_value and rate_limit_unit must be provided together";
|
|
8109
|
+
function hasCompleteRateLimitPair(value) {
|
|
8110
|
+
return value.rate_limit_value === void 0 === (value.rate_limit_unit === void 0);
|
|
8111
|
+
}
|
|
8112
|
+
var createProviderSchema = z24.object(PROVIDERS_TOOL_SCHEMAS.createProvider).refine(hasCompleteRateLimitPair, {
|
|
8113
|
+
path: ["rate_limit_unit"],
|
|
8114
|
+
message: RATE_LIMIT_PAIR_MESSAGE
|
|
8115
|
+
});
|
|
8116
|
+
var updateProviderSchema = z24.object(PROVIDERS_TOOL_SCHEMAS.updateProvider).refine(hasCompleteRateLimitPair, {
|
|
8117
|
+
path: ["rate_limit_unit"],
|
|
8118
|
+
message: RATE_LIMIT_PAIR_MESSAGE
|
|
8119
|
+
});
|
|
7944
8120
|
function registerProvidersTools(server, service) {
|
|
7945
8121
|
server.registerTool(
|
|
7946
8122
|
"list_providers",
|
|
@@ -7963,6 +8139,7 @@ function registerProvidersTools(server, service) {
|
|
|
7963
8139
|
status: provider.status,
|
|
7964
8140
|
note: provider.note,
|
|
7965
8141
|
usage_limits: provider.usage_limits ? {
|
|
8142
|
+
type: provider.usage_limits.type,
|
|
7966
8143
|
credit_limit: provider.usage_limits.credit_limit,
|
|
7967
8144
|
alert_threshold: provider.usage_limits.alert_threshold,
|
|
7968
8145
|
periodic_reset: provider.usage_limits.periodic_reset
|
|
@@ -7985,7 +8162,8 @@ function registerProvidersTools(server, service) {
|
|
|
7985
8162
|
description: "Create a workspace provider backed by an org integration. The provider inherits the integration key, but its limits and expiration are enforced independently for that workspace. Returns the new provider id and slug.",
|
|
7986
8163
|
inputSchema: PROVIDERS_TOOL_SCHEMAS.createProvider
|
|
7987
8164
|
},
|
|
7988
|
-
async (
|
|
8165
|
+
async (rawParams) => {
|
|
8166
|
+
const params = createProviderSchema.parse(rawParams);
|
|
7989
8167
|
const result = await service.providers.createProvider({
|
|
7990
8168
|
name: params.name,
|
|
7991
8169
|
integration_id: params.integration_id,
|
|
@@ -8029,6 +8207,7 @@ function registerProvidersTools(server, service) {
|
|
|
8029
8207
|
status: provider.status,
|
|
8030
8208
|
note: provider.note,
|
|
8031
8209
|
usage_limits: provider.usage_limits ? {
|
|
8210
|
+
type: provider.usage_limits.type,
|
|
8032
8211
|
credit_limit: provider.usage_limits.credit_limit,
|
|
8033
8212
|
alert_threshold: provider.usage_limits.alert_threshold,
|
|
8034
8213
|
periodic_reset: provider.usage_limits.periodic_reset
|
|
@@ -8047,21 +8226,29 @@ function registerProvidersTools(server, service) {
|
|
|
8047
8226
|
server.registerTool(
|
|
8048
8227
|
"update_provider",
|
|
8049
8228
|
{
|
|
8050
|
-
description: "Update a provider's metadata, limits, or expiration. reset_usage clears accumulated usage counters immediately, so use it only when you intend to reset quota tracking. Returns the updated provider id and slug.",
|
|
8229
|
+
description: "Update a provider's metadata, limits, or expiration. reset_usage clears accumulated usage counters immediately, so use it only when you intend to reset quota tracking. Returns the updated provider id and slug. Limit updates read the current limits and write them back, and Portkey has no conditional writes, so concurrent limit updates to the same resource can overwrite each other. Serialize them.",
|
|
8051
8230
|
inputSchema: PROVIDERS_TOOL_SCHEMAS.updateProvider
|
|
8052
8231
|
},
|
|
8053
|
-
async (
|
|
8232
|
+
async (rawParams) => {
|
|
8233
|
+
const params = updateProviderSchema.parse(rawParams);
|
|
8234
|
+
const usageLimits = await mergeUsageLimitsUpdate(
|
|
8235
|
+
buildUsageLimitsUpdate({
|
|
8236
|
+
credit_limit: params.credit_limit,
|
|
8237
|
+
alert_threshold: params.alert_threshold,
|
|
8238
|
+
type: params.usage_limit_type,
|
|
8239
|
+
periodic_reset: params.periodic_reset
|
|
8240
|
+
}),
|
|
8241
|
+
async () => (await service.providers.getProvider(
|
|
8242
|
+
params.slug,
|
|
8243
|
+
params.workspace_id
|
|
8244
|
+
)).usage_limits
|
|
8245
|
+
);
|
|
8054
8246
|
const result = await service.providers.updateProvider(
|
|
8055
8247
|
params.slug,
|
|
8056
8248
|
{
|
|
8057
8249
|
name: params.name,
|
|
8058
8250
|
note: params.note,
|
|
8059
|
-
usage_limits:
|
|
8060
|
-
credit_limit: params.credit_limit,
|
|
8061
|
-
alert_threshold: params.alert_threshold,
|
|
8062
|
-
type: params.usage_limit_type,
|
|
8063
|
-
periodic_reset: params.periodic_reset
|
|
8064
|
-
}),
|
|
8251
|
+
usage_limits: usageLimits,
|
|
8065
8252
|
rate_limits: params.rate_limit_value !== void 0 && params.rate_limit_unit !== void 0 ? buildRateLimits({
|
|
8066
8253
|
value: params.rate_limit_value,
|
|
8067
8254
|
unit: params.rate_limit_unit
|
|
@@ -8950,6 +9137,14 @@ function formatWorkspaceDefaults(defaults) {
|
|
|
8950
9137
|
metadata: defaults.metadata
|
|
8951
9138
|
};
|
|
8952
9139
|
}
|
|
9140
|
+
function formatWorkspaceFlagsAndLimits(workspace) {
|
|
9141
|
+
return {
|
|
9142
|
+
is_default: workspace.is_default ?? workspace.defaults?.is_default,
|
|
9143
|
+
defaults: formatWorkspaceDefaults(workspace.defaults),
|
|
9144
|
+
usage_limits: workspace.usage_limits ?? null,
|
|
9145
|
+
rate_limits: workspace.rate_limits ?? null
|
|
9146
|
+
};
|
|
9147
|
+
}
|
|
8953
9148
|
function formatWorkspaceSummary(workspace) {
|
|
8954
9149
|
return {
|
|
8955
9150
|
id: workspace.id,
|
|
@@ -8958,7 +9153,7 @@ function formatWorkspaceSummary(workspace) {
|
|
|
8958
9153
|
description: workspace.description,
|
|
8959
9154
|
created_at: workspace.created_at,
|
|
8960
9155
|
last_updated_at: workspace.last_updated_at,
|
|
8961
|
-
|
|
9156
|
+
...formatWorkspaceFlagsAndLimits(workspace)
|
|
8962
9157
|
};
|
|
8963
9158
|
}
|
|
8964
9159
|
function formatWorkspaceMember(user) {
|
|
@@ -8980,7 +9175,7 @@ function formatWorkspaceDetail(workspace) {
|
|
|
8980
9175
|
description: workspace.description,
|
|
8981
9176
|
created_at: workspace.created_at,
|
|
8982
9177
|
last_updated_at: workspace.last_updated_at,
|
|
8983
|
-
|
|
9178
|
+
...formatWorkspaceFlagsAndLimits(workspace),
|
|
8984
9179
|
users: workspace.users.map(formatWorkspaceMember)
|
|
8985
9180
|
};
|
|
8986
9181
|
}
|
|
@@ -9327,7 +9522,9 @@ var DESTRUCTIVE_TOOL_PREFIXES = [
|
|
|
9327
9522
|
"delete_",
|
|
9328
9523
|
"remove_",
|
|
9329
9524
|
"cancel_",
|
|
9330
|
-
"reset_"
|
|
9525
|
+
"reset_",
|
|
9526
|
+
"update_",
|
|
9527
|
+
"archive_"
|
|
9331
9528
|
];
|
|
9332
9529
|
var ENTERPRISE_GATED_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
9333
9530
|
"get_cost_analytics",
|
|
@@ -9460,12 +9657,12 @@ function getToolErrorMessage(error) {
|
|
|
9460
9657
|
return String(error);
|
|
9461
9658
|
}
|
|
9462
9659
|
var STANDARD_TOOL_OUTPUT_SCHEMA = {
|
|
9463
|
-
ok: z29.boolean().describe("
|
|
9464
|
-
data: z29.unknown().optional().describe("
|
|
9660
|
+
ok: z29.boolean().describe("Call succeeded"),
|
|
9661
|
+
data: z29.unknown().optional().describe("Success payload"),
|
|
9465
9662
|
error: z29.object({
|
|
9466
|
-
message: z29.string().describe("
|
|
9467
|
-
details: z29.unknown().optional().describe("
|
|
9468
|
-
}).optional().describe("
|
|
9663
|
+
message: z29.string().describe("Error message"),
|
|
9664
|
+
details: z29.unknown().optional().describe("Extra error details")
|
|
9665
|
+
}).optional().describe("Failure details")
|
|
9469
9666
|
};
|
|
9470
9667
|
var TOOL_SUCCESS_DATA_SCHEMAS = {
|
|
9471
9668
|
create_access_policy: CreateAccessPolicyResponseSchema,
|
|
@@ -9483,7 +9680,10 @@ var TOOL_SUCCESS_DATA_SCHEMAS = {
|
|
|
9483
9680
|
warning: z29.string().describe("Required handling guidance for the one-time secret"),
|
|
9484
9681
|
id: z29.string().uuid().describe("Rotated API key UUID"),
|
|
9485
9682
|
key: z29.string().describe("New API key secret, returned only once"),
|
|
9486
|
-
|
|
9683
|
+
// Offsets such as +00:00 are valid RFC 3339, and the field is optional in
|
|
9684
|
+
// the spec. A strict schema here fails after the rotation already ran,
|
|
9685
|
+
// which would drop the one-time secret.
|
|
9686
|
+
key_transition_expires_at: z29.iso.datetime({ offset: true }).optional().describe("Time when the previous key stops working")
|
|
9487
9687
|
}),
|
|
9488
9688
|
create_secret_reference: z29.object({
|
|
9489
9689
|
message: z29.string().describe("Creation confirmation"),
|
|
@@ -9500,9 +9700,9 @@ var TOOL_SUCCESS_DATA_SCHEMAS = {
|
|
|
9500
9700
|
manager_type: SecretManagerTypeSchema.describe(
|
|
9501
9701
|
"External secret manager type"
|
|
9502
9702
|
),
|
|
9503
|
-
status: z29.
|
|
9504
|
-
created_at: z29.iso.datetime().describe("ISO 8601 creation timestamp"),
|
|
9505
|
-
last_updated_at: z29.iso.datetime().describe("ISO 8601 last-update timestamp")
|
|
9703
|
+
status: z29.string().describe("Current reference status, ACTIVE for usable references"),
|
|
9704
|
+
created_at: z29.iso.datetime({ offset: true }).describe("ISO 8601 creation timestamp"),
|
|
9705
|
+
last_updated_at: z29.iso.datetime({ offset: true }).describe("ISO 8601 last-update timestamp")
|
|
9506
9706
|
})
|
|
9507
9707
|
).describe(
|
|
9508
9708
|
"Current page of Secret References without authentication values"
|
|
@@ -9521,10 +9721,10 @@ var TOOL_SUCCESS_DATA_SCHEMAS = {
|
|
|
9521
9721
|
secret_key: z29.string().nullable().describe("Selected key within a structured secret"),
|
|
9522
9722
|
allow_all_workspaces: z29.boolean().describe("Whether all workspaces may use the reference"),
|
|
9523
9723
|
tags: z29.record(z29.string(), z29.string()).nullable().describe("String metadata tags"),
|
|
9524
|
-
status: z29.
|
|
9724
|
+
status: z29.string().describe("Current reference status"),
|
|
9525
9725
|
created_by: z29.string().describe("Creator identifier"),
|
|
9526
|
-
created_at: z29.iso.datetime().describe("ISO 8601 creation timestamp"),
|
|
9527
|
-
last_updated_at: z29.iso.datetime().describe("ISO 8601 last-update timestamp"),
|
|
9726
|
+
created_at: z29.iso.datetime({ offset: true }).describe("ISO 8601 creation timestamp"),
|
|
9727
|
+
last_updated_at: z29.iso.datetime({ offset: true }).describe("ISO 8601 last-update timestamp"),
|
|
9528
9728
|
auth_config: z29.record(z29.string(), z29.unknown()).describe("Authentication configuration with sensitive values redacted"),
|
|
9529
9729
|
object: z29.literal("secret-reference").describe("Portkey object type")
|
|
9530
9730
|
}),
|
|
@@ -9542,7 +9742,7 @@ function getToolOutputSchema(toolName) {
|
|
|
9542
9742
|
if (!dataSchema) return STANDARD_TOOL_OUTPUT_SCHEMA;
|
|
9543
9743
|
return {
|
|
9544
9744
|
...STANDARD_TOOL_OUTPUT_SCHEMA,
|
|
9545
|
-
data: dataSchema.optional().describe("
|
|
9745
|
+
data: dataSchema.optional().describe("Success payload")
|
|
9546
9746
|
};
|
|
9547
9747
|
}
|
|
9548
9748
|
function isStandardToolEnvelope(value) {
|
|
@@ -9604,10 +9804,31 @@ function normalizeToolResult(result) {
|
|
|
9604
9804
|
structuredContent: envelope
|
|
9605
9805
|
};
|
|
9606
9806
|
}
|
|
9807
|
+
function measureToolResultBytes(result) {
|
|
9808
|
+
const text = getFirstTextContent(result) ?? "";
|
|
9809
|
+
return Buffer.byteLength(JSON.stringify(text)) + Buffer.byteLength(text);
|
|
9810
|
+
}
|
|
9811
|
+
function enforceToolResultLimit(toolName, result) {
|
|
9812
|
+
const limit = getMaxToolResultBytes();
|
|
9813
|
+
const bytes = measureToolResultBytes(result);
|
|
9814
|
+
if (bytes <= limit) return result;
|
|
9815
|
+
return normalizeToolResult({
|
|
9816
|
+
content: [
|
|
9817
|
+
{
|
|
9818
|
+
type: "text",
|
|
9819
|
+
text: `Tool "${toolName}" produced a ${bytes}-byte result, over the ${limit}-byte limit (${MAX_TOOL_RESULT_BYTES_ENV}). Nothing was truncated. Narrow the request with filters, a smaller page_size or a shorter time range, or raise the limit.`
|
|
9820
|
+
}
|
|
9821
|
+
],
|
|
9822
|
+
isError: true
|
|
9823
|
+
});
|
|
9824
|
+
}
|
|
9607
9825
|
function wrapToolCallback(toolName, callback) {
|
|
9608
9826
|
return async (...args) => {
|
|
9609
9827
|
try {
|
|
9610
|
-
return
|
|
9828
|
+
return enforceToolResultLimit(
|
|
9829
|
+
toolName,
|
|
9830
|
+
normalizeToolResult(await callback(...args))
|
|
9831
|
+
);
|
|
9611
9832
|
} catch (error) {
|
|
9612
9833
|
const message = getToolErrorMessage(error);
|
|
9613
9834
|
const isValidationError = error instanceof z29.ZodError;
|
|
@@ -9616,23 +9837,64 @@ function wrapToolCallback(toolName, callback) {
|
|
|
9616
9837
|
error: message,
|
|
9617
9838
|
metadata: { toolName }
|
|
9618
9839
|
});
|
|
9619
|
-
return
|
|
9620
|
-
|
|
9621
|
-
|
|
9622
|
-
|
|
9840
|
+
return enforceToolResultLimit(
|
|
9841
|
+
toolName,
|
|
9842
|
+
normalizeToolResult({
|
|
9843
|
+
content: [{ type: "text", text }],
|
|
9844
|
+
isError: true
|
|
9845
|
+
})
|
|
9846
|
+
);
|
|
9623
9847
|
}
|
|
9624
9848
|
};
|
|
9625
9849
|
}
|
|
9626
9850
|
var registrationSchemas = /* @__PURE__ */ new WeakMap();
|
|
9851
|
+
var outputSchemasByTool = /* @__PURE__ */ new Map();
|
|
9852
|
+
var jsonSchemaConversions = 0;
|
|
9853
|
+
function memoizeJsonSchemaConversion(schema) {
|
|
9854
|
+
const standard = schema["~standard"];
|
|
9855
|
+
const converters = standard?.jsonSchema;
|
|
9856
|
+
if (!standard || !converters) return schema;
|
|
9857
|
+
const memoize = (direction) => {
|
|
9858
|
+
const convert = converters[direction];
|
|
9859
|
+
if (!convert) return void 0;
|
|
9860
|
+
const results = /* @__PURE__ */ new Map();
|
|
9861
|
+
return (options) => {
|
|
9862
|
+
const key = JSON.stringify(options ?? null);
|
|
9863
|
+
let result = results.get(key);
|
|
9864
|
+
if (!result) {
|
|
9865
|
+
jsonSchemaConversions += 1;
|
|
9866
|
+
result = convert(options);
|
|
9867
|
+
results.set(key, result);
|
|
9868
|
+
}
|
|
9869
|
+
return result;
|
|
9870
|
+
};
|
|
9871
|
+
};
|
|
9872
|
+
return Object.create(schema, {
|
|
9873
|
+
"~standard": {
|
|
9874
|
+
value: {
|
|
9875
|
+
...standard,
|
|
9876
|
+
jsonSchema: { input: memoize("input"), output: memoize("output") }
|
|
9877
|
+
}
|
|
9878
|
+
}
|
|
9879
|
+
});
|
|
9880
|
+
}
|
|
9627
9881
|
function normalizeRegistrationSchema(schema) {
|
|
9628
|
-
if (!isRecord(schema)
|
|
9629
|
-
|
|
9630
|
-
|
|
9631
|
-
|
|
9632
|
-
|
|
9633
|
-
|
|
9882
|
+
if (!isRecord(schema)) return schema;
|
|
9883
|
+
if (registrationSchemas.has(schema)) return registrationSchemas.get(schema);
|
|
9884
|
+
const normalized = memoizeJsonSchemaConversion(
|
|
9885
|
+
"~standard" in schema ? schema : z29.object(schema)
|
|
9886
|
+
);
|
|
9887
|
+
registrationSchemas.set(schema, normalized);
|
|
9634
9888
|
return normalized;
|
|
9635
9889
|
}
|
|
9890
|
+
function getRegistrationOutputSchema(toolName) {
|
|
9891
|
+
let schema = outputSchemasByTool.get(toolName);
|
|
9892
|
+
if (!schema) {
|
|
9893
|
+
schema = getToolOutputSchema(toolName);
|
|
9894
|
+
outputSchemasByTool.set(toolName, schema);
|
|
9895
|
+
}
|
|
9896
|
+
return schema;
|
|
9897
|
+
}
|
|
9636
9898
|
function createSafeToolServer(server) {
|
|
9637
9899
|
const originalRegisterTool = server.registerTool.bind(server);
|
|
9638
9900
|
const safeServer = Object.create(server);
|
|
@@ -9648,7 +9910,7 @@ function createSafeToolServer(server) {
|
|
|
9648
9910
|
...description === void 0 ? {} : { description },
|
|
9649
9911
|
inputSchema: normalizeRegistrationSchema(config.inputSchema),
|
|
9650
9912
|
outputSchema: normalizeRegistrationSchema(
|
|
9651
|
-
config.outputSchema ??
|
|
9913
|
+
config.outputSchema ?? getRegistrationOutputSchema(name)
|
|
9652
9914
|
),
|
|
9653
9915
|
annotations: {
|
|
9654
9916
|
...inferToolAnnotations(name),
|
|
@@ -9852,6 +10114,7 @@ function createMcpServer(options = {}) {
|
|
|
9852
10114
|
// src/index.ts
|
|
9853
10115
|
function main() {
|
|
9854
10116
|
try {
|
|
10117
|
+
assertByteLimitsConfigured();
|
|
9855
10118
|
if (!process.env.PORTKEY_API_KEY) {
|
|
9856
10119
|
Logger.warn(
|
|
9857
10120
|
"PORTKEY_API_KEY is not set; tool calls will fail until it is configured."
|