portkey-admin-mcp 0.3.5 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +6 -6
  2. package/build/index.js +1142 -1694
  3. package/build/server.js +1202 -1730
  4. package/package.json +3 -3
package/build/server.js CHANGED
@@ -205,15 +205,19 @@ var BaseService = class {
205
205
  apiKey;
206
206
  baseUrl;
207
207
  timeout = 3e4;
208
- constructor(apiKeyOverride) {
208
+ constructor(apiKeyOverride, baseUrlOverride) {
209
209
  const apiKey = apiKeyOverride ?? process.env.PORTKEY_API_KEY;
210
210
  if (!apiKey) {
211
211
  throw new Error("PORTKEY_API_KEY environment variable is not set");
212
212
  }
213
213
  this.apiKey = apiKey;
214
- const baseUrl = process.env.PORTKEY_BASE_URL ?? DEFAULT_BASE_URL;
215
- validateUrl(baseUrl);
216
- this.baseUrl = baseUrl;
214
+ if (baseUrlOverride !== void 0) {
215
+ this.baseUrl = baseUrlOverride;
216
+ } else {
217
+ const baseUrl = process.env.PORTKEY_BASE_URL ?? DEFAULT_BASE_URL;
218
+ validateUrl(baseUrl);
219
+ this.baseUrl = baseUrl;
220
+ }
217
221
  }
218
222
  encodePathSegment(value) {
219
223
  return encodeURIComponent(value);
@@ -276,7 +280,7 @@ var BaseService = class {
276
280
  if (options.allowNoContent && response.status === 204) {
277
281
  return {};
278
282
  }
279
- return response.json();
283
+ return await response.json();
280
284
  } catch (error) {
281
285
  const duration_ms = Date.now() - startTime;
282
286
  if (!(error instanceof FetchError)) {
@@ -530,8 +534,11 @@ var ConfigsService = class extends BaseService {
530
534
  config: JSON.parse(response.config || "{}")
531
535
  };
532
536
  }
533
- async listConfigs() {
534
- return this.get("/configs");
537
+ async listConfigs(params) {
538
+ return this.get("/configs", {
539
+ page_size: params?.page_size,
540
+ current_page: params?.current_page
541
+ });
535
542
  }
536
543
  async getConfig(slug) {
537
544
  const response = await this.get(
@@ -611,6 +618,7 @@ var GuardrailsService = class extends BaseService {
611
618
  // src/services/health.service.ts
612
619
  var CACHE_TTL_MS = 1e4;
613
620
  var HealthService = class extends BaseService {
621
+ timeout = 5e3;
614
622
  cachedHealth = null;
615
623
  /**
616
624
  * Ping the Portkey API to check health
@@ -629,7 +637,7 @@ var HealthService = class extends BaseService {
629
637
  }
630
638
  const startTime = Date.now();
631
639
  try {
632
- await this.getWithTimeout("/configs", 5e3);
640
+ await this.get("/configs");
633
641
  const latency_ms = Date.now() - startTime;
634
642
  const result = {
635
643
  status: "ok",
@@ -646,35 +654,6 @@ var HealthService = class extends BaseService {
646
654
  throw new Error(`Health check failed: ${errorMessage} (${latency_ms}ms)`);
647
655
  }
648
656
  }
649
- /**
650
- * Internal method to call GET with custom timeout
651
- */
652
- async getWithTimeout(path, timeout) {
653
- const url = `${this.baseUrl}${path}`;
654
- const controller = new AbortController();
655
- const timeoutId = setTimeout(() => controller.abort(), timeout);
656
- try {
657
- const response = await fetch(url, {
658
- method: "GET",
659
- headers: {
660
- "x-portkey-api-key": this.apiKey,
661
- Accept: "application/json"
662
- },
663
- signal: controller.signal
664
- });
665
- if (!response.ok) {
666
- throw new Error(`HTTP ${response.status}`);
667
- }
668
- return response.json();
669
- } catch (error) {
670
- if (error instanceof Error && error.name === "AbortError") {
671
- throw new Error(`Request timed out after ${timeout}ms`);
672
- }
673
- throw error;
674
- } finally {
675
- clearTimeout(timeoutId);
676
- }
677
- }
678
657
  };
679
658
 
680
659
  // src/services/integrations.service.ts
@@ -756,8 +735,11 @@ var IntegrationsService = class extends BaseService {
756
735
  // src/services/keys.service.ts
757
736
  var KeysService = class extends BaseService {
758
737
  // Virtual Keys
759
- async listVirtualKeys() {
760
- return this.get("/virtual-keys");
738
+ async listVirtualKeys(params) {
739
+ return this.get("/virtual-keys", {
740
+ page_size: params?.page_size,
741
+ current_page: params?.current_page
742
+ });
761
743
  }
762
744
  // Phase 2: Virtual Keys CRUD
763
745
  async createVirtualKey(data) {
@@ -1079,9 +1061,13 @@ var McpServersService = class extends BaseService {
1079
1061
  {}
1080
1062
  );
1081
1063
  }
1082
- async listMcpServerCapabilities(id) {
1064
+ async listMcpServerCapabilities(id, params) {
1083
1065
  return this.get(
1084
- `/mcp-servers/${this.encodePathSegment(id)}/capabilities`
1066
+ `/mcp-servers/${this.encodePathSegment(id)}/capabilities`,
1067
+ {
1068
+ current_page: params?.current_page,
1069
+ page_size: params?.page_size
1070
+ }
1085
1071
  );
1086
1072
  }
1087
1073
  async updateMcpServerCapabilities(id, data) {
@@ -1091,9 +1077,13 @@ var McpServersService = class extends BaseService {
1091
1077
  );
1092
1078
  return { success: true };
1093
1079
  }
1094
- async listMcpServerUserAccess(id) {
1080
+ async listMcpServerUserAccess(id, params) {
1095
1081
  return this.get(
1096
- `/mcp-servers/${this.encodePathSegment(id)}/user-access`
1082
+ `/mcp-servers/${this.encodePathSegment(id)}/user-access`,
1083
+ {
1084
+ current_page: params?.current_page,
1085
+ page_size: params?.page_size
1086
+ }
1097
1087
  );
1098
1088
  }
1099
1089
  async updateMcpServerUserAccess(id, data) {
@@ -1277,7 +1267,8 @@ var PromptsService = class extends BaseService {
1277
1267
  const { dry_run = false, app, env } = data;
1278
1268
  const existingPrompts = await this.listPrompts({
1279
1269
  collection_id: data.collection_id,
1280
- search: data.name
1270
+ search: data.name,
1271
+ page_size: 10
1281
1272
  });
1282
1273
  const existingPrompt = existingPrompts.data.find(
1283
1274
  (p) => p.name.toLowerCase() === data.name.toLowerCase()
@@ -1384,7 +1375,8 @@ var PromptsService = class extends BaseService {
1384
1375
  const targetName = data.target_name || sourcePrompt.name.replace(/-(dev|staging|prod)$/, "") + `-${data.target_env}`;
1385
1376
  const existingTargets = await this.listPrompts({
1386
1377
  collection_id: data.target_collection_id,
1387
- search: targetName
1378
+ search: targetName,
1379
+ page_size: 10
1388
1380
  });
1389
1381
  const existingTarget = existingTargets.data.find(
1390
1382
  (p) => p.name.toLowerCase() === targetName.toLowerCase()
@@ -1514,8 +1506,11 @@ var TracingService = class extends BaseService {
1514
1506
 
1515
1507
  // src/services/users.service.ts
1516
1508
  var UsersService = class extends BaseService {
1517
- async listUsers() {
1518
- return this.get("/admin/users");
1509
+ async listUsers(params) {
1510
+ return this.get("/admin/users", {
1511
+ page_size: params?.page_size,
1512
+ current_page: params?.current_page
1513
+ });
1519
1514
  }
1520
1515
  async inviteUser(data) {
1521
1516
  return this.post("/admin/users/invites", data);
@@ -1564,8 +1559,11 @@ var UsersService = class extends BaseService {
1564
1559
  return { success: true };
1565
1560
  }
1566
1561
  // Phase 1: User Invites CRUD
1567
- async listUserInvites() {
1568
- return this.get("/admin/users/invites");
1562
+ async listUserInvites(params) {
1563
+ return this.get("/admin/users/invites", {
1564
+ page_size: params?.page_size,
1565
+ current_page: params?.current_page
1566
+ });
1569
1567
  }
1570
1568
  async getUserInvite(inviteId) {
1571
1569
  return this.get(
@@ -1642,6 +1640,7 @@ var WorkspacesService = class extends BaseService {
1642
1640
  };
1643
1641
 
1644
1642
  // src/services/index.ts
1643
+ import crypto2 from "node:crypto";
1645
1644
  function resolvePortkeyApiKey(apiKey) {
1646
1645
  const resolvedApiKey = apiKey ?? process.env.PORTKEY_API_KEY;
1647
1646
  if (!resolvedApiKey) {
@@ -1652,23 +1651,13 @@ function resolvePortkeyApiKey(apiKey) {
1652
1651
  return resolvedApiKey;
1653
1652
  }
1654
1653
  function getSharedServiceCacheKey(apiKey) {
1654
+ const keyDigest = crypto2.createHash("sha256").update(resolvePortkeyApiKey(apiKey)).digest("hex");
1655
1655
  return JSON.stringify({
1656
- apiKey: resolvePortkeyApiKey(apiKey),
1656
+ apiKey: keyDigest,
1657
1657
  baseUrl: process.env.PORTKEY_BASE_URL?.trim() || ""
1658
1658
  });
1659
1659
  }
1660
1660
  var sharedPortkeyServices = /* @__PURE__ */ new Map();
1661
- var sharedHealthServices = /* @__PURE__ */ new Map();
1662
- function getSharedHealthService(apiKey) {
1663
- const cacheKey = getSharedServiceCacheKey(apiKey);
1664
- const cached = sharedHealthServices.get(cacheKey);
1665
- if (cached) {
1666
- return cached;
1667
- }
1668
- const service = new HealthService(resolvePortkeyApiKey(apiKey));
1669
- sharedHealthServices.set(cacheKey, service);
1670
- return service;
1671
- }
1672
1661
  var PortkeyService = class {
1673
1662
  users;
1674
1663
  workspaces;
@@ -1691,25 +1680,33 @@ var PortkeyService = class {
1691
1680
  health;
1692
1681
  constructor(apiKey) {
1693
1682
  const resolvedApiKey = resolvePortkeyApiKey(apiKey);
1694
- this.users = new UsersService(resolvedApiKey);
1695
- this.workspaces = new WorkspacesService(resolvedApiKey);
1696
- this.configs = new ConfigsService(resolvedApiKey);
1697
- this.keys = new KeysService(resolvedApiKey);
1698
- this.collections = new CollectionsService(resolvedApiKey);
1699
- this.prompts = new PromptsService(resolvedApiKey);
1700
- this.analytics = new AnalyticsService(resolvedApiKey);
1701
- this.guardrails = new GuardrailsService(resolvedApiKey);
1702
- this.integrations = new IntegrationsService(resolvedApiKey);
1703
- this.limits = new LimitsService(resolvedApiKey);
1704
- this.audit = new AuditService(resolvedApiKey);
1705
- this.labels = new LabelsService(resolvedApiKey);
1706
- this.partials = new PartialsService(resolvedApiKey);
1707
- this.tracing = new TracingService(resolvedApiKey);
1708
- this.logging = new LoggingService(resolvedApiKey);
1709
- this.providers = new ProvidersService(resolvedApiKey);
1710
- this.mcpIntegrations = new McpIntegrationsService(resolvedApiKey);
1711
- this.mcpServers = new McpServersService(resolvedApiKey);
1712
- this.health = getSharedHealthService(resolvedApiKey);
1683
+ const resolvedBaseUrl = process.env.PORTKEY_BASE_URL ?? "https://api.portkey.ai/v1";
1684
+ validateUrl(resolvedBaseUrl);
1685
+ this.users = new UsersService(resolvedApiKey, resolvedBaseUrl);
1686
+ this.workspaces = new WorkspacesService(resolvedApiKey, resolvedBaseUrl);
1687
+ this.configs = new ConfigsService(resolvedApiKey, resolvedBaseUrl);
1688
+ this.keys = new KeysService(resolvedApiKey, resolvedBaseUrl);
1689
+ this.collections = new CollectionsService(resolvedApiKey, resolvedBaseUrl);
1690
+ this.prompts = new PromptsService(resolvedApiKey, resolvedBaseUrl);
1691
+ this.analytics = new AnalyticsService(resolvedApiKey, resolvedBaseUrl);
1692
+ this.guardrails = new GuardrailsService(resolvedApiKey, resolvedBaseUrl);
1693
+ this.integrations = new IntegrationsService(
1694
+ resolvedApiKey,
1695
+ resolvedBaseUrl
1696
+ );
1697
+ this.limits = new LimitsService(resolvedApiKey, resolvedBaseUrl);
1698
+ this.audit = new AuditService(resolvedApiKey, resolvedBaseUrl);
1699
+ this.labels = new LabelsService(resolvedApiKey, resolvedBaseUrl);
1700
+ this.partials = new PartialsService(resolvedApiKey, resolvedBaseUrl);
1701
+ this.tracing = new TracingService(resolvedApiKey, resolvedBaseUrl);
1702
+ this.logging = new LoggingService(resolvedApiKey, resolvedBaseUrl);
1703
+ this.providers = new ProvidersService(resolvedApiKey, resolvedBaseUrl);
1704
+ this.mcpIntegrations = new McpIntegrationsService(
1705
+ resolvedApiKey,
1706
+ resolvedBaseUrl
1707
+ );
1708
+ this.mcpServers = new McpServersService(resolvedApiKey, resolvedBaseUrl);
1709
+ this.health = new HealthService(resolvedApiKey, resolvedBaseUrl);
1713
1710
  }
1714
1711
  };
1715
1712
  function getSharedPortkeyService(apiKey) {
@@ -1726,6 +1723,11 @@ function getSharedPortkeyService(apiKey) {
1726
1723
  // src/tools/index.ts
1727
1724
  import { z as z20 } from "zod";
1728
1725
 
1726
+ // src/lib/type-guards.ts
1727
+ function isRecord(value) {
1728
+ return typeof value === "object" && value !== null;
1729
+ }
1730
+
1729
1731
  // src/tools/analytics.tools.ts
1730
1732
  import { z } from "zod";
1731
1733
  var baseAnalyticsSchema = {
@@ -1801,41 +1803,6 @@ var baseAnalyticsSchema = {
1801
1803
  ),
1802
1804
  prompt_slug: z.string().optional().describe("Filter by prompt slug")
1803
1805
  };
1804
- var requestAnalyticsSchema = {
1805
- ...baseAnalyticsSchema,
1806
- status_codes: z.array(z.string()).optional().describe(
1807
- "Structured alias for status_code. Use an array of HTTP status codes; normalized to the legacy comma-separated Portkey query param."
1808
- ),
1809
- virtual_key_slugs: z.array(z.string()).optional().describe(
1810
- "Structured alias for virtual_keys. Use an array of virtual key slugs; normalized to the legacy comma-separated Portkey query param."
1811
- ),
1812
- config_slugs: z.array(z.string()).optional().describe(
1813
- "Structured alias for configs. Use an array of config slugs; normalized to the legacy comma-separated Portkey query param."
1814
- ),
1815
- api_key_ids: z.preprocess((value) => {
1816
- if (value == null) {
1817
- return value;
1818
- }
1819
- if (Array.isArray(value)) {
1820
- return value.map((item) => String(item)).join(",");
1821
- }
1822
- return value;
1823
- }, z.string().optional()).describe(
1824
- "API key UUIDs. Accepts the legacy comma-separated string or a structured array; normalized to the legacy Portkey query param before the request is sent."
1825
- ),
1826
- trace_ids: z.array(z.string()).optional().describe(
1827
- "Structured alias for trace_id. Use an array of trace IDs; normalized to the legacy comma-separated Portkey query param."
1828
- ),
1829
- span_ids: z.array(z.string()).optional().describe(
1830
- "Structured alias for span_id. Use an array of span IDs; normalized to the legacy comma-separated Portkey query param."
1831
- ),
1832
- provider_models: z.array(z.string()).optional().describe(
1833
- "Structured alias for ai_org_model. Use provider__model strings in an array; normalized to the legacy comma-separated Portkey query param."
1834
- ),
1835
- metadata_filter: z.record(z.string(), z.unknown()).optional().describe(
1836
- "Structured alias for metadata. Use an object such as { env: 'prod' }; normalized to a JSON string before the request is sent."
1837
- )
1838
- };
1839
1806
  var paginatedAnalyticsSchema = {
1840
1807
  ...baseAnalyticsSchema,
1841
1808
  current_page: z.coerce.number().positive().optional().describe("Page number for pagination"),
@@ -1960,9 +1927,7 @@ function registerAnalyticsTools(server, service) {
1960
1927
  average_cost_per_request: analytics.summary.avg
1961
1928
  },
1962
1929
  dataPoints
1963
- ),
1964
- null,
1965
- 2
1930
+ )
1966
1931
  )
1967
1932
  }
1968
1933
  ]
@@ -1972,7 +1937,7 @@ function registerAnalyticsTools(server, service) {
1972
1937
  server.tool(
1973
1938
  "get_request_analytics",
1974
1939
  "Get request-volume time-series data with summary.total_requests, summary.successful_requests, summary.failed_requests, and per-bucket total/success/failed counts. Use this for traffic and reliability trends; use get_error_analytics when you only need error counts.",
1975
- requestAnalyticsSchema,
1940
+ baseAnalyticsSchema,
1976
1941
  async (params) => {
1977
1942
  const analytics = await service.analytics.getRequestAnalytics(
1978
1943
  normalizeAnalyticsParams(params)
@@ -1995,9 +1960,7 @@ function registerAnalyticsTools(server, service) {
1995
1960
  failed_requests: analytics.summary.failed
1996
1961
  },
1997
1962
  dataPoints
1998
- ),
1999
- null,
2000
- 2
1963
+ )
2001
1964
  )
2002
1965
  }
2003
1966
  ]
@@ -2030,9 +1993,7 @@ function registerAnalyticsTools(server, service) {
2030
1993
  completion_tokens: analytics.summary.completion
2031
1994
  },
2032
1995
  dataPoints
2033
- ),
2034
- null,
2035
- 2
1996
+ )
2036
1997
  )
2037
1998
  }
2038
1999
  ]
@@ -2067,9 +2028,7 @@ function registerAnalyticsTools(server, service) {
2067
2028
  p99_latency_ms: analytics.summary.p99
2068
2029
  },
2069
2030
  dataPoints
2070
- ),
2071
- null,
2072
- 2
2031
+ )
2073
2032
  )
2074
2033
  }
2075
2034
  ]
@@ -2098,9 +2057,7 @@ function registerAnalyticsTools(server, service) {
2098
2057
  total_errors: analytics.summary.total
2099
2058
  },
2100
2059
  dataPoints
2101
- ),
2102
- null,
2103
- 2
2060
+ )
2104
2061
  )
2105
2062
  }
2106
2063
  ]
@@ -2129,9 +2086,7 @@ function registerAnalyticsTools(server, service) {
2129
2086
  error_rate_percent: analytics.summary.rate
2130
2087
  },
2131
2088
  dataPoints
2132
- ),
2133
- null,
2134
- 2
2089
+ )
2135
2090
  )
2136
2091
  }
2137
2092
  ]
@@ -2162,9 +2117,7 @@ function registerAnalyticsTools(server, service) {
2162
2117
  avg_latency: analytics.summary.avg
2163
2118
  },
2164
2119
  dataPoints
2165
- ),
2166
- null,
2167
- 2
2120
+ )
2168
2121
  )
2169
2122
  }
2170
2123
  ]
@@ -2197,9 +2150,7 @@ function registerAnalyticsTools(server, service) {
2197
2150
  total_misses: analytics.summary.total_misses
2198
2151
  },
2199
2152
  dataPoints
2200
- ),
2201
- null,
2202
- 2
2153
+ )
2203
2154
  )
2204
2155
  }
2205
2156
  ]
@@ -2230,9 +2181,7 @@ function registerAnalyticsTools(server, service) {
2230
2181
  total_new_users: analytics.summary.total_new_users
2231
2182
  },
2232
2183
  dataPoints
2233
- ),
2234
- null,
2235
- 2
2184
+ )
2236
2185
  )
2237
2186
  }
2238
2187
  ]
@@ -2251,11 +2200,7 @@ function registerAnalyticsTools(server, service) {
2251
2200
  content: [
2252
2201
  {
2253
2202
  type: "text",
2254
- text: JSON.stringify(
2255
- formatGenericGraphAnalytics(analytics),
2256
- null,
2257
- 2
2258
- )
2203
+ text: JSON.stringify(formatGenericGraphAnalytics(analytics))
2259
2204
  }
2260
2205
  ]
2261
2206
  };
@@ -2273,11 +2218,7 @@ function registerAnalyticsTools(server, service) {
2273
2218
  content: [
2274
2219
  {
2275
2220
  type: "text",
2276
- text: JSON.stringify(
2277
- formatGenericGraphAnalytics(analytics),
2278
- null,
2279
- 2
2280
- )
2221
+ text: JSON.stringify(formatGenericGraphAnalytics(analytics))
2281
2222
  }
2282
2223
  ]
2283
2224
  };
@@ -2295,11 +2236,7 @@ function registerAnalyticsTools(server, service) {
2295
2236
  content: [
2296
2237
  {
2297
2238
  type: "text",
2298
- text: JSON.stringify(
2299
- formatGenericGraphAnalytics(analytics),
2300
- null,
2301
- 2
2302
- )
2239
+ text: JSON.stringify(formatGenericGraphAnalytics(analytics))
2303
2240
  }
2304
2241
  ]
2305
2242
  };
@@ -2317,11 +2254,7 @@ function registerAnalyticsTools(server, service) {
2317
2254
  content: [
2318
2255
  {
2319
2256
  type: "text",
2320
- text: JSON.stringify(
2321
- formatGenericGraphAnalytics(analytics),
2322
- null,
2323
- 2
2324
- )
2257
+ text: JSON.stringify(formatGenericGraphAnalytics(analytics))
2325
2258
  }
2326
2259
  ]
2327
2260
  };
@@ -2339,11 +2272,7 @@ function registerAnalyticsTools(server, service) {
2339
2272
  content: [
2340
2273
  {
2341
2274
  type: "text",
2342
- text: JSON.stringify(
2343
- formatGenericGraphAnalytics(analytics),
2344
- null,
2345
- 2
2346
- )
2275
+ text: JSON.stringify(formatGenericGraphAnalytics(analytics))
2347
2276
  }
2348
2277
  ]
2349
2278
  };
@@ -2361,11 +2290,7 @@ function registerAnalyticsTools(server, service) {
2361
2290
  content: [
2362
2291
  {
2363
2292
  type: "text",
2364
- text: JSON.stringify(
2365
- formatGenericGraphAnalytics(analytics),
2366
- null,
2367
- 2
2368
- )
2293
+ text: JSON.stringify(formatGenericGraphAnalytics(analytics))
2369
2294
  }
2370
2295
  ]
2371
2296
  };
@@ -2383,11 +2308,7 @@ function registerAnalyticsTools(server, service) {
2383
2308
  content: [
2384
2309
  {
2385
2310
  type: "text",
2386
- text: JSON.stringify(
2387
- formatGenericGraphAnalytics(analytics),
2388
- null,
2389
- 2
2390
- )
2311
+ text: JSON.stringify(formatGenericGraphAnalytics(analytics))
2391
2312
  }
2392
2313
  ]
2393
2314
  };
@@ -2405,11 +2326,7 @@ function registerAnalyticsTools(server, service) {
2405
2326
  content: [
2406
2327
  {
2407
2328
  type: "text",
2408
- text: JSON.stringify(
2409
- formatGenericGraphAnalytics(analytics),
2410
- null,
2411
- 2
2412
- )
2329
+ text: JSON.stringify(formatGenericGraphAnalytics(analytics))
2413
2330
  }
2414
2331
  ]
2415
2332
  };
@@ -2427,11 +2344,7 @@ function registerAnalyticsTools(server, service) {
2427
2344
  content: [
2428
2345
  {
2429
2346
  type: "text",
2430
- text: JSON.stringify(
2431
- formatGroupedAnalytics(analytics, "users"),
2432
- null,
2433
- 2
2434
- )
2347
+ text: JSON.stringify(formatGroupedAnalytics(analytics, "users"))
2435
2348
  }
2436
2349
  ]
2437
2350
  };
@@ -2449,11 +2362,7 @@ function registerAnalyticsTools(server, service) {
2449
2362
  content: [
2450
2363
  {
2451
2364
  type: "text",
2452
- text: JSON.stringify(
2453
- formatGroupedAnalytics(analytics, "models"),
2454
- null,
2455
- 2
2456
- )
2365
+ text: JSON.stringify(formatGroupedAnalytics(analytics, "models"))
2457
2366
  }
2458
2367
  ]
2459
2368
  };
@@ -2474,9 +2383,7 @@ function registerAnalyticsTools(server, service) {
2474
2383
  {
2475
2384
  type: "text",
2476
2385
  text: JSON.stringify(
2477
- formatGroupedAnalytics(analytics, "metadata_groups"),
2478
- null,
2479
- 2
2386
+ formatGroupedAnalytics(analytics, "metadata_groups")
2480
2387
  )
2481
2388
  }
2482
2389
  ]
@@ -2529,31 +2436,27 @@ function registerAuditTools(server, service) {
2529
2436
  content: [
2530
2437
  {
2531
2438
  type: "text",
2532
- text: JSON.stringify(
2533
- {
2534
- total: result.total,
2535
- current_page: result.current_page,
2536
- page_size: result.page_size,
2537
- audit_logs: result.data.map((log) => ({
2538
- id: log.id,
2539
- action: log.action,
2540
- actor_id: log.actor_id,
2541
- actor_email: log.actor_email,
2542
- actor_name: log.actor_name,
2543
- resource_type: log.resource_type,
2544
- resource_id: log.resource_id,
2545
- resource_name: log.resource_name,
2546
- workspace_id: log.workspace_id,
2547
- organisation_id: log.organisation_id,
2548
- metadata: log.metadata,
2549
- ip_address: log.ip_address,
2550
- user_agent: log.user_agent,
2551
- created_at: log.created_at
2552
- }))
2553
- },
2554
- null,
2555
- 2
2556
- )
2439
+ text: JSON.stringify({
2440
+ total: result.total,
2441
+ current_page: result.current_page,
2442
+ page_size: result.page_size,
2443
+ audit_logs: result.data.map((log) => ({
2444
+ id: log.id,
2445
+ action: log.action,
2446
+ actor_id: log.actor_id,
2447
+ actor_email: log.actor_email,
2448
+ actor_name: log.actor_name,
2449
+ resource_type: log.resource_type,
2450
+ resource_id: log.resource_id,
2451
+ resource_name: log.resource_name,
2452
+ workspace_id: log.workspace_id,
2453
+ organisation_id: log.organisation_id,
2454
+ metadata: log.metadata,
2455
+ ip_address: log.ip_address,
2456
+ user_agent: log.user_agent,
2457
+ created_at: log.created_at
2458
+ }))
2459
+ })
2557
2460
  }
2558
2461
  ]
2559
2462
  };
@@ -2599,21 +2502,17 @@ function registerCollectionsTools(server, service) {
2599
2502
  content: [
2600
2503
  {
2601
2504
  type: "text",
2602
- text: JSON.stringify(
2603
- {
2604
- total: collections.total,
2605
- collections: collections.data.map((collection) => ({
2606
- id: collection.id,
2607
- name: collection.name,
2608
- slug: collection.slug,
2609
- workspace_id: collection.workspace_id,
2610
- created_at: collection.created_at,
2611
- last_updated_at: collection.last_updated_at
2612
- }))
2613
- },
2614
- null,
2615
- 2
2616
- )
2505
+ text: JSON.stringify({
2506
+ total: collections.total,
2507
+ collections: collections.data.map((collection) => ({
2508
+ id: collection.id,
2509
+ name: collection.name,
2510
+ slug: collection.slug,
2511
+ workspace_id: collection.workspace_id,
2512
+ created_at: collection.created_at,
2513
+ last_updated_at: collection.last_updated_at
2514
+ }))
2515
+ })
2617
2516
  }
2618
2517
  ]
2619
2518
  };
@@ -2629,15 +2528,11 @@ function registerCollectionsTools(server, service) {
2629
2528
  content: [
2630
2529
  {
2631
2530
  type: "text",
2632
- text: JSON.stringify(
2633
- {
2634
- message: `Successfully created collection "${params.name}"`,
2635
- id: result.id,
2636
- slug: result.slug
2637
- },
2638
- null,
2639
- 2
2640
- )
2531
+ text: JSON.stringify({
2532
+ message: `Successfully created collection "${params.name}"`,
2533
+ id: result.id,
2534
+ slug: result.slug
2535
+ })
2641
2536
  }
2642
2537
  ]
2643
2538
  };
@@ -2655,18 +2550,14 @@ function registerCollectionsTools(server, service) {
2655
2550
  content: [
2656
2551
  {
2657
2552
  type: "text",
2658
- text: JSON.stringify(
2659
- {
2660
- id: collection.id,
2661
- name: collection.name,
2662
- slug: collection.slug,
2663
- workspace_id: collection.workspace_id,
2664
- created_at: collection.created_at,
2665
- last_updated_at: collection.last_updated_at
2666
- },
2667
- null,
2668
- 2
2669
- )
2553
+ text: JSON.stringify({
2554
+ id: collection.id,
2555
+ name: collection.name,
2556
+ slug: collection.slug,
2557
+ workspace_id: collection.workspace_id,
2558
+ created_at: collection.created_at,
2559
+ last_updated_at: collection.last_updated_at
2560
+ })
2670
2561
  }
2671
2562
  ]
2672
2563
  };
@@ -2685,14 +2576,10 @@ function registerCollectionsTools(server, service) {
2685
2576
  content: [
2686
2577
  {
2687
2578
  type: "text",
2688
- text: JSON.stringify(
2689
- {
2690
- message: `Successfully updated collection "${params.collection_id}"`,
2691
- success: true
2692
- },
2693
- null,
2694
- 2
2695
- )
2579
+ text: JSON.stringify({
2580
+ message: `Successfully updated collection "${params.collection_id}"`,
2581
+ success: true
2582
+ })
2696
2583
  }
2697
2584
  ]
2698
2585
  };
@@ -2710,14 +2597,10 @@ function registerCollectionsTools(server, service) {
2710
2597
  content: [
2711
2598
  {
2712
2599
  type: "text",
2713
- text: JSON.stringify(
2714
- {
2715
- message: `Successfully deleted collection "${params.collection_id}"`,
2716
- success: result.success
2717
- },
2718
- null,
2719
- 2
2720
- )
2600
+ text: JSON.stringify({
2601
+ message: `Successfully deleted collection "${params.collection_id}"`,
2602
+ success: result.success
2603
+ })
2721
2604
  }
2722
2605
  ]
2723
2606
  };
@@ -2728,7 +2611,10 @@ function registerCollectionsTools(server, service) {
2728
2611
  // src/tools/configs.tools.ts
2729
2612
  import { z as z4 } from "zod";
2730
2613
  var CONFIGS_TOOL_SCHEMAS = {
2731
- listConfigs: {},
2614
+ listConfigs: {
2615
+ current_page: z4.coerce.number().positive().optional().describe("Page number for pagination"),
2616
+ page_size: z4.coerce.number().positive().max(100).optional().describe("Number of results per page (max 100)")
2617
+ },
2732
2618
  getConfig: {
2733
2619
  slug: z4.string().describe(
2734
2620
  "The unique identifier (slug) of the configuration to retrieve. This can be found in the configuration's URL or from the list_configs tool response"
@@ -2776,6 +2662,19 @@ var CONFIGS_TOOL_SCHEMAS = {
2776
2662
  slug: z4.string().describe("Configuration slug to list versions for")
2777
2663
  }
2778
2664
  };
2665
+ var configPayloadSchema = z4.object({
2666
+ cache_mode: z4.enum(["simple", "semantic"]).optional(),
2667
+ cache_max_age: z4.coerce.number().positive().optional(),
2668
+ retry_attempts: z4.coerce.number().positive().max(5).optional(),
2669
+ retry_on_status_codes: z4.array(z4.coerce.number()).optional(),
2670
+ strategy_mode: z4.enum(["loadbalance", "fallback"]).optional(),
2671
+ targets: z4.array(
2672
+ z4.object({
2673
+ provider: z4.string().optional(),
2674
+ virtual_key: z4.string().optional()
2675
+ })
2676
+ ).optional()
2677
+ });
2779
2678
  function buildConfigPayload(params) {
2780
2679
  const cache = params.cache_mode !== void 0 || params.cache_max_age !== void 0 ? {
2781
2680
  ...params.cache_mode !== void 0 ? { mode: params.cache_mode } : {},
@@ -2800,31 +2699,30 @@ function registerConfigsTools(server, service) {
2800
2699
  "list_configs",
2801
2700
  "List configs in the org with id, slug, name, status, workspace, and timestamps. Use this summary view to find a slug; use get_config for the full routing, cache, retry, and target settings before updating or deleting.",
2802
2701
  CONFIGS_TOOL_SCHEMAS.listConfigs,
2803
- async () => {
2804
- const configs = await service.configs.listConfigs();
2702
+ async (params) => {
2703
+ const configs = await service.configs.listConfigs({
2704
+ current_page: params.current_page,
2705
+ page_size: params.page_size
2706
+ });
2805
2707
  return {
2806
2708
  content: [
2807
2709
  {
2808
2710
  type: "text",
2809
- text: JSON.stringify(
2810
- {
2811
- total: configs.total,
2812
- configurations: (configs.data ?? []).map((config) => ({
2813
- id: config.id,
2814
- name: config.name,
2815
- slug: config.slug,
2816
- workspace_id: config.workspace_id,
2817
- status: config.status,
2818
- is_default: config.is_default,
2819
- created_at: config.created_at,
2820
- last_updated_at: config.last_updated_at,
2821
- owner_id: config.owner_id,
2822
- updated_by: config.updated_by
2823
- }))
2824
- },
2825
- null,
2826
- 2
2827
- )
2711
+ text: JSON.stringify({
2712
+ total: configs.total,
2713
+ configurations: (configs.data ?? []).map((config) => ({
2714
+ id: config.id,
2715
+ name: config.name,
2716
+ slug: config.slug,
2717
+ workspace_id: config.workspace_id,
2718
+ status: config.status,
2719
+ is_default: config.is_default,
2720
+ created_at: config.created_at,
2721
+ last_updated_at: config.last_updated_at,
2722
+ owner_id: config.owner_id,
2723
+ updated_by: config.updated_by
2724
+ }))
2725
+ })
2828
2726
  }
2829
2727
  ]
2830
2728
  };
@@ -2840,35 +2738,31 @@ function registerConfigsTools(server, service) {
2840
2738
  content: [
2841
2739
  {
2842
2740
  type: "text",
2843
- text: JSON.stringify(
2844
- {
2845
- id: response.id,
2846
- slug: response.slug,
2847
- name: response.name,
2848
- status: response.status,
2849
- config: {
2850
- cache: response.config.cache && {
2851
- mode: response.config.cache.mode,
2852
- max_age: response.config.cache.max_age
2853
- },
2854
- retry: response.config.retry && {
2855
- attempts: response.config.retry.attempts,
2856
- on_status_codes: response.config.retry.on_status_codes
2857
- },
2858
- strategy: response.config.strategy && {
2859
- mode: response.config.strategy.mode
2860
- },
2861
- targets: response.config.targets?.map(
2862
- (target) => ({
2863
- provider: target.provider,
2864
- virtual_key: target.virtual_key
2865
- })
2866
- )
2867
- }
2868
- },
2869
- null,
2870
- 2
2871
- )
2741
+ text: JSON.stringify({
2742
+ id: response.id,
2743
+ slug: response.slug,
2744
+ name: response.name,
2745
+ status: response.status,
2746
+ config: {
2747
+ cache: response.config.cache && {
2748
+ mode: response.config.cache.mode,
2749
+ max_age: response.config.cache.max_age
2750
+ },
2751
+ retry: response.config.retry && {
2752
+ attempts: response.config.retry.attempts,
2753
+ on_status_codes: response.config.retry.on_status_codes
2754
+ },
2755
+ strategy: response.config.strategy && {
2756
+ mode: response.config.strategy.mode
2757
+ },
2758
+ targets: response.config.targets?.map(
2759
+ (target) => ({
2760
+ provider: target.provider,
2761
+ virtual_key: target.virtual_key
2762
+ })
2763
+ )
2764
+ }
2765
+ })
2872
2766
  }
2873
2767
  ]
2874
2768
  };
@@ -2900,15 +2794,11 @@ function registerConfigsTools(server, service) {
2900
2794
  content: [
2901
2795
  {
2902
2796
  type: "text",
2903
- text: JSON.stringify(
2904
- {
2905
- message: `Successfully created configuration "${params.name}"`,
2906
- id: result.id,
2907
- version_id: result.version_id
2908
- },
2909
- null,
2910
- 2
2911
- )
2797
+ text: JSON.stringify({
2798
+ message: `Successfully created configuration "${params.name}"`,
2799
+ id: result.id,
2800
+ version_id: result.version_id
2801
+ })
2912
2802
  }
2913
2803
  ]
2914
2804
  };
@@ -2934,16 +2824,12 @@ function registerConfigsTools(server, service) {
2934
2824
  content: [
2935
2825
  {
2936
2826
  type: "text",
2937
- text: JSON.stringify(
2938
- {
2939
- message: `Successfully updated configuration "${params.slug}"`,
2940
- id: result.id,
2941
- slug: result.slug,
2942
- config: result.config
2943
- },
2944
- null,
2945
- 2
2946
- )
2827
+ text: JSON.stringify({
2828
+ message: `Successfully updated configuration "${params.slug}"`,
2829
+ id: result.id,
2830
+ slug: result.slug,
2831
+ config: result.config
2832
+ })
2947
2833
  }
2948
2834
  ]
2949
2835
  };
@@ -2959,14 +2845,10 @@ function registerConfigsTools(server, service) {
2959
2845
  content: [
2960
2846
  {
2961
2847
  type: "text",
2962
- text: JSON.stringify(
2963
- {
2964
- message: `Successfully deleted configuration "${params.slug}"`,
2965
- success: result.success
2966
- },
2967
- null,
2968
- 2
2969
- )
2848
+ text: JSON.stringify({
2849
+ message: `Successfully deleted configuration "${params.slug}"`,
2850
+ success: result.success
2851
+ })
2970
2852
  }
2971
2853
  ]
2972
2854
  };
@@ -2982,20 +2864,16 @@ function registerConfigsTools(server, service) {
2982
2864
  content: [
2983
2865
  {
2984
2866
  type: "text",
2985
- text: JSON.stringify(
2986
- {
2987
- total: result.total,
2988
- versions: (result.data ?? []).map((version) => ({
2989
- id: version.id,
2990
- version: version.version,
2991
- config: version.config,
2992
- created_at: version.created_at,
2993
- created_by: version.created_by
2994
- }))
2995
- },
2996
- null,
2997
- 2
2998
- )
2867
+ text: JSON.stringify({
2868
+ total: result.total,
2869
+ versions: (result.data ?? []).map((version) => ({
2870
+ id: version.id,
2871
+ version: version.version,
2872
+ config: version.config,
2873
+ created_at: version.created_at,
2874
+ created_by: version.created_by
2875
+ }))
2876
+ })
2999
2877
  }
3000
2878
  ]
3001
2879
  };
@@ -3064,25 +2942,21 @@ function registerGuardrailsTools(server, service) {
3064
2942
  content: [
3065
2943
  {
3066
2944
  type: "text",
3067
- text: JSON.stringify(
3068
- {
3069
- total: result.total,
3070
- guardrails: result.data.map((guardrail) => ({
3071
- id: guardrail.id,
3072
- name: guardrail.name,
3073
- slug: guardrail.slug,
3074
- status: guardrail.status,
3075
- workspace_id: guardrail.workspace_id,
3076
- organisation_id: guardrail.organisation_id,
3077
- created_at: guardrail.created_at,
3078
- last_updated_at: guardrail.last_updated_at,
3079
- owner_id: guardrail.owner_id,
3080
- updated_by: guardrail.updated_by
3081
- }))
3082
- },
3083
- null,
3084
- 2
3085
- )
2945
+ text: JSON.stringify({
2946
+ total: result.total,
2947
+ guardrails: result.data.map((guardrail) => ({
2948
+ id: guardrail.id,
2949
+ name: guardrail.name,
2950
+ slug: guardrail.slug,
2951
+ status: guardrail.status,
2952
+ workspace_id: guardrail.workspace_id,
2953
+ organisation_id: guardrail.organisation_id,
2954
+ created_at: guardrail.created_at,
2955
+ last_updated_at: guardrail.last_updated_at,
2956
+ owner_id: guardrail.owner_id,
2957
+ updated_by: guardrail.updated_by
2958
+ }))
2959
+ })
3086
2960
  }
3087
2961
  ]
3088
2962
  };
@@ -3100,24 +2974,20 @@ function registerGuardrailsTools(server, service) {
3100
2974
  content: [
3101
2975
  {
3102
2976
  type: "text",
3103
- text: JSON.stringify(
3104
- {
3105
- id: guardrail.id,
3106
- name: guardrail.name,
3107
- slug: guardrail.slug,
3108
- status: guardrail.status,
3109
- workspace_id: guardrail.workspace_id,
3110
- organisation_id: guardrail.organisation_id,
3111
- checks: guardrail.checks,
3112
- actions: guardrail.actions,
3113
- created_at: guardrail.created_at,
3114
- last_updated_at: guardrail.last_updated_at,
3115
- owner_id: guardrail.owner_id,
3116
- updated_by: guardrail.updated_by
3117
- },
3118
- null,
3119
- 2
3120
- )
2977
+ text: JSON.stringify({
2978
+ id: guardrail.id,
2979
+ name: guardrail.name,
2980
+ slug: guardrail.slug,
2981
+ status: guardrail.status,
2982
+ workspace_id: guardrail.workspace_id,
2983
+ organisation_id: guardrail.organisation_id,
2984
+ checks: guardrail.checks,
2985
+ actions: guardrail.actions,
2986
+ created_at: guardrail.created_at,
2987
+ last_updated_at: guardrail.last_updated_at,
2988
+ owner_id: guardrail.owner_id,
2989
+ updated_by: guardrail.updated_by
2990
+ })
3121
2991
  }
3122
2992
  ]
3123
2993
  };
@@ -3139,16 +3009,12 @@ function registerGuardrailsTools(server, service) {
3139
3009
  content: [
3140
3010
  {
3141
3011
  type: "text",
3142
- text: JSON.stringify(
3143
- {
3144
- message: `Successfully created guardrail "${params.name}"`,
3145
- id: result.id,
3146
- slug: result.slug,
3147
- version_id: result.version_id
3148
- },
3149
- null,
3150
- 2
3151
- )
3012
+ text: JSON.stringify({
3013
+ message: `Successfully created guardrail "${params.name}"`,
3014
+ id: result.id,
3015
+ slug: result.slug,
3016
+ version_id: result.version_id
3017
+ })
3152
3018
  }
3153
3019
  ]
3154
3020
  };
@@ -3177,16 +3043,12 @@ function registerGuardrailsTools(server, service) {
3177
3043
  content: [
3178
3044
  {
3179
3045
  type: "text",
3180
- text: JSON.stringify(
3181
- {
3182
- message: `Successfully updated guardrail "${params.guardrail_id}"`,
3183
- id: result.id,
3184
- slug: result.slug,
3185
- version_id: result.version_id
3186
- },
3187
- null,
3188
- 2
3189
- )
3046
+ text: JSON.stringify({
3047
+ message: `Successfully updated guardrail "${params.guardrail_id}"`,
3048
+ id: result.id,
3049
+ slug: result.slug,
3050
+ version_id: result.version_id
3051
+ })
3190
3052
  }
3191
3053
  ]
3192
3054
  };
@@ -3204,14 +3066,10 @@ function registerGuardrailsTools(server, service) {
3204
3066
  content: [
3205
3067
  {
3206
3068
  type: "text",
3207
- text: JSON.stringify(
3208
- {
3209
- message: `Successfully deleted guardrail "${params.guardrail_id}"`,
3210
- success: result.success
3211
- },
3212
- null,
3213
- 2
3214
- )
3069
+ text: JSON.stringify({
3070
+ message: `Successfully deleted guardrail "${params.guardrail_id}"`,
3071
+ success: result.success
3072
+ })
3215
3073
  }
3216
3074
  ]
3217
3075
  };
@@ -3354,6 +3212,28 @@ var INTEGRATIONS_TOOL_SCHEMAS = {
3354
3212
  ).describe("Array of workspace configurations to update")
3355
3213
  }
3356
3214
  };
3215
+ function buildIntegrationConfigurations(params) {
3216
+ const configurations = {};
3217
+ if (params.api_version !== void 0)
3218
+ configurations.api_version = params.api_version;
3219
+ if (params.resource_name !== void 0)
3220
+ configurations.resource_name = params.resource_name;
3221
+ if (params.deployment_name !== void 0)
3222
+ configurations.deployment_name = params.deployment_name;
3223
+ if (params.aws_region !== void 0)
3224
+ configurations.aws_region = params.aws_region;
3225
+ if (params.aws_access_key_id !== void 0)
3226
+ configurations.aws_access_key_id = params.aws_access_key_id;
3227
+ if (params.aws_secret_access_key !== void 0)
3228
+ configurations.aws_secret_access_key = params.aws_secret_access_key;
3229
+ if (params.vertex_project_id !== void 0)
3230
+ configurations.vertex_project_id = params.vertex_project_id;
3231
+ if (params.vertex_region !== void 0)
3232
+ configurations.vertex_region = params.vertex_region;
3233
+ if (params.custom_host !== void 0)
3234
+ configurations.custom_host = params.custom_host;
3235
+ return Object.keys(configurations).length > 0 ? configurations : void 0;
3236
+ }
3357
3237
  function registerIntegrationsTools(server, service) {
3358
3238
  server.tool(
3359
3239
  "list_integrations",
@@ -3370,24 +3250,20 @@ function registerIntegrationsTools(server, service) {
3370
3250
  content: [
3371
3251
  {
3372
3252
  type: "text",
3373
- text: JSON.stringify(
3374
- {
3375
- total: integrations.total,
3376
- integrations: integrations.data.map((integration) => ({
3377
- id: integration.id,
3378
- name: integration.name,
3379
- slug: integration.slug,
3380
- ai_provider_id: integration.ai_provider_id,
3381
- status: integration.status,
3382
- description: integration.description,
3383
- organisation_id: integration.organisation_id,
3384
- created_at: integration.created_at,
3385
- last_updated_at: integration.last_updated_at
3386
- }))
3387
- },
3388
- null,
3389
- 2
3390
- )
3253
+ text: JSON.stringify({
3254
+ total: integrations.total,
3255
+ integrations: integrations.data.map((integration) => ({
3256
+ id: integration.id,
3257
+ name: integration.name,
3258
+ slug: integration.slug,
3259
+ ai_provider_id: integration.ai_provider_id,
3260
+ status: integration.status,
3261
+ description: integration.description,
3262
+ organisation_id: integration.organisation_id,
3263
+ created_at: integration.created_at,
3264
+ last_updated_at: integration.last_updated_at
3265
+ }))
3266
+ })
3391
3267
  }
3392
3268
  ]
3393
3269
  };
@@ -3398,22 +3274,6 @@ function registerIntegrationsTools(server, service) {
3398
3274
  "Create an org-level provider integration. Some backends need provider-specific fields, and the new integration becomes the source for downstream providers and workspace access. Returns the new integration id and slug.",
3399
3275
  INTEGRATIONS_TOOL_SCHEMAS.createIntegration,
3400
3276
  async (params) => {
3401
- const configurations = {};
3402
- if (params.api_version) configurations.api_version = params.api_version;
3403
- if (params.resource_name)
3404
- configurations.resource_name = params.resource_name;
3405
- if (params.deployment_name)
3406
- configurations.deployment_name = params.deployment_name;
3407
- if (params.aws_region) configurations.aws_region = params.aws_region;
3408
- if (params.aws_access_key_id)
3409
- configurations.aws_access_key_id = params.aws_access_key_id;
3410
- if (params.aws_secret_access_key)
3411
- configurations.aws_secret_access_key = params.aws_secret_access_key;
3412
- if (params.vertex_project_id)
3413
- configurations.vertex_project_id = params.vertex_project_id;
3414
- if (params.vertex_region)
3415
- configurations.vertex_region = params.vertex_region;
3416
- if (params.custom_host) configurations.custom_host = params.custom_host;
3417
3277
  const result = await service.integrations.createIntegration({
3418
3278
  name: params.name,
3419
3279
  ai_provider_id: params.ai_provider_id,
@@ -3421,21 +3281,17 @@ function registerIntegrationsTools(server, service) {
3421
3281
  key: params.key,
3422
3282
  description: params.description,
3423
3283
  workspace_id: params.workspace_id,
3424
- configurations: Object.keys(configurations).length > 0 ? configurations : void 0
3284
+ configurations: buildIntegrationConfigurations(params)
3425
3285
  });
3426
3286
  return {
3427
3287
  content: [
3428
3288
  {
3429
3289
  type: "text",
3430
- text: JSON.stringify(
3431
- {
3432
- message: `Successfully created integration "${params.name}"`,
3433
- id: result.id,
3434
- slug: result.slug
3435
- },
3436
- null,
3437
- 2
3438
- )
3290
+ text: JSON.stringify({
3291
+ message: `Successfully created integration "${params.name}"`,
3292
+ id: result.id,
3293
+ slug: result.slug
3294
+ })
3439
3295
  }
3440
3296
  ]
3441
3297
  };
@@ -3453,26 +3309,22 @@ function registerIntegrationsTools(server, service) {
3453
3309
  content: [
3454
3310
  {
3455
3311
  type: "text",
3456
- text: JSON.stringify(
3457
- {
3458
- id: integration.id,
3459
- name: integration.name,
3460
- slug: integration.slug,
3461
- ai_provider_id: integration.ai_provider_id,
3462
- status: integration.status,
3463
- description: integration.description,
3464
- organisation_id: integration.organisation_id,
3465
- masked_key: integration.masked_key,
3466
- configurations: integration.configurations,
3467
- global_workspace_access_settings: integration.global_workspace_access_settings,
3468
- allow_all_models: integration.allow_all_models,
3469
- workspace_count: integration.workspace_count,
3470
- created_at: integration.created_at,
3471
- last_updated_at: integration.last_updated_at
3472
- },
3473
- null,
3474
- 2
3475
- )
3312
+ text: JSON.stringify({
3313
+ id: integration.id,
3314
+ name: integration.name,
3315
+ slug: integration.slug,
3316
+ ai_provider_id: integration.ai_provider_id,
3317
+ status: integration.status,
3318
+ description: integration.description,
3319
+ organisation_id: integration.organisation_id,
3320
+ masked_key: integration.masked_key,
3321
+ configurations: integration.configurations,
3322
+ global_workspace_access_settings: integration.global_workspace_access_settings,
3323
+ allow_all_models: integration.allow_all_models,
3324
+ workspace_count: integration.workspace_count,
3325
+ created_at: integration.created_at,
3326
+ last_updated_at: integration.last_updated_at
3327
+ })
3476
3328
  }
3477
3329
  ]
3478
3330
  };
@@ -3483,43 +3335,20 @@ function registerIntegrationsTools(server, service) {
3483
3335
  "Update an integration's name, key, or provider-specific config. Key and config changes take effect immediately and can disrupt dependent providers or live requests.",
3484
3336
  INTEGRATIONS_TOOL_SCHEMAS.updateIntegration,
3485
3337
  async (params) => {
3486
- const configurations = {};
3487
- if (params.api_version !== void 0)
3488
- configurations.api_version = params.api_version;
3489
- if (params.resource_name !== void 0)
3490
- configurations.resource_name = params.resource_name;
3491
- if (params.deployment_name !== void 0)
3492
- configurations.deployment_name = params.deployment_name;
3493
- if (params.aws_region !== void 0)
3494
- configurations.aws_region = params.aws_region;
3495
- if (params.aws_access_key_id !== void 0)
3496
- configurations.aws_access_key_id = params.aws_access_key_id;
3497
- if (params.aws_secret_access_key !== void 0)
3498
- configurations.aws_secret_access_key = params.aws_secret_access_key;
3499
- if (params.vertex_project_id !== void 0)
3500
- configurations.vertex_project_id = params.vertex_project_id;
3501
- if (params.vertex_region !== void 0)
3502
- configurations.vertex_region = params.vertex_region;
3503
- if (params.custom_host !== void 0)
3504
- configurations.custom_host = params.custom_host;
3505
3338
  const result = await service.integrations.updateIntegration(params.slug, {
3506
3339
  name: params.name,
3507
3340
  key: params.key,
3508
3341
  description: params.description,
3509
- configurations: Object.keys(configurations).length > 0 ? configurations : void 0
3342
+ configurations: buildIntegrationConfigurations(params)
3510
3343
  });
3511
3344
  return {
3512
3345
  content: [
3513
3346
  {
3514
3347
  type: "text",
3515
- text: JSON.stringify(
3516
- {
3517
- message: `Successfully updated integration "${params.slug}"`,
3518
- success: result.success
3519
- },
3520
- null,
3521
- 2
3522
- )
3348
+ text: JSON.stringify({
3349
+ message: `Successfully updated integration "${params.slug}"`,
3350
+ success: result.success
3351
+ })
3523
3352
  }
3524
3353
  ]
3525
3354
  };
@@ -3535,14 +3364,10 @@ function registerIntegrationsTools(server, service) {
3535
3364
  content: [
3536
3365
  {
3537
3366
  type: "text",
3538
- text: JSON.stringify(
3539
- {
3540
- message: `Successfully deleted integration "${params.slug}"`,
3541
- success: result.success
3542
- },
3543
- null,
3544
- 2
3545
- )
3367
+ text: JSON.stringify({
3368
+ message: `Successfully deleted integration "${params.slug}"`,
3369
+ success: result.success
3370
+ })
3546
3371
  }
3547
3372
  ]
3548
3373
  };
@@ -3564,23 +3389,19 @@ function registerIntegrationsTools(server, service) {
3564
3389
  content: [
3565
3390
  {
3566
3391
  type: "text",
3567
- text: JSON.stringify(
3568
- {
3569
- total: models.total,
3570
- integration_slug: params.slug,
3571
- models: models.data.map((model) => ({
3572
- id: model.id,
3573
- model_id: model.model_id,
3574
- model_name: model.model_name,
3575
- enabled: model.enabled,
3576
- custom: model.custom,
3577
- created_at: model.created_at,
3578
- last_updated_at: model.last_updated_at
3579
- }))
3580
- },
3581
- null,
3582
- 2
3583
- )
3392
+ text: JSON.stringify({
3393
+ total: models.total,
3394
+ integration_slug: params.slug,
3395
+ models: models.data.map((model) => ({
3396
+ id: model.id,
3397
+ model_id: model.model_id,
3398
+ model_name: model.model_name,
3399
+ enabled: model.enabled,
3400
+ custom: model.custom,
3401
+ created_at: model.created_at,
3402
+ last_updated_at: model.last_updated_at
3403
+ }))
3404
+ })
3584
3405
  }
3585
3406
  ]
3586
3407
  };
@@ -3601,15 +3422,11 @@ function registerIntegrationsTools(server, service) {
3601
3422
  content: [
3602
3423
  {
3603
3424
  type: "text",
3604
- text: JSON.stringify(
3605
- {
3606
- message: `Successfully updated models for integration "${params.slug}"`,
3607
- success: result.success,
3608
- models_updated: params.models.length
3609
- },
3610
- null,
3611
- 2
3612
- )
3425
+ text: JSON.stringify({
3426
+ message: `Successfully updated models for integration "${params.slug}"`,
3427
+ success: result.success,
3428
+ models_updated: params.models.length
3429
+ })
3613
3430
  }
3614
3431
  ]
3615
3432
  };
@@ -3628,14 +3445,10 @@ function registerIntegrationsTools(server, service) {
3628
3445
  content: [
3629
3446
  {
3630
3447
  type: "text",
3631
- text: JSON.stringify(
3632
- {
3633
- message: `Successfully deleted model "${params.model_slug}" from integration "${params.slug}"`,
3634
- success: result.success
3635
- },
3636
- null,
3637
- 2
3638
- )
3448
+ text: JSON.stringify({
3449
+ message: `Successfully deleted model "${params.model_slug}" from integration "${params.slug}"`,
3450
+ success: result.success
3451
+ })
3639
3452
  }
3640
3453
  ]
3641
3454
  };
@@ -3657,24 +3470,20 @@ function registerIntegrationsTools(server, service) {
3657
3470
  content: [
3658
3471
  {
3659
3472
  type: "text",
3660
- text: JSON.stringify(
3661
- {
3662
- total: workspaces.total,
3663
- integration_slug: params.slug,
3664
- workspaces: workspaces.data.map((ws) => ({
3665
- id: ws.id,
3666
- workspace_id: ws.workspace_id,
3667
- workspace_name: ws.workspace_name,
3668
- enabled: ws.enabled,
3669
- usage_limits: ws.usage_limits,
3670
- rate_limits: ws.rate_limits,
3671
- created_at: ws.created_at,
3672
- last_updated_at: ws.last_updated_at
3673
- }))
3674
- },
3675
- null,
3676
- 2
3677
- )
3473
+ text: JSON.stringify({
3474
+ total: workspaces.total,
3475
+ integration_slug: params.slug,
3476
+ workspaces: workspaces.data.map((ws) => ({
3477
+ id: ws.id,
3478
+ workspace_id: ws.workspace_id,
3479
+ workspace_name: ws.workspace_name,
3480
+ enabled: ws.enabled,
3481
+ usage_limits: ws.usage_limits,
3482
+ rate_limits: ws.rate_limits,
3483
+ created_at: ws.created_at,
3484
+ last_updated_at: ws.last_updated_at
3485
+ }))
3486
+ })
3678
3487
  }
3679
3488
  ]
3680
3489
  };
@@ -3706,15 +3515,11 @@ function registerIntegrationsTools(server, service) {
3706
3515
  content: [
3707
3516
  {
3708
3517
  type: "text",
3709
- text: JSON.stringify(
3710
- {
3711
- message: `Successfully updated workspace access for integration "${params.slug}"`,
3712
- success: result.success,
3713
- workspaces_updated: params.workspaces.length
3714
- },
3715
- null,
3716
- 2
3717
- )
3518
+ text: JSON.stringify({
3519
+ message: `Successfully updated workspace access for integration "${params.slug}"`,
3520
+ success: result.success,
3521
+ workspaces_updated: params.workspaces.length
3522
+ })
3718
3523
  }
3719
3524
  ]
3720
3525
  };
@@ -3725,7 +3530,10 @@ function registerIntegrationsTools(server, service) {
3725
3530
  // src/tools/keys.tools.ts
3726
3531
  import { z as z7 } from "zod";
3727
3532
  var KEYS_TOOL_SCHEMAS = {
3728
- listVirtualKeys: {},
3533
+ listVirtualKeys: {
3534
+ current_page: z7.coerce.number().positive().optional().describe("Page number for pagination"),
3535
+ page_size: z7.coerce.number().positive().max(100).optional().describe("Number of results per page (max 100)")
3536
+ },
3729
3537
  createVirtualKey: {
3730
3538
  name: z7.string().describe("Display name for the virtual key"),
3731
3539
  provider: z7.string().describe(
@@ -3807,43 +3615,58 @@ var KEYS_TOOL_SCHEMAS = {
3807
3615
  id: z7.string().uuid().describe("The UUID of the API key to delete")
3808
3616
  }
3809
3617
  };
3618
+ var createApiKeySchema = z7.object(KEYS_TOOL_SCHEMAS.createApiKey).superRefine((value, ctx) => {
3619
+ if (value.type === "workspace" && !value.workspace_id) {
3620
+ ctx.addIssue({
3621
+ code: z7.ZodIssueCode.custom,
3622
+ path: ["workspace_id"],
3623
+ message: "workspace_id is required when type is 'workspace'"
3624
+ });
3625
+ }
3626
+ if (value.sub_type === "user" && !value.user_id) {
3627
+ ctx.addIssue({
3628
+ code: z7.ZodIssueCode.custom,
3629
+ path: ["user_id"],
3630
+ message: "user_id is required when sub_type is 'user'"
3631
+ });
3632
+ }
3633
+ });
3810
3634
  function registerKeysTools(server, service) {
3811
3635
  server.tool(
3812
3636
  "list_virtual_keys",
3813
3637
  "List provider API keys stored as virtual keys in your Portkey org. Use this to find slugs before wiring prompts/configs or auditing limits. Returns total plus name, slug, status, usage limits, rate limits, reset state, and model config.",
3814
3638
  KEYS_TOOL_SCHEMAS.listVirtualKeys,
3815
- async () => {
3816
- const virtualKeys = await service.keys.listVirtualKeys();
3639
+ async (params) => {
3640
+ const virtualKeys = await service.keys.listVirtualKeys({
3641
+ current_page: params.current_page,
3642
+ page_size: params.page_size
3643
+ });
3817
3644
  return {
3818
3645
  content: [
3819
3646
  {
3820
3647
  type: "text",
3821
- text: JSON.stringify(
3822
- {
3823
- total: virtualKeys.total,
3824
- virtual_keys: virtualKeys.data.map((key) => ({
3825
- name: key.name,
3826
- slug: key.slug,
3827
- status: key.status,
3828
- note: key.note,
3829
- usage_limits: key.usage_limits ? {
3830
- credit_limit: key.usage_limits.credit_limit,
3831
- alert_threshold: key.usage_limits.alert_threshold,
3832
- periodic_reset: key.usage_limits.periodic_reset
3833
- } : null,
3834
- rate_limits: key.rate_limits?.map((limit) => ({
3835
- type: limit.type,
3836
- unit: limit.unit,
3837
- value: limit.value
3838
- })) ?? null,
3839
- reset_usage: key.reset_usage,
3840
- created_at: key.created_at,
3841
- model_config: key.model_config
3842
- }))
3843
- },
3844
- null,
3845
- 2
3846
- )
3648
+ text: JSON.stringify({
3649
+ total: virtualKeys.total,
3650
+ virtual_keys: virtualKeys.data.map((key) => ({
3651
+ name: key.name,
3652
+ slug: key.slug,
3653
+ status: key.status,
3654
+ note: key.note,
3655
+ usage_limits: key.usage_limits ? {
3656
+ credit_limit: key.usage_limits.credit_limit,
3657
+ alert_threshold: key.usage_limits.alert_threshold,
3658
+ periodic_reset: key.usage_limits.periodic_reset
3659
+ } : null,
3660
+ rate_limits: key.rate_limits?.map((limit) => ({
3661
+ type: limit.type,
3662
+ unit: limit.unit,
3663
+ value: limit.value
3664
+ })) ?? null,
3665
+ reset_usage: key.reset_usage,
3666
+ created_at: key.created_at,
3667
+ model_config: key.model_config
3668
+ }))
3669
+ })
3847
3670
  }
3848
3671
  ]
3849
3672
  };
@@ -3874,15 +3697,11 @@ function registerKeysTools(server, service) {
3874
3697
  content: [
3875
3698
  {
3876
3699
  type: "text",
3877
- text: JSON.stringify(
3878
- {
3879
- message: `Successfully created virtual key "${params.name}"`,
3880
- success: result.success,
3881
- slug
3882
- },
3883
- null,
3884
- 2
3885
- )
3700
+ text: JSON.stringify({
3701
+ message: `Successfully created virtual key "${params.name}"`,
3702
+ success: result.success,
3703
+ slug
3704
+ })
3886
3705
  }
3887
3706
  ]
3888
3707
  };
@@ -3898,29 +3717,25 @@ function registerKeysTools(server, service) {
3898
3717
  content: [
3899
3718
  {
3900
3719
  type: "text",
3901
- text: JSON.stringify(
3902
- {
3903
- name: virtualKey.name,
3904
- slug: virtualKey.slug,
3905
- status: virtualKey.status,
3906
- note: virtualKey.note,
3907
- usage_limits: virtualKey.usage_limits ? {
3908
- credit_limit: virtualKey.usage_limits.credit_limit,
3909
- alert_threshold: virtualKey.usage_limits.alert_threshold,
3910
- periodic_reset: virtualKey.usage_limits.periodic_reset
3911
- } : null,
3912
- rate_limits: virtualKey.rate_limits?.map((limit) => ({
3913
- type: limit.type,
3914
- unit: limit.unit,
3915
- value: limit.value
3916
- })) ?? null,
3917
- reset_usage: virtualKey.reset_usage,
3918
- created_at: virtualKey.created_at,
3919
- model_config: virtualKey.model_config
3920
- },
3921
- null,
3922
- 2
3923
- )
3720
+ text: JSON.stringify({
3721
+ name: virtualKey.name,
3722
+ slug: virtualKey.slug,
3723
+ status: virtualKey.status,
3724
+ note: virtualKey.note,
3725
+ usage_limits: virtualKey.usage_limits ? {
3726
+ credit_limit: virtualKey.usage_limits.credit_limit,
3727
+ alert_threshold: virtualKey.usage_limits.alert_threshold,
3728
+ periodic_reset: virtualKey.usage_limits.periodic_reset
3729
+ } : null,
3730
+ rate_limits: virtualKey.rate_limits?.map((limit) => ({
3731
+ type: limit.type,
3732
+ unit: limit.unit,
3733
+ value: limit.value
3734
+ })) ?? null,
3735
+ reset_usage: virtualKey.reset_usage,
3736
+ created_at: virtualKey.created_at,
3737
+ model_config: virtualKey.model_config
3738
+ })
3924
3739
  }
3925
3740
  ]
3926
3741
  };
@@ -3945,16 +3760,12 @@ function registerKeysTools(server, service) {
3945
3760
  content: [
3946
3761
  {
3947
3762
  type: "text",
3948
- text: JSON.stringify(
3949
- {
3950
- message: `Successfully updated virtual key "${params.slug}"`,
3951
- name: result.name,
3952
- slug: result.slug,
3953
- status: result.status
3954
- },
3955
- null,
3956
- 2
3957
- )
3763
+ text: JSON.stringify({
3764
+ message: `Successfully updated virtual key "${params.slug}"`,
3765
+ name: result.name,
3766
+ slug: result.slug,
3767
+ status: result.status
3768
+ })
3958
3769
  }
3959
3770
  ]
3960
3771
  };
@@ -3970,14 +3781,10 @@ function registerKeysTools(server, service) {
3970
3781
  content: [
3971
3782
  {
3972
3783
  type: "text",
3973
- text: JSON.stringify(
3974
- {
3975
- message: `Successfully deleted virtual key "${params.slug}"`,
3976
- success: result.success
3977
- },
3978
- null,
3979
- 2
3980
- )
3784
+ text: JSON.stringify({
3785
+ message: `Successfully deleted virtual key "${params.slug}"`,
3786
+ success: result.success
3787
+ })
3981
3788
  }
3982
3789
  ]
3983
3790
  };
@@ -3985,70 +3792,45 @@ function registerKeysTools(server, service) {
3985
3792
  );
3986
3793
  server.tool(
3987
3794
  "create_api_key",
3988
- "Create a Portkey API key for auth. Org keys grant broader access; workspace keys are scoped. The secret is only returned once, and using the key grants access immediately according to its scopes, defaults, and limits. Workspace keys require workspace_id and user keys require user_id.",
3795
+ "Create a Portkey API key for auth. Org keys grant broader access; workspace keys are scoped. WARNING: The key secret is returned ONCE in the tool result and will be visible in MCP transcripts and LLM context \u2014 store it securely immediately. Using the key grants access immediately according to its scopes, defaults, and limits. Workspace keys require workspace_id and user keys require user_id.",
3989
3796
  KEYS_TOOL_SCHEMAS.createApiKey,
3990
3797
  async (params) => {
3991
- if (params.type === "workspace" && !params.workspace_id) {
3992
- return {
3993
- content: [
3994
- {
3995
- type: "text",
3996
- text: "Error creating API key: workspace_id is required for workspace-type keys"
3997
- }
3998
- ],
3999
- isError: true
4000
- };
4001
- }
4002
- if (params.sub_type === "user" && !params.user_id) {
4003
- return {
4004
- content: [
4005
- {
4006
- type: "text",
4007
- text: "Error creating API key: user_id is required for user sub-type keys"
4008
- }
4009
- ],
4010
- isError: true
4011
- };
4012
- }
3798
+ const validated = createApiKeySchema.parse(params);
4013
3799
  const result = await service.keys.createApiKey(
4014
- params.type,
4015
- params.sub_type,
3800
+ validated.type,
3801
+ validated.sub_type,
4016
3802
  {
4017
- name: params.name,
4018
- description: params.description,
4019
- workspace_id: params.workspace_id,
4020
- user_id: params.user_id,
4021
- scopes: params.scopes,
3803
+ name: validated.name,
3804
+ description: validated.description,
3805
+ workspace_id: validated.workspace_id,
3806
+ user_id: validated.user_id,
3807
+ scopes: validated.scopes,
4022
3808
  usage_limits: buildUsageLimits({
4023
- credit_limit: params.credit_limit,
4024
- alert_threshold: params.alert_threshold
3809
+ credit_limit: validated.credit_limit,
3810
+ alert_threshold: validated.alert_threshold
4025
3811
  }),
4026
- rate_limits: buildRateLimitsRpm(params.rate_limit_rpm),
3812
+ rate_limits: buildRateLimitsRpm(validated.rate_limit_rpm),
4027
3813
  defaults: (() => {
4028
3814
  const d = {};
4029
- if (params.default_config_id !== void 0)
4030
- d.config_id = params.default_config_id;
4031
- if (params.default_metadata !== void 0)
4032
- d.metadata = params.default_metadata;
3815
+ if (validated.default_config_id !== void 0)
3816
+ d.config_id = validated.default_config_id;
3817
+ if (validated.default_metadata !== void 0)
3818
+ d.metadata = validated.default_metadata;
4033
3819
  return Object.keys(d).length > 0 ? d : void 0;
4034
3820
  })(),
4035
- alert_emails: params.alert_emails,
4036
- expires_at: params.expires_at
3821
+ alert_emails: validated.alert_emails,
3822
+ expires_at: validated.expires_at
4037
3823
  }
4038
3824
  );
4039
3825
  return {
4040
3826
  content: [
4041
3827
  {
4042
3828
  type: "text",
4043
- text: JSON.stringify(
4044
- {
4045
- message: `Successfully created API key "${params.name}"`,
4046
- id: result.id,
4047
- key: result.key
4048
- },
4049
- null,
4050
- 2
4051
- )
3829
+ text: JSON.stringify({
3830
+ message: `Successfully created API key "${validated.name}"`,
3831
+ id: result.id,
3832
+ key: result.key
3833
+ })
4052
3834
  }
4053
3835
  ]
4054
3836
  };
@@ -4068,40 +3850,36 @@ function registerKeysTools(server, service) {
4068
3850
  content: [
4069
3851
  {
4070
3852
  type: "text",
4071
- text: JSON.stringify(
4072
- {
4073
- total: apiKeys.total,
4074
- api_keys: apiKeys.data.map((key) => ({
4075
- id: key.id,
4076
- name: key.name,
4077
- description: key.description,
4078
- type: key.type,
4079
- status: key.status,
4080
- organisation_id: key.organisation_id,
4081
- workspace_id: key.workspace_id,
4082
- user_id: key.user_id,
4083
- scopes: key.scopes,
4084
- usage_limits: key.usage_limits ? {
4085
- credit_limit: key.usage_limits.credit_limit,
4086
- alert_threshold: key.usage_limits.alert_threshold,
4087
- periodic_reset: key.usage_limits.periodic_reset
4088
- } : null,
4089
- rate_limits: key.rate_limits?.map((limit) => ({
4090
- type: limit.type,
4091
- unit: limit.unit,
4092
- value: limit.value
4093
- })) ?? null,
4094
- defaults: key.defaults,
4095
- alert_emails: key.alert_emails,
4096
- expires_at: key.expires_at,
4097
- created_at: key.created_at,
4098
- last_updated_at: key.last_updated_at,
4099
- creation_mode: key.creation_mode
4100
- }))
4101
- },
4102
- null,
4103
- 2
4104
- )
3853
+ text: JSON.stringify({
3854
+ total: apiKeys.total,
3855
+ api_keys: apiKeys.data.map((key) => ({
3856
+ id: key.id,
3857
+ name: key.name,
3858
+ description: key.description,
3859
+ type: key.type,
3860
+ status: key.status,
3861
+ organisation_id: key.organisation_id,
3862
+ workspace_id: key.workspace_id,
3863
+ user_id: key.user_id,
3864
+ scopes: key.scopes,
3865
+ usage_limits: key.usage_limits ? {
3866
+ credit_limit: key.usage_limits.credit_limit,
3867
+ alert_threshold: key.usage_limits.alert_threshold,
3868
+ periodic_reset: key.usage_limits.periodic_reset
3869
+ } : null,
3870
+ rate_limits: key.rate_limits?.map((limit) => ({
3871
+ type: limit.type,
3872
+ unit: limit.unit,
3873
+ value: limit.value
3874
+ })) ?? null,
3875
+ defaults: key.defaults,
3876
+ alert_emails: key.alert_emails,
3877
+ expires_at: key.expires_at,
3878
+ created_at: key.created_at,
3879
+ last_updated_at: key.last_updated_at,
3880
+ creation_mode: key.creation_mode
3881
+ }))
3882
+ })
4105
3883
  }
4106
3884
  ]
4107
3885
  };
@@ -4117,38 +3895,34 @@ function registerKeysTools(server, service) {
4117
3895
  content: [
4118
3896
  {
4119
3897
  type: "text",
4120
- text: JSON.stringify(
4121
- {
4122
- id: apiKey.id,
4123
- name: apiKey.name,
4124
- description: apiKey.description,
4125
- type: apiKey.type,
4126
- status: apiKey.status,
4127
- organisation_id: apiKey.organisation_id,
4128
- workspace_id: apiKey.workspace_id,
4129
- user_id: apiKey.user_id,
4130
- scopes: apiKey.scopes,
4131
- usage_limits: apiKey.usage_limits ? {
4132
- credit_limit: apiKey.usage_limits.credit_limit,
4133
- alert_threshold: apiKey.usage_limits.alert_threshold,
4134
- periodic_reset: apiKey.usage_limits.periodic_reset
4135
- } : null,
4136
- rate_limits: apiKey.rate_limits?.map((limit) => ({
4137
- type: limit.type,
4138
- unit: limit.unit,
4139
- value: limit.value
4140
- })) ?? null,
4141
- defaults: apiKey.defaults,
4142
- alert_emails: apiKey.alert_emails,
4143
- expires_at: apiKey.expires_at,
4144
- reset_usage: apiKey.reset_usage,
4145
- created_at: apiKey.created_at,
4146
- last_updated_at: apiKey.last_updated_at,
4147
- creation_mode: apiKey.creation_mode
4148
- },
4149
- null,
4150
- 2
4151
- )
3898
+ text: JSON.stringify({
3899
+ id: apiKey.id,
3900
+ name: apiKey.name,
3901
+ description: apiKey.description,
3902
+ type: apiKey.type,
3903
+ status: apiKey.status,
3904
+ organisation_id: apiKey.organisation_id,
3905
+ workspace_id: apiKey.workspace_id,
3906
+ user_id: apiKey.user_id,
3907
+ scopes: apiKey.scopes,
3908
+ usage_limits: apiKey.usage_limits ? {
3909
+ credit_limit: apiKey.usage_limits.credit_limit,
3910
+ alert_threshold: apiKey.usage_limits.alert_threshold,
3911
+ periodic_reset: apiKey.usage_limits.periodic_reset
3912
+ } : null,
3913
+ rate_limits: apiKey.rate_limits?.map((limit) => ({
3914
+ type: limit.type,
3915
+ unit: limit.unit,
3916
+ value: limit.value
3917
+ })) ?? null,
3918
+ defaults: apiKey.defaults,
3919
+ alert_emails: apiKey.alert_emails,
3920
+ expires_at: apiKey.expires_at,
3921
+ reset_usage: apiKey.reset_usage,
3922
+ created_at: apiKey.created_at,
3923
+ last_updated_at: apiKey.last_updated_at,
3924
+ creation_mode: apiKey.creation_mode
3925
+ })
4152
3926
  }
4153
3927
  ]
4154
3928
  };
@@ -4179,14 +3953,10 @@ function registerKeysTools(server, service) {
4179
3953
  content: [
4180
3954
  {
4181
3955
  type: "text",
4182
- text: JSON.stringify(
4183
- {
4184
- message: `Successfully updated API key "${params.id}"`,
4185
- success: result.success
4186
- },
4187
- null,
4188
- 2
4189
- )
3956
+ text: JSON.stringify({
3957
+ message: `Successfully updated API key "${params.id}"`,
3958
+ success: result.success
3959
+ })
4190
3960
  }
4191
3961
  ]
4192
3962
  };
@@ -4202,14 +3972,10 @@ function registerKeysTools(server, service) {
4202
3972
  content: [
4203
3973
  {
4204
3974
  type: "text",
4205
- text: JSON.stringify(
4206
- {
4207
- message: `Successfully deleted API key "${params.id}"`,
4208
- success: result.success
4209
- },
4210
- null,
4211
- 2
4212
- )
3975
+ text: JSON.stringify({
3976
+ message: `Successfully deleted API key "${params.id}"`,
3977
+ success: result.success
3978
+ })
4213
3979
  }
4214
3980
  ]
4215
3981
  };
@@ -4279,14 +4045,10 @@ function registerLabelsTools(server, service) {
4279
4045
  content: [
4280
4046
  {
4281
4047
  type: "text",
4282
- text: JSON.stringify(
4283
- {
4284
- message: `Successfully created label "${params.name}"`,
4285
- id: result.id
4286
- },
4287
- null,
4288
- 2
4289
- )
4048
+ text: JSON.stringify({
4049
+ message: `Successfully created label "${params.name}"`,
4050
+ id: result.id
4051
+ })
4290
4052
  }
4291
4053
  ]
4292
4054
  };
@@ -4302,23 +4064,19 @@ function registerLabelsTools(server, service) {
4302
4064
  content: [
4303
4065
  {
4304
4066
  type: "text",
4305
- text: JSON.stringify(
4306
- {
4307
- total: result.total,
4308
- labels: result.data.map((label) => ({
4309
- id: label.id,
4310
- name: label.name,
4311
- description: label.description,
4312
- color_code: label.color_code,
4313
- is_universal: label.is_universal,
4314
- status: label.status,
4315
- created_at: label.created_at,
4316
- last_updated_at: label.last_updated_at
4317
- }))
4318
- },
4319
- null,
4320
- 2
4321
- )
4067
+ text: JSON.stringify({
4068
+ total: result.total,
4069
+ labels: result.data.map((label) => ({
4070
+ id: label.id,
4071
+ name: label.name,
4072
+ description: label.description,
4073
+ color_code: label.color_code,
4074
+ is_universal: label.is_universal,
4075
+ status: label.status,
4076
+ created_at: label.created_at,
4077
+ last_updated_at: label.last_updated_at
4078
+ }))
4079
+ })
4322
4080
  }
4323
4081
  ]
4324
4082
  };
@@ -4337,22 +4095,18 @@ function registerLabelsTools(server, service) {
4337
4095
  content: [
4338
4096
  {
4339
4097
  type: "text",
4340
- text: JSON.stringify(
4341
- {
4342
- id: label.id,
4343
- name: label.name,
4344
- description: label.description,
4345
- color_code: label.color_code,
4346
- organisation_id: label.organisation_id,
4347
- workspace_id: label.workspace_id,
4348
- is_universal: label.is_universal,
4349
- status: label.status,
4350
- created_at: label.created_at,
4351
- last_updated_at: label.last_updated_at
4352
- },
4353
- null,
4354
- 2
4355
- )
4098
+ text: JSON.stringify({
4099
+ id: label.id,
4100
+ name: label.name,
4101
+ description: label.description,
4102
+ color_code: label.color_code,
4103
+ organisation_id: label.organisation_id,
4104
+ workspace_id: label.workspace_id,
4105
+ is_universal: label.is_universal,
4106
+ status: label.status,
4107
+ created_at: label.created_at,
4108
+ last_updated_at: label.last_updated_at
4109
+ })
4356
4110
  }
4357
4111
  ]
4358
4112
  };
@@ -4369,14 +4123,10 @@ function registerLabelsTools(server, service) {
4369
4123
  content: [
4370
4124
  {
4371
4125
  type: "text",
4372
- text: JSON.stringify(
4373
- {
4374
- message: `Successfully updated label "${label_id}"`,
4375
- success: true
4376
- },
4377
- null,
4378
- 2
4379
- )
4126
+ text: JSON.stringify({
4127
+ message: `Successfully updated label "${label_id}"`,
4128
+ success: true
4129
+ })
4380
4130
  }
4381
4131
  ]
4382
4132
  };
@@ -4392,14 +4142,10 @@ function registerLabelsTools(server, service) {
4392
4142
  content: [
4393
4143
  {
4394
4144
  type: "text",
4395
- text: JSON.stringify(
4396
- {
4397
- message: `Successfully deleted label "${params.label_id}"`,
4398
- success: true
4399
- },
4400
- null,
4401
- 2
4402
- )
4145
+ text: JSON.stringify({
4146
+ message: `Successfully deleted label "${params.label_id}"`,
4147
+ success: true
4148
+ })
4403
4149
  }
4404
4150
  ]
4405
4151
  };
@@ -4544,14 +4290,10 @@ function registerLimitsTools(server, service) {
4544
4290
  content: [
4545
4291
  {
4546
4292
  type: "text",
4547
- text: JSON.stringify(
4548
- {
4549
- total: result.total,
4550
- rate_limits: result.data.map(formatRateLimit)
4551
- },
4552
- null,
4553
- 2
4554
- )
4293
+ text: JSON.stringify({
4294
+ total: result.total,
4295
+ rate_limits: result.data.map(formatRateLimit)
4296
+ })
4555
4297
  }
4556
4298
  ]
4557
4299
  };
@@ -4567,7 +4309,7 @@ function registerLimitsTools(server, service) {
4567
4309
  content: [
4568
4310
  {
4569
4311
  type: "text",
4570
- text: JSON.stringify(formatRateLimit(result), null, 2)
4312
+ text: JSON.stringify(formatRateLimit(result))
4571
4313
  }
4572
4314
  ]
4573
4315
  };
@@ -4592,14 +4334,10 @@ function registerLimitsTools(server, service) {
4592
4334
  content: [
4593
4335
  {
4594
4336
  type: "text",
4595
- text: JSON.stringify(
4596
- {
4597
- message: `Successfully created rate limit${params.name ? ` "${params.name}"` : ""}`,
4598
- rate_limit: formatRateLimit(result)
4599
- },
4600
- null,
4601
- 2
4602
- )
4337
+ text: JSON.stringify({
4338
+ message: `Successfully created rate limit${params.name ? ` "${params.name}"` : ""}`,
4339
+ rate_limit: formatRateLimit(result)
4340
+ })
4603
4341
  }
4604
4342
  ]
4605
4343
  };
@@ -4619,14 +4357,10 @@ function registerLimitsTools(server, service) {
4619
4357
  content: [
4620
4358
  {
4621
4359
  type: "text",
4622
- text: JSON.stringify(
4623
- {
4624
- message: `Successfully updated rate limit "${params.id}"`,
4625
- rate_limit: formatRateLimit(result)
4626
- },
4627
- null,
4628
- 2
4629
- )
4360
+ text: JSON.stringify({
4361
+ message: `Successfully updated rate limit "${params.id}"`,
4362
+ rate_limit: formatRateLimit(result)
4363
+ })
4630
4364
  }
4631
4365
  ]
4632
4366
  };
@@ -4642,14 +4376,10 @@ function registerLimitsTools(server, service) {
4642
4376
  content: [
4643
4377
  {
4644
4378
  type: "text",
4645
- text: JSON.stringify(
4646
- {
4647
- message: `Successfully deleted rate limit "${params.id}"`,
4648
- success: true
4649
- },
4650
- null,
4651
- 2
4652
- )
4379
+ text: JSON.stringify({
4380
+ message: `Successfully deleted rate limit "${params.id}"`,
4381
+ success: true
4382
+ })
4653
4383
  }
4654
4384
  ]
4655
4385
  };
@@ -4665,14 +4395,10 @@ function registerLimitsTools(server, service) {
4665
4395
  content: [
4666
4396
  {
4667
4397
  type: "text",
4668
- text: JSON.stringify(
4669
- {
4670
- total: result.total,
4671
- usage_limits: result.data.map(formatUsageLimit)
4672
- },
4673
- null,
4674
- 2
4675
- )
4398
+ text: JSON.stringify({
4399
+ total: result.total,
4400
+ usage_limits: result.data.map(formatUsageLimit)
4401
+ })
4676
4402
  }
4677
4403
  ]
4678
4404
  };
@@ -4688,7 +4414,7 @@ function registerLimitsTools(server, service) {
4688
4414
  content: [
4689
4415
  {
4690
4416
  type: "text",
4691
- text: JSON.stringify(formatUsageLimit(result), null, 2)
4417
+ text: JSON.stringify(formatUsageLimit(result))
4692
4418
  }
4693
4419
  ]
4694
4420
  };
@@ -4714,14 +4440,10 @@ function registerLimitsTools(server, service) {
4714
4440
  content: [
4715
4441
  {
4716
4442
  type: "text",
4717
- text: JSON.stringify(
4718
- {
4719
- message: `Successfully created usage limit${params.name ? ` "${params.name}"` : ""}`,
4720
- usage_limit: formatUsageLimit(result)
4721
- },
4722
- null,
4723
- 2
4724
- )
4443
+ text: JSON.stringify({
4444
+ message: `Successfully created usage limit${params.name ? ` "${params.name}"` : ""}`,
4445
+ usage_limit: formatUsageLimit(result)
4446
+ })
4725
4447
  }
4726
4448
  ]
4727
4449
  };
@@ -4743,14 +4465,10 @@ function registerLimitsTools(server, service) {
4743
4465
  content: [
4744
4466
  {
4745
4467
  type: "text",
4746
- text: JSON.stringify(
4747
- {
4748
- message: `Successfully updated usage limit "${params.id}"`,
4749
- usage_limit: formatUsageLimit(result)
4750
- },
4751
- null,
4752
- 2
4753
- )
4468
+ text: JSON.stringify({
4469
+ message: `Successfully updated usage limit "${params.id}"`,
4470
+ usage_limit: formatUsageLimit(result)
4471
+ })
4754
4472
  }
4755
4473
  ]
4756
4474
  };
@@ -4766,14 +4484,10 @@ function registerLimitsTools(server, service) {
4766
4484
  content: [
4767
4485
  {
4768
4486
  type: "text",
4769
- text: JSON.stringify(
4770
- {
4771
- message: `Successfully deleted usage limit "${params.id}"`,
4772
- success: true
4773
- },
4774
- null,
4775
- 2
4776
- )
4487
+ text: JSON.stringify({
4488
+ message: `Successfully deleted usage limit "${params.id}"`,
4489
+ success: true
4490
+ })
4777
4491
  }
4778
4492
  ]
4779
4493
  };
@@ -4791,14 +4505,10 @@ function registerLimitsTools(server, service) {
4791
4505
  content: [
4792
4506
  {
4793
4507
  type: "text",
4794
- text: JSON.stringify(
4795
- {
4796
- total: result.total,
4797
- entities: result.data.map(formatUsageLimitEntity)
4798
- },
4799
- null,
4800
- 2
4801
- )
4508
+ text: JSON.stringify({
4509
+ total: result.total,
4510
+ entities: result.data.map(formatUsageLimitEntity)
4511
+ })
4802
4512
  }
4803
4513
  ]
4804
4514
  };
@@ -4817,14 +4527,10 @@ function registerLimitsTools(server, service) {
4817
4527
  content: [
4818
4528
  {
4819
4529
  type: "text",
4820
- text: JSON.stringify(
4821
- {
4822
- message: `Successfully reset usage for entity "${params.entity_id}" on limit "${params.limit_id}"`,
4823
- success: true
4824
- },
4825
- null,
4826
- 2
4827
- )
4530
+ text: JSON.stringify({
4531
+ message: `Successfully reset usage for entity "${params.entity_id}" on limit "${params.limit_id}"`,
4532
+ success: true
4533
+ })
4828
4534
  }
4829
4535
  ]
4830
4536
  };
@@ -4956,14 +4662,10 @@ function registerLoggingTools(server, service) {
4956
4662
  content: [
4957
4663
  {
4958
4664
  type: "text",
4959
- text: JSON.stringify(
4960
- {
4961
- message: "Successfully inserted log entry",
4962
- success: result.success
4963
- },
4964
- null,
4965
- 2
4966
- )
4665
+ text: JSON.stringify({
4666
+ message: "Successfully inserted log entry",
4667
+ success: result.success
4668
+ })
4967
4669
  }
4968
4670
  ]
4969
4671
  };
@@ -4992,16 +4694,12 @@ function registerLoggingTools(server, service) {
4992
4694
  content: [
4993
4695
  {
4994
4696
  type: "text",
4995
- text: JSON.stringify(
4996
- {
4997
- message: "Successfully created log export",
4998
- id: result.id,
4999
- total: result.total,
5000
- object: result.object
5001
- },
5002
- null,
5003
- 2
5004
- )
4697
+ text: JSON.stringify({
4698
+ message: "Successfully created log export",
4699
+ id: result.id,
4700
+ total: result.total,
4701
+ object: result.object
4702
+ })
5005
4703
  }
5006
4704
  ]
5007
4705
  };
@@ -5019,24 +4717,20 @@ function registerLoggingTools(server, service) {
5019
4717
  content: [
5020
4718
  {
5021
4719
  type: "text",
5022
- text: JSON.stringify(
5023
- {
5024
- total: result.total,
5025
- exports: result.data.map((exp) => ({
5026
- id: exp.id,
5027
- status: exp.status,
5028
- description: exp.description,
5029
- filters: exp.filters,
5030
- requested_data: exp.requested_data,
5031
- workspace_id: exp.workspace_id,
5032
- created_at: exp.created_at,
5033
- last_updated_at: exp.last_updated_at,
5034
- created_by: exp.created_by
5035
- }))
5036
- },
5037
- null,
5038
- 2
5039
- )
4720
+ text: JSON.stringify({
4721
+ total: result.total,
4722
+ exports: result.data.map((exp) => ({
4723
+ id: exp.id,
4724
+ status: exp.status,
4725
+ description: exp.description,
4726
+ filters: exp.filters,
4727
+ requested_data: exp.requested_data,
4728
+ workspace_id: exp.workspace_id,
4729
+ created_at: exp.created_at,
4730
+ last_updated_at: exp.last_updated_at,
4731
+ created_by: exp.created_by
4732
+ }))
4733
+ })
5040
4734
  }
5041
4735
  ]
5042
4736
  };
@@ -5052,22 +4746,18 @@ function registerLoggingTools(server, service) {
5052
4746
  content: [
5053
4747
  {
5054
4748
  type: "text",
5055
- text: JSON.stringify(
5056
- {
5057
- id: result.id,
5058
- status: result.status,
5059
- description: result.description,
5060
- filters: result.filters,
5061
- requested_data: result.requested_data,
5062
- organisation_id: result.organisation_id,
5063
- workspace_id: result.workspace_id,
5064
- created_at: result.created_at,
5065
- last_updated_at: result.last_updated_at,
5066
- created_by: result.created_by
5067
- },
5068
- null,
5069
- 2
5070
- )
4749
+ text: JSON.stringify({
4750
+ id: result.id,
4751
+ status: result.status,
4752
+ description: result.description,
4753
+ filters: result.filters,
4754
+ requested_data: result.requested_data,
4755
+ organisation_id: result.organisation_id,
4756
+ workspace_id: result.workspace_id,
4757
+ created_at: result.created_at,
4758
+ last_updated_at: result.last_updated_at,
4759
+ created_by: result.created_by
4760
+ })
5071
4761
  }
5072
4762
  ]
5073
4763
  };
@@ -5083,15 +4773,11 @@ function registerLoggingTools(server, service) {
5083
4773
  content: [
5084
4774
  {
5085
4775
  type: "text",
5086
- text: JSON.stringify(
5087
- {
5088
- message: result.message,
5089
- export_id: params.export_id,
5090
- status: "started"
5091
- },
5092
- null,
5093
- 2
5094
- )
4776
+ text: JSON.stringify({
4777
+ message: result.message,
4778
+ export_id: params.export_id,
4779
+ status: "started"
4780
+ })
5095
4781
  }
5096
4782
  ]
5097
4783
  };
@@ -5107,15 +4793,11 @@ function registerLoggingTools(server, service) {
5107
4793
  content: [
5108
4794
  {
5109
4795
  type: "text",
5110
- text: JSON.stringify(
5111
- {
5112
- message: result.message,
5113
- export_id: params.export_id,
5114
- status: "cancelled"
5115
- },
5116
- null,
5117
- 2
5118
- )
4796
+ text: JSON.stringify({
4797
+ message: result.message,
4798
+ export_id: params.export_id,
4799
+ status: "cancelled"
4800
+ })
5119
4801
  }
5120
4802
  ]
5121
4803
  };
@@ -5131,15 +4813,11 @@ function registerLoggingTools(server, service) {
5131
4813
  content: [
5132
4814
  {
5133
4815
  type: "text",
5134
- text: JSON.stringify(
5135
- {
5136
- message: "Download URL generated successfully",
5137
- export_id: params.export_id,
5138
- signed_url: result.signed_url
5139
- },
5140
- null,
5141
- 2
5142
- )
4816
+ text: JSON.stringify({
4817
+ message: "Download URL generated successfully",
4818
+ export_id: params.export_id,
4819
+ signed_url: result.signed_url
4820
+ })
5143
4821
  }
5144
4822
  ]
5145
4823
  };
@@ -5170,16 +4848,12 @@ function registerLoggingTools(server, service) {
5170
4848
  content: [
5171
4849
  {
5172
4850
  type: "text",
5173
- text: JSON.stringify(
5174
- {
5175
- message: "Successfully updated log export",
5176
- id: result.id,
5177
- total: result.total,
5178
- object: result.object
5179
- },
5180
- null,
5181
- 2
5182
- )
4851
+ text: JSON.stringify({
4852
+ message: "Successfully updated log export",
4853
+ id: result.id,
4854
+ total: result.total,
4855
+ object: result.object
4856
+ })
5183
4857
  }
5184
4858
  ]
5185
4859
  };
@@ -5259,12 +4933,12 @@ var MCP_INTEGRATIONS_TOOL_SCHEMAS = {
5259
4933
  ).min(1).describe("Array of workspace access updates")
5260
4934
  }
5261
4935
  };
5262
- function isRecord(value) {
4936
+ function isRecord2(value) {
5263
4937
  return typeof value === "object" && value !== null;
5264
4938
  }
5265
4939
  function getCustomHeaderNames(configurations) {
5266
4940
  const customHeaders = configurations?.custom_headers;
5267
- return isRecord(customHeaders) ? Object.keys(customHeaders) : void 0;
4941
+ return isRecord2(customHeaders) ? Object.keys(customHeaders) : void 0;
5268
4942
  }
5269
4943
  function formatMcpIntegration(integration) {
5270
4944
  return {
@@ -5322,15 +4996,11 @@ function registerMcpIntegrationsTools(server, service) {
5322
4996
  content: [
5323
4997
  {
5324
4998
  type: "text",
5325
- text: JSON.stringify(
5326
- {
5327
- total: result.total,
5328
- has_more: result.has_more,
5329
- integrations: result.data.map(formatMcpIntegration)
5330
- },
5331
- null,
5332
- 2
5333
- )
4999
+ text: JSON.stringify({
5000
+ total: result.total,
5001
+ has_more: result.has_more,
5002
+ integrations: result.data.map(formatMcpIntegration)
5003
+ })
5334
5004
  }
5335
5005
  ]
5336
5006
  };
@@ -5361,15 +5031,11 @@ function registerMcpIntegrationsTools(server, service) {
5361
5031
  content: [
5362
5032
  {
5363
5033
  type: "text",
5364
- text: JSON.stringify(
5365
- {
5366
- message: `Successfully created MCP integration "${params.name}"`,
5367
- id: result.id,
5368
- slug: result.slug
5369
- },
5370
- null,
5371
- 2
5372
- )
5034
+ text: JSON.stringify({
5035
+ message: `Successfully created MCP integration "${params.name}"`,
5036
+ id: result.id,
5037
+ slug: result.slug
5038
+ })
5373
5039
  }
5374
5040
  ]
5375
5041
  };
@@ -5387,7 +5053,7 @@ function registerMcpIntegrationsTools(server, service) {
5387
5053
  content: [
5388
5054
  {
5389
5055
  type: "text",
5390
- text: JSON.stringify(formatMcpIntegration(integration), null, 2)
5056
+ text: JSON.stringify(formatMcpIntegration(integration))
5391
5057
  }
5392
5058
  ]
5393
5059
  };
@@ -5407,14 +5073,10 @@ function registerMcpIntegrationsTools(server, service) {
5407
5073
  content: [
5408
5074
  {
5409
5075
  type: "text",
5410
- text: JSON.stringify(
5411
- {
5412
- message: `Successfully updated MCP integration "${id}"`,
5413
- success: true
5414
- },
5415
- null,
5416
- 2
5417
- )
5076
+ text: JSON.stringify({
5077
+ message: `Successfully updated MCP integration "${id}"`,
5078
+ success: true
5079
+ })
5418
5080
  }
5419
5081
  ]
5420
5082
  };
@@ -5430,14 +5092,10 @@ function registerMcpIntegrationsTools(server, service) {
5430
5092
  content: [
5431
5093
  {
5432
5094
  type: "text",
5433
- text: JSON.stringify(
5434
- {
5435
- message: `Successfully deleted MCP integration "${params.id}"`,
5436
- success: true
5437
- },
5438
- null,
5439
- 2
5440
- )
5095
+ text: JSON.stringify({
5096
+ message: `Successfully deleted MCP integration "${params.id}"`,
5097
+ success: true
5098
+ })
5441
5099
  }
5442
5100
  ]
5443
5101
  };
@@ -5455,11 +5113,7 @@ function registerMcpIntegrationsTools(server, service) {
5455
5113
  content: [
5456
5114
  {
5457
5115
  type: "text",
5458
- text: JSON.stringify(
5459
- formatMcpIntegrationMetadata(metadata),
5460
- null,
5461
- 2
5462
- )
5116
+ text: JSON.stringify(formatMcpIntegrationMetadata(metadata))
5463
5117
  }
5464
5118
  ]
5465
5119
  };
@@ -5475,11 +5129,10 @@ function registerMcpIntegrationsTools(server, service) {
5475
5129
  content: [
5476
5130
  {
5477
5131
  type: "text",
5478
- text: JSON.stringify(
5479
- { total: result.total, capabilities: result.data },
5480
- null,
5481
- 2
5482
- )
5132
+ text: JSON.stringify({
5133
+ total: result.total,
5134
+ capabilities: result.data
5135
+ })
5483
5136
  }
5484
5137
  ]
5485
5138
  };
@@ -5500,14 +5153,10 @@ function registerMcpIntegrationsTools(server, service) {
5500
5153
  content: [
5501
5154
  {
5502
5155
  type: "text",
5503
- text: JSON.stringify(
5504
- {
5505
- message: `Successfully updated capabilities for MCP integration "${params.id}"`,
5506
- success: true
5507
- },
5508
- null,
5509
- 2
5510
- )
5156
+ text: JSON.stringify({
5157
+ message: `Successfully updated capabilities for MCP integration "${params.id}"`,
5158
+ success: true
5159
+ })
5511
5160
  }
5512
5161
  ]
5513
5162
  };
@@ -5525,17 +5174,11 @@ function registerMcpIntegrationsTools(server, service) {
5525
5174
  content: [
5526
5175
  {
5527
5176
  type: "text",
5528
- text: JSON.stringify(
5529
- {
5530
- global_workspace_access: result.global_workspace_access,
5531
- workspace_count: result.workspaces.length,
5532
- workspaces: result.workspaces.map(
5533
- formatMcpIntegrationWorkspace
5534
- )
5535
- },
5536
- null,
5537
- 2
5538
- )
5177
+ text: JSON.stringify({
5178
+ global_workspace_access: result.global_workspace_access,
5179
+ workspace_count: result.workspaces.length,
5180
+ workspaces: result.workspaces.map(formatMcpIntegrationWorkspace)
5181
+ })
5539
5182
  }
5540
5183
  ]
5541
5184
  };
@@ -5553,14 +5196,10 @@ function registerMcpIntegrationsTools(server, service) {
5553
5196
  content: [
5554
5197
  {
5555
5198
  type: "text",
5556
- text: JSON.stringify(
5557
- {
5558
- message: `Successfully updated workspace access for MCP integration "${params.id}"`,
5559
- success: true
5560
- },
5561
- null,
5562
- 2
5563
- )
5199
+ text: JSON.stringify({
5200
+ message: `Successfully updated workspace access for MCP integration "${params.id}"`,
5201
+ success: true
5202
+ })
5564
5203
  }
5565
5204
  ]
5566
5205
  };
@@ -5570,6 +5209,13 @@ function registerMcpIntegrationsTools(server, service) {
5570
5209
 
5571
5210
  // src/tools/mcp-servers.tools.ts
5572
5211
  import { z as z12 } from "zod";
5212
+
5213
+ // src/tools/utils.ts
5214
+ function formatFullName(firstName, lastName) {
5215
+ return [firstName, lastName].filter(Boolean).join(" ").trim();
5216
+ }
5217
+
5218
+ // src/tools/mcp-servers.tools.ts
5573
5219
  var MCP_SERVERS_TOOL_SCHEMAS = {
5574
5220
  listMcpServers: {
5575
5221
  current_page: z12.coerce.number().positive().optional().describe("Page number for pagination"),
@@ -5597,7 +5243,9 @@ var MCP_SERVERS_TOOL_SCHEMAS = {
5597
5243
  id: z12.string().describe("The MCP server ID or slug to test")
5598
5244
  },
5599
5245
  listMcpServerCapabilities: {
5600
- id: z12.string().describe("The MCP server ID or slug")
5246
+ id: z12.string().describe("The MCP server ID or slug"),
5247
+ current_page: z12.coerce.number().positive().optional().describe("Page number for pagination"),
5248
+ page_size: z12.coerce.number().positive().max(100).optional().describe("Number of results per page (max 100)")
5601
5249
  },
5602
5250
  updateMcpServerCapabilities: {
5603
5251
  id: z12.string().describe("The MCP server ID or slug"),
@@ -5610,7 +5258,9 @@ var MCP_SERVERS_TOOL_SCHEMAS = {
5610
5258
  ).min(1).describe("Array of capability updates")
5611
5259
  },
5612
5260
  listMcpServerUserAccess: {
5613
- id: z12.string().describe("The MCP server ID or slug")
5261
+ id: z12.string().describe("The MCP server ID or slug"),
5262
+ current_page: z12.coerce.number().positive().optional().describe("Page number for pagination"),
5263
+ page_size: z12.coerce.number().positive().max(100).optional().describe("Number of results per page (max 100)")
5614
5264
  },
5615
5265
  updateMcpServerUserAccess: {
5616
5266
  id: z12.string().describe("The MCP server ID or slug"),
@@ -5621,10 +5271,7 @@ var MCP_SERVERS_TOOL_SCHEMAS = {
5621
5271
  })
5622
5272
  ).min(1).describe("Array of user access updates")
5623
5273
  }
5624
- };
5625
- function formatFullName(firstName, lastName) {
5626
- return [firstName, lastName].filter(Boolean).join(" ").trim();
5627
- }
5274
+ };
5628
5275
  function formatMcpServer(server) {
5629
5276
  return {
5630
5277
  id: server.id,
@@ -5666,14 +5313,10 @@ function registerMcpServersTools(server, service) {
5666
5313
  content: [
5667
5314
  {
5668
5315
  type: "text",
5669
- text: JSON.stringify(
5670
- {
5671
- total: result.total,
5672
- servers: result.data.map(formatMcpServer)
5673
- },
5674
- null,
5675
- 2
5676
- )
5316
+ text: JSON.stringify({
5317
+ total: result.total,
5318
+ servers: result.data.map(formatMcpServer)
5319
+ })
5677
5320
  }
5678
5321
  ]
5679
5322
  };
@@ -5689,15 +5332,11 @@ function registerMcpServersTools(server, service) {
5689
5332
  content: [
5690
5333
  {
5691
5334
  type: "text",
5692
- text: JSON.stringify(
5693
- {
5694
- message: `Successfully created MCP server "${params.name}"`,
5695
- id: result.id,
5696
- slug: result.slug
5697
- },
5698
- null,
5699
- 2
5700
- )
5335
+ text: JSON.stringify({
5336
+ message: `Successfully created MCP server "${params.name}"`,
5337
+ id: result.id,
5338
+ slug: result.slug
5339
+ })
5701
5340
  }
5702
5341
  ]
5703
5342
  };
@@ -5713,7 +5352,7 @@ function registerMcpServersTools(server, service) {
5713
5352
  content: [
5714
5353
  {
5715
5354
  type: "text",
5716
- text: JSON.stringify(formatMcpServer(mcpServer), null, 2)
5355
+ text: JSON.stringify(formatMcpServer(mcpServer))
5717
5356
  }
5718
5357
  ]
5719
5358
  };
@@ -5730,14 +5369,10 @@ function registerMcpServersTools(server, service) {
5730
5369
  content: [
5731
5370
  {
5732
5371
  type: "text",
5733
- text: JSON.stringify(
5734
- {
5735
- message: `Successfully updated MCP server "${id}"`,
5736
- success: true
5737
- },
5738
- null,
5739
- 2
5740
- )
5372
+ text: JSON.stringify({
5373
+ message: `Successfully updated MCP server "${id}"`,
5374
+ success: true
5375
+ })
5741
5376
  }
5742
5377
  ]
5743
5378
  };
@@ -5753,14 +5388,10 @@ function registerMcpServersTools(server, service) {
5753
5388
  content: [
5754
5389
  {
5755
5390
  type: "text",
5756
- text: JSON.stringify(
5757
- {
5758
- message: `Successfully deleted MCP server "${params.id}"`,
5759
- success: true
5760
- },
5761
- null,
5762
- 2
5763
- )
5391
+ text: JSON.stringify({
5392
+ message: `Successfully deleted MCP server "${params.id}"`,
5393
+ success: true
5394
+ })
5764
5395
  }
5765
5396
  ]
5766
5397
  };
@@ -5776,7 +5407,7 @@ function registerMcpServersTools(server, service) {
5776
5407
  content: [
5777
5408
  {
5778
5409
  type: "text",
5779
- text: JSON.stringify(formatMcpServerTest(result), null, 2)
5410
+ text: JSON.stringify(formatMcpServerTest(result))
5780
5411
  }
5781
5412
  ]
5782
5413
  };
@@ -5788,17 +5419,21 @@ function registerMcpServersTools(server, service) {
5788
5419
  MCP_SERVERS_TOOL_SCHEMAS.listMcpServerCapabilities,
5789
5420
  async (params) => {
5790
5421
  const result = await service.mcpServers.listMcpServerCapabilities(
5791
- params.id
5422
+ params.id,
5423
+ {
5424
+ current_page: params.current_page,
5425
+ page_size: params.page_size
5426
+ }
5792
5427
  );
5793
5428
  return {
5794
5429
  content: [
5795
5430
  {
5796
5431
  type: "text",
5797
- text: JSON.stringify(
5798
- { total: result.total, capabilities: result.data },
5799
- null,
5800
- 2
5801
- )
5432
+ text: JSON.stringify({
5433
+ total: result.total,
5434
+ has_more: result.has_more,
5435
+ capabilities: result.data
5436
+ })
5802
5437
  }
5803
5438
  ]
5804
5439
  };
@@ -5816,14 +5451,10 @@ function registerMcpServersTools(server, service) {
5816
5451
  content: [
5817
5452
  {
5818
5453
  type: "text",
5819
- text: JSON.stringify(
5820
- {
5821
- message: `Successfully updated capabilities for MCP server "${params.id}"`,
5822
- success: true
5823
- },
5824
- null,
5825
- 2
5826
- )
5454
+ text: JSON.stringify({
5455
+ message: `Successfully updated capabilities for MCP server "${params.id}"`,
5456
+ success: true
5457
+ })
5827
5458
  }
5828
5459
  ]
5829
5460
  };
@@ -5835,21 +5466,22 @@ function registerMcpServersTools(server, service) {
5835
5466
  MCP_SERVERS_TOOL_SCHEMAS.listMcpServerUserAccess,
5836
5467
  async (params) => {
5837
5468
  const result = await service.mcpServers.listMcpServerUserAccess(
5838
- params.id
5469
+ params.id,
5470
+ {
5471
+ current_page: params.current_page,
5472
+ page_size: params.page_size
5473
+ }
5839
5474
  );
5840
5475
  return {
5841
5476
  content: [
5842
5477
  {
5843
5478
  type: "text",
5844
- text: JSON.stringify(
5845
- {
5846
- default_user_access: result.default_user_access,
5847
- total: result.total,
5848
- users: result.data.map(formatMcpServerUserAccess)
5849
- },
5850
- null,
5851
- 2
5852
- )
5479
+ text: JSON.stringify({
5480
+ default_user_access: result.default_user_access,
5481
+ total: result.total,
5482
+ has_more: result.has_more,
5483
+ users: result.data.map(formatMcpServerUserAccess)
5484
+ })
5853
5485
  }
5854
5486
  ]
5855
5487
  };
@@ -5867,14 +5499,10 @@ function registerMcpServersTools(server, service) {
5867
5499
  content: [
5868
5500
  {
5869
5501
  type: "text",
5870
- text: JSON.stringify(
5871
- {
5872
- message: `Successfully updated user access for MCP server "${params.id}"`,
5873
- success: true
5874
- },
5875
- null,
5876
- 2
5877
- )
5502
+ text: JSON.stringify({
5503
+ message: `Successfully updated user access for MCP server "${params.id}"`,
5504
+ success: true
5505
+ })
5878
5506
  }
5879
5507
  ]
5880
5508
  };
@@ -5935,16 +5563,12 @@ function registerPartialsTools(server, service) {
5935
5563
  content: [
5936
5564
  {
5937
5565
  type: "text",
5938
- text: JSON.stringify(
5939
- {
5940
- message: `Successfully created prompt partial "${params.name}"`,
5941
- id: result.id,
5942
- slug: result.slug,
5943
- version_id: result.version_id
5944
- },
5945
- null,
5946
- 2
5947
- )
5566
+ text: JSON.stringify({
5567
+ message: `Successfully created prompt partial "${params.name}"`,
5568
+ id: result.id,
5569
+ slug: result.slug,
5570
+ version_id: result.version_id
5571
+ })
5948
5572
  }
5949
5573
  ]
5950
5574
  };
@@ -5960,22 +5584,18 @@ function registerPartialsTools(server, service) {
5960
5584
  content: [
5961
5585
  {
5962
5586
  type: "text",
5963
- text: JSON.stringify(
5964
- {
5965
- total: partials.length,
5966
- partials: partials.map((p) => ({
5967
- id: p.id,
5968
- slug: p.slug,
5969
- name: p.name,
5970
- collection_id: p.collection_id,
5971
- status: p.status,
5972
- created_at: p.created_at,
5973
- last_updated_at: p.last_updated_at
5974
- }))
5975
- },
5976
- null,
5977
- 2
5978
- )
5587
+ text: JSON.stringify({
5588
+ total: partials.length,
5589
+ partials: partials.map((p) => ({
5590
+ id: p.id,
5591
+ slug: p.slug,
5592
+ name: p.name,
5593
+ collection_id: p.collection_id,
5594
+ status: p.status,
5595
+ created_at: p.created_at,
5596
+ last_updated_at: p.last_updated_at
5597
+ }))
5598
+ })
5979
5599
  }
5980
5600
  ]
5981
5601
  };
@@ -5993,23 +5613,19 @@ function registerPartialsTools(server, service) {
5993
5613
  content: [
5994
5614
  {
5995
5615
  type: "text",
5996
- text: JSON.stringify(
5997
- {
5998
- id: partial.id,
5999
- slug: partial.slug,
6000
- name: partial.name,
6001
- collection_id: partial.collection_id,
6002
- string: partial.string,
6003
- version: partial.version,
6004
- version_description: partial.version_description,
6005
- prompt_partial_version_id: partial.prompt_partial_version_id,
6006
- status: partial.status,
6007
- created_at: partial.created_at,
6008
- last_updated_at: partial.last_updated_at
6009
- },
6010
- null,
6011
- 2
6012
- )
5616
+ text: JSON.stringify({
5617
+ id: partial.id,
5618
+ slug: partial.slug,
5619
+ name: partial.name,
5620
+ collection_id: partial.collection_id,
5621
+ string: partial.string,
5622
+ version: partial.version,
5623
+ version_description: partial.version_description,
5624
+ prompt_partial_version_id: partial.prompt_partial_version_id,
5625
+ status: partial.status,
5626
+ created_at: partial.created_at,
5627
+ last_updated_at: partial.last_updated_at
5628
+ })
6013
5629
  }
6014
5630
  ]
6015
5631
  };
@@ -6029,14 +5645,10 @@ function registerPartialsTools(server, service) {
6029
5645
  content: [
6030
5646
  {
6031
5647
  type: "text",
6032
- text: JSON.stringify(
6033
- {
6034
- message: `Successfully updated prompt partial "${prompt_partial_id}"`,
6035
- prompt_partial_version_id: result.prompt_partial_version_id
6036
- },
6037
- null,
6038
- 2
6039
- )
5648
+ text: JSON.stringify({
5649
+ message: `Successfully updated prompt partial "${prompt_partial_id}"`,
5650
+ prompt_partial_version_id: result.prompt_partial_version_id
5651
+ })
6040
5652
  }
6041
5653
  ]
6042
5654
  };
@@ -6052,14 +5664,10 @@ function registerPartialsTools(server, service) {
6052
5664
  content: [
6053
5665
  {
6054
5666
  type: "text",
6055
- text: JSON.stringify(
6056
- {
6057
- message: `Successfully deleted prompt partial "${params.prompt_partial_id}"`,
6058
- success: true
6059
- },
6060
- null,
6061
- 2
6062
- )
5667
+ text: JSON.stringify({
5668
+ message: `Successfully deleted prompt partial "${params.prompt_partial_id}"`,
5669
+ success: true
5670
+ })
6063
5671
  }
6064
5672
  ]
6065
5673
  };
@@ -6077,24 +5685,20 @@ function registerPartialsTools(server, service) {
6077
5685
  content: [
6078
5686
  {
6079
5687
  type: "text",
6080
- text: JSON.stringify(
6081
- {
6082
- prompt_partial_id: params.prompt_partial_id,
6083
- total_versions: versions.length,
6084
- versions: versions.map((v) => ({
6085
- prompt_partial_id: v.prompt_partial_id,
6086
- prompt_partial_version_id: v.prompt_partial_version_id,
6087
- slug: v.slug,
6088
- version: v.version,
6089
- description: v.description,
6090
- status: v.prompt_version_status,
6091
- created_at: v.created_at,
6092
- content_preview: v.string.length > 200 ? `${v.string.substring(0, 200)}...` : v.string
6093
- }))
6094
- },
6095
- null,
6096
- 2
6097
- )
5688
+ text: JSON.stringify({
5689
+ prompt_partial_id: params.prompt_partial_id,
5690
+ total_versions: versions.length,
5691
+ versions: versions.map((v) => ({
5692
+ prompt_partial_id: v.prompt_partial_id,
5693
+ prompt_partial_version_id: v.prompt_partial_version_id,
5694
+ slug: v.slug,
5695
+ version: v.version,
5696
+ description: v.description,
5697
+ status: v.prompt_version_status,
5698
+ created_at: v.created_at,
5699
+ content_preview: v.string.length > 200 ? `${v.string.substring(0, 200)}...` : v.string
5700
+ }))
5701
+ })
6098
5702
  }
6099
5703
  ]
6100
5704
  };
@@ -6112,16 +5716,12 @@ function registerPartialsTools(server, service) {
6112
5716
  content: [
6113
5717
  {
6114
5718
  type: "text",
6115
- text: JSON.stringify(
6116
- {
6117
- message: `Successfully published version ${params.version} as default for partial "${params.prompt_partial_id}"`,
6118
- prompt_partial_id: params.prompt_partial_id,
6119
- published_version: params.version,
6120
- success: true
6121
- },
6122
- null,
6123
- 2
6124
- )
5719
+ text: JSON.stringify({
5720
+ message: `Successfully published version ${params.version} as default for partial "${params.prompt_partial_id}"`,
5721
+ prompt_partial_id: params.prompt_partial_id,
5722
+ published_version: params.version,
5723
+ success: true
5724
+ })
6125
5725
  }
6126
5726
  ]
6127
5727
  };
@@ -6497,16 +6097,12 @@ function registerPromptsTools(server, service) {
6497
6097
  content: [
6498
6098
  {
6499
6099
  type: "text",
6500
- text: JSON.stringify(
6501
- {
6502
- message: `Successfully created prompt "${params.name}"`,
6503
- id: result.id,
6504
- slug: result.slug,
6505
- version_id: result.version_id
6506
- },
6507
- null,
6508
- 2
6509
- )
6100
+ text: JSON.stringify({
6101
+ message: `Successfully created prompt "${params.name}"`,
6102
+ id: result.id,
6103
+ slug: result.slug,
6104
+ version_id: result.version_id
6105
+ })
6510
6106
  }
6511
6107
  ]
6512
6108
  };
@@ -6522,11 +6118,7 @@ function registerPromptsTools(server, service) {
6522
6118
  content: [
6523
6119
  {
6524
6120
  type: "text",
6525
- text: JSON.stringify(
6526
- formatPromptListResponse(prompts, params),
6527
- null,
6528
- 2
6529
- )
6121
+ text: JSON.stringify(formatPromptListResponse(prompts, params))
6530
6122
  }
6531
6123
  ]
6532
6124
  };
@@ -6558,37 +6150,33 @@ function registerPromptsTools(server, service) {
6558
6150
  content: [
6559
6151
  {
6560
6152
  type: "text",
6561
- text: JSON.stringify(
6562
- {
6563
- id: prompt.id,
6564
- name: prompt.name,
6565
- slug: prompt.slug,
6566
- collection_id: prompt.collection_id,
6567
- created_at: prompt.created_at,
6568
- last_updated_at: prompt.last_updated_at,
6569
- current_version: prompt.current_version ? {
6570
- id: prompt.current_version.id,
6571
- version_number: prompt.current_version.version_number,
6572
- description: prompt.current_version.version_description,
6573
- model: prompt.current_version.model,
6574
- template_format: templateFormat,
6575
- template: templateString,
6576
- parameters: prompt.current_version.parameters,
6577
- metadata: prompt.current_version.template_metadata,
6578
- has_tools: !!prompt.current_version.tools?.length,
6579
- has_functions: !!prompt.current_version.functions?.length
6580
- } : null,
6581
- version_count: (prompt.versions || []).length,
6582
- versions: (prompt.versions || []).map((v) => ({
6583
- id: v.id,
6584
- version_number: v.version_number,
6585
- description: v.version_description,
6586
- created_at: v.created_at
6587
- }))
6588
- },
6589
- null,
6590
- 2
6591
- )
6153
+ text: JSON.stringify({
6154
+ id: prompt.id,
6155
+ name: prompt.name,
6156
+ slug: prompt.slug,
6157
+ collection_id: prompt.collection_id,
6158
+ created_at: prompt.created_at,
6159
+ last_updated_at: prompt.last_updated_at,
6160
+ current_version: prompt.current_version ? {
6161
+ id: prompt.current_version.id,
6162
+ version_number: prompt.current_version.version_number,
6163
+ description: prompt.current_version.version_description,
6164
+ model: prompt.current_version.model,
6165
+ template_format: templateFormat,
6166
+ template: templateString,
6167
+ parameters: prompt.current_version.parameters,
6168
+ metadata: prompt.current_version.template_metadata,
6169
+ has_tools: !!prompt.current_version.tools?.length,
6170
+ has_functions: !!prompt.current_version.functions?.length
6171
+ } : null,
6172
+ version_count: (prompt.versions || []).length,
6173
+ versions: (prompt.versions || []).map((v) => ({
6174
+ id: v.id,
6175
+ version_number: v.version_number,
6176
+ description: v.version_description,
6177
+ created_at: v.created_at
6178
+ }))
6179
+ })
6592
6180
  }
6593
6181
  ]
6594
6182
  };
@@ -6644,16 +6232,12 @@ function registerPromptsTools(server, service) {
6644
6232
  content: [
6645
6233
  {
6646
6234
  type: "text",
6647
- text: JSON.stringify(
6648
- {
6649
- message: "Successfully updated prompt",
6650
- id: result.id,
6651
- slug: result.slug,
6652
- new_version_id: result.prompt_version_id
6653
- },
6654
- null,
6655
- 2
6656
- )
6235
+ text: JSON.stringify({
6236
+ message: "Successfully updated prompt",
6237
+ id: result.id,
6238
+ slug: result.slug,
6239
+ new_version_id: result.prompt_version_id
6240
+ })
6657
6241
  }
6658
6242
  ]
6659
6243
  };
@@ -6669,14 +6253,10 @@ function registerPromptsTools(server, service) {
6669
6253
  content: [
6670
6254
  {
6671
6255
  type: "text",
6672
- text: JSON.stringify(
6673
- {
6674
- message: `Successfully deleted prompt "${params.prompt_id}"`,
6675
- success: true
6676
- },
6677
- null,
6678
- 2
6679
- )
6256
+ text: JSON.stringify({
6257
+ message: `Successfully deleted prompt "${params.prompt_id}"`,
6258
+ success: true
6259
+ })
6680
6260
  }
6681
6261
  ]
6682
6262
  };
@@ -6694,16 +6274,12 @@ function registerPromptsTools(server, service) {
6694
6274
  content: [
6695
6275
  {
6696
6276
  type: "text",
6697
- text: JSON.stringify(
6698
- {
6699
- message: `Successfully published version ${params.version} of prompt "${params.prompt_id}"`,
6700
- prompt_id: params.prompt_id,
6701
- published_version: params.version,
6702
- success: true
6703
- },
6704
- null,
6705
- 2
6706
- )
6277
+ text: JSON.stringify({
6278
+ message: `Successfully published version ${params.version} of prompt "${params.prompt_id}"`,
6279
+ prompt_id: params.prompt_id,
6280
+ published_version: params.version,
6281
+ success: true
6282
+ })
6707
6283
  }
6708
6284
  ]
6709
6285
  };
@@ -6721,27 +6297,23 @@ function registerPromptsTools(server, service) {
6721
6297
  content: [
6722
6298
  {
6723
6299
  type: "text",
6724
- text: JSON.stringify(
6725
- {
6726
- prompt_id: params.prompt_id,
6727
- total_versions: versions.length,
6728
- versions: versions.map((v) => ({
6729
- id: v.id,
6730
- version_number: v.prompt_version,
6731
- description: v.prompt_description,
6732
- status: v.status,
6733
- label_id: v.label_id,
6734
- created_at: v.created_at,
6735
- template_preview: (() => {
6736
- const tmpl = v.prompt_template;
6737
- const str = typeof tmpl === "string" ? tmpl : typeof tmpl === "object" && tmpl !== null && "string" in tmpl ? tmpl.string : JSON.stringify(tmpl);
6738
- return str.substring(0, 200) + (str.length > 200 ? "..." : "");
6739
- })()
6740
- }))
6741
- },
6742
- null,
6743
- 2
6744
- )
6300
+ text: JSON.stringify({
6301
+ prompt_id: params.prompt_id,
6302
+ total_versions: versions.length,
6303
+ versions: versions.map((v) => ({
6304
+ id: v.id,
6305
+ version_number: v.prompt_version,
6306
+ description: v.prompt_description,
6307
+ status: v.status,
6308
+ label_id: v.label_id,
6309
+ created_at: v.created_at,
6310
+ template_preview: (() => {
6311
+ const tmpl = v.prompt_template;
6312
+ const str = typeof tmpl === "string" ? tmpl : typeof tmpl === "object" && tmpl !== null && "string" in tmpl ? tmpl.string : JSON.stringify(tmpl);
6313
+ return str.substring(0, 200) + (str.length > 200 ? "..." : "");
6314
+ })()
6315
+ }))
6316
+ })
6745
6317
  }
6746
6318
  ]
6747
6319
  };
@@ -6760,20 +6332,16 @@ function registerPromptsTools(server, service) {
6760
6332
  content: [
6761
6333
  {
6762
6334
  type: "text",
6763
- text: JSON.stringify(
6764
- {
6765
- success: result.success,
6766
- rendered_messages: result.data.messages,
6767
- model: result.data.model,
6768
- hyperparameters: {
6769
- max_tokens: result.data.max_tokens,
6770
- temperature: result.data.temperature,
6771
- top_p: result.data.top_p
6772
- }
6773
- },
6774
- null,
6775
- 2
6776
- )
6335
+ text: JSON.stringify({
6336
+ success: result.success,
6337
+ rendered_messages: result.data.messages,
6338
+ model: result.data.model,
6339
+ hyperparameters: {
6340
+ max_tokens: result.data.max_tokens,
6341
+ temperature: result.data.temperature,
6342
+ top_p: result.data.top_p
6343
+ }
6344
+ })
6777
6345
  }
6778
6346
  ]
6779
6347
  };
@@ -6798,21 +6366,17 @@ function registerPromptsTools(server, service) {
6798
6366
  content: [
6799
6367
  {
6800
6368
  type: "text",
6801
- text: JSON.stringify(
6802
- {
6803
- id: result.id,
6804
- model: result.model,
6805
- response: choice?.message?.content ?? null,
6806
- finish_reason: choice?.finish_reason ?? null,
6807
- usage: result.usage ? {
6808
- prompt_tokens: result.usage.prompt_tokens,
6809
- completion_tokens: result.usage.completion_tokens,
6810
- total_tokens: result.usage.total_tokens
6811
- } : null
6812
- },
6813
- null,
6814
- 2
6815
- )
6369
+ text: JSON.stringify({
6370
+ id: result.id,
6371
+ model: result.model,
6372
+ response: choice?.message?.content ?? null,
6373
+ finish_reason: choice?.finish_reason ?? null,
6374
+ usage: result.usage ? {
6375
+ prompt_tokens: result.usage.prompt_tokens,
6376
+ completion_tokens: result.usage.completion_tokens,
6377
+ total_tokens: result.usage.total_tokens
6378
+ } : null
6379
+ })
6816
6380
  }
6817
6381
  ]
6818
6382
  };
@@ -6855,18 +6419,14 @@ function registerPromptsTools(server, service) {
6855
6419
  content: [
6856
6420
  {
6857
6421
  type: "text",
6858
- text: JSON.stringify(
6859
- {
6860
- action: result.action,
6861
- dry_run: result.dry_run,
6862
- message: result.message,
6863
- prompt_id: result.prompt_id ?? void 0,
6864
- slug: result.slug ?? void 0,
6865
- version_id: result.version_id ?? void 0
6866
- },
6867
- null,
6868
- 2
6869
- )
6422
+ text: JSON.stringify({
6423
+ action: result.action,
6424
+ dry_run: result.dry_run,
6425
+ message: result.message,
6426
+ prompt_id: result.prompt_id ?? void 0,
6427
+ slug: result.slug ?? void 0,
6428
+ version_id: result.version_id ?? void 0
6429
+ })
6870
6430
  }
6871
6431
  ]
6872
6432
  };
@@ -6888,23 +6448,19 @@ function registerPromptsTools(server, service) {
6888
6448
  content: [
6889
6449
  {
6890
6450
  type: "text",
6891
- text: JSON.stringify(
6892
- {
6893
- message: `Successfully promoted prompt to ${params.target_env}`,
6894
- source: {
6895
- prompt_id: result.source_prompt_id,
6896
- version_id: result.source_version_id
6897
- },
6898
- target: {
6899
- prompt_id: result.target_prompt_id,
6900
- version_id: result.target_version_id,
6901
- action: result.action
6902
- },
6903
- promoted_at: result.promoted_at
6451
+ text: JSON.stringify({
6452
+ message: `Successfully promoted prompt to ${params.target_env}`,
6453
+ source: {
6454
+ prompt_id: result.source_prompt_id,
6455
+ version_id: result.source_version_id
6904
6456
  },
6905
- null,
6906
- 2
6907
- )
6457
+ target: {
6458
+ prompt_id: result.target_prompt_id,
6459
+ version_id: result.target_version_id,
6460
+ action: result.action
6461
+ },
6462
+ promoted_at: result.promoted_at
6463
+ })
6908
6464
  }
6909
6465
  ]
6910
6466
  };
@@ -6920,16 +6476,12 @@ function registerPromptsTools(server, service) {
6920
6476
  content: [
6921
6477
  {
6922
6478
  type: "text",
6923
- text: JSON.stringify(
6924
- {
6925
- valid: result.valid,
6926
- errors: result.errors,
6927
- warnings: result.warnings,
6928
- metadata: params
6929
- },
6930
- null,
6931
- 2
6932
- )
6479
+ text: JSON.stringify({
6480
+ valid: result.valid,
6481
+ errors: result.errors,
6482
+ warnings: result.warnings,
6483
+ metadata: params
6484
+ })
6933
6485
  }
6934
6486
  ]
6935
6487
  };
@@ -6948,7 +6500,7 @@ function registerPromptsTools(server, service) {
6948
6500
  content: [
6949
6501
  {
6950
6502
  type: "text",
6951
- text: JSON.stringify(formatPromptVersion(version), null, 2)
6503
+ text: JSON.stringify(formatPromptVersion(version))
6952
6504
  }
6953
6505
  ]
6954
6506
  };
@@ -6959,17 +6511,6 @@ function registerPromptsTools(server, service) {
6959
6511
  "Update a specific prompt version's label assignment. This only assigns or removes a label, and null clears the label after you look up ids with list_prompt_labels.",
6960
6512
  PROMPTS_TOOL_SCHEMAS.updatePromptVersion,
6961
6513
  async (params) => {
6962
- if (params.label_id === void 0) {
6963
- return {
6964
- content: [
6965
- {
6966
- type: "text",
6967
- text: "Error: label_id is required \u2014 pass a label ID to assign, or null to remove the label"
6968
- }
6969
- ],
6970
- isError: true
6971
- };
6972
- }
6973
6514
  await service.prompts.updatePromptVersion(
6974
6515
  params.prompt_id,
6975
6516
  params.version_id,
@@ -6981,14 +6522,10 @@ function registerPromptsTools(server, service) {
6981
6522
  content: [
6982
6523
  {
6983
6524
  type: "text",
6984
- text: JSON.stringify(
6985
- {
6986
- message: `Successfully updated version "${params.version_id}" of prompt "${params.prompt_id}"`,
6987
- success: true
6988
- },
6989
- null,
6990
- 2
6991
- )
6525
+ text: JSON.stringify({
6526
+ message: `Successfully updated version "${params.version_id}" of prompt "${params.prompt_id}"`,
6527
+ success: true
6528
+ })
6992
6529
  }
6993
6530
  ]
6994
6531
  };
@@ -7076,33 +6613,29 @@ function registerProvidersTools(server, service) {
7076
6613
  content: [
7077
6614
  {
7078
6615
  type: "text",
7079
- text: JSON.stringify(
7080
- {
7081
- total: providers.total,
7082
- providers: providers.data.map((provider) => ({
7083
- name: provider.name,
7084
- slug: provider.slug,
7085
- integration_id: provider.integration_id,
7086
- status: provider.status,
7087
- note: provider.note,
7088
- usage_limits: provider.usage_limits ? {
7089
- credit_limit: provider.usage_limits.credit_limit,
7090
- alert_threshold: provider.usage_limits.alert_threshold,
7091
- periodic_reset: provider.usage_limits.periodic_reset
7092
- } : null,
7093
- rate_limits: provider.rate_limits?.map((limit) => ({
7094
- type: limit.type,
7095
- unit: limit.unit,
7096
- value: limit.value
7097
- })) ?? null,
7098
- reset_usage: provider.reset_usage,
7099
- expires_at: provider.expires_at,
7100
- created_at: provider.created_at
7101
- }))
7102
- },
7103
- null,
7104
- 2
7105
- )
6616
+ text: JSON.stringify({
6617
+ total: providers.total,
6618
+ providers: providers.data.map((provider) => ({
6619
+ name: provider.name,
6620
+ slug: provider.slug,
6621
+ integration_id: provider.integration_id,
6622
+ status: provider.status,
6623
+ note: provider.note,
6624
+ usage_limits: provider.usage_limits ? {
6625
+ credit_limit: provider.usage_limits.credit_limit,
6626
+ alert_threshold: provider.usage_limits.alert_threshold,
6627
+ periodic_reset: provider.usage_limits.periodic_reset
6628
+ } : null,
6629
+ rate_limits: provider.rate_limits?.map((limit) => ({
6630
+ type: limit.type,
6631
+ unit: limit.unit,
6632
+ value: limit.value
6633
+ })) ?? null,
6634
+ reset_usage: provider.reset_usage,
6635
+ expires_at: provider.expires_at,
6636
+ created_at: provider.created_at
6637
+ }))
6638
+ })
7106
6639
  }
7107
6640
  ]
7108
6641
  };
@@ -7135,15 +6668,11 @@ function registerProvidersTools(server, service) {
7135
6668
  content: [
7136
6669
  {
7137
6670
  type: "text",
7138
- text: JSON.stringify(
7139
- {
7140
- message: `Successfully created provider "${params.name}"`,
7141
- id: result.id,
7142
- slug: result.slug
7143
- },
7144
- null,
7145
- 2
7146
- )
6671
+ text: JSON.stringify({
6672
+ message: `Successfully created provider "${params.name}"`,
6673
+ id: result.id,
6674
+ slug: result.slug
6675
+ })
7147
6676
  }
7148
6677
  ]
7149
6678
  };
@@ -7162,30 +6691,26 @@ function registerProvidersTools(server, service) {
7162
6691
  content: [
7163
6692
  {
7164
6693
  type: "text",
7165
- text: JSON.stringify(
7166
- {
7167
- name: provider.name,
7168
- slug: provider.slug,
7169
- integration_id: provider.integration_id,
7170
- status: provider.status,
7171
- note: provider.note,
7172
- usage_limits: provider.usage_limits ? {
7173
- credit_limit: provider.usage_limits.credit_limit,
7174
- alert_threshold: provider.usage_limits.alert_threshold,
7175
- periodic_reset: provider.usage_limits.periodic_reset
7176
- } : null,
7177
- rate_limits: provider.rate_limits?.map((limit) => ({
7178
- type: limit.type,
7179
- unit: limit.unit,
7180
- value: limit.value
7181
- })) ?? null,
7182
- reset_usage: provider.reset_usage,
7183
- expires_at: provider.expires_at,
7184
- created_at: provider.created_at
7185
- },
7186
- null,
7187
- 2
7188
- )
6694
+ text: JSON.stringify({
6695
+ name: provider.name,
6696
+ slug: provider.slug,
6697
+ integration_id: provider.integration_id,
6698
+ status: provider.status,
6699
+ note: provider.note,
6700
+ usage_limits: provider.usage_limits ? {
6701
+ credit_limit: provider.usage_limits.credit_limit,
6702
+ alert_threshold: provider.usage_limits.alert_threshold,
6703
+ periodic_reset: provider.usage_limits.periodic_reset
6704
+ } : null,
6705
+ rate_limits: provider.rate_limits?.map((limit) => ({
6706
+ type: limit.type,
6707
+ unit: limit.unit,
6708
+ value: limit.value
6709
+ })) ?? null,
6710
+ reset_usage: provider.reset_usage,
6711
+ expires_at: provider.expires_at,
6712
+ created_at: provider.created_at
6713
+ })
7189
6714
  }
7190
6715
  ]
7191
6716
  };
@@ -7220,15 +6745,11 @@ function registerProvidersTools(server, service) {
7220
6745
  content: [
7221
6746
  {
7222
6747
  type: "text",
7223
- text: JSON.stringify(
7224
- {
7225
- message: `Successfully updated provider "${params.slug}"`,
7226
- id: result.id,
7227
- slug: result.slug
7228
- },
7229
- null,
7230
- 2
7231
- )
6748
+ text: JSON.stringify({
6749
+ message: `Successfully updated provider "${params.slug}"`,
6750
+ id: result.id,
6751
+ slug: result.slug
6752
+ })
7232
6753
  }
7233
6754
  ]
7234
6755
  };
@@ -7244,14 +6765,10 @@ function registerProvidersTools(server, service) {
7244
6765
  content: [
7245
6766
  {
7246
6767
  type: "text",
7247
- text: JSON.stringify(
7248
- {
7249
- message: `Successfully deleted provider "${params.slug}"`,
7250
- success: true
7251
- },
7252
- null,
7253
- 2
7254
- )
6768
+ text: JSON.stringify({
6769
+ message: `Successfully deleted provider "${params.slug}"`,
6770
+ success: true
6771
+ })
7255
6772
  }
7256
6773
  ]
7257
6774
  };
@@ -7301,15 +6818,11 @@ function registerTracingTools(server, service) {
7301
6818
  content: [
7302
6819
  {
7303
6820
  type: "text",
7304
- text: JSON.stringify(
7305
- {
7306
- message: `Successfully created feedback for trace "${params.trace_id}"`,
7307
- status: result.status,
7308
- feedback_ids: result.feedback_ids
7309
- },
7310
- null,
7311
- 2
7312
- )
6821
+ text: JSON.stringify({
6822
+ message: `Successfully created feedback for trace "${params.trace_id}"`,
6823
+ status: result.status,
6824
+ feedback_ids: result.feedback_ids
6825
+ })
7313
6826
  }
7314
6827
  ]
7315
6828
  };
@@ -7329,15 +6842,11 @@ function registerTracingTools(server, service) {
7329
6842
  content: [
7330
6843
  {
7331
6844
  type: "text",
7332
- text: JSON.stringify(
7333
- {
7334
- message: `Successfully updated feedback "${params.id}"`,
7335
- status: result.status,
7336
- feedback_ids: result.feedback_ids
7337
- },
7338
- null,
7339
- 2
7340
- )
6845
+ text: JSON.stringify({
6846
+ message: `Successfully updated feedback "${params.id}"`,
6847
+ status: result.status,
6848
+ feedback_ids: result.feedback_ids
6849
+ })
7341
6850
  }
7342
6851
  ]
7343
6852
  };
@@ -7348,7 +6857,10 @@ function registerTracingTools(server, service) {
7348
6857
  // src/tools/users.tools.ts
7349
6858
  import { z as z18 } from "zod";
7350
6859
  var USERS_TOOL_SCHEMAS = {
7351
- listAllUsers: {},
6860
+ listAllUsers: {
6861
+ current_page: z18.coerce.number().positive().optional().describe("Page number for pagination"),
6862
+ page_size: z18.coerce.number().positive().max(100).optional().describe("Number of results per page (max 100)")
6863
+ },
7352
6864
  inviteUser: {
7353
6865
  email: z18.string().email().describe("Email address of the user to invite"),
7354
6866
  role: z18.enum(["admin", "member"]).describe(
@@ -7402,7 +6914,10 @@ var USERS_TOOL_SCHEMAS = {
7402
6914
  deleteUser: {
7403
6915
  user_id: z18.string().describe("The user ID to delete")
7404
6916
  },
7405
- listUserInvites: {},
6917
+ listUserInvites: {
6918
+ current_page: z18.coerce.number().positive().optional().describe("Page number for pagination"),
6919
+ page_size: z18.coerce.number().positive().max(100).optional().describe("Number of results per page (max 100)")
6920
+ },
7406
6921
  getUserInvite: {
7407
6922
  invite_id: z18.string().describe("The invite ID to retrieve")
7408
6923
  },
@@ -7413,13 +6928,10 @@ var USERS_TOOL_SCHEMAS = {
7413
6928
  invite_id: z18.string().describe("The invite ID to resend")
7414
6929
  }
7415
6930
  };
7416
- function formatFullName2(firstName, lastName) {
7417
- return [firstName, lastName].filter(Boolean).join(" ").trim();
7418
- }
7419
6931
  function formatUser(user) {
7420
6932
  return {
7421
6933
  id: user.id,
7422
- name: formatFullName2(user.first_name, user.last_name),
6934
+ name: formatFullName(user.first_name, user.last_name),
7423
6935
  email: user.email,
7424
6936
  role: user.role,
7425
6937
  created_at: user.created_at,
@@ -7448,20 +6960,19 @@ function registerUsersTools(server, service) {
7448
6960
  "list_all_users",
7449
6961
  "List accepted org users with id, name, email, role, and timestamps. Use this to find a user_id before get_user, update_user, delete_user, or add_workspace_member; use list_user_invites for pending invitations.",
7450
6962
  USERS_TOOL_SCHEMAS.listAllUsers,
7451
- async () => {
7452
- const users = await service.users.listUsers();
6963
+ async (params) => {
6964
+ const users = await service.users.listUsers({
6965
+ current_page: params.current_page,
6966
+ page_size: params.page_size
6967
+ });
7453
6968
  return {
7454
6969
  content: [
7455
6970
  {
7456
6971
  type: "text",
7457
- text: JSON.stringify(
7458
- {
7459
- total: users.total,
7460
- users: users.data.map(formatUser)
7461
- },
7462
- null,
7463
- 2
7464
- )
6972
+ text: JSON.stringify({
6973
+ total: users.total,
6974
+ users: users.data.map(formatUser)
6975
+ })
7465
6976
  }
7466
6977
  ]
7467
6978
  };
@@ -7477,15 +6988,11 @@ function registerUsersTools(server, service) {
7477
6988
  content: [
7478
6989
  {
7479
6990
  type: "text",
7480
- text: JSON.stringify(
7481
- {
7482
- message: `Successfully invited ${params.email} as ${params.role}`,
7483
- invite_id: result.id,
7484
- invite_link: result.invite_link
7485
- },
7486
- null,
7487
- 2
7488
- )
6991
+ text: JSON.stringify({
6992
+ message: `Successfully invited ${params.email} as ${params.role}`,
6993
+ invite_id: result.id,
6994
+ invite_link: result.invite_link
6995
+ })
7489
6996
  }
7490
6997
  ]
7491
6998
  };
@@ -7501,14 +7008,10 @@ function registerUsersTools(server, service) {
7501
7008
  content: [
7502
7009
  {
7503
7010
  type: "text",
7504
- text: JSON.stringify(
7505
- {
7506
- total_users: stats.total,
7507
- users: stats.data.map(formatUserAnalyticsGroup)
7508
- },
7509
- null,
7510
- 2
7511
- )
7011
+ text: JSON.stringify({
7012
+ total_users: stats.total,
7013
+ users: stats.data.map(formatUserAnalyticsGroup)
7014
+ })
7512
7015
  }
7513
7016
  ]
7514
7017
  };
@@ -7524,7 +7027,7 @@ function registerUsersTools(server, service) {
7524
7027
  content: [
7525
7028
  {
7526
7029
  type: "text",
7527
- text: JSON.stringify(formatUser(user), null, 2)
7030
+ text: JSON.stringify(formatUser(user))
7528
7031
  }
7529
7032
  ]
7530
7033
  };
@@ -7541,14 +7044,10 @@ function registerUsersTools(server, service) {
7541
7044
  content: [
7542
7045
  {
7543
7046
  type: "text",
7544
- text: JSON.stringify(
7545
- {
7546
- message: "Successfully updated user",
7547
- user: formatUser(user)
7548
- },
7549
- null,
7550
- 2
7551
- )
7047
+ text: JSON.stringify({
7048
+ message: "Successfully updated user",
7049
+ user: formatUser(user)
7050
+ })
7552
7051
  }
7553
7052
  ]
7554
7053
  };
@@ -7564,14 +7063,10 @@ function registerUsersTools(server, service) {
7564
7063
  content: [
7565
7064
  {
7566
7065
  type: "text",
7567
- text: JSON.stringify(
7568
- {
7569
- message: `Successfully deleted user ${params.user_id}`,
7570
- success: true
7571
- },
7572
- null,
7573
- 2
7574
- )
7066
+ text: JSON.stringify({
7067
+ message: `Successfully deleted user ${params.user_id}`,
7068
+ success: true
7069
+ })
7575
7070
  }
7576
7071
  ]
7577
7072
  };
@@ -7581,20 +7076,19 @@ function registerUsersTools(server, service) {
7581
7076
  "list_user_invites",
7582
7077
  "List pending and sent invitations with id, email, role, status, and expiry. Use this to check invite state; use list_all_users for users who already accepted.",
7583
7078
  USERS_TOOL_SCHEMAS.listUserInvites,
7584
- async () => {
7585
- const invites = await service.users.listUserInvites();
7079
+ async (params) => {
7080
+ const invites = await service.users.listUserInvites({
7081
+ current_page: params.current_page,
7082
+ page_size: params.page_size
7083
+ });
7586
7084
  return {
7587
7085
  content: [
7588
7086
  {
7589
7087
  type: "text",
7590
- text: JSON.stringify(
7591
- {
7592
- total: invites.total,
7593
- invites: invites.data.map(formatUserInvite)
7594
- },
7595
- null,
7596
- 2
7597
- )
7088
+ text: JSON.stringify({
7089
+ total: invites.total,
7090
+ invites: invites.data.map(formatUserInvite)
7091
+ })
7598
7092
  }
7599
7093
  ]
7600
7094
  };
@@ -7610,7 +7104,7 @@ function registerUsersTools(server, service) {
7610
7104
  content: [
7611
7105
  {
7612
7106
  type: "text",
7613
- text: JSON.stringify(formatUserInvite(invite), null, 2)
7107
+ text: JSON.stringify(formatUserInvite(invite))
7614
7108
  }
7615
7109
  ]
7616
7110
  };
@@ -7626,14 +7120,10 @@ function registerUsersTools(server, service) {
7626
7120
  content: [
7627
7121
  {
7628
7122
  type: "text",
7629
- text: JSON.stringify(
7630
- {
7631
- message: `Successfully deleted invite ${params.invite_id}`,
7632
- success: true
7633
- },
7634
- null,
7635
- 2
7636
- )
7123
+ text: JSON.stringify({
7124
+ message: `Successfully deleted invite ${params.invite_id}`,
7125
+ success: true
7126
+ })
7637
7127
  }
7638
7128
  ]
7639
7129
  };
@@ -7649,14 +7139,10 @@ function registerUsersTools(server, service) {
7649
7139
  content: [
7650
7140
  {
7651
7141
  type: "text",
7652
- text: JSON.stringify(
7653
- {
7654
- message: `Successfully resent invite ${params.invite_id}`,
7655
- success: true
7656
- },
7657
- null,
7658
- 2
7659
- )
7142
+ text: JSON.stringify({
7143
+ message: `Successfully resent invite ${params.invite_id}`,
7144
+ success: true
7145
+ })
7660
7146
  }
7661
7147
  ]
7662
7148
  };
@@ -7722,9 +7208,6 @@ var WORKSPACES_TOOL_SCHEMAS = {
7722
7208
  user_id: z19.string().describe("The user ID to remove")
7723
7209
  }
7724
7210
  };
7725
- function formatFullName3(firstName, lastName) {
7726
- return [firstName, lastName].filter(Boolean).join(" ").trim();
7727
- }
7728
7211
  function formatWorkspaceDefaults(defaults) {
7729
7212
  if (!defaults) {
7730
7213
  return null;
@@ -7748,7 +7231,7 @@ function formatWorkspaceSummary(workspace) {
7748
7231
  function formatWorkspaceMember(user) {
7749
7232
  return {
7750
7233
  id: user.id,
7751
- name: formatFullName3(user.first_name, user.last_name),
7234
+ name: formatFullName(user.first_name, user.last_name),
7752
7235
  organization_role: user.org_role,
7753
7236
  workspace_role: user.role,
7754
7237
  status: user.status,
@@ -7779,14 +7262,10 @@ function registerWorkspacesTools(server, service) {
7779
7262
  content: [
7780
7263
  {
7781
7264
  type: "text",
7782
- text: JSON.stringify(
7783
- {
7784
- total: workspaces.total,
7785
- workspaces: workspaces.data.map(formatWorkspaceSummary)
7786
- },
7787
- null,
7788
- 2
7789
- )
7265
+ text: JSON.stringify({
7266
+ total: workspaces.total,
7267
+ workspaces: workspaces.data.map(formatWorkspaceSummary)
7268
+ })
7790
7269
  }
7791
7270
  ]
7792
7271
  };
@@ -7804,7 +7283,7 @@ function registerWorkspacesTools(server, service) {
7804
7283
  content: [
7805
7284
  {
7806
7285
  type: "text",
7807
- text: JSON.stringify(formatWorkspaceDetail(workspace), null, 2)
7286
+ text: JSON.stringify(formatWorkspaceDetail(workspace))
7808
7287
  }
7809
7288
  ]
7810
7289
  };
@@ -7828,14 +7307,10 @@ function registerWorkspacesTools(server, service) {
7828
7307
  content: [
7829
7308
  {
7830
7309
  type: "text",
7831
- text: JSON.stringify(
7832
- {
7833
- message: `Successfully created workspace "${params.name}"`,
7834
- workspace: formatWorkspaceSummary(workspace)
7835
- },
7836
- null,
7837
- 2
7838
- )
7310
+ text: JSON.stringify({
7311
+ message: `Successfully created workspace "${params.name}"`,
7312
+ workspace: formatWorkspaceSummary(workspace)
7313
+ })
7839
7314
  }
7840
7315
  ]
7841
7316
  };
@@ -7858,14 +7333,10 @@ function registerWorkspacesTools(server, service) {
7858
7333
  content: [
7859
7334
  {
7860
7335
  type: "text",
7861
- text: JSON.stringify(
7862
- {
7863
- message: "Successfully updated workspace",
7864
- workspace: formatWorkspaceSummary(workspace)
7865
- },
7866
- null,
7867
- 2
7868
- )
7336
+ text: JSON.stringify({
7337
+ message: "Successfully updated workspace",
7338
+ workspace: formatWorkspaceSummary(workspace)
7339
+ })
7869
7340
  }
7870
7341
  ]
7871
7342
  };
@@ -7881,14 +7352,10 @@ function registerWorkspacesTools(server, service) {
7881
7352
  content: [
7882
7353
  {
7883
7354
  type: "text",
7884
- text: JSON.stringify(
7885
- {
7886
- message: `Successfully deleted workspace ${params.workspace_id}`,
7887
- success: true
7888
- },
7889
- null,
7890
- 2
7891
- )
7355
+ text: JSON.stringify({
7356
+ message: `Successfully deleted workspace ${params.workspace_id}`,
7357
+ success: true
7358
+ })
7892
7359
  }
7893
7360
  ]
7894
7361
  };
@@ -7910,14 +7377,10 @@ function registerWorkspacesTools(server, service) {
7910
7377
  content: [
7911
7378
  {
7912
7379
  type: "text",
7913
- text: JSON.stringify(
7914
- {
7915
- message: `Successfully added user to workspace as ${params.role}`,
7916
- member: formatWorkspaceMember(member)
7917
- },
7918
- null,
7919
- 2
7920
- )
7380
+ text: JSON.stringify({
7381
+ message: `Successfully added user to workspace as ${params.role}`,
7382
+ member: formatWorkspaceMember(member)
7383
+ })
7921
7384
  }
7922
7385
  ]
7923
7386
  };
@@ -7935,14 +7398,10 @@ function registerWorkspacesTools(server, service) {
7935
7398
  content: [
7936
7399
  {
7937
7400
  type: "text",
7938
- text: JSON.stringify(
7939
- {
7940
- total: members.total,
7941
- members: members.data.map(formatWorkspaceMember)
7942
- },
7943
- null,
7944
- 2
7945
- )
7401
+ text: JSON.stringify({
7402
+ total: members.total,
7403
+ members: members.data.map(formatWorkspaceMember)
7404
+ })
7946
7405
  }
7947
7406
  ]
7948
7407
  };
@@ -7961,7 +7420,7 @@ function registerWorkspacesTools(server, service) {
7961
7420
  content: [
7962
7421
  {
7963
7422
  type: "text",
7964
- text: JSON.stringify(formatWorkspaceMember(member), null, 2)
7423
+ text: JSON.stringify(formatWorkspaceMember(member))
7965
7424
  }
7966
7425
  ]
7967
7426
  };
@@ -7983,14 +7442,10 @@ function registerWorkspacesTools(server, service) {
7983
7442
  content: [
7984
7443
  {
7985
7444
  type: "text",
7986
- text: JSON.stringify(
7987
- {
7988
- message: `Successfully updated member role to ${params.role}`,
7989
- member: formatWorkspaceMember(member)
7990
- },
7991
- null,
7992
- 2
7993
- )
7445
+ text: JSON.stringify({
7446
+ message: `Successfully updated member role to ${params.role}`,
7447
+ member: formatWorkspaceMember(member)
7448
+ })
7994
7449
  }
7995
7450
  ]
7996
7451
  };
@@ -8009,14 +7464,10 @@ function registerWorkspacesTools(server, service) {
8009
7464
  content: [
8010
7465
  {
8011
7466
  type: "text",
8012
- text: JSON.stringify(
8013
- {
8014
- message: `Successfully removed user from workspace`,
8015
- success: true
8016
- },
8017
- null,
8018
- 2
8019
- )
7467
+ text: JSON.stringify({
7468
+ message: `Successfully removed user from workspace`,
7469
+ success: true
7470
+ })
8020
7471
  }
8021
7472
  ]
8022
7473
  };
@@ -8110,7 +7561,7 @@ var ENTERPRISE_GATED_TOOL_NAMES = /* @__PURE__ */ new Set([
8110
7561
  ]);
8111
7562
  var ENTERPRISE_GATED_DESCRIPTION_NOTE = "Enterprise-gated. Returns 403 on non-Enterprise Portkey plans.";
8112
7563
  function isToolAnnotationsLike(value) {
8113
- if (!isRecord2(value)) {
7564
+ if (!isRecord(value)) {
8114
7565
  return false;
8115
7566
  }
8116
7567
  const keys = Object.keys(value);
@@ -8170,17 +7621,14 @@ var STANDARD_TOOL_OUTPUT_SCHEMA = {
8170
7621
  details: z20.unknown().optional().describe("Optional structured error details")
8171
7622
  }).optional().describe("Structured error payload when ok is false")
8172
7623
  };
8173
- function isRecord2(value) {
8174
- return typeof value === "object" && value !== null;
8175
- }
8176
7624
  function isStandardToolEnvelope(value) {
8177
- if (!isRecord2(value) || typeof value.ok !== "boolean") {
7625
+ if (!isRecord(value) || typeof value.ok !== "boolean") {
8178
7626
  return false;
8179
7627
  }
8180
7628
  if (value.ok) {
8181
7629
  return "data" in value;
8182
7630
  }
8183
- return isRecord2(value.error) && typeof value.error.message === "string";
7631
+ return isRecord(value.error) && typeof value.error.message === "string";
8184
7632
  }
8185
7633
  function tryParseJson(text) {
8186
7634
  try {
@@ -8210,13 +7658,13 @@ function getErrorDetails(result) {
8210
7658
  if (parsed === void 0) {
8211
7659
  return { message: text };
8212
7660
  }
8213
- if (isRecord2(parsed) && typeof parsed.message === "string") {
7661
+ if (isRecord(parsed) && typeof parsed.message === "string") {
8214
7662
  return { message: parsed.message, details: parsed };
8215
7663
  }
8216
7664
  return { message: text, details: parsed };
8217
7665
  }
8218
7666
  function formatToolEnvelope(envelope) {
8219
- return JSON.stringify(envelope, null, 2);
7667
+ return JSON.stringify(envelope);
8220
7668
  }
8221
7669
  function normalizeToolResult(result) {
8222
7670
  const envelope = isStandardToolEnvelope(result.structuredContent) ? result.structuredContent : result.isError ? {
@@ -8354,7 +7802,7 @@ function registerAllTools(server, service, options = {}) {
8354
7802
  }
8355
7803
 
8356
7804
  // src/lib/auth.ts
8357
- import crypto2 from "node:crypto";
7805
+ import crypto3 from "node:crypto";
8358
7806
  import { createRemoteJWKSet, jwtVerify } from "jose";
8359
7807
  var AUTH_SCHEMES = {
8360
7808
  bearer: "Bearer"
@@ -8469,9 +7917,9 @@ function extractBearerToken(req) {
8469
7917
  return token.trim();
8470
7918
  }
8471
7919
  function timingSafeEqual(a, b) {
8472
- const left = crypto2.createHash("sha256").update(a, "utf8").digest();
8473
- const right = crypto2.createHash("sha256").update(b, "utf8").digest();
8474
- return crypto2.timingSafeEqual(left, right);
7920
+ const left = crypto3.createHash("sha256").update(a, "utf8").digest();
7921
+ const right = crypto3.createHash("sha256").update(b, "utf8").digest();
7922
+ return crypto3.timingSafeEqual(left, right);
8475
7923
  }
8476
7924
  var jwksCache = /* @__PURE__ */ new Map();
8477
7925
  async function verifyClerkToken(token, config) {
@@ -8637,7 +8085,6 @@ function getServerConfig() {
8637
8085
  }
8638
8086
 
8639
8087
  // src/lib/event-store.ts
8640
- import { createClient } from "redis";
8641
8088
  var EVENT_STORE_CLEANUP_INTERVAL_MS = 3e4;
8642
8089
  var SAFE_EVENT_ID_PATTERN = /^[\w-]{1,128}$/;
8643
8090
  function assertSafeRedisId(id, kind) {
@@ -8753,22 +8200,14 @@ var InMemoryEventStore = class {
8753
8200
  };
8754
8201
  var RedisEventStore = class {
8755
8202
  client;
8203
+ redisUrl;
8756
8204
  ttlSeconds;
8757
8205
  keyPrefix;
8758
8206
  connectPromise;
8759
8207
  constructor(redisUrl, keyPrefix, ttlSeconds) {
8208
+ this.redisUrl = redisUrl;
8760
8209
  this.ttlSeconds = ttlSeconds;
8761
8210
  this.keyPrefix = keyPrefix;
8762
- this.client = createClient({
8763
- url: redisUrl
8764
- });
8765
- this.client.on("error", (error) => {
8766
- Logger.error("Redis event store error", {
8767
- metadata: {
8768
- error: error instanceof Error ? error.message : String(error)
8769
- }
8770
- });
8771
- });
8772
8211
  }
8773
8212
  counterKey() {
8774
8213
  return `${this.keyPrefix}:counter`;
@@ -8780,6 +8219,17 @@ var RedisEventStore = class {
8780
8219
  return `${this.keyPrefix}:stream:${assertSafeRedisId(streamId, "streamId")}:events`;
8781
8220
  }
8782
8221
  async ensureConnected() {
8222
+ if (!this.client) {
8223
+ const { createClient } = await import("redis");
8224
+ this.client = createClient({ url: this.redisUrl });
8225
+ this.client.on("error", (error) => {
8226
+ Logger.error("Redis event store error", {
8227
+ metadata: {
8228
+ error: error instanceof Error ? error.message : String(error)
8229
+ }
8230
+ });
8231
+ });
8232
+ }
8783
8233
  if (this.client.isOpen) {
8784
8234
  return;
8785
8235
  }
@@ -8791,12 +8241,19 @@ var RedisEventStore = class {
8791
8241
  }
8792
8242
  await this.connectPromise;
8793
8243
  }
8244
+ getConnectedClient() {
8245
+ if (!this.client) {
8246
+ throw new Error("Redis client not initialized");
8247
+ }
8248
+ return this.client;
8249
+ }
8794
8250
  async storeEvent(streamId, message) {
8795
8251
  await this.ensureConnected();
8796
- const eventId = String(await this.client.incr(this.counterKey()));
8252
+ const client = this.getConnectedClient();
8253
+ const eventId = String(await client.incr(this.counterKey()));
8797
8254
  const eventKey = this.eventKey(eventId);
8798
8255
  const streamKey = this.streamEventsKey(streamId);
8799
- const tx = this.client.multi();
8256
+ const tx = client.multi();
8800
8257
  tx.hSet(eventKey, {
8801
8258
  streamId,
8802
8259
  message: JSON.stringify(message)
@@ -8815,14 +8272,18 @@ var RedisEventStore = class {
8815
8272
  return void 0;
8816
8273
  }
8817
8274
  await this.ensureConnected();
8818
- const streamId = await this.client.hGet(this.eventKey(eventId), "streamId");
8275
+ const streamId = await this.getConnectedClient().hGet(
8276
+ this.eventKey(eventId),
8277
+ "streamId"
8278
+ );
8819
8279
  return streamId || void 0;
8820
8280
  }
8821
8281
  async replayEventsAfter(lastEventId, {
8822
8282
  send
8823
8283
  }) {
8824
8284
  await this.ensureConnected();
8825
- const baseEvent = await this.client.hGetAll(this.eventKey(lastEventId));
8285
+ const client = this.getConnectedClient();
8286
+ const baseEvent = await client.hGetAll(this.eventKey(lastEventId));
8826
8287
  const streamId = baseEvent.streamId;
8827
8288
  if (!streamId) {
8828
8289
  throw new Error(`Event not found for replay: ${lastEventId}`);
@@ -8831,7 +8292,7 @@ var RedisEventStore = class {
8831
8292
  if (!Number.isFinite(baseScore)) {
8832
8293
  throw new Error(`Invalid replay event ID: ${lastEventId}`);
8833
8294
  }
8834
- const eventIds = await this.client.zRangeByScore(
8295
+ const eventIds = await client.zRangeByScore(
8835
8296
  this.streamEventsKey(streamId),
8836
8297
  `(${baseScore}`,
8837
8298
  "+inf"
@@ -8839,7 +8300,7 @@ var RedisEventStore = class {
8839
8300
  if (eventIds.length === 0) {
8840
8301
  return streamId;
8841
8302
  }
8842
- const tx = this.client.multi();
8303
+ const tx = client.multi();
8843
8304
  for (const eventId of eventIds) {
8844
8305
  tx.hGet(this.eventKey(eventId), "message");
8845
8306
  }
@@ -8860,6 +8321,9 @@ var RedisEventStore = class {
8860
8321
  return streamId;
8861
8322
  }
8862
8323
  async close() {
8324
+ if (!this.client) {
8325
+ return;
8326
+ }
8863
8327
  if (!this.client.isOpen && this.connectPromise) {
8864
8328
  try {
8865
8329
  await this.connectPromise;
@@ -9459,9 +8923,6 @@ function respondJsonRpcClientError(res, statusCode, message, code = -32602) {
9459
8923
  id: null
9460
8924
  });
9461
8925
  }
9462
- function isRecord3(value) {
9463
- return typeof value === "object" && value !== null;
9464
- }
9465
8926
  function parseRequestedToolDomains(rawQuery) {
9466
8927
  if (rawQuery === void 0) {
9467
8928
  return void 0;
@@ -9502,7 +8963,7 @@ function areToolDomainsEqual(left, right) {
9502
8963
  );
9503
8964
  }
9504
8965
  function getNegotiatedProtocolVersion(body) {
9505
- if (!isRecord3(body) || !isRecord3(body.params)) {
8966
+ if (!isRecord(body) || !isRecord(body.params)) {
9506
8967
  return void 0;
9507
8968
  }
9508
8969
  const requestedVersion = body.params.protocolVersion;
@@ -9511,15 +8972,24 @@ function getNegotiatedProtocolVersion(body) {
9511
8972
  }
9512
8973
  return SUPPORTED_PROTOCOL_VERSIONS.includes(requestedVersion) ? requestedVersion : LATEST_PROTOCOL_VERSION;
9513
8974
  }
8975
+ function sanitizeProtocolVersion(version) {
8976
+ return version.replace(/[^A-Za-z0-9._-]/g, "").slice(0, 64);
8977
+ }
8978
+ function getMcpProtocolVersion(req) {
8979
+ const raw = req.headers["mcp-protocol-version"];
8980
+ return typeof raw === "string" ? raw : void 0;
8981
+ }
9514
8982
  function validateRequiredProtocolVersion(protocolVersion, expectedProtocolVersion) {
9515
8983
  if (!protocolVersion) {
9516
8984
  return "Bad Request: MCP-Protocol-Version header is required for requests after initialization";
9517
8985
  }
9518
8986
  if (!SUPPORTED_PROTOCOL_VERSIONS.includes(protocolVersion)) {
9519
- return `Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`;
8987
+ const safe = sanitizeProtocolVersion(protocolVersion);
8988
+ return `Bad Request: Unsupported protocol version: ${safe} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`;
9520
8989
  }
9521
8990
  if (expectedProtocolVersion !== void 0 && protocolVersion !== expectedProtocolVersion) {
9522
- return `Bad Request: MCP-Protocol-Version ${protocolVersion} does not match negotiated session protocol version ${expectedProtocolVersion}`;
8991
+ const safe = sanitizeProtocolVersion(protocolVersion);
8992
+ return `Bad Request: MCP-Protocol-Version ${safe} does not match negotiated session protocol version ${expectedProtocolVersion}`;
9523
8993
  }
9524
8994
  return void 0;
9525
8995
  }
@@ -9534,7 +9004,12 @@ function createHttpAppRuntime() {
9534
9004
  const corsOriginConfig = allowedOrigins.includes(
9535
9005
  "*"
9536
9006
  ) ? true : allowedOrigins;
9537
- const healthService = process.env.PORTKEY_API_KEY ? getSharedHealthService() : null;
9007
+ if (allowedOrigins.includes("*") && authConfig.mode === "none") {
9008
+ Logger.warn(
9009
+ "CORS wildcard (ALLOWED_ORIGINS=*) combined with MCP_AUTH_MODE=none: all origins are accepted with no authentication. Do not expose this server publicly."
9010
+ );
9011
+ }
9012
+ const healthService = process.env.PORTKEY_API_KEY ? getSharedPortkeyService().health : null;
9538
9013
  const isStatefulSessionMode = config.sessionMode === "stateful";
9539
9014
  const publicBaseUrl = buildConfiguredPublicBaseUrl(config);
9540
9015
  const sessionStore = new SessionStore(config.maxSessions);
@@ -9585,10 +9060,10 @@ function createHttpAppRuntime() {
9585
9060
  app.use(
9586
9061
  helmet({
9587
9062
  frameguard: { action: "deny" },
9588
- strictTransportSecurity: {
9063
+ strictTransportSecurity: config.tls.enabled ? {
9589
9064
  maxAge: 31536e3,
9590
9065
  includeSubDomains: true
9591
- }
9066
+ } : false
9592
9067
  })
9593
9068
  );
9594
9069
  app.use(express.json({ limit: requestBodyLimit }));
@@ -9745,15 +9220,12 @@ function createHttpAppRuntime() {
9745
9220
  tls: {
9746
9221
  enabled: config.tls.enabled,
9747
9222
  protocol: config.protocol
9748
- },
9749
- redis: {
9750
- configured: Boolean(config.eventStore.redisUrl)
9751
9223
  }
9752
9224
  });
9753
9225
  });
9754
9226
  app.post("/mcp", async (req, res) => {
9755
9227
  let requestedToolDomains;
9756
- const protocolVersionHeader = typeof req.headers["mcp-protocol-version"] === "string" ? req.headers["mcp-protocol-version"] : void 0;
9228
+ const protocolVersionHeader = getMcpProtocolVersion(req);
9757
9229
  try {
9758
9230
  requestedToolDomains = parseRequestedToolDomains(req.query.tools);
9759
9231
  } catch (error) {
@@ -9915,7 +9387,7 @@ function createHttpAppRuntime() {
9915
9387
  return;
9916
9388
  }
9917
9389
  const sessionId = req.headers["mcp-session-id"];
9918
- const protocolVersionHeader = typeof req.headers["mcp-protocol-version"] === "string" ? req.headers["mcp-protocol-version"] : void 0;
9390
+ const protocolVersionHeader = getMcpProtocolVersion(req);
9919
9391
  let requestedToolDomains;
9920
9392
  try {
9921
9393
  requestedToolDomains = parseRequestedToolDomains(req.query.tools);
@@ -9983,7 +9455,7 @@ function createHttpAppRuntime() {
9983
9455
  return;
9984
9456
  }
9985
9457
  const sessionId = req.headers["mcp-session-id"];
9986
- const protocolVersionHeader = typeof req.headers["mcp-protocol-version"] === "string" ? req.headers["mcp-protocol-version"] : void 0;
9458
+ const protocolVersionHeader = getMcpProtocolVersion(req);
9987
9459
  if (!sessionId) {
9988
9460
  res.status(400).json({
9989
9461
  jsonrpc: "2.0",