portkey-admin-mcp 0.16.4 → 0.16.5
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 +134 -129
- package/build/index.js +516 -261
- package/build/server.js +546 -231
- package/docs/DISTRIBUTION.md +48 -24
- package/docs/VERCEL_DEPLOYMENT.md +4 -3
- package/package.json +3 -3
package/build/server.js
CHANGED
|
@@ -157,6 +157,70 @@ var FetchError = class extends Error {
|
|
|
157
157
|
status;
|
|
158
158
|
response;
|
|
159
159
|
};
|
|
160
|
+
var DEFAULT_MAX_UPSTREAM_BODY_BYTES = 8 * 1024 * 1024;
|
|
161
|
+
var DEFAULT_MAX_TOOL_RESULT_BYTES = 4 * 1024 * 1024;
|
|
162
|
+
var MAX_CONFIGURABLE_BYTES = 1024 * 1024 * 1024;
|
|
163
|
+
var MAX_UPSTREAM_BODY_BYTES_ENV = "PORTKEY_MAX_UPSTREAM_BODY_BYTES";
|
|
164
|
+
var MAX_TOOL_RESULT_BYTES_ENV = "PORTKEY_MAX_TOOL_RESULT_BYTES";
|
|
165
|
+
function resolveByteLimit(envName, fallback) {
|
|
166
|
+
const raw = process.env[envName]?.trim();
|
|
167
|
+
if (!raw) return fallback;
|
|
168
|
+
const parsed = /^\d+$/.test(raw) ? Number(raw) : Number.NaN;
|
|
169
|
+
if (!Number.isSafeInteger(parsed) || parsed < 1 || parsed > MAX_CONFIGURABLE_BYTES) {
|
|
170
|
+
throw new Error(
|
|
171
|
+
`Invalid ${envName} value: ${raw}. Must be a positive integer number of bytes (1-${MAX_CONFIGURABLE_BYTES})`
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
return parsed;
|
|
175
|
+
}
|
|
176
|
+
function getMaxUpstreamBodyBytes() {
|
|
177
|
+
return resolveByteLimit(
|
|
178
|
+
MAX_UPSTREAM_BODY_BYTES_ENV,
|
|
179
|
+
DEFAULT_MAX_UPSTREAM_BODY_BYTES
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
function getMaxToolResultBytes() {
|
|
183
|
+
return resolveByteLimit(
|
|
184
|
+
MAX_TOOL_RESULT_BYTES_ENV,
|
|
185
|
+
DEFAULT_MAX_TOOL_RESULT_BYTES
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
function assertByteLimitsConfigured() {
|
|
189
|
+
getMaxUpstreamBodyBytes();
|
|
190
|
+
getMaxToolResultBytes();
|
|
191
|
+
}
|
|
192
|
+
var ResponseBodyTooLargeError = class extends Error {
|
|
193
|
+
constructor(limit) {
|
|
194
|
+
super(`Response body is larger than the ${limit}-byte limit`);
|
|
195
|
+
this.limit = limit;
|
|
196
|
+
this.name = "ResponseBodyTooLargeError";
|
|
197
|
+
}
|
|
198
|
+
limit;
|
|
199
|
+
};
|
|
200
|
+
async function readBoundedText(response, maxBytes) {
|
|
201
|
+
if (!response.body) return "";
|
|
202
|
+
const reader = response.body.getReader();
|
|
203
|
+
const chunks = [];
|
|
204
|
+
let received = 0;
|
|
205
|
+
try {
|
|
206
|
+
for (; ; ) {
|
|
207
|
+
const { done, value } = await reader.read();
|
|
208
|
+
if (done) break;
|
|
209
|
+
received += value.byteLength;
|
|
210
|
+
if (received > maxBytes) {
|
|
211
|
+
await reader.cancel().catch(() => void 0);
|
|
212
|
+
throw new ResponseBodyTooLargeError(maxBytes);
|
|
213
|
+
}
|
|
214
|
+
chunks.push(value);
|
|
215
|
+
}
|
|
216
|
+
} finally {
|
|
217
|
+
reader.releaseLock();
|
|
218
|
+
}
|
|
219
|
+
return new TextDecoder().decode(Buffer.concat(chunks));
|
|
220
|
+
}
|
|
221
|
+
async function readBoundedJson(response, maxBytes) {
|
|
222
|
+
return JSON.parse(await readBoundedText(response, maxBytes));
|
|
223
|
+
}
|
|
160
224
|
async function fetchWithTimeout(url, options = {}) {
|
|
161
225
|
const { timeout = 3e4, ...fetchOptions } = options;
|
|
162
226
|
return fetch(url, {
|
|
@@ -176,9 +240,9 @@ function buildQueryString(params) {
|
|
|
176
240
|
if (entries.length === 0) return "";
|
|
177
241
|
return `?${new URLSearchParams(entries).toString()}`;
|
|
178
242
|
}
|
|
179
|
-
async function parseErrorResponse(response) {
|
|
243
|
+
async function parseErrorResponse(response, maxBytes = DEFAULT_MAX_UPSTREAM_BODY_BYTES) {
|
|
180
244
|
try {
|
|
181
|
-
const body = await response
|
|
245
|
+
const body = await readBoundedJson(response, maxBytes);
|
|
182
246
|
const err = body.error ?? body.data ?? body ?? {};
|
|
183
247
|
const code = err?.errorCode ?? err?.code;
|
|
184
248
|
return {
|
|
@@ -188,10 +252,10 @@ async function parseErrorResponse(response) {
|
|
|
188
252
|
code,
|
|
189
253
|
type: err?.type
|
|
190
254
|
};
|
|
191
|
-
} catch {
|
|
255
|
+
} catch (error) {
|
|
192
256
|
return {
|
|
193
257
|
status_code: response.status,
|
|
194
|
-
message: `HTTP error! status: ${response.status}`
|
|
258
|
+
message: error instanceof ResponseBodyTooLargeError ? `HTTP error! status: ${response.status} (error body over the ${maxBytes}-byte limit)` : `HTTP error! status: ${response.status}`
|
|
195
259
|
};
|
|
196
260
|
}
|
|
197
261
|
}
|
|
@@ -463,6 +527,7 @@ var BaseService = class {
|
|
|
463
527
|
paramKeys: options.params ? Object.keys(options.params) : []
|
|
464
528
|
}
|
|
465
529
|
});
|
|
530
|
+
const maxBodyBytes = getMaxUpstreamBodyBytes();
|
|
466
531
|
try {
|
|
467
532
|
const response = await fetchWithTimeout(url, {
|
|
468
533
|
method,
|
|
@@ -473,7 +538,7 @@ var BaseService = class {
|
|
|
473
538
|
});
|
|
474
539
|
const duration_ms = Date.now() - startTime;
|
|
475
540
|
if (!response.ok) {
|
|
476
|
-
const apiError = await parseErrorResponse(response);
|
|
541
|
+
const apiError = await parseErrorResponse(response, maxBodyBytes);
|
|
477
542
|
Logger.error("HTTP request failed", {
|
|
478
543
|
requestId,
|
|
479
544
|
method,
|
|
@@ -494,7 +559,16 @@ var BaseService = class {
|
|
|
494
559
|
if (options.allowNoContent && response.status === 204) {
|
|
495
560
|
return NO_CONTENT;
|
|
496
561
|
}
|
|
497
|
-
|
|
562
|
+
try {
|
|
563
|
+
return await readBoundedJson(response, maxBodyBytes);
|
|
564
|
+
} catch (error) {
|
|
565
|
+
if (error instanceof ResponseBodyTooLargeError) {
|
|
566
|
+
throw new Error(
|
|
567
|
+
`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.`
|
|
568
|
+
);
|
|
569
|
+
}
|
|
570
|
+
throw error;
|
|
571
|
+
}
|
|
498
572
|
} catch (error) {
|
|
499
573
|
const duration_ms = Date.now() - startTime;
|
|
500
574
|
if (!(error instanceof FetchError)) {
|
|
@@ -570,9 +644,9 @@ var BaseService = class {
|
|
|
570
644
|
})
|
|
571
645
|
);
|
|
572
646
|
}
|
|
573
|
-
async put(path, body) {
|
|
647
|
+
async put(path, body, params) {
|
|
574
648
|
return this.rejectNoContent(
|
|
575
|
-
await this.executeRequest("PUT", path, { body })
|
|
649
|
+
await this.executeRequest("PUT", path, { body, params })
|
|
576
650
|
);
|
|
577
651
|
}
|
|
578
652
|
/**
|
|
@@ -644,7 +718,7 @@ var AnalyticsService = class extends BaseService {
|
|
|
644
718
|
* Helper method to build query params from analytics parameters
|
|
645
719
|
*/
|
|
646
720
|
buildAnalyticsParams(params) {
|
|
647
|
-
|
|
721
|
+
return {
|
|
648
722
|
time_of_generation_min: params.time_of_generation_min,
|
|
649
723
|
time_of_generation_max: params.time_of_generation_max,
|
|
650
724
|
total_units_min: params.total_units_min,
|
|
@@ -661,7 +735,7 @@ var AnalyticsService = class extends BaseService {
|
|
|
661
735
|
virtual_keys: params.virtual_keys,
|
|
662
736
|
configs: params.configs,
|
|
663
737
|
workspace_slug: params.workspace_slug,
|
|
664
|
-
include_all_workspaces: params.include_all_workspaces
|
|
738
|
+
include_all_workspaces: params.include_all_workspaces,
|
|
665
739
|
exclude_workspace_slugs: params.exclude_workspace_slugs,
|
|
666
740
|
api_key_ids: params.api_key_ids,
|
|
667
741
|
metadata: params.metadata,
|
|
@@ -669,21 +743,14 @@ var AnalyticsService = class extends BaseService {
|
|
|
669
743
|
deployment_id: params.deployment_id,
|
|
670
744
|
trace_id: params.trace_id,
|
|
671
745
|
span_id: params.span_id,
|
|
672
|
-
prompt_slug: params.prompt_slug
|
|
746
|
+
prompt_slug: params.prompt_slug,
|
|
747
|
+
current_page: params.current_page,
|
|
748
|
+
page_size: params.page_size,
|
|
749
|
+
order_by: params.order_by,
|
|
750
|
+
order_by_type: params.order_by_type,
|
|
751
|
+
columns: params.columns,
|
|
752
|
+
include_total: params.include_total
|
|
673
753
|
};
|
|
674
|
-
if ("current_page" in params) {
|
|
675
|
-
baseParams.current_page = params.current_page;
|
|
676
|
-
}
|
|
677
|
-
if ("page_size" in params) {
|
|
678
|
-
baseParams.page_size = params.page_size;
|
|
679
|
-
}
|
|
680
|
-
if ("order_by" in params) baseParams.order_by = params.order_by;
|
|
681
|
-
if ("order_by_type" in params)
|
|
682
|
-
baseParams.order_by_type = params.order_by_type;
|
|
683
|
-
if ("columns" in params) baseParams.columns = params.columns;
|
|
684
|
-
if ("include_total" in params)
|
|
685
|
-
baseParams.include_total = params.include_total;
|
|
686
|
-
return baseParams;
|
|
687
754
|
}
|
|
688
755
|
// ==================== Cost Analytics ====================
|
|
689
756
|
async getCostAnalytics(params) {
|
|
@@ -1595,9 +1662,10 @@ var McpIntegrationsService = class extends BaseService {
|
|
|
1595
1662
|
`/mcp-integrations/${this.encodePathSegment(id)}/metadata`
|
|
1596
1663
|
);
|
|
1597
1664
|
}
|
|
1598
|
-
async listMcpIntegrationCapabilities(id) {
|
|
1665
|
+
async listMcpIntegrationCapabilities(id, params) {
|
|
1599
1666
|
return this.get(
|
|
1600
|
-
`/mcp-integrations/${this.encodePathSegment(id)}/capabilities
|
|
1667
|
+
`/mcp-integrations/${this.encodePathSegment(id)}/capabilities`,
|
|
1668
|
+
{ type: params?.type }
|
|
1601
1669
|
);
|
|
1602
1670
|
}
|
|
1603
1671
|
async updateMcpIntegrationCapabilities(id, data) {
|
|
@@ -1641,6 +1709,8 @@ var McpServersService = class extends BaseService {
|
|
|
1641
1709
|
current_page: params?.current_page,
|
|
1642
1710
|
page_size: params?.page_size,
|
|
1643
1711
|
workspace_id: params?.workspace_id,
|
|
1712
|
+
id: params?.id,
|
|
1713
|
+
search: params?.search,
|
|
1644
1714
|
tags: params?.tags === void 0 ? void 0 : JSON.stringify(params.tags)
|
|
1645
1715
|
});
|
|
1646
1716
|
}
|
|
@@ -1669,7 +1739,8 @@ var McpServersService = class extends BaseService {
|
|
|
1669
1739
|
`/mcp-servers/${this.encodePathSegment(id)}/capabilities`,
|
|
1670
1740
|
{
|
|
1671
1741
|
current_page: params?.current_page,
|
|
1672
|
-
page_size: params?.page_size
|
|
1742
|
+
page_size: params?.page_size,
|
|
1743
|
+
type: params?.type
|
|
1673
1744
|
}
|
|
1674
1745
|
);
|
|
1675
1746
|
}
|
|
@@ -1685,7 +1756,8 @@ var McpServersService = class extends BaseService {
|
|
|
1685
1756
|
`/mcp-servers/${this.encodePathSegment(id)}/user-access`,
|
|
1686
1757
|
{
|
|
1687
1758
|
current_page: params?.current_page,
|
|
1688
|
-
page_size: params?.page_size
|
|
1759
|
+
page_size: params?.page_size,
|
|
1760
|
+
search: params?.search
|
|
1689
1761
|
}
|
|
1690
1762
|
);
|
|
1691
1763
|
}
|
|
@@ -1784,6 +1856,8 @@ var PromptsService = class extends BaseService {
|
|
|
1784
1856
|
string: raw.string ?? "",
|
|
1785
1857
|
parameters: raw.parameters ?? {},
|
|
1786
1858
|
model: raw.model,
|
|
1859
|
+
ai_model_id: raw.ai_model_id,
|
|
1860
|
+
finetune_id: raw.finetune_id,
|
|
1787
1861
|
virtual_key: raw.virtual_key,
|
|
1788
1862
|
functions: raw.functions ?? void 0,
|
|
1789
1863
|
tools: raw.tools ?? void 0,
|
|
@@ -1795,12 +1869,14 @@ var PromptsService = class extends BaseService {
|
|
|
1795
1869
|
object: "prompt"
|
|
1796
1870
|
};
|
|
1797
1871
|
}
|
|
1798
|
-
async updatePrompt(promptId, data) {
|
|
1872
|
+
async updatePrompt(promptId, data, options = {}) {
|
|
1799
1873
|
const { template_metadata, is_raw_template, ...rest } = data;
|
|
1800
1874
|
const body = {
|
|
1801
1875
|
...rest,
|
|
1802
|
-
//
|
|
1803
|
-
|
|
1876
|
+
// Partial updates backfill missing version fields from the latest
|
|
1877
|
+
// version. Callers that send a complete version turn this off so absent
|
|
1878
|
+
// fields are cleared instead of inherited.
|
|
1879
|
+
patch: options.patch ?? true
|
|
1804
1880
|
};
|
|
1805
1881
|
if (template_metadata !== void 0) {
|
|
1806
1882
|
body.prompt_metadata = template_metadata;
|
|
@@ -2027,24 +2103,42 @@ var PromptsService = class extends BaseService {
|
|
|
2027
2103
|
data.target_collection_id
|
|
2028
2104
|
);
|
|
2029
2105
|
if (existingTarget) {
|
|
2030
|
-
const
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
...sourceVersion.
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2106
|
+
const virtualKey2 = data.virtual_key || sourceVersion.virtual_key;
|
|
2107
|
+
if (!sourceVersion.string || !(sourceVersion.model || sourceVersion.ai_model_id || sourceVersion.finetune_id) || !virtualKey2) {
|
|
2108
|
+
throw new Error(
|
|
2109
|
+
"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)"
|
|
2110
|
+
);
|
|
2111
|
+
}
|
|
2112
|
+
const updateResult = await this.updatePrompt(
|
|
2113
|
+
existingTarget.id,
|
|
2114
|
+
{
|
|
2115
|
+
string: sourceVersion.string,
|
|
2116
|
+
parameters: sourceVersion.parameters ?? {},
|
|
2117
|
+
...sourceVersion.model && { model: sourceVersion.model },
|
|
2118
|
+
...sourceVersion.ai_model_id && {
|
|
2119
|
+
ai_model_id: sourceVersion.ai_model_id
|
|
2120
|
+
},
|
|
2121
|
+
...sourceVersion.finetune_id && {
|
|
2122
|
+
finetune_id: sourceVersion.finetune_id
|
|
2123
|
+
},
|
|
2124
|
+
virtual_key: virtualKey2,
|
|
2125
|
+
functions: sourceVersion.functions ?? [],
|
|
2126
|
+
tools: sourceVersion.tools ?? [],
|
|
2127
|
+
...sourceVersion.tool_choice !== void 0 && {
|
|
2128
|
+
tool_choice: sourceVersion.tool_choice
|
|
2129
|
+
},
|
|
2130
|
+
is_raw_template: sourceVersion.is_raw_template ?? false,
|
|
2131
|
+
version_description: `Promoted from ${sourcePrompt.slug} v${sourceVersion.version_number}`,
|
|
2132
|
+
template_metadata: {
|
|
2133
|
+
...sourceVersion.template_metadata,
|
|
2134
|
+
env: data.target_env,
|
|
2135
|
+
promoted_from: sourcePrompt.slug,
|
|
2136
|
+
promoted_from_version: sourceVersion.version_number.toString(),
|
|
2137
|
+
promoted_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
2138
|
+
}
|
|
2139
|
+
},
|
|
2140
|
+
{ patch: false }
|
|
2141
|
+
);
|
|
2048
2142
|
return {
|
|
2049
2143
|
source_prompt_id: data.source_prompt_id,
|
|
2050
2144
|
source_version_id: sourceVersion.id,
|
|
@@ -2128,12 +2222,17 @@ var ProvidersService = class extends BaseService {
|
|
|
2128
2222
|
});
|
|
2129
2223
|
}
|
|
2130
2224
|
async updateProvider(slug, data, workspaceId) {
|
|
2131
|
-
|
|
2132
|
-
|
|
2225
|
+
return this.put(
|
|
2226
|
+
`/providers/${this.encodePathSegment(slug)}`,
|
|
2227
|
+
data,
|
|
2228
|
+
{ workspace_id: workspaceId || void 0 }
|
|
2229
|
+
);
|
|
2133
2230
|
}
|
|
2134
2231
|
async deleteProvider(slug, workspaceId) {
|
|
2135
|
-
const
|
|
2136
|
-
|
|
2232
|
+
const result = await this.delete(
|
|
2233
|
+
`/providers/${this.encodePathSegment(slug)}`,
|
|
2234
|
+
{ workspace_id: workspaceId || void 0 }
|
|
2235
|
+
);
|
|
2137
2236
|
return isNoContent(result) ? {} : result;
|
|
2138
2237
|
}
|
|
2139
2238
|
};
|
|
@@ -2360,7 +2459,7 @@ function getSharedServiceCacheKey(apiKey) {
|
|
|
2360
2459
|
const keyDigest = createHmac("sha256", SERVICE_CACHE_HMAC_KEY).update(apiKey).digest("hex");
|
|
2361
2460
|
return JSON.stringify({
|
|
2362
2461
|
apiKey: keyDigest,
|
|
2363
|
-
baseUrl: process.env.PORTKEY_BASE_URL
|
|
2462
|
+
baseUrl: process.env.PORTKEY_BASE_URL ?? DEFAULT_BASE_URL
|
|
2364
2463
|
});
|
|
2365
2464
|
}
|
|
2366
2465
|
var sharedPortkeyServices = /* @__PURE__ */ new Map();
|
|
@@ -2390,8 +2489,7 @@ var PortkeyService = class {
|
|
|
2390
2489
|
health;
|
|
2391
2490
|
constructor(apiKey) {
|
|
2392
2491
|
const resolvedApiKey = resolvePortkeyApiKey(apiKey);
|
|
2393
|
-
const resolvedBaseUrl = process.env.PORTKEY_BASE_URL ??
|
|
2394
|
-
validateUrl(resolvedBaseUrl);
|
|
2492
|
+
const resolvedBaseUrl = process.env.PORTKEY_BASE_URL ?? DEFAULT_BASE_URL;
|
|
2395
2493
|
this.accessPolicies = new AccessPoliciesService(
|
|
2396
2494
|
resolvedApiKey,
|
|
2397
2495
|
resolvedBaseUrl
|
|
@@ -2465,8 +2563,8 @@ var SecretReferenceListItemSchema = z3.object({
|
|
|
2465
2563
|
slug: z3.string(),
|
|
2466
2564
|
manager_type: SecretManagerTypeSchema,
|
|
2467
2565
|
status: z3.literal("ACTIVE"),
|
|
2468
|
-
created_at: z3.iso.datetime(),
|
|
2469
|
-
last_updated_at: z3.iso.datetime(),
|
|
2566
|
+
created_at: z3.iso.datetime({ offset: true }),
|
|
2567
|
+
last_updated_at: z3.iso.datetime({ offset: true }),
|
|
2470
2568
|
object: z3.literal("secret-reference")
|
|
2471
2569
|
});
|
|
2472
2570
|
var ListSecretReferencesResponseSchema = z3.object({
|
|
@@ -2809,7 +2907,7 @@ var GENERIC_GRAPH_ANALYTICS_TOOLS = [
|
|
|
2809
2907
|
},
|
|
2810
2908
|
{
|
|
2811
2909
|
name: "get_user_requests_analytics",
|
|
2812
|
-
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
|
|
2910
|
+
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.",
|
|
2813
2911
|
method: (analytics, params) => analytics.getUserRequestsAnalytics(params)
|
|
2814
2912
|
},
|
|
2815
2913
|
{
|
|
@@ -2869,57 +2967,27 @@ function normalizeMetadataFilter(value) {
|
|
|
2869
2967
|
}
|
|
2870
2968
|
return void 0;
|
|
2871
2969
|
}
|
|
2970
|
+
var ANALYTICS_PARAM_ALIASES = [
|
|
2971
|
+
["status_codes", "status_code", normalizeCommaSeparatedParam],
|
|
2972
|
+
["virtual_key_slugs", "virtual_keys", normalizeCommaSeparatedParam],
|
|
2973
|
+
["config_slugs", "configs", normalizeCommaSeparatedParam],
|
|
2974
|
+
["api_key_ids", "api_key_ids", normalizeCommaSeparatedParam],
|
|
2975
|
+
["metadata_filter", "metadata", normalizeMetadataFilter],
|
|
2976
|
+
["provider_models", "ai_org_model", normalizeCommaSeparatedParam],
|
|
2977
|
+
["deployment_ids", "deployment_id", normalizeCommaSeparatedParam],
|
|
2978
|
+
["trace_ids", "trace_id", normalizeCommaSeparatedParam],
|
|
2979
|
+
["span_ids", "span_id", normalizeCommaSeparatedParam]
|
|
2980
|
+
];
|
|
2872
2981
|
function normalizeAnalyticsParams(params) {
|
|
2873
|
-
const {
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
config_slugs,
|
|
2877
|
-
api_key_ids,
|
|
2878
|
-
trace_ids,
|
|
2879
|
-
span_ids,
|
|
2880
|
-
provider_models,
|
|
2881
|
-
deployment_ids,
|
|
2882
|
-
metadata_filter,
|
|
2883
|
-
...legacyParams
|
|
2884
|
-
} = params;
|
|
2885
|
-
const normalizedParams = {
|
|
2886
|
-
...legacyParams
|
|
2887
|
-
};
|
|
2888
|
-
const statusCode = normalizeCommaSeparatedParam(status_codes) ?? normalizeCommaSeparatedParam(legacyParams.status_code);
|
|
2889
|
-
if (statusCode !== void 0) {
|
|
2890
|
-
normalizedParams.status_code = statusCode;
|
|
2982
|
+
const normalizedParams = { ...params };
|
|
2983
|
+
for (const [alias] of ANALYTICS_PARAM_ALIASES) {
|
|
2984
|
+
delete normalizedParams[alias];
|
|
2891
2985
|
}
|
|
2892
|
-
const
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
if (configs !== void 0) {
|
|
2898
|
-
normalizedParams.configs = configs;
|
|
2899
|
-
}
|
|
2900
|
-
const apiKeyIds = normalizeCommaSeparatedParam(api_key_ids) ?? normalizeCommaSeparatedParam(legacyParams.api_key_ids);
|
|
2901
|
-
if (apiKeyIds !== void 0) {
|
|
2902
|
-
normalizedParams.api_key_ids = apiKeyIds;
|
|
2903
|
-
}
|
|
2904
|
-
const metadata = normalizeMetadataFilter(metadata_filter) ?? normalizeMetadataFilter(legacyParams.metadata);
|
|
2905
|
-
if (metadata !== void 0) {
|
|
2906
|
-
normalizedParams.metadata = metadata;
|
|
2907
|
-
}
|
|
2908
|
-
const providerModels = normalizeCommaSeparatedParam(provider_models) ?? normalizeCommaSeparatedParam(legacyParams.ai_org_model);
|
|
2909
|
-
if (providerModels !== void 0) {
|
|
2910
|
-
normalizedParams.ai_org_model = providerModels;
|
|
2911
|
-
}
|
|
2912
|
-
const deploymentId = normalizeCommaSeparatedParam(deployment_ids) ?? normalizeCommaSeparatedParam(legacyParams.deployment_id);
|
|
2913
|
-
if (deploymentId !== void 0) {
|
|
2914
|
-
normalizedParams.deployment_id = deploymentId;
|
|
2915
|
-
}
|
|
2916
|
-
const traceId = normalizeCommaSeparatedParam(trace_ids) ?? normalizeCommaSeparatedParam(legacyParams.trace_id);
|
|
2917
|
-
if (traceId !== void 0) {
|
|
2918
|
-
normalizedParams.trace_id = traceId;
|
|
2919
|
-
}
|
|
2920
|
-
const spanId = normalizeCommaSeparatedParam(span_ids) ?? normalizeCommaSeparatedParam(legacyParams.span_id);
|
|
2921
|
-
if (spanId !== void 0) {
|
|
2922
|
-
normalizedParams.span_id = spanId;
|
|
2986
|
+
for (const [alias, legacy, normalize] of ANALYTICS_PARAM_ALIASES) {
|
|
2987
|
+
const value = normalize(params[alias]) ?? normalize(params[legacy]);
|
|
2988
|
+
if (value !== void 0) {
|
|
2989
|
+
normalizedParams[legacy] = value;
|
|
2990
|
+
}
|
|
2923
2991
|
}
|
|
2924
2992
|
return normalizedParams;
|
|
2925
2993
|
}
|
|
@@ -2981,7 +3049,7 @@ function registerAnalyticsTools(server, service) {
|
|
|
2981
3049
|
server.registerTool(
|
|
2982
3050
|
"get_token_analytics",
|
|
2983
3051
|
{
|
|
2984
|
-
description: "Get token-usage time-series data with summary.
|
|
3052
|
+
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.",
|
|
2985
3053
|
inputSchema: baseAnalyticsSchema
|
|
2986
3054
|
},
|
|
2987
3055
|
async (params) => {
|
|
@@ -2991,15 +3059,13 @@ function registerAnalyticsTools(server, service) {
|
|
|
2991
3059
|
const dataPoints = analytics.data_points.map((point) => ({
|
|
2992
3060
|
timestamp: point.timestamp,
|
|
2993
3061
|
total: point.total,
|
|
2994
|
-
|
|
2995
|
-
completion: point.completion
|
|
3062
|
+
avg: point.avg
|
|
2996
3063
|
}));
|
|
2997
3064
|
return jsonResult(
|
|
2998
3065
|
formatGraphAnalytics(
|
|
2999
3066
|
{
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
completion_tokens: analytics.summary.completion
|
|
3067
|
+
total: analytics.summary.total,
|
|
3068
|
+
avg: analytics.summary.avg
|
|
3003
3069
|
},
|
|
3004
3070
|
dataPoints
|
|
3005
3071
|
)
|
|
@@ -3113,7 +3179,7 @@ function registerAnalyticsTools(server, service) {
|
|
|
3113
3179
|
server.registerTool(
|
|
3114
3180
|
"get_cache_hit_rate",
|
|
3115
3181
|
{
|
|
3116
|
-
description: "Get cache-effectiveness time-series data with summary.hit_rate
|
|
3182
|
+
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.",
|
|
3117
3183
|
inputSchema: baseAnalyticsSchema
|
|
3118
3184
|
},
|
|
3119
3185
|
async (params) => {
|
|
@@ -3122,16 +3188,17 @@ function registerAnalyticsTools(server, service) {
|
|
|
3122
3188
|
);
|
|
3123
3189
|
const dataPoints = analytics.data_points.map((point) => ({
|
|
3124
3190
|
timestamp: point.timestamp,
|
|
3191
|
+
simple_hits: point.simple_hits,
|
|
3192
|
+
semantic_hits: point.semantic_hits,
|
|
3125
3193
|
rate: point.rate,
|
|
3126
|
-
|
|
3127
|
-
|
|
3194
|
+
cumulative_simple_cache_savings: point.cumulative_simple_cache_savings,
|
|
3195
|
+
cumulative_semantic_cache_savings: point.cumulative_semantic_cache_savings
|
|
3128
3196
|
}));
|
|
3129
3197
|
return jsonResult(
|
|
3130
3198
|
formatGraphAnalytics(
|
|
3131
3199
|
{
|
|
3132
3200
|
hit_rate: analytics.summary.rate,
|
|
3133
|
-
total_hits: analytics.summary.
|
|
3134
|
-
total_misses: analytics.summary.total_misses
|
|
3201
|
+
total_hits: analytics.summary.total
|
|
3135
3202
|
},
|
|
3136
3203
|
dataPoints
|
|
3137
3204
|
)
|
|
@@ -3155,7 +3222,7 @@ function registerAnalyticsTools(server, service) {
|
|
|
3155
3222
|
server.registerTool(
|
|
3156
3223
|
"get_users_analytics",
|
|
3157
3224
|
{
|
|
3158
|
-
description: "Get user
|
|
3225
|
+
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.",
|
|
3159
3226
|
inputSchema: baseAnalyticsSchema
|
|
3160
3227
|
},
|
|
3161
3228
|
async (params) => {
|
|
@@ -3164,14 +3231,12 @@ function registerAnalyticsTools(server, service) {
|
|
|
3164
3231
|
);
|
|
3165
3232
|
const dataPoints = analytics.data_points.map((point) => ({
|
|
3166
3233
|
timestamp: point.timestamp,
|
|
3167
|
-
|
|
3168
|
-
new_users: point.new_users
|
|
3234
|
+
total: point.total
|
|
3169
3235
|
}));
|
|
3170
3236
|
return jsonResult(
|
|
3171
3237
|
formatGraphAnalytics(
|
|
3172
3238
|
{
|
|
3173
|
-
|
|
3174
|
-
total_new_users: analytics.summary.total_new_users
|
|
3239
|
+
total: analytics.summary.total
|
|
3175
3240
|
},
|
|
3176
3241
|
dataPoints
|
|
3177
3242
|
)
|
|
@@ -3194,7 +3259,7 @@ function registerAnalyticsTools(server, service) {
|
|
|
3194
3259
|
server.registerTool(
|
|
3195
3260
|
"get_analytics_group_users",
|
|
3196
3261
|
{
|
|
3197
|
-
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
|
|
3262
|
+
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.",
|
|
3198
3263
|
inputSchema: paginatedAnalyticsSchema
|
|
3199
3264
|
},
|
|
3200
3265
|
async (params) => {
|
|
@@ -3688,7 +3753,6 @@ function registerConfigsTools(server, service) {
|
|
|
3688
3753
|
inputSchema: CONFIGS_TOOL_SCHEMAS.updateConfig,
|
|
3689
3754
|
annotations: {
|
|
3690
3755
|
readOnlyHint: false,
|
|
3691
|
-
destructiveHint: false,
|
|
3692
3756
|
idempotentHint: false,
|
|
3693
3757
|
openWorldHint: false
|
|
3694
3758
|
}
|
|
@@ -4133,7 +4197,6 @@ function registerGuardrailsTools(server, service) {
|
|
|
4133
4197
|
annotations: {
|
|
4134
4198
|
title: "Update Organisation Guardrail Defaults",
|
|
4135
4199
|
readOnlyHint: false,
|
|
4136
|
-
destructiveHint: false,
|
|
4137
4200
|
idempotentHint: true,
|
|
4138
4201
|
openWorldHint: true
|
|
4139
4202
|
}
|
|
@@ -4402,31 +4465,68 @@ import { z as z15 } from "zod";
|
|
|
4402
4465
|
|
|
4403
4466
|
// src/lib/limits.ts
|
|
4404
4467
|
var PERIODIC_RESET_DEFAULT = "monthly";
|
|
4468
|
+
function hasUsageLimitInput(params) {
|
|
4469
|
+
return params.credit_limit !== void 0 || params.alert_threshold !== void 0 || params.type !== void 0 || params.periodic_reset !== void 0;
|
|
4470
|
+
}
|
|
4471
|
+
function copyDefinedUsageLimitFields(params, limits) {
|
|
4472
|
+
if (params.type !== void 0) {
|
|
4473
|
+
limits.type = params.type;
|
|
4474
|
+
}
|
|
4475
|
+
if (params.periodic_reset !== void 0) {
|
|
4476
|
+
limits.periodic_reset = params.periodic_reset;
|
|
4477
|
+
}
|
|
4478
|
+
if (params.credit_limit !== void 0) {
|
|
4479
|
+
limits.credit_limit = params.credit_limit;
|
|
4480
|
+
}
|
|
4481
|
+
if (params.alert_threshold !== void 0) {
|
|
4482
|
+
limits.alert_threshold = params.alert_threshold;
|
|
4483
|
+
}
|
|
4484
|
+
return limits;
|
|
4485
|
+
}
|
|
4405
4486
|
function buildUsageLimits(params) {
|
|
4406
|
-
if (params
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4487
|
+
if (!hasUsageLimitInput(params)) {
|
|
4488
|
+
return void 0;
|
|
4489
|
+
}
|
|
4490
|
+
return copyDefinedUsageLimitFields(params, {
|
|
4491
|
+
type: "cost",
|
|
4492
|
+
periodic_reset: PERIODIC_RESET_DEFAULT
|
|
4493
|
+
});
|
|
4494
|
+
}
|
|
4495
|
+
function buildUsageLimitsUpdate(params) {
|
|
4496
|
+
if (!hasUsageLimitInput(params)) {
|
|
4497
|
+
return void 0;
|
|
4498
|
+
}
|
|
4499
|
+
return copyDefinedUsageLimitFields(params, {});
|
|
4500
|
+
}
|
|
4501
|
+
async function mergeUsageLimitsUpdate(supplied, readExisting) {
|
|
4502
|
+
if (supplied === void 0) {
|
|
4503
|
+
return void 0;
|
|
4504
|
+
}
|
|
4505
|
+
const existing = await readExisting();
|
|
4506
|
+
const base = existing ? {} : { type: "cost", periodic_reset: PERIODIC_RESET_DEFAULT };
|
|
4507
|
+
if (existing) {
|
|
4508
|
+
for (const key of [
|
|
4509
|
+
"type",
|
|
4510
|
+
"credit_limit",
|
|
4511
|
+
"alert_threshold",
|
|
4512
|
+
"periodic_reset",
|
|
4513
|
+
"periodic_reset_days"
|
|
4514
|
+
]) {
|
|
4515
|
+
if (existing[key] !== void 0) {
|
|
4516
|
+
Object.assign(base, { [key]: existing[key] });
|
|
4517
|
+
}
|
|
4413
4518
|
}
|
|
4414
|
-
if (
|
|
4415
|
-
|
|
4519
|
+
if (supplied.periodic_reset !== void 0) {
|
|
4520
|
+
delete base.periodic_reset_days;
|
|
4521
|
+
} else if (base.periodic_reset_days !== void 0 && base.periodic_reset_days !== null) {
|
|
4522
|
+
delete base.periodic_reset;
|
|
4416
4523
|
}
|
|
4417
|
-
return limits;
|
|
4418
4524
|
}
|
|
4419
|
-
return
|
|
4525
|
+
return { ...base, ...supplied };
|
|
4420
4526
|
}
|
|
4421
4527
|
function buildRateLimitsRpm(rpmValue) {
|
|
4422
4528
|
if (rpmValue !== void 0) {
|
|
4423
|
-
return
|
|
4424
|
-
{
|
|
4425
|
-
type: "requests",
|
|
4426
|
-
unit: "rpm",
|
|
4427
|
-
value: rpmValue
|
|
4428
|
-
}
|
|
4429
|
-
];
|
|
4529
|
+
return buildRateLimits({ value: rpmValue, unit: "rpm" });
|
|
4430
4530
|
}
|
|
4431
4531
|
return void 0;
|
|
4432
4532
|
}
|
|
@@ -5180,7 +5280,9 @@ var KEYS_TOOL_SCHEMAS = {
|
|
|
5180
5280
|
alert_threshold: z16.coerce.number().min(0).max(100).optional().describe("New alert threshold percentage (0-100)"),
|
|
5181
5281
|
rate_limit_rpm: z16.coerce.number().positive().optional().describe("New rate limit in requests per minute"),
|
|
5182
5282
|
rate_limits: z16.array(apiKeyRateLimitSchema).nullable().optional().describe("Replacement request or token rate limits, or null to clear"),
|
|
5183
|
-
reset_usage: z16.
|
|
5283
|
+
reset_usage: z16.boolean().optional().describe(
|
|
5284
|
+
"Set to true to reset current usage; an exhausted key returns to active"
|
|
5285
|
+
),
|
|
5184
5286
|
default_config_id: z16.string().optional().describe("New default configuration ID"),
|
|
5185
5287
|
default_metadata: z16.record(z16.string(), z16.string()).optional().describe("New default metadata key-value pairs"),
|
|
5186
5288
|
default_allow_config_override: z16.boolean().optional().describe("Whether callers may override the key's default config"),
|
|
@@ -5227,6 +5329,7 @@ var createApiKeySchema = z16.object(KEYS_TOOL_SCHEMAS.createApiKey).superRefine(
|
|
|
5227
5329
|
});
|
|
5228
5330
|
function formatKeyUsageLimits(limits) {
|
|
5229
5331
|
return limits ? {
|
|
5332
|
+
type: limits.type,
|
|
5230
5333
|
credit_limit: limits.credit_limit,
|
|
5231
5334
|
alert_threshold: limits.alert_threshold,
|
|
5232
5335
|
periodic_reset: limits.periodic_reset
|
|
@@ -5372,18 +5475,22 @@ function registerKeysTools(server, service) {
|
|
|
5372
5475
|
server.registerTool(
|
|
5373
5476
|
"update_virtual_key",
|
|
5374
5477
|
{
|
|
5375
|
-
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.",
|
|
5478
|
+
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.",
|
|
5376
5479
|
inputSchema: KEYS_TOOL_SCHEMAS.updateVirtualKey
|
|
5377
5480
|
},
|
|
5378
5481
|
async (params) => {
|
|
5482
|
+
const usageLimits = await mergeUsageLimitsUpdate(
|
|
5483
|
+
buildUsageLimitsUpdate({
|
|
5484
|
+
credit_limit: params.credit_limit,
|
|
5485
|
+
alert_threshold: params.alert_threshold
|
|
5486
|
+
}),
|
|
5487
|
+
async () => (await service.keys.getVirtualKey(params.slug)).usage_limits
|
|
5488
|
+
);
|
|
5379
5489
|
const result = await service.keys.updateVirtualKey(params.slug, {
|
|
5380
5490
|
name: params.name,
|
|
5381
5491
|
key: params.key,
|
|
5382
5492
|
note: params.note,
|
|
5383
|
-
usage_limits:
|
|
5384
|
-
credit_limit: params.credit_limit,
|
|
5385
|
-
alert_threshold: params.alert_threshold
|
|
5386
|
-
}),
|
|
5493
|
+
usage_limits: usageLimits,
|
|
5387
5494
|
rate_limits: buildRateLimitsRpm(params.rate_limit_rpm),
|
|
5388
5495
|
deploymentConfig: params.deployment_configurations?.map(
|
|
5389
5496
|
(configuration) => ({
|
|
@@ -5492,18 +5599,22 @@ function registerKeysTools(server, service) {
|
|
|
5492
5599
|
server.registerTool(
|
|
5493
5600
|
"update_api_key",
|
|
5494
5601
|
{
|
|
5495
|
-
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.",
|
|
5602
|
+
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.",
|
|
5496
5603
|
inputSchema: KEYS_TOOL_SCHEMAS.updateApiKey
|
|
5497
5604
|
},
|
|
5498
5605
|
async (params) => {
|
|
5606
|
+
const usageLimits = await mergeUsageLimitsUpdate(
|
|
5607
|
+
buildUsageLimitsUpdate({
|
|
5608
|
+
credit_limit: params.credit_limit,
|
|
5609
|
+
alert_threshold: params.alert_threshold
|
|
5610
|
+
}),
|
|
5611
|
+
async () => (await service.keys.getApiKey(params.id)).usage_limits
|
|
5612
|
+
);
|
|
5499
5613
|
const result = await service.keys.updateApiKey(params.id, {
|
|
5500
5614
|
name: params.name,
|
|
5501
5615
|
description: params.description,
|
|
5502
5616
|
scopes: params.scopes,
|
|
5503
|
-
usage_limits:
|
|
5504
|
-
credit_limit: params.credit_limit,
|
|
5505
|
-
alert_threshold: params.alert_threshold
|
|
5506
|
-
}),
|
|
5617
|
+
usage_limits: usageLimits,
|
|
5507
5618
|
rate_limits: params.rate_limits === void 0 ? buildRateLimitsRpm(params.rate_limit_rpm) : params.rate_limits,
|
|
5508
5619
|
...params.reset_usage !== void 0 ? { reset_usage: params.reset_usage } : {},
|
|
5509
5620
|
defaults: params.default_config_id !== void 0 || params.default_metadata !== void 0 || params.default_allow_config_override !== void 0 ? {
|
|
@@ -6377,7 +6488,10 @@ var MCP_INTEGRATIONS_TOOL_SCHEMAS = {
|
|
|
6377
6488
|
"Additional documented or forward-compatible configuration fields. For headers auth, configurations.custom_headers is a string-to-string header map."
|
|
6378
6489
|
),
|
|
6379
6490
|
workspace_id: z20.string().optional().describe(
|
|
6380
|
-
"Workspace ID
|
|
6491
|
+
"Workspace ID; set it to create the integration at workspace level. With an organisation admin key, give this or organisation_id."
|
|
6492
|
+
),
|
|
6493
|
+
organisation_id: z20.string().optional().describe(
|
|
6494
|
+
"Organisation ID; required with an organisation admin API key when workspace_id is omitted"
|
|
6381
6495
|
),
|
|
6382
6496
|
secret_mappings: mcpSecretMappingsSchema.optional().describe(
|
|
6383
6497
|
"Runtime Secret Reference mappings; every configurations.<field> target must be unique"
|
|
@@ -6415,7 +6529,8 @@ var MCP_INTEGRATIONS_TOOL_SCHEMAS = {
|
|
|
6415
6529
|
id: z20.string().describe("The MCP integration ID or slug")
|
|
6416
6530
|
},
|
|
6417
6531
|
listMcpIntegrationCapabilities: {
|
|
6418
|
-
id: z20.string().describe("The MCP integration ID or slug")
|
|
6532
|
+
id: z20.string().describe("The MCP integration ID or slug"),
|
|
6533
|
+
type: z20.enum(["tool", "prompt", "resource", "resource_template"]).optional().describe("Only return capabilities of this type")
|
|
6419
6534
|
},
|
|
6420
6535
|
updateMcpIntegrationCapabilities: {
|
|
6421
6536
|
id: z20.string().describe("The MCP integration ID or slug"),
|
|
@@ -6437,7 +6552,15 @@ var MCP_INTEGRATIONS_TOOL_SCHEMAS = {
|
|
|
6437
6552
|
id: z20.string().describe("Workspace ID"),
|
|
6438
6553
|
enabled: z20.boolean().describe("Whether workspace has access")
|
|
6439
6554
|
})
|
|
6440
|
-
).
|
|
6555
|
+
).describe(
|
|
6556
|
+
"Array of workspace access updates; may be empty when only changing global_workspace_access"
|
|
6557
|
+
),
|
|
6558
|
+
global_workspace_access: z20.object({
|
|
6559
|
+
enabled: z20.boolean().describe("Whether every workspace gets access by default")
|
|
6560
|
+
}).optional().describe("Organisation-wide workspace access default"),
|
|
6561
|
+
override_existing_workspace_access: z20.boolean().optional().describe(
|
|
6562
|
+
"When true, global_workspace_access replaces existing per-workspace settings"
|
|
6563
|
+
)
|
|
6441
6564
|
}
|
|
6442
6565
|
};
|
|
6443
6566
|
var createMcpIntegrationSchema = z20.object(MCP_INTEGRATIONS_TOOL_SCHEMAS.createMcpIntegration).superRefine((value, ctx) => {
|
|
@@ -6640,7 +6763,12 @@ function registerMcpIntegrationsTools(server, service) {
|
|
|
6640
6763
|
inputSchema: MCP_INTEGRATIONS_TOOL_SCHEMAS.listMcpIntegrationCapabilities
|
|
6641
6764
|
},
|
|
6642
6765
|
async (params) => {
|
|
6643
|
-
const result = await service.mcpIntegrations.listMcpIntegrationCapabilities(
|
|
6766
|
+
const result = await service.mcpIntegrations.listMcpIntegrationCapabilities(
|
|
6767
|
+
params.id,
|
|
6768
|
+
{
|
|
6769
|
+
type: params.type
|
|
6770
|
+
}
|
|
6771
|
+
);
|
|
6644
6772
|
return jsonResult({
|
|
6645
6773
|
total: result.total,
|
|
6646
6774
|
capabilities: result.data
|
|
@@ -6654,7 +6782,6 @@ function registerMcpIntegrationsTools(server, service) {
|
|
|
6654
6782
|
inputSchema: MCP_INTEGRATIONS_TOOL_SCHEMAS.updateMcpIntegrationCapabilities,
|
|
6655
6783
|
annotations: {
|
|
6656
6784
|
readOnlyHint: false,
|
|
6657
|
-
destructiveHint: false,
|
|
6658
6785
|
idempotentHint: true,
|
|
6659
6786
|
openWorldHint: false
|
|
6660
6787
|
}
|
|
@@ -6696,14 +6823,17 @@ function registerMcpIntegrationsTools(server, service) {
|
|
|
6696
6823
|
inputSchema: MCP_INTEGRATIONS_TOOL_SCHEMAS.updateMcpIntegrationWorkspaces,
|
|
6697
6824
|
annotations: {
|
|
6698
6825
|
readOnlyHint: false,
|
|
6699
|
-
destructiveHint: false,
|
|
6700
6826
|
idempotentHint: true,
|
|
6701
6827
|
openWorldHint: false
|
|
6702
6828
|
}
|
|
6703
6829
|
},
|
|
6704
6830
|
async (params) => {
|
|
6705
6831
|
await service.mcpIntegrations.updateMcpIntegrationWorkspaces(params.id, {
|
|
6706
|
-
workspaces: params.workspaces
|
|
6832
|
+
workspaces: params.workspaces,
|
|
6833
|
+
...params.global_workspace_access !== void 0 ? { global_workspace_access: params.global_workspace_access } : {},
|
|
6834
|
+
...params.override_existing_workspace_access !== void 0 ? {
|
|
6835
|
+
override_existing_workspace_access: params.override_existing_workspace_access
|
|
6836
|
+
} : {}
|
|
6707
6837
|
});
|
|
6708
6838
|
return jsonResult({
|
|
6709
6839
|
message: `Successfully updated workspace access for MCP integration "${params.id}"`,
|
|
@@ -6720,7 +6850,9 @@ var MCP_SERVERS_TOOL_SCHEMAS = {
|
|
|
6720
6850
|
tags: resourceTagsSchema.optional().describe("Match resources carrying all supplied tags"),
|
|
6721
6851
|
current_page: CurrentPageSchema,
|
|
6722
6852
|
page_size: PageSizeSchema.describe("Number of results per page (max 100)"),
|
|
6723
|
-
workspace_id: z21.string().optional().describe("Filter by workspace ID")
|
|
6853
|
+
workspace_id: z21.string().optional().describe("Filter by workspace ID"),
|
|
6854
|
+
id: z21.string().optional().describe("Filter by MCP server ID, or several IDs separated by commas"),
|
|
6855
|
+
search: z21.string().max(255).optional().describe("Search MCP servers (up to 255 characters)")
|
|
6724
6856
|
},
|
|
6725
6857
|
createMcpServer: {
|
|
6726
6858
|
tags: resourceTagsSchema.nullable().optional().describe(
|
|
@@ -6729,7 +6861,10 @@ var MCP_SERVERS_TOOL_SCHEMAS = {
|
|
|
6729
6861
|
name: z21.string().describe("Display name for the MCP server"),
|
|
6730
6862
|
mcp_integration_id: z21.string().describe("ID or slug of the MCP integration this server belongs to"),
|
|
6731
6863
|
slug: z21.string().optional().describe("Custom slug. Auto-generated if omitted"),
|
|
6732
|
-
description: z21.string().optional().describe("Description of the MCP server")
|
|
6864
|
+
description: z21.string().optional().describe("Description of the MCP server"),
|
|
6865
|
+
workspace_id: z21.string().optional().describe(
|
|
6866
|
+
"Workspace ID or slug; required with an organisation admin API key"
|
|
6867
|
+
)
|
|
6733
6868
|
},
|
|
6734
6869
|
getMcpServer: {
|
|
6735
6870
|
id: z21.string().describe("The MCP server ID or slug to retrieve")
|
|
@@ -6751,7 +6886,8 @@ var MCP_SERVERS_TOOL_SCHEMAS = {
|
|
|
6751
6886
|
listMcpServerCapabilities: {
|
|
6752
6887
|
id: z21.string().describe("The MCP server ID or slug"),
|
|
6753
6888
|
current_page: CurrentPageSchema,
|
|
6754
|
-
page_size: PageSizeSchema.describe("Number of results per page (max 100)")
|
|
6889
|
+
page_size: PageSizeSchema.describe("Number of results per page (max 100)"),
|
|
6890
|
+
type: z21.enum(["tool", "prompt", "resource", "resource_template"]).optional().describe("Only return capabilities of this type")
|
|
6755
6891
|
},
|
|
6756
6892
|
updateMcpServerCapabilities: {
|
|
6757
6893
|
id: z21.string().describe("The MCP server ID or slug"),
|
|
@@ -6766,7 +6902,8 @@ var MCP_SERVERS_TOOL_SCHEMAS = {
|
|
|
6766
6902
|
listMcpServerUserAccess: {
|
|
6767
6903
|
id: z21.string().describe("The MCP server ID or slug"),
|
|
6768
6904
|
current_page: CurrentPageSchema,
|
|
6769
|
-
page_size: PageSizeSchema.describe("Number of results per page (max 100)")
|
|
6905
|
+
page_size: PageSizeSchema.describe("Number of results per page (max 100)"),
|
|
6906
|
+
search: z21.string().optional().describe("Search by user name or email")
|
|
6770
6907
|
},
|
|
6771
6908
|
updateMcpServerUserAccess: {
|
|
6772
6909
|
id: z21.string().describe("The MCP server ID or slug"),
|
|
@@ -6775,7 +6912,10 @@ var MCP_SERVERS_TOOL_SCHEMAS = {
|
|
|
6775
6912
|
user_id: z21.string().describe("User ID"),
|
|
6776
6913
|
enabled: z21.boolean().describe("Whether user has access")
|
|
6777
6914
|
})
|
|
6778
|
-
).min(1).describe("Array of user access updates")
|
|
6915
|
+
).min(1).optional().describe("Array of user access updates"),
|
|
6916
|
+
default_user_access: z21.enum(["allow", "deny"]).optional().describe(
|
|
6917
|
+
"Server default for users without an explicit override. Provide this, users, or both"
|
|
6918
|
+
)
|
|
6779
6919
|
},
|
|
6780
6920
|
listMcpServerConnections: {
|
|
6781
6921
|
id: z21.string().describe("MCP server ID or slug whose connections to list"),
|
|
@@ -6802,6 +6942,13 @@ var MCP_SERVERS_TOOL_SCHEMAS = {
|
|
|
6802
6942
|
)
|
|
6803
6943
|
}
|
|
6804
6944
|
};
|
|
6945
|
+
var updateMcpServerUserAccessSchema = z21.object(MCP_SERVERS_TOOL_SCHEMAS.updateMcpServerUserAccess).refine(
|
|
6946
|
+
(value) => value.users !== void 0 || value.default_user_access !== void 0,
|
|
6947
|
+
{
|
|
6948
|
+
message: "Provide users, default_user_access, or both",
|
|
6949
|
+
path: ["users"]
|
|
6950
|
+
}
|
|
6951
|
+
);
|
|
6805
6952
|
function formatMcpServer(server) {
|
|
6806
6953
|
return {
|
|
6807
6954
|
id: server.id,
|
|
@@ -6982,7 +7129,8 @@ function registerMcpServersTools(server, service) {
|
|
|
6982
7129
|
params.id,
|
|
6983
7130
|
{
|
|
6984
7131
|
current_page: params.current_page,
|
|
6985
|
-
page_size: params.page_size
|
|
7132
|
+
page_size: params.page_size,
|
|
7133
|
+
type: params.type
|
|
6986
7134
|
}
|
|
6987
7135
|
);
|
|
6988
7136
|
return jsonResult({
|
|
@@ -7019,7 +7167,8 @@ function registerMcpServersTools(server, service) {
|
|
|
7019
7167
|
params.id,
|
|
7020
7168
|
{
|
|
7021
7169
|
current_page: params.current_page,
|
|
7022
|
-
page_size: params.page_size
|
|
7170
|
+
page_size: params.page_size,
|
|
7171
|
+
search: params.search
|
|
7023
7172
|
}
|
|
7024
7173
|
);
|
|
7025
7174
|
return jsonResult({
|
|
@@ -7033,12 +7182,14 @@ function registerMcpServersTools(server, service) {
|
|
|
7033
7182
|
server.registerTool(
|
|
7034
7183
|
"update_mcp_server_user_access",
|
|
7035
7184
|
{
|
|
7036
|
-
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.",
|
|
7185
|
+
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.",
|
|
7037
7186
|
inputSchema: MCP_SERVERS_TOOL_SCHEMAS.updateMcpServerUserAccess
|
|
7038
7187
|
},
|
|
7039
|
-
async (
|
|
7188
|
+
async (rawParams) => {
|
|
7189
|
+
const params = updateMcpServerUserAccessSchema.parse(rawParams);
|
|
7040
7190
|
await service.mcpServers.updateMcpServerUserAccess(params.id, {
|
|
7041
|
-
user_access: params.users
|
|
7191
|
+
...params.users !== void 0 ? { user_access: params.users } : {},
|
|
7192
|
+
...params.default_user_access !== void 0 ? { default_user_access: params.default_user_access } : {}
|
|
7042
7193
|
});
|
|
7043
7194
|
return jsonResult({
|
|
7044
7195
|
message: `Successfully updated user access for MCP server "${params.id}"`,
|
|
@@ -7737,7 +7888,7 @@ function registerPromptsTools(server, service) {
|
|
|
7737
7888
|
server.registerTool(
|
|
7738
7889
|
"run_prompt_completion",
|
|
7739
7890
|
{
|
|
7740
|
-
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.",
|
|
7891
|
+
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.",
|
|
7741
7892
|
inputSchema: PROMPTS_TOOL_SCHEMAS.runPromptCompletion
|
|
7742
7893
|
},
|
|
7743
7894
|
async (params) => {
|
|
@@ -7755,6 +7906,9 @@ function registerPromptsTools(server, service) {
|
|
|
7755
7906
|
id: result.id,
|
|
7756
7907
|
model: result.model,
|
|
7757
7908
|
response: choice?.message?.content ?? null,
|
|
7909
|
+
// Returned as data only. The server never executes a tool call.
|
|
7910
|
+
...choice?.message?.tool_calls?.length ? { tool_calls: choice.message.tool_calls } : {},
|
|
7911
|
+
...choice?.message?.function_call ? { function_call: choice.message.function_call } : {},
|
|
7758
7912
|
finish_reason: choice?.finish_reason ?? null,
|
|
7759
7913
|
usage: result.usage ? {
|
|
7760
7914
|
prompt_tokens: result.usage.prompt_tokens,
|
|
@@ -7937,14 +8091,16 @@ var PROVIDERS_TOOL_SCHEMAS = {
|
|
|
7937
8091
|
credit_limit: z24.coerce.number().positive().optional().describe("New credit limit for usage"),
|
|
7938
8092
|
alert_threshold: z24.coerce.number().min(0).max(100).optional().describe("New alert threshold percentage (0-100)"),
|
|
7939
8093
|
usage_limit_type: z24.enum(["cost", "tokens"]).optional().describe(
|
|
7940
|
-
"
|
|
8094
|
+
"Usage limit type: 'cost' or 'tokens'. If omitted, preserves the existing type; defaults to 'cost' when no limits exist."
|
|
7941
8095
|
),
|
|
7942
8096
|
periodic_reset: z24.enum(["monthly", "weekly"]).optional().describe(
|
|
7943
|
-
"
|
|
8097
|
+
"Reset period: 'monthly' or 'weekly'. If omitted, preserves the existing cadence, including custom reset days; defaults to 'monthly' when no limits exist."
|
|
8098
|
+
),
|
|
8099
|
+
rate_limit_value: z24.coerce.number().positive().optional().describe(
|
|
8100
|
+
"New rate limit value. Must be provided together with rate_limit_unit."
|
|
7944
8101
|
),
|
|
7945
|
-
rate_limit_value: z24.coerce.number().positive().optional().describe("New rate limit value"),
|
|
7946
8102
|
rate_limit_unit: z24.enum(["rpm", "rph", "rpd"]).optional().describe(
|
|
7947
|
-
"Rate limit unit: 'rpm' (requests per minute), 'rph' (requests per hour), or 'rpd' (requests per day)"
|
|
8103
|
+
"Rate limit unit: 'rpm' (requests per minute), 'rph' (requests per hour), or 'rpd' (requests per day). Must be provided together with rate_limit_value."
|
|
7948
8104
|
),
|
|
7949
8105
|
expires_at: z24.string().optional().describe("New expiration date in ISO 8601 format"),
|
|
7950
8106
|
reset_usage: z24.boolean().optional().describe("Set to true to reset accumulated usage metrics")
|
|
@@ -7954,6 +8110,18 @@ var PROVIDERS_TOOL_SCHEMAS = {
|
|
|
7954
8110
|
workspace_id: z24.string().optional().describe("Workspace ID - required when using organization admin keys")
|
|
7955
8111
|
}
|
|
7956
8112
|
};
|
|
8113
|
+
var RATE_LIMIT_PAIR_MESSAGE = "rate_limit_value and rate_limit_unit must be provided together";
|
|
8114
|
+
function hasCompleteRateLimitPair(value) {
|
|
8115
|
+
return value.rate_limit_value === void 0 === (value.rate_limit_unit === void 0);
|
|
8116
|
+
}
|
|
8117
|
+
var createProviderSchema = z24.object(PROVIDERS_TOOL_SCHEMAS.createProvider).refine(hasCompleteRateLimitPair, {
|
|
8118
|
+
path: ["rate_limit_unit"],
|
|
8119
|
+
message: RATE_LIMIT_PAIR_MESSAGE
|
|
8120
|
+
});
|
|
8121
|
+
var updateProviderSchema = z24.object(PROVIDERS_TOOL_SCHEMAS.updateProvider).refine(hasCompleteRateLimitPair, {
|
|
8122
|
+
path: ["rate_limit_unit"],
|
|
8123
|
+
message: RATE_LIMIT_PAIR_MESSAGE
|
|
8124
|
+
});
|
|
7957
8125
|
function registerProvidersTools(server, service) {
|
|
7958
8126
|
server.registerTool(
|
|
7959
8127
|
"list_providers",
|
|
@@ -7976,6 +8144,7 @@ function registerProvidersTools(server, service) {
|
|
|
7976
8144
|
status: provider.status,
|
|
7977
8145
|
note: provider.note,
|
|
7978
8146
|
usage_limits: provider.usage_limits ? {
|
|
8147
|
+
type: provider.usage_limits.type,
|
|
7979
8148
|
credit_limit: provider.usage_limits.credit_limit,
|
|
7980
8149
|
alert_threshold: provider.usage_limits.alert_threshold,
|
|
7981
8150
|
periodic_reset: provider.usage_limits.periodic_reset
|
|
@@ -7998,7 +8167,8 @@ function registerProvidersTools(server, service) {
|
|
|
7998
8167
|
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.",
|
|
7999
8168
|
inputSchema: PROVIDERS_TOOL_SCHEMAS.createProvider
|
|
8000
8169
|
},
|
|
8001
|
-
async (
|
|
8170
|
+
async (rawParams) => {
|
|
8171
|
+
const params = createProviderSchema.parse(rawParams);
|
|
8002
8172
|
const result = await service.providers.createProvider({
|
|
8003
8173
|
name: params.name,
|
|
8004
8174
|
integration_id: params.integration_id,
|
|
@@ -8042,6 +8212,7 @@ function registerProvidersTools(server, service) {
|
|
|
8042
8212
|
status: provider.status,
|
|
8043
8213
|
note: provider.note,
|
|
8044
8214
|
usage_limits: provider.usage_limits ? {
|
|
8215
|
+
type: provider.usage_limits.type,
|
|
8045
8216
|
credit_limit: provider.usage_limits.credit_limit,
|
|
8046
8217
|
alert_threshold: provider.usage_limits.alert_threshold,
|
|
8047
8218
|
periodic_reset: provider.usage_limits.periodic_reset
|
|
@@ -8060,21 +8231,29 @@ function registerProvidersTools(server, service) {
|
|
|
8060
8231
|
server.registerTool(
|
|
8061
8232
|
"update_provider",
|
|
8062
8233
|
{
|
|
8063
|
-
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.",
|
|
8234
|
+
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.",
|
|
8064
8235
|
inputSchema: PROVIDERS_TOOL_SCHEMAS.updateProvider
|
|
8065
8236
|
},
|
|
8066
|
-
async (
|
|
8237
|
+
async (rawParams) => {
|
|
8238
|
+
const params = updateProviderSchema.parse(rawParams);
|
|
8239
|
+
const usageLimits = await mergeUsageLimitsUpdate(
|
|
8240
|
+
buildUsageLimitsUpdate({
|
|
8241
|
+
credit_limit: params.credit_limit,
|
|
8242
|
+
alert_threshold: params.alert_threshold,
|
|
8243
|
+
type: params.usage_limit_type,
|
|
8244
|
+
periodic_reset: params.periodic_reset
|
|
8245
|
+
}),
|
|
8246
|
+
async () => (await service.providers.getProvider(
|
|
8247
|
+
params.slug,
|
|
8248
|
+
params.workspace_id
|
|
8249
|
+
)).usage_limits
|
|
8250
|
+
);
|
|
8067
8251
|
const result = await service.providers.updateProvider(
|
|
8068
8252
|
params.slug,
|
|
8069
8253
|
{
|
|
8070
8254
|
name: params.name,
|
|
8071
8255
|
note: params.note,
|
|
8072
|
-
usage_limits:
|
|
8073
|
-
credit_limit: params.credit_limit,
|
|
8074
|
-
alert_threshold: params.alert_threshold,
|
|
8075
|
-
type: params.usage_limit_type,
|
|
8076
|
-
periodic_reset: params.periodic_reset
|
|
8077
|
-
}),
|
|
8256
|
+
usage_limits: usageLimits,
|
|
8078
8257
|
rate_limits: params.rate_limit_value !== void 0 && params.rate_limit_unit !== void 0 ? buildRateLimits({
|
|
8079
8258
|
value: params.rate_limit_value,
|
|
8080
8259
|
unit: params.rate_limit_unit
|
|
@@ -8963,6 +9142,14 @@ function formatWorkspaceDefaults(defaults) {
|
|
|
8963
9142
|
metadata: defaults.metadata
|
|
8964
9143
|
};
|
|
8965
9144
|
}
|
|
9145
|
+
function formatWorkspaceFlagsAndLimits(workspace) {
|
|
9146
|
+
return {
|
|
9147
|
+
is_default: workspace.is_default ?? workspace.defaults?.is_default,
|
|
9148
|
+
defaults: formatWorkspaceDefaults(workspace.defaults),
|
|
9149
|
+
usage_limits: workspace.usage_limits ?? null,
|
|
9150
|
+
rate_limits: workspace.rate_limits ?? null
|
|
9151
|
+
};
|
|
9152
|
+
}
|
|
8966
9153
|
function formatWorkspaceSummary(workspace) {
|
|
8967
9154
|
return {
|
|
8968
9155
|
id: workspace.id,
|
|
@@ -8971,7 +9158,7 @@ function formatWorkspaceSummary(workspace) {
|
|
|
8971
9158
|
description: workspace.description,
|
|
8972
9159
|
created_at: workspace.created_at,
|
|
8973
9160
|
last_updated_at: workspace.last_updated_at,
|
|
8974
|
-
|
|
9161
|
+
...formatWorkspaceFlagsAndLimits(workspace)
|
|
8975
9162
|
};
|
|
8976
9163
|
}
|
|
8977
9164
|
function formatWorkspaceMember(user) {
|
|
@@ -8993,7 +9180,7 @@ function formatWorkspaceDetail(workspace) {
|
|
|
8993
9180
|
description: workspace.description,
|
|
8994
9181
|
created_at: workspace.created_at,
|
|
8995
9182
|
last_updated_at: workspace.last_updated_at,
|
|
8996
|
-
|
|
9183
|
+
...formatWorkspaceFlagsAndLimits(workspace),
|
|
8997
9184
|
users: workspace.users.map(formatWorkspaceMember)
|
|
8998
9185
|
};
|
|
8999
9186
|
}
|
|
@@ -9340,7 +9527,9 @@ var DESTRUCTIVE_TOOL_PREFIXES = [
|
|
|
9340
9527
|
"delete_",
|
|
9341
9528
|
"remove_",
|
|
9342
9529
|
"cancel_",
|
|
9343
|
-
"reset_"
|
|
9530
|
+
"reset_",
|
|
9531
|
+
"update_",
|
|
9532
|
+
"archive_"
|
|
9344
9533
|
];
|
|
9345
9534
|
var ENTERPRISE_GATED_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
9346
9535
|
"get_cost_analytics",
|
|
@@ -9473,12 +9662,12 @@ function getToolErrorMessage(error) {
|
|
|
9473
9662
|
return String(error);
|
|
9474
9663
|
}
|
|
9475
9664
|
var STANDARD_TOOL_OUTPUT_SCHEMA = {
|
|
9476
|
-
ok: z29.boolean().describe("
|
|
9477
|
-
data: z29.unknown().optional().describe("
|
|
9665
|
+
ok: z29.boolean().describe("Call succeeded"),
|
|
9666
|
+
data: z29.unknown().optional().describe("Success payload"),
|
|
9478
9667
|
error: z29.object({
|
|
9479
|
-
message: z29.string().describe("
|
|
9480
|
-
details: z29.unknown().optional().describe("
|
|
9481
|
-
}).optional().describe("
|
|
9668
|
+
message: z29.string().describe("Error message"),
|
|
9669
|
+
details: z29.unknown().optional().describe("Extra error details")
|
|
9670
|
+
}).optional().describe("Failure details")
|
|
9482
9671
|
};
|
|
9483
9672
|
var TOOL_SUCCESS_DATA_SCHEMAS = {
|
|
9484
9673
|
create_access_policy: CreateAccessPolicyResponseSchema,
|
|
@@ -9496,7 +9685,10 @@ var TOOL_SUCCESS_DATA_SCHEMAS = {
|
|
|
9496
9685
|
warning: z29.string().describe("Required handling guidance for the one-time secret"),
|
|
9497
9686
|
id: z29.string().uuid().describe("Rotated API key UUID"),
|
|
9498
9687
|
key: z29.string().describe("New API key secret, returned only once"),
|
|
9499
|
-
|
|
9688
|
+
// Offsets such as +00:00 are valid RFC 3339, and the field is optional in
|
|
9689
|
+
// the spec. A strict schema here fails after the rotation already ran,
|
|
9690
|
+
// which would drop the one-time secret.
|
|
9691
|
+
key_transition_expires_at: z29.iso.datetime({ offset: true }).optional().describe("Time when the previous key stops working")
|
|
9500
9692
|
}),
|
|
9501
9693
|
create_secret_reference: z29.object({
|
|
9502
9694
|
message: z29.string().describe("Creation confirmation"),
|
|
@@ -9513,9 +9705,9 @@ var TOOL_SUCCESS_DATA_SCHEMAS = {
|
|
|
9513
9705
|
manager_type: SecretManagerTypeSchema.describe(
|
|
9514
9706
|
"External secret manager type"
|
|
9515
9707
|
),
|
|
9516
|
-
status: z29.
|
|
9517
|
-
created_at: z29.iso.datetime().describe("ISO 8601 creation timestamp"),
|
|
9518
|
-
last_updated_at: z29.iso.datetime().describe("ISO 8601 last-update timestamp")
|
|
9708
|
+
status: z29.string().describe("Current reference status, ACTIVE for usable references"),
|
|
9709
|
+
created_at: z29.iso.datetime({ offset: true }).describe("ISO 8601 creation timestamp"),
|
|
9710
|
+
last_updated_at: z29.iso.datetime({ offset: true }).describe("ISO 8601 last-update timestamp")
|
|
9519
9711
|
})
|
|
9520
9712
|
).describe(
|
|
9521
9713
|
"Current page of Secret References without authentication values"
|
|
@@ -9534,10 +9726,10 @@ var TOOL_SUCCESS_DATA_SCHEMAS = {
|
|
|
9534
9726
|
secret_key: z29.string().nullable().describe("Selected key within a structured secret"),
|
|
9535
9727
|
allow_all_workspaces: z29.boolean().describe("Whether all workspaces may use the reference"),
|
|
9536
9728
|
tags: z29.record(z29.string(), z29.string()).nullable().describe("String metadata tags"),
|
|
9537
|
-
status: z29.
|
|
9729
|
+
status: z29.string().describe("Current reference status"),
|
|
9538
9730
|
created_by: z29.string().describe("Creator identifier"),
|
|
9539
|
-
created_at: z29.iso.datetime().describe("ISO 8601 creation timestamp"),
|
|
9540
|
-
last_updated_at: z29.iso.datetime().describe("ISO 8601 last-update timestamp"),
|
|
9731
|
+
created_at: z29.iso.datetime({ offset: true }).describe("ISO 8601 creation timestamp"),
|
|
9732
|
+
last_updated_at: z29.iso.datetime({ offset: true }).describe("ISO 8601 last-update timestamp"),
|
|
9541
9733
|
auth_config: z29.record(z29.string(), z29.unknown()).describe("Authentication configuration with sensitive values redacted"),
|
|
9542
9734
|
object: z29.literal("secret-reference").describe("Portkey object type")
|
|
9543
9735
|
}),
|
|
@@ -9555,7 +9747,7 @@ function getToolOutputSchema(toolName) {
|
|
|
9555
9747
|
if (!dataSchema) return STANDARD_TOOL_OUTPUT_SCHEMA;
|
|
9556
9748
|
return {
|
|
9557
9749
|
...STANDARD_TOOL_OUTPUT_SCHEMA,
|
|
9558
|
-
data: dataSchema.optional().describe("
|
|
9750
|
+
data: dataSchema.optional().describe("Success payload")
|
|
9559
9751
|
};
|
|
9560
9752
|
}
|
|
9561
9753
|
function isStandardToolEnvelope(value) {
|
|
@@ -9617,10 +9809,31 @@ function normalizeToolResult(result) {
|
|
|
9617
9809
|
structuredContent: envelope
|
|
9618
9810
|
};
|
|
9619
9811
|
}
|
|
9812
|
+
function measureToolResultBytes(result) {
|
|
9813
|
+
const text = getFirstTextContent(result) ?? "";
|
|
9814
|
+
return Buffer.byteLength(JSON.stringify(text)) + Buffer.byteLength(text);
|
|
9815
|
+
}
|
|
9816
|
+
function enforceToolResultLimit(toolName, result) {
|
|
9817
|
+
const limit = getMaxToolResultBytes();
|
|
9818
|
+
const bytes = measureToolResultBytes(result);
|
|
9819
|
+
if (bytes <= limit) return result;
|
|
9820
|
+
return normalizeToolResult({
|
|
9821
|
+
content: [
|
|
9822
|
+
{
|
|
9823
|
+
type: "text",
|
|
9824
|
+
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.`
|
|
9825
|
+
}
|
|
9826
|
+
],
|
|
9827
|
+
isError: true
|
|
9828
|
+
});
|
|
9829
|
+
}
|
|
9620
9830
|
function wrapToolCallback(toolName, callback) {
|
|
9621
9831
|
return async (...args) => {
|
|
9622
9832
|
try {
|
|
9623
|
-
return
|
|
9833
|
+
return enforceToolResultLimit(
|
|
9834
|
+
toolName,
|
|
9835
|
+
normalizeToolResult(await callback(...args))
|
|
9836
|
+
);
|
|
9624
9837
|
} catch (error) {
|
|
9625
9838
|
const message = getToolErrorMessage(error);
|
|
9626
9839
|
const isValidationError = error instanceof z29.ZodError;
|
|
@@ -9629,23 +9842,64 @@ function wrapToolCallback(toolName, callback) {
|
|
|
9629
9842
|
error: message,
|
|
9630
9843
|
metadata: { toolName }
|
|
9631
9844
|
});
|
|
9632
|
-
return
|
|
9633
|
-
|
|
9634
|
-
|
|
9635
|
-
|
|
9845
|
+
return enforceToolResultLimit(
|
|
9846
|
+
toolName,
|
|
9847
|
+
normalizeToolResult({
|
|
9848
|
+
content: [{ type: "text", text }],
|
|
9849
|
+
isError: true
|
|
9850
|
+
})
|
|
9851
|
+
);
|
|
9636
9852
|
}
|
|
9637
9853
|
};
|
|
9638
9854
|
}
|
|
9639
9855
|
var registrationSchemas = /* @__PURE__ */ new WeakMap();
|
|
9856
|
+
var outputSchemasByTool = /* @__PURE__ */ new Map();
|
|
9857
|
+
var jsonSchemaConversions = 0;
|
|
9858
|
+
function memoizeJsonSchemaConversion(schema) {
|
|
9859
|
+
const standard = schema["~standard"];
|
|
9860
|
+
const converters = standard?.jsonSchema;
|
|
9861
|
+
if (!standard || !converters) return schema;
|
|
9862
|
+
const memoize = (direction) => {
|
|
9863
|
+
const convert = converters[direction];
|
|
9864
|
+
if (!convert) return void 0;
|
|
9865
|
+
const results = /* @__PURE__ */ new Map();
|
|
9866
|
+
return (options) => {
|
|
9867
|
+
const key = JSON.stringify(options ?? null);
|
|
9868
|
+
let result = results.get(key);
|
|
9869
|
+
if (!result) {
|
|
9870
|
+
jsonSchemaConversions += 1;
|
|
9871
|
+
result = convert(options);
|
|
9872
|
+
results.set(key, result);
|
|
9873
|
+
}
|
|
9874
|
+
return result;
|
|
9875
|
+
};
|
|
9876
|
+
};
|
|
9877
|
+
return Object.create(schema, {
|
|
9878
|
+
"~standard": {
|
|
9879
|
+
value: {
|
|
9880
|
+
...standard,
|
|
9881
|
+
jsonSchema: { input: memoize("input"), output: memoize("output") }
|
|
9882
|
+
}
|
|
9883
|
+
}
|
|
9884
|
+
});
|
|
9885
|
+
}
|
|
9640
9886
|
function normalizeRegistrationSchema(schema) {
|
|
9641
|
-
if (!isRecord(schema)
|
|
9642
|
-
|
|
9643
|
-
|
|
9644
|
-
|
|
9645
|
-
|
|
9646
|
-
|
|
9887
|
+
if (!isRecord(schema)) return schema;
|
|
9888
|
+
if (registrationSchemas.has(schema)) return registrationSchemas.get(schema);
|
|
9889
|
+
const normalized = memoizeJsonSchemaConversion(
|
|
9890
|
+
"~standard" in schema ? schema : z29.object(schema)
|
|
9891
|
+
);
|
|
9892
|
+
registrationSchemas.set(schema, normalized);
|
|
9647
9893
|
return normalized;
|
|
9648
9894
|
}
|
|
9895
|
+
function getRegistrationOutputSchema(toolName) {
|
|
9896
|
+
let schema = outputSchemasByTool.get(toolName);
|
|
9897
|
+
if (!schema) {
|
|
9898
|
+
schema = getToolOutputSchema(toolName);
|
|
9899
|
+
outputSchemasByTool.set(toolName, schema);
|
|
9900
|
+
}
|
|
9901
|
+
return schema;
|
|
9902
|
+
}
|
|
9649
9903
|
function createSafeToolServer(server) {
|
|
9650
9904
|
const originalRegisterTool = server.registerTool.bind(server);
|
|
9651
9905
|
const safeServer = Object.create(server);
|
|
@@ -9661,7 +9915,7 @@ function createSafeToolServer(server) {
|
|
|
9661
9915
|
...description === void 0 ? {} : { description },
|
|
9662
9916
|
inputSchema: normalizeRegistrationSchema(config.inputSchema),
|
|
9663
9917
|
outputSchema: normalizeRegistrationSchema(
|
|
9664
|
-
config.outputSchema ??
|
|
9918
|
+
config.outputSchema ?? getRegistrationOutputSchema(name)
|
|
9665
9919
|
),
|
|
9666
9920
|
annotations: {
|
|
9667
9921
|
...inferToolAnnotations(name),
|
|
@@ -9789,9 +10043,9 @@ function getHttpAuthConfigFromEnv() {
|
|
|
9789
10043
|
`MCP_AUTH_MODE=clerk configuration error (${issues.join("; ")})`
|
|
9790
10044
|
);
|
|
9791
10045
|
}
|
|
9792
|
-
if (!allowedSubjects && !allowedOrganizationIds
|
|
10046
|
+
if (!allowedSubjects && !allowedOrganizationIds) {
|
|
9793
10047
|
throw new Error(
|
|
9794
|
-
"MCP_AUTH_MODE=clerk requires an
|
|
10048
|
+
"MCP_AUTH_MODE=clerk requires an identity-bound authorization policy. Set CLERK_ALLOWED_SUBJECTS or CLERK_ALLOWED_ORGANIZATION_IDS. CLERK_ALLOWED_ROLES and CLERK_REQUIRED_PERMISSIONS can narrow the policy but can't authorize on their own."
|
|
9795
10049
|
);
|
|
9796
10050
|
}
|
|
9797
10051
|
}
|
|
@@ -9854,25 +10108,76 @@ function asStringArray(value) {
|
|
|
9854
10108
|
function unique(values) {
|
|
9855
10109
|
return [...new Set(values)];
|
|
9856
10110
|
}
|
|
10111
|
+
function decodeClerkV2Permissions(features, per, fpm) {
|
|
10112
|
+
if (typeof features !== "string" || typeof per !== "string" || typeof fpm !== "string" || !per || !fpm) {
|
|
10113
|
+
return [];
|
|
10114
|
+
}
|
|
10115
|
+
const orgFeatures = [];
|
|
10116
|
+
for (const part of features.split(",")) {
|
|
10117
|
+
const entry = part.trim();
|
|
10118
|
+
const colon = entry.indexOf(":");
|
|
10119
|
+
if (colon === -1) {
|
|
10120
|
+
return [];
|
|
10121
|
+
}
|
|
10122
|
+
const scope = entry.slice(0, colon);
|
|
10123
|
+
const feature = entry.slice(colon + 1);
|
|
10124
|
+
if (scope === "o" || scope === "ou" || scope === "uo") {
|
|
10125
|
+
orgFeatures.push(feature);
|
|
10126
|
+
}
|
|
10127
|
+
}
|
|
10128
|
+
const permissionNames = per.split(",").map((name) => name.trim());
|
|
10129
|
+
const masks = fpm.split(",").map((mask) => mask.trim());
|
|
10130
|
+
const granted = [];
|
|
10131
|
+
for (const [featureIndex, feature] of orgFeatures.entries()) {
|
|
10132
|
+
const rawMask = masks[featureIndex];
|
|
10133
|
+
if (!feature || rawMask === void 0 || !/^\d+$/.test(rawMask)) {
|
|
10134
|
+
continue;
|
|
10135
|
+
}
|
|
10136
|
+
const mask = BigInt(rawMask);
|
|
10137
|
+
for (const [permissionIndex, name] of permissionNames.entries()) {
|
|
10138
|
+
if (name && mask >> BigInt(permissionIndex) & 1n) {
|
|
10139
|
+
granted.push(`org:${feature}:${name}`);
|
|
10140
|
+
}
|
|
10141
|
+
}
|
|
10142
|
+
}
|
|
10143
|
+
return granted;
|
|
10144
|
+
}
|
|
9857
10145
|
function authorizeClerkClaims(payload, config) {
|
|
9858
10146
|
const subject = asString(payload.sub);
|
|
9859
10147
|
if (!subject) {
|
|
9860
10148
|
throw new ClerkAuthorizationError("Clerk token is missing a subject");
|
|
9861
10149
|
}
|
|
9862
|
-
|
|
9863
|
-
|
|
9864
|
-
|
|
9865
|
-
|
|
9866
|
-
|
|
9867
|
-
|
|
10150
|
+
let organizationId;
|
|
10151
|
+
let roles;
|
|
10152
|
+
let permissions;
|
|
10153
|
+
if (payload.v === 2) {
|
|
10154
|
+
const organization = typeof payload.o === "object" && payload.o !== null ? payload.o : void 0;
|
|
10155
|
+
organizationId = asString(organization?.id);
|
|
10156
|
+
const role = asString(organization?.rol);
|
|
10157
|
+
roles = unique([
|
|
10158
|
+
...role ? [`org:${role}`] : [],
|
|
9868
10159
|
...asStringArray(payload.roles)
|
|
9869
|
-
]
|
|
9870
|
-
|
|
9871
|
-
|
|
9872
|
-
|
|
9873
|
-
|
|
9874
|
-
|
|
9875
|
-
|
|
10160
|
+
]);
|
|
10161
|
+
permissions = unique([
|
|
10162
|
+
...decodeClerkV2Permissions(
|
|
10163
|
+
payload.fea,
|
|
10164
|
+
organization?.per,
|
|
10165
|
+
organization?.fpm
|
|
10166
|
+
),
|
|
10167
|
+
...asStringArray(payload.permissions)
|
|
10168
|
+
]);
|
|
10169
|
+
} else {
|
|
10170
|
+
organizationId = asString(payload.org_id);
|
|
10171
|
+
roles = unique(
|
|
10172
|
+
[asString(payload.org_role), ...asStringArray(payload.roles)].filter(
|
|
10173
|
+
(role) => Boolean(role)
|
|
10174
|
+
)
|
|
10175
|
+
);
|
|
10176
|
+
permissions = unique([
|
|
10177
|
+
...asStringArray(payload.org_permissions),
|
|
10178
|
+
...asStringArray(payload.permissions)
|
|
10179
|
+
]);
|
|
10180
|
+
}
|
|
9876
10181
|
if (config.allowedSubjects && !config.allowedSubjects.includes(subject)) {
|
|
9877
10182
|
throw new ClerkAuthorizationError("Clerk subject is not authorized");
|
|
9878
10183
|
}
|
|
@@ -9918,6 +10223,9 @@ async function verifyClerkToken(token, config) {
|
|
|
9918
10223
|
audience: config.audience,
|
|
9919
10224
|
clockTolerance: "5s"
|
|
9920
10225
|
});
|
|
10226
|
+
if (payload.sts === "pending") {
|
|
10227
|
+
throw new Error("Clerk session is pending");
|
|
10228
|
+
}
|
|
9921
10229
|
return authorizeClerkClaims(payload, config);
|
|
9922
10230
|
}
|
|
9923
10231
|
async function mcpAuthMiddleware(req, res, next) {
|
|
@@ -10888,13 +11196,18 @@ function createReadyHandler(deps) {
|
|
|
10888
11196
|
});
|
|
10889
11197
|
return;
|
|
10890
11198
|
} catch (error) {
|
|
11199
|
+
Logger.error("Portkey readiness check failed", {
|
|
11200
|
+
metadata: {
|
|
11201
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
11202
|
+
}
|
|
11203
|
+
});
|
|
10891
11204
|
res.status(503).json({
|
|
10892
11205
|
status: "not_ready",
|
|
10893
11206
|
activeRequests,
|
|
10894
11207
|
sessionMode: "stateless",
|
|
10895
11208
|
portkey: {
|
|
10896
11209
|
status: "error",
|
|
10897
|
-
error:
|
|
11210
|
+
error: "Upstream readiness check failed"
|
|
10898
11211
|
},
|
|
10899
11212
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
10900
11213
|
});
|
|
@@ -11082,6 +11395,8 @@ function createHttpAppRuntime() {
|
|
|
11082
11395
|
const config = getServerConfig();
|
|
11083
11396
|
const authConfig = getHttpAuthConfig();
|
|
11084
11397
|
assertSafeHttpAuthConfig(authConfig);
|
|
11398
|
+
parseConfiguredToolDomains();
|
|
11399
|
+
assertByteLimitsConfigured();
|
|
11085
11400
|
const readyCheckMode = getReadyCheckMode();
|
|
11086
11401
|
const requestBodyLimit = process.env.MCP_MAX_REQUEST_SIZE?.trim() || "1mb";
|
|
11087
11402
|
const allowedOrigins = getAllowedOrigins();
|