@inkeep/agents-core 0.22.12 → 0.23.1

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.
@@ -1,3 +1,5 @@
1
+ import { LoggerOptions, TransportSingleOptions, Logger } from 'pino';
2
+
1
3
  declare const DELEGATION_FROM_SUB_AGENT_ID = "delegation.from_sub_agent_id";
2
4
  declare const DELEGATION_TO_SUB_AGENT_ID = "delegation.to_sub_agent_id";
3
5
  declare const DELEGATION_ID = "delegation.id";
@@ -276,4 +278,159 @@ declare const QUERY_DEFAULTS: {
276
278
  readonly EMPTY_GROUP_BY: readonly [];
277
279
  };
278
280
 
279
- export { AI_OPERATIONS as A, DELEGATION_FROM_SUB_AGENT_ID as D, FIELD_TYPES as F, OPERATORS as O, PANEL_TYPES as P, QUERY_FIELD_CONFIGS as Q, REDUCE_OPERATIONS as R, SPAN_NAMES as S, TRANSFER_FROM_SUB_AGENT_ID as T, UNKNOWN_VALUE as U, DELEGATION_TO_SUB_AGENT_ID as a, DELEGATION_ID as b, TRANSFER_TO_SUB_AGENT_ID as c, SPAN_KEYS as d, ACTIVITY_TYPES as e, ACTIVITY_STATUS as f, AGENT_IDS as g, ACTIVITY_NAMES as h, AI_TOOL_TYPES as i, DATA_TYPES as j, QUERY_EXPRESSIONS as k, ORDER_DIRECTIONS as l, QUERY_TYPES as m, DATA_SOURCES as n, AGGREGATE_OPERATORS as o, QUERY_DEFAULTS as p };
281
+ /**
282
+ * Configuration options for PinoLogger
283
+ */
284
+ interface PinoLoggerConfig {
285
+ /** Pino logger options */
286
+ options?: LoggerOptions;
287
+ /** Pino transport configuration */
288
+ transportConfigs?: TransportSingleOptions[];
289
+ }
290
+ /**
291
+ * Pino logger implementation with transport customization support
292
+ */
293
+ declare class PinoLogger {
294
+ private name;
295
+ private transportConfigs;
296
+ private pinoInstance;
297
+ private options;
298
+ constructor(name: string, config?: PinoLoggerConfig);
299
+ /**
300
+ * Recreate the pino instance with current transports
301
+ */
302
+ private recreateInstance;
303
+ /**
304
+ * Add a new transport to the logger
305
+ */
306
+ addTransport(transportConfig: TransportSingleOptions): void;
307
+ /**
308
+ * Remove a transport by index
309
+ */
310
+ removeTransport(index: number): void;
311
+ /**
312
+ * Get current transports
313
+ */
314
+ getTransports(): TransportSingleOptions[];
315
+ /**
316
+ * Update logger options
317
+ */
318
+ updateOptions(options: Partial<LoggerOptions>): void;
319
+ /**
320
+ * Get the underlying pino instance for advanced usage
321
+ */
322
+ getPinoInstance(): Logger;
323
+ error(data: any, message: string): void;
324
+ warn(data: any, message: string): void;
325
+ info(data: any, message: string): void;
326
+ debug(data: any, message: string): void;
327
+ }
328
+ /**
329
+ * Logger factory configuration
330
+ */
331
+ interface LoggerFactoryConfig {
332
+ defaultLogger?: PinoLogger;
333
+ loggerFactory?: (name: string) => PinoLogger;
334
+ /** Configuration for creating PinoLogger instances when using createPinoLoggerFactory */
335
+ pinoConfig?: PinoLoggerConfig;
336
+ }
337
+ /**
338
+ * Global logger factory singleton
339
+ */
340
+ declare class LoggerFactory {
341
+ private config;
342
+ private loggers;
343
+ /**
344
+ * Configure the logger factory
345
+ */
346
+ configure(config: LoggerFactoryConfig): void;
347
+ /**
348
+ * Get or create a logger instance
349
+ */
350
+ getLogger(name: string): PinoLogger;
351
+ /**
352
+ * Reset factory to default state
353
+ */
354
+ reset(): void;
355
+ }
356
+ declare const loggerFactory: LoggerFactory;
357
+ /**
358
+ * Convenience function to get a logger
359
+ */
360
+ declare function getLogger(name: string): PinoLogger;
361
+
362
+ /**
363
+ * Centralized authentication detection utilities for MCP tools
364
+ * Uses proper MCP OAuth specification (RFC 9728 + RFC 8414) for discovery
365
+ */
366
+
367
+ /**
368
+ * OAuth configuration interface
369
+ */
370
+ interface OAuthConfig {
371
+ authorizationUrl: string;
372
+ tokenUrl: string;
373
+ registrationUrl?: string;
374
+ supportsDynamicRegistration: boolean;
375
+ scopes?: string;
376
+ }
377
+ /**
378
+ * MCP OAuth flow initiation result
379
+ */
380
+ interface McpOAuthFlowResult {
381
+ authorizationUrl: string;
382
+ codeVerifier: string;
383
+ state: string;
384
+ clientInformation: any;
385
+ scopes?: string;
386
+ metadata: any;
387
+ resourceUrl?: string;
388
+ }
389
+ /**
390
+ * MCP OAuth token exchange result
391
+ */
392
+ interface McpTokenExchangeResult {
393
+ access_token: string;
394
+ refresh_token?: string;
395
+ expires_at?: Date;
396
+ token_type: string;
397
+ scope?: string;
398
+ }
399
+ /**
400
+ * Initiate MCP OAuth flow using the official MCP SDK
401
+ */
402
+ declare function initiateMcpOAuthFlow({ mcpServerUrl, redirectUri, state, clientName, clientUri, logoUri, defaultClientId, logger, }: {
403
+ mcpServerUrl: string;
404
+ redirectUri: string;
405
+ state: string;
406
+ clientName?: string;
407
+ clientUri?: string;
408
+ logoUri?: string;
409
+ defaultClientId?: string;
410
+ logger?: PinoLogger;
411
+ }): Promise<McpOAuthFlowResult>;
412
+ /**
413
+ * Exchange authorization code for tokens using MCP SDK
414
+ */
415
+ declare function exchangeMcpAuthorizationCode({ mcpServerUrl, metadata, clientInformation, authorizationCode, codeVerifier, redirectUri, resourceUrl, logger, }: {
416
+ mcpServerUrl: string;
417
+ metadata: any;
418
+ clientInformation: any;
419
+ authorizationCode: string;
420
+ codeVerifier: string;
421
+ redirectUri: string;
422
+ resourceUrl?: string;
423
+ logger?: PinoLogger;
424
+ }): Promise<McpTokenExchangeResult>;
425
+ /**
426
+ * Detect if MCP OAuth authentication is specifically required for a tool
427
+ * Uses proper MCP OAuth specification discovery methods
428
+ */
429
+ declare const detectAuthenticationRequired: ({ serverUrl, toolId, error, logger, }: {
430
+ serverUrl: string;
431
+ toolId: string;
432
+ error?: Error;
433
+ logger?: PinoLogger;
434
+ }) => Promise<boolean>;
435
+
436
+ export { AI_OPERATIONS as A, DELEGATION_FROM_SUB_AGENT_ID as D, FIELD_TYPES as F, type LoggerFactoryConfig as L, type McpOAuthFlowResult as M, OPERATORS as O, PANEL_TYPES as P, QUERY_FIELD_CONFIGS as Q, REDUCE_OPERATIONS as R, SPAN_NAMES as S, TRANSFER_FROM_SUB_AGENT_ID as T, UNKNOWN_VALUE as U, DELEGATION_TO_SUB_AGENT_ID as a, DELEGATION_ID as b, TRANSFER_TO_SUB_AGENT_ID as c, detectAuthenticationRequired as d, SPAN_KEYS as e, ACTIVITY_TYPES as f, ACTIVITY_STATUS as g, AGENT_IDS as h, ACTIVITY_NAMES as i, AI_TOOL_TYPES as j, DATA_TYPES as k, QUERY_EXPRESSIONS as l, ORDER_DIRECTIONS as m, QUERY_TYPES as n, DATA_SOURCES as o, AGGREGATE_OPERATORS as p, QUERY_DEFAULTS as q, PinoLogger as r, getLogger as s, type OAuthConfig as t, type McpTokenExchangeResult as u, initiateMcpOAuthFlow as v, exchangeMcpAuthorizationCode as w, type PinoLoggerConfig as x, loggerFactory as y };
@@ -1,3 +1,5 @@
1
+ import { LoggerOptions, TransportSingleOptions, Logger } from 'pino';
2
+
1
3
  declare const DELEGATION_FROM_SUB_AGENT_ID = "delegation.from_sub_agent_id";
2
4
  declare const DELEGATION_TO_SUB_AGENT_ID = "delegation.to_sub_agent_id";
3
5
  declare const DELEGATION_ID = "delegation.id";
@@ -276,4 +278,159 @@ declare const QUERY_DEFAULTS: {
276
278
  readonly EMPTY_GROUP_BY: readonly [];
277
279
  };
278
280
 
279
- export { AI_OPERATIONS as A, DELEGATION_FROM_SUB_AGENT_ID as D, FIELD_TYPES as F, OPERATORS as O, PANEL_TYPES as P, QUERY_FIELD_CONFIGS as Q, REDUCE_OPERATIONS as R, SPAN_NAMES as S, TRANSFER_FROM_SUB_AGENT_ID as T, UNKNOWN_VALUE as U, DELEGATION_TO_SUB_AGENT_ID as a, DELEGATION_ID as b, TRANSFER_TO_SUB_AGENT_ID as c, SPAN_KEYS as d, ACTIVITY_TYPES as e, ACTIVITY_STATUS as f, AGENT_IDS as g, ACTIVITY_NAMES as h, AI_TOOL_TYPES as i, DATA_TYPES as j, QUERY_EXPRESSIONS as k, ORDER_DIRECTIONS as l, QUERY_TYPES as m, DATA_SOURCES as n, AGGREGATE_OPERATORS as o, QUERY_DEFAULTS as p };
281
+ /**
282
+ * Configuration options for PinoLogger
283
+ */
284
+ interface PinoLoggerConfig {
285
+ /** Pino logger options */
286
+ options?: LoggerOptions;
287
+ /** Pino transport configuration */
288
+ transportConfigs?: TransportSingleOptions[];
289
+ }
290
+ /**
291
+ * Pino logger implementation with transport customization support
292
+ */
293
+ declare class PinoLogger {
294
+ private name;
295
+ private transportConfigs;
296
+ private pinoInstance;
297
+ private options;
298
+ constructor(name: string, config?: PinoLoggerConfig);
299
+ /**
300
+ * Recreate the pino instance with current transports
301
+ */
302
+ private recreateInstance;
303
+ /**
304
+ * Add a new transport to the logger
305
+ */
306
+ addTransport(transportConfig: TransportSingleOptions): void;
307
+ /**
308
+ * Remove a transport by index
309
+ */
310
+ removeTransport(index: number): void;
311
+ /**
312
+ * Get current transports
313
+ */
314
+ getTransports(): TransportSingleOptions[];
315
+ /**
316
+ * Update logger options
317
+ */
318
+ updateOptions(options: Partial<LoggerOptions>): void;
319
+ /**
320
+ * Get the underlying pino instance for advanced usage
321
+ */
322
+ getPinoInstance(): Logger;
323
+ error(data: any, message: string): void;
324
+ warn(data: any, message: string): void;
325
+ info(data: any, message: string): void;
326
+ debug(data: any, message: string): void;
327
+ }
328
+ /**
329
+ * Logger factory configuration
330
+ */
331
+ interface LoggerFactoryConfig {
332
+ defaultLogger?: PinoLogger;
333
+ loggerFactory?: (name: string) => PinoLogger;
334
+ /** Configuration for creating PinoLogger instances when using createPinoLoggerFactory */
335
+ pinoConfig?: PinoLoggerConfig;
336
+ }
337
+ /**
338
+ * Global logger factory singleton
339
+ */
340
+ declare class LoggerFactory {
341
+ private config;
342
+ private loggers;
343
+ /**
344
+ * Configure the logger factory
345
+ */
346
+ configure(config: LoggerFactoryConfig): void;
347
+ /**
348
+ * Get or create a logger instance
349
+ */
350
+ getLogger(name: string): PinoLogger;
351
+ /**
352
+ * Reset factory to default state
353
+ */
354
+ reset(): void;
355
+ }
356
+ declare const loggerFactory: LoggerFactory;
357
+ /**
358
+ * Convenience function to get a logger
359
+ */
360
+ declare function getLogger(name: string): PinoLogger;
361
+
362
+ /**
363
+ * Centralized authentication detection utilities for MCP tools
364
+ * Uses proper MCP OAuth specification (RFC 9728 + RFC 8414) for discovery
365
+ */
366
+
367
+ /**
368
+ * OAuth configuration interface
369
+ */
370
+ interface OAuthConfig {
371
+ authorizationUrl: string;
372
+ tokenUrl: string;
373
+ registrationUrl?: string;
374
+ supportsDynamicRegistration: boolean;
375
+ scopes?: string;
376
+ }
377
+ /**
378
+ * MCP OAuth flow initiation result
379
+ */
380
+ interface McpOAuthFlowResult {
381
+ authorizationUrl: string;
382
+ codeVerifier: string;
383
+ state: string;
384
+ clientInformation: any;
385
+ scopes?: string;
386
+ metadata: any;
387
+ resourceUrl?: string;
388
+ }
389
+ /**
390
+ * MCP OAuth token exchange result
391
+ */
392
+ interface McpTokenExchangeResult {
393
+ access_token: string;
394
+ refresh_token?: string;
395
+ expires_at?: Date;
396
+ token_type: string;
397
+ scope?: string;
398
+ }
399
+ /**
400
+ * Initiate MCP OAuth flow using the official MCP SDK
401
+ */
402
+ declare function initiateMcpOAuthFlow({ mcpServerUrl, redirectUri, state, clientName, clientUri, logoUri, defaultClientId, logger, }: {
403
+ mcpServerUrl: string;
404
+ redirectUri: string;
405
+ state: string;
406
+ clientName?: string;
407
+ clientUri?: string;
408
+ logoUri?: string;
409
+ defaultClientId?: string;
410
+ logger?: PinoLogger;
411
+ }): Promise<McpOAuthFlowResult>;
412
+ /**
413
+ * Exchange authorization code for tokens using MCP SDK
414
+ */
415
+ declare function exchangeMcpAuthorizationCode({ mcpServerUrl, metadata, clientInformation, authorizationCode, codeVerifier, redirectUri, resourceUrl, logger, }: {
416
+ mcpServerUrl: string;
417
+ metadata: any;
418
+ clientInformation: any;
419
+ authorizationCode: string;
420
+ codeVerifier: string;
421
+ redirectUri: string;
422
+ resourceUrl?: string;
423
+ logger?: PinoLogger;
424
+ }): Promise<McpTokenExchangeResult>;
425
+ /**
426
+ * Detect if MCP OAuth authentication is specifically required for a tool
427
+ * Uses proper MCP OAuth specification discovery methods
428
+ */
429
+ declare const detectAuthenticationRequired: ({ serverUrl, toolId, error, logger, }: {
430
+ serverUrl: string;
431
+ toolId: string;
432
+ error?: Error;
433
+ logger?: PinoLogger;
434
+ }) => Promise<boolean>;
435
+
436
+ export { AI_OPERATIONS as A, DELEGATION_FROM_SUB_AGENT_ID as D, FIELD_TYPES as F, type LoggerFactoryConfig as L, type McpOAuthFlowResult as M, OPERATORS as O, PANEL_TYPES as P, QUERY_FIELD_CONFIGS as Q, REDUCE_OPERATIONS as R, SPAN_NAMES as S, TRANSFER_FROM_SUB_AGENT_ID as T, UNKNOWN_VALUE as U, DELEGATION_TO_SUB_AGENT_ID as a, DELEGATION_ID as b, TRANSFER_TO_SUB_AGENT_ID as c, detectAuthenticationRequired as d, SPAN_KEYS as e, ACTIVITY_TYPES as f, ACTIVITY_STATUS as g, AGENT_IDS as h, ACTIVITY_NAMES as i, AI_TOOL_TYPES as j, DATA_TYPES as k, QUERY_EXPRESSIONS as l, ORDER_DIRECTIONS as m, QUERY_TYPES as n, DATA_SOURCES as o, AGGREGATE_OPERATORS as p, QUERY_DEFAULTS as q, PinoLogger as r, getLogger as s, type OAuthConfig as t, type McpTokenExchangeResult as u, initiateMcpOAuthFlow as v, exchangeMcpAuthorizationCode as w, type PinoLoggerConfig as x, loggerFactory as y };
@@ -1,3 +1,5 @@
1
+ import { registerClient, startAuthorization, exchangeAuthorization, discoverOAuthProtectedResourceMetadata, discoverAuthorizationServerMetadata } from '@modelcontextprotocol/sdk/client/auth.js';
2
+
1
3
  // src/constants/otel-attributes.ts
2
4
  var DELEGATION_FROM_SUB_AGENT_ID = "delegation.from_sub_agent_id";
3
5
  var DELEGATION_TO_SUB_AGENT_ID = "delegation.to_sub_agent_id";
@@ -279,5 +281,166 @@ var QUERY_DEFAULTS = {
279
281
  LIMIT_1000: 1e3,
280
282
  EMPTY_GROUP_BY: []
281
283
  };
284
+ function discoverScopes(resourceMetadata, metadata) {
285
+ const resourceScopes = resourceMetadata?.scopes_supported;
286
+ const oauthScopes = metadata?.scopes_supported;
287
+ const scopes = (resourceScopes?.length ? resourceScopes : oauthScopes) || [];
288
+ return scopes.length > 0 ? scopes.join(" ") : void 0;
289
+ }
290
+ async function discoverMcpMetadata(mcpServerUrl, logger) {
291
+ try {
292
+ let resourceMetadata = null;
293
+ let authServerUrl = new URL(mcpServerUrl);
294
+ try {
295
+ resourceMetadata = await discoverOAuthProtectedResourceMetadata(mcpServerUrl);
296
+ if (resourceMetadata?.authorization_servers?.length && resourceMetadata.authorization_servers[0]) {
297
+ authServerUrl = new URL(resourceMetadata.authorization_servers[0]);
298
+ }
299
+ } catch {
300
+ }
301
+ const metadata = await discoverAuthorizationServerMetadata(authServerUrl);
302
+ if (!metadata) {
303
+ throw new Error("Failed to discover OAuth authorization server metadata");
304
+ }
305
+ logger?.debug(
306
+ {
307
+ tokenEndpoint: metadata.token_endpoint,
308
+ authEndpoint: metadata.authorization_endpoint
309
+ },
310
+ "MCP metadata discovery successful"
311
+ );
312
+ const discoveredScopes = discoverScopes(resourceMetadata ?? void 0, metadata);
313
+ return {
314
+ success: true,
315
+ metadata,
316
+ ...resourceMetadata && { resourceMetadata },
317
+ ...discoveredScopes && { scopes: discoveredScopes }
318
+ };
319
+ } catch (err) {
320
+ const errorMessage = err instanceof Error ? err.message : String(err);
321
+ logger?.debug({ error: errorMessage }, "MCP metadata discovery failed");
322
+ return { success: false, error: errorMessage };
323
+ }
324
+ }
325
+ async function initiateMcpOAuthFlow({
326
+ mcpServerUrl,
327
+ redirectUri,
328
+ state,
329
+ clientName = "Inkeep Agent Framework",
330
+ clientUri = "https://inkeep.com",
331
+ logoUri,
332
+ defaultClientId = "mcp-client",
333
+ logger
334
+ }) {
335
+ const discoveryResult = await discoverMcpMetadata(mcpServerUrl, logger);
336
+ if (!discoveryResult.success || !discoveryResult.metadata) {
337
+ throw new Error(`OAuth not supported by this server: ${discoveryResult.error}`);
338
+ }
339
+ const { metadata, resourceMetadata, scopes: discoveredScopes } = discoveryResult;
340
+ const clientMetadata = {
341
+ redirect_uris: [redirectUri],
342
+ token_endpoint_auth_method: "none",
343
+ // PKCE - no client secret
344
+ grant_types: ["authorization_code", "refresh_token"],
345
+ response_types: ["code"],
346
+ client_name: clientName,
347
+ client_uri: clientUri,
348
+ ...logoUri && { logo_uri: logoUri }
349
+ };
350
+ let clientInformation;
351
+ if (metadata.registration_endpoint) {
352
+ clientInformation = await registerClient(mcpServerUrl, {
353
+ metadata,
354
+ clientMetadata
355
+ });
356
+ } else {
357
+ clientInformation = {
358
+ client_id: defaultClientId,
359
+ ...clientMetadata
360
+ };
361
+ }
362
+ const resource = resourceMetadata?.resource ? new URL(resourceMetadata.resource) : void 0;
363
+ const authResult = await startAuthorization(mcpServerUrl, {
364
+ metadata,
365
+ clientInformation,
366
+ redirectUrl: redirectUri,
367
+ state,
368
+ scope: discoveredScopes || "",
369
+ ...resource && { resource }
370
+ });
371
+ logger?.debug(
372
+ {
373
+ authorizationUrl: authResult.authorizationUrl.href,
374
+ scopes: discoveredScopes,
375
+ clientId: clientInformation.client_id
376
+ },
377
+ "MCP OAuth flow initiated successfully"
378
+ );
379
+ return {
380
+ authorizationUrl: authResult.authorizationUrl.href,
381
+ codeVerifier: authResult.codeVerifier,
382
+ state,
383
+ clientInformation,
384
+ metadata,
385
+ resourceUrl: resource?.href || void 0,
386
+ ...discoveredScopes && { scopes: discoveredScopes }
387
+ };
388
+ }
389
+ async function exchangeMcpAuthorizationCode({
390
+ mcpServerUrl,
391
+ metadata,
392
+ clientInformation,
393
+ authorizationCode,
394
+ codeVerifier,
395
+ redirectUri,
396
+ resourceUrl,
397
+ logger
398
+ }) {
399
+ const resource = resourceUrl ? new URL(resourceUrl) : void 0;
400
+ const tokens = await exchangeAuthorization(mcpServerUrl, {
401
+ metadata,
402
+ clientInformation,
403
+ authorizationCode,
404
+ codeVerifier,
405
+ redirectUri,
406
+ ...resource && { resource }
407
+ });
408
+ logger?.debug(
409
+ {
410
+ tokenType: tokens.token_type,
411
+ hasRefreshToken: !!tokens.refresh_token,
412
+ expiresIn: tokens.expires_in
413
+ },
414
+ "MCP token exchange successful"
415
+ );
416
+ return {
417
+ access_token: tokens.access_token,
418
+ refresh_token: tokens.refresh_token,
419
+ expires_at: tokens.expires_in ? new Date(Date.now() + tokens.expires_in * 1e3) : void 0,
420
+ token_type: tokens.token_type || "Bearer",
421
+ scope: tokens.scope
422
+ };
423
+ }
424
+ var detectAuthenticationRequired = async ({
425
+ serverUrl,
426
+ toolId,
427
+ error,
428
+ logger
429
+ }) => {
430
+ try {
431
+ const discoveryResult = await discoverMcpMetadata(serverUrl, logger);
432
+ if (discoveryResult.success && discoveryResult.metadata) {
433
+ logger?.info({ toolId, serverUrl }, "MCP OAuth support confirmed via metadata discovery");
434
+ return true;
435
+ }
436
+ } catch (discoveryError) {
437
+ logger?.debug({ toolId, discoveryError }, "MCP OAuth metadata discovery failed");
438
+ }
439
+ logger?.debug(
440
+ { toolId, error: error?.message },
441
+ "No MCP OAuth authentication requirement detected"
442
+ );
443
+ return false;
444
+ };
282
445
 
283
- export { ACTIVITY_NAMES, ACTIVITY_STATUS, ACTIVITY_TYPES, AGENT_IDS, AGGREGATE_OPERATORS, AI_OPERATIONS, AI_TOOL_TYPES, DATA_SOURCES, DATA_TYPES, DELEGATION_FROM_SUB_AGENT_ID, DELEGATION_ID, DELEGATION_TO_SUB_AGENT_ID, FIELD_TYPES, OPERATORS, ORDER_DIRECTIONS, PANEL_TYPES, QUERY_DEFAULTS, QUERY_EXPRESSIONS, QUERY_FIELD_CONFIGS, QUERY_TYPES, REDUCE_OPERATIONS, SPAN_KEYS, SPAN_NAMES, TRANSFER_FROM_SUB_AGENT_ID, TRANSFER_TO_SUB_AGENT_ID, UNKNOWN_VALUE };
446
+ export { ACTIVITY_NAMES, ACTIVITY_STATUS, ACTIVITY_TYPES, AGENT_IDS, AGGREGATE_OPERATORS, AI_OPERATIONS, AI_TOOL_TYPES, DATA_SOURCES, DATA_TYPES, DELEGATION_FROM_SUB_AGENT_ID, DELEGATION_ID, DELEGATION_TO_SUB_AGENT_ID, FIELD_TYPES, OPERATORS, ORDER_DIRECTIONS, PANEL_TYPES, QUERY_DEFAULTS, QUERY_EXPRESSIONS, QUERY_FIELD_CONFIGS, QUERY_TYPES, REDUCE_OPERATIONS, SPAN_KEYS, SPAN_NAMES, TRANSFER_FROM_SUB_AGENT_ID, TRANSFER_TO_SUB_AGENT_ID, UNKNOWN_VALUE, detectAuthenticationRequired, exchangeMcpAuthorizationCode, initiateMcpOAuthFlow };
@@ -1,4 +1,4 @@
1
- import { AgentWithinContextOfProjectSchema, resourceIdSchema, MAX_ID_LENGTH } from './chunk-4SE2FOJY.js';
1
+ import { AgentWithinContextOfProjectSchema, resourceIdSchema, MAX_ID_LENGTH } from './chunk-HN77JIDP.js';
2
2
  import { z } from 'zod';
3
3
 
4
4
  // src/validation/agentFull.ts
@@ -389,7 +389,8 @@ var McpToolSchema = ToolInsertSchema.extend({
389
389
  status: ToolStatusSchema.default("unknown"),
390
390
  version: z.string().optional(),
391
391
  createdAt: z.date(),
392
- updatedAt: z.date()
392
+ updatedAt: z.date(),
393
+ expiresAt: z.date().optional()
393
394
  });
394
395
  var MCPToolConfigSchema = McpToolSchema.omit({
395
396
  config: true,
@@ -6,6 +6,7 @@ var drizzleZod = require('drizzle-zod');
6
6
  var drizzleOrm = require('drizzle-orm');
7
7
  var sqliteCore = require('drizzle-orm/sqlite-core');
8
8
  var Ajv = require('ajv');
9
+ var auth_js = require('@modelcontextprotocol/sdk/client/auth.js');
9
10
 
10
11
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
12
 
@@ -1251,7 +1252,8 @@ var McpToolSchema = ToolInsertSchema.extend({
1251
1252
  status: ToolStatusSchema.default("unknown"),
1252
1253
  version: zodOpenapi.z.string().optional(),
1253
1254
  createdAt: zodOpenapi.z.date(),
1254
- updatedAt: zodOpenapi.z.date()
1255
+ updatedAt: zodOpenapi.z.date(),
1256
+ expiresAt: zodOpenapi.z.date().optional()
1255
1257
  });
1256
1258
  McpToolSchema.omit({
1257
1259
  config: true,
@@ -1997,6 +1999,68 @@ var QUERY_DEFAULTS = {
1997
1999
  LIMIT_1000: 1e3,
1998
2000
  EMPTY_GROUP_BY: []
1999
2001
  };
2002
+ function discoverScopes(resourceMetadata, metadata) {
2003
+ const resourceScopes = resourceMetadata?.scopes_supported;
2004
+ const oauthScopes = metadata?.scopes_supported;
2005
+ const scopes = (resourceScopes?.length ? resourceScopes : oauthScopes) || [];
2006
+ return scopes.length > 0 ? scopes.join(" ") : void 0;
2007
+ }
2008
+ async function discoverMcpMetadata(mcpServerUrl, logger) {
2009
+ try {
2010
+ let resourceMetadata = null;
2011
+ let authServerUrl = new URL(mcpServerUrl);
2012
+ try {
2013
+ resourceMetadata = await auth_js.discoverOAuthProtectedResourceMetadata(mcpServerUrl);
2014
+ if (resourceMetadata?.authorization_servers?.length && resourceMetadata.authorization_servers[0]) {
2015
+ authServerUrl = new URL(resourceMetadata.authorization_servers[0]);
2016
+ }
2017
+ } catch {
2018
+ }
2019
+ const metadata = await auth_js.discoverAuthorizationServerMetadata(authServerUrl);
2020
+ if (!metadata) {
2021
+ throw new Error("Failed to discover OAuth authorization server metadata");
2022
+ }
2023
+ logger?.debug(
2024
+ {
2025
+ tokenEndpoint: metadata.token_endpoint,
2026
+ authEndpoint: metadata.authorization_endpoint
2027
+ },
2028
+ "MCP metadata discovery successful"
2029
+ );
2030
+ const discoveredScopes = discoverScopes(resourceMetadata ?? void 0, metadata);
2031
+ return {
2032
+ success: true,
2033
+ metadata,
2034
+ ...resourceMetadata && { resourceMetadata },
2035
+ ...discoveredScopes && { scopes: discoveredScopes }
2036
+ };
2037
+ } catch (err) {
2038
+ const errorMessage = err instanceof Error ? err.message : String(err);
2039
+ logger?.debug({ error: errorMessage }, "MCP metadata discovery failed");
2040
+ return { success: false, error: errorMessage };
2041
+ }
2042
+ }
2043
+ var detectAuthenticationRequired = async ({
2044
+ serverUrl,
2045
+ toolId,
2046
+ error,
2047
+ logger
2048
+ }) => {
2049
+ try {
2050
+ const discoveryResult = await discoverMcpMetadata(serverUrl, logger);
2051
+ if (discoveryResult.success && discoveryResult.metadata) {
2052
+ logger?.info({ toolId, serverUrl }, "MCP OAuth support confirmed via metadata discovery");
2053
+ return true;
2054
+ }
2055
+ } catch (discoveryError) {
2056
+ logger?.debug({ toolId, discoveryError }, "MCP OAuth metadata discovery failed");
2057
+ }
2058
+ logger?.debug(
2059
+ { toolId, error: error?.message },
2060
+ "No MCP OAuth authentication requirement detected"
2061
+ );
2062
+ return false;
2063
+ };
2000
2064
 
2001
2065
  // src/client-exports.ts
2002
2066
  var TenantParamsSchema2 = zod.z.object({
@@ -2221,6 +2285,7 @@ exports.TenantProjectParamsSchema = TenantProjectParamsSchema2;
2221
2285
  exports.ToolApiInsertSchema = ToolApiInsertSchema2;
2222
2286
  exports.UNKNOWN_VALUE = UNKNOWN_VALUE;
2223
2287
  exports.URL_SAFE_ID_PATTERN = URL_SAFE_ID_PATTERN2;
2288
+ exports.detectAuthenticationRequired = detectAuthenticationRequired;
2224
2289
  exports.generateIdFromName = generateIdFromName;
2225
2290
  exports.resourceIdSchema = resourceIdSchema2;
2226
2291
  exports.validatePropsAsJsonSchema = validatePropsAsJsonSchema;
@@ -1,8 +1,9 @@
1
- export { h as ACTIVITY_NAMES, f as ACTIVITY_STATUS, e as ACTIVITY_TYPES, g as AGENT_IDS, o as AGGREGATE_OPERATORS, A as AI_OPERATIONS, i as AI_TOOL_TYPES, n as DATA_SOURCES, j as DATA_TYPES, D as DELEGATION_FROM_SUB_AGENT_ID, b as DELEGATION_ID, a as DELEGATION_TO_SUB_AGENT_ID, F as FIELD_TYPES, O as OPERATORS, l as ORDER_DIRECTIONS, P as PANEL_TYPES, p as QUERY_DEFAULTS, k as QUERY_EXPRESSIONS, Q as QUERY_FIELD_CONFIGS, m as QUERY_TYPES, R as REDUCE_OPERATIONS, d as SPAN_KEYS, S as SPAN_NAMES, T as TRANSFER_FROM_SUB_AGENT_ID, c as TRANSFER_TO_SUB_AGENT_ID, U as UNKNOWN_VALUE } from './signoz-queries-Bqpkx5sK.cjs';
1
+ export { i as ACTIVITY_NAMES, g as ACTIVITY_STATUS, f as ACTIVITY_TYPES, h as AGENT_IDS, p as AGGREGATE_OPERATORS, A as AI_OPERATIONS, j as AI_TOOL_TYPES, o as DATA_SOURCES, k as DATA_TYPES, D as DELEGATION_FROM_SUB_AGENT_ID, b as DELEGATION_ID, a as DELEGATION_TO_SUB_AGENT_ID, F as FIELD_TYPES, O as OPERATORS, m as ORDER_DIRECTIONS, P as PANEL_TYPES, q as QUERY_DEFAULTS, l as QUERY_EXPRESSIONS, Q as QUERY_FIELD_CONFIGS, n as QUERY_TYPES, R as REDUCE_OPERATIONS, e as SPAN_KEYS, S as SPAN_NAMES, T as TRANSFER_FROM_SUB_AGENT_ID, c as TRANSFER_TO_SUB_AGENT_ID, U as UNKNOWN_VALUE, d as detectAuthenticationRequired } from './auth-detection-BO8bSpe4.cjs';
2
2
  import { z } from 'zod';
3
- import { C as ConversationHistoryConfig, F as FunctionApiInsertSchema, A as ApiKeyApiUpdateSchema, a as FullAgentAgentInsertSchema } from './utility-usOTNbMG.cjs';
4
- export { e as AgentStopWhen, b as AgentStopWhenSchema, h as CredentialStoreType, j as FunctionApiSelectSchema, k as FunctionApiUpdateSchema, i as MCPTransportType, g as ModelSettings, M as ModelSettingsSchema, d as StopWhen, S as StopWhenSchema, f as SubAgentStopWhen, c as SubAgentStopWhenSchema } from './utility-usOTNbMG.cjs';
3
+ import { C as ConversationHistoryConfig, F as FunctionApiInsertSchema, A as ApiKeyApiUpdateSchema, a as FullAgentAgentInsertSchema } from './utility-mGrlR4Ta.cjs';
4
+ export { e as AgentStopWhen, b as AgentStopWhenSchema, h as CredentialStoreType, j as FunctionApiSelectSchema, k as FunctionApiUpdateSchema, i as MCPTransportType, g as ModelSettings, M as ModelSettingsSchema, d as StopWhen, S as StopWhenSchema, f as SubAgentStopWhen, c as SubAgentStopWhenSchema } from './utility-mGrlR4Ta.cjs';
5
5
  export { v as validatePropsAsJsonSchema } from './props-validation-BMR1qNiy.cjs';
6
+ import 'pino';
6
7
  import 'drizzle-zod';
7
8
  import 'drizzle-orm/sqlite-core';
8
9
  import '@hono/zod-openapi';
@@ -1,8 +1,9 @@
1
- export { h as ACTIVITY_NAMES, f as ACTIVITY_STATUS, e as ACTIVITY_TYPES, g as AGENT_IDS, o as AGGREGATE_OPERATORS, A as AI_OPERATIONS, i as AI_TOOL_TYPES, n as DATA_SOURCES, j as DATA_TYPES, D as DELEGATION_FROM_SUB_AGENT_ID, b as DELEGATION_ID, a as DELEGATION_TO_SUB_AGENT_ID, F as FIELD_TYPES, O as OPERATORS, l as ORDER_DIRECTIONS, P as PANEL_TYPES, p as QUERY_DEFAULTS, k as QUERY_EXPRESSIONS, Q as QUERY_FIELD_CONFIGS, m as QUERY_TYPES, R as REDUCE_OPERATIONS, d as SPAN_KEYS, S as SPAN_NAMES, T as TRANSFER_FROM_SUB_AGENT_ID, c as TRANSFER_TO_SUB_AGENT_ID, U as UNKNOWN_VALUE } from './signoz-queries-Bqpkx5sK.js';
1
+ export { i as ACTIVITY_NAMES, g as ACTIVITY_STATUS, f as ACTIVITY_TYPES, h as AGENT_IDS, p as AGGREGATE_OPERATORS, A as AI_OPERATIONS, j as AI_TOOL_TYPES, o as DATA_SOURCES, k as DATA_TYPES, D as DELEGATION_FROM_SUB_AGENT_ID, b as DELEGATION_ID, a as DELEGATION_TO_SUB_AGENT_ID, F as FIELD_TYPES, O as OPERATORS, m as ORDER_DIRECTIONS, P as PANEL_TYPES, q as QUERY_DEFAULTS, l as QUERY_EXPRESSIONS, Q as QUERY_FIELD_CONFIGS, n as QUERY_TYPES, R as REDUCE_OPERATIONS, e as SPAN_KEYS, S as SPAN_NAMES, T as TRANSFER_FROM_SUB_AGENT_ID, c as TRANSFER_TO_SUB_AGENT_ID, U as UNKNOWN_VALUE, d as detectAuthenticationRequired } from './auth-detection-BO8bSpe4.js';
2
2
  import { z } from 'zod';
3
- import { C as ConversationHistoryConfig, F as FunctionApiInsertSchema, A as ApiKeyApiUpdateSchema, a as FullAgentAgentInsertSchema } from './utility-usOTNbMG.js';
4
- export { e as AgentStopWhen, b as AgentStopWhenSchema, h as CredentialStoreType, j as FunctionApiSelectSchema, k as FunctionApiUpdateSchema, i as MCPTransportType, g as ModelSettings, M as ModelSettingsSchema, d as StopWhen, S as StopWhenSchema, f as SubAgentStopWhen, c as SubAgentStopWhenSchema } from './utility-usOTNbMG.js';
3
+ import { C as ConversationHistoryConfig, F as FunctionApiInsertSchema, A as ApiKeyApiUpdateSchema, a as FullAgentAgentInsertSchema } from './utility-mGrlR4Ta.js';
4
+ export { e as AgentStopWhen, b as AgentStopWhenSchema, h as CredentialStoreType, j as FunctionApiSelectSchema, k as FunctionApiUpdateSchema, i as MCPTransportType, g as ModelSettings, M as ModelSettingsSchema, d as StopWhen, S as StopWhenSchema, f as SubAgentStopWhen, c as SubAgentStopWhenSchema } from './utility-mGrlR4Ta.js';
5
5
  export { v as validatePropsAsJsonSchema } from './props-validation-BMR1qNiy.js';
6
+ import 'pino';
6
7
  import 'drizzle-zod';
7
8
  import 'drizzle-orm/sqlite-core';
8
9
  import '@hono/zod-openapi';
@@ -1,6 +1,6 @@
1
- export { ACTIVITY_NAMES, ACTIVITY_STATUS, ACTIVITY_TYPES, AGENT_IDS, AGGREGATE_OPERATORS, AI_OPERATIONS, AI_TOOL_TYPES, DATA_SOURCES, DATA_TYPES, DELEGATION_FROM_SUB_AGENT_ID, DELEGATION_ID, DELEGATION_TO_SUB_AGENT_ID, FIELD_TYPES, OPERATORS, ORDER_DIRECTIONS, PANEL_TYPES, QUERY_DEFAULTS, QUERY_EXPRESSIONS, QUERY_FIELD_CONFIGS, QUERY_TYPES, REDUCE_OPERATIONS, SPAN_KEYS, SPAN_NAMES, TRANSFER_FROM_SUB_AGENT_ID, TRANSFER_TO_SUB_AGENT_ID, UNKNOWN_VALUE } from './chunk-QFIITHNT.js';
2
- import { ModelSettingsSchema, FullAgentAgentInsertSchema, ArtifactComponentApiInsertSchema } from './chunk-4SE2FOJY.js';
3
- export { AgentStopWhenSchema, FunctionApiInsertSchema, FunctionApiSelectSchema, FunctionApiUpdateSchema, ModelSettingsSchema, StopWhenSchema, SubAgentStopWhenSchema, validatePropsAsJsonSchema } from './chunk-4SE2FOJY.js';
1
+ export { ACTIVITY_NAMES, ACTIVITY_STATUS, ACTIVITY_TYPES, AGENT_IDS, AGGREGATE_OPERATORS, AI_OPERATIONS, AI_TOOL_TYPES, DATA_SOURCES, DATA_TYPES, DELEGATION_FROM_SUB_AGENT_ID, DELEGATION_ID, DELEGATION_TO_SUB_AGENT_ID, FIELD_TYPES, OPERATORS, ORDER_DIRECTIONS, PANEL_TYPES, QUERY_DEFAULTS, QUERY_EXPRESSIONS, QUERY_FIELD_CONFIGS, QUERY_TYPES, REDUCE_OPERATIONS, SPAN_KEYS, SPAN_NAMES, TRANSFER_FROM_SUB_AGENT_ID, TRANSFER_TO_SUB_AGENT_ID, UNKNOWN_VALUE, detectAuthenticationRequired } from './chunk-5GAUAB2P.js';
2
+ import { ModelSettingsSchema, FullAgentAgentInsertSchema, ArtifactComponentApiInsertSchema } from './chunk-HN77JIDP.js';
3
+ export { AgentStopWhenSchema, FunctionApiInsertSchema, FunctionApiSelectSchema, FunctionApiUpdateSchema, ModelSettingsSchema, StopWhenSchema, SubAgentStopWhenSchema, validatePropsAsJsonSchema } from './chunk-HN77JIDP.js';
4
4
  import { CredentialStoreType } from './chunk-YFHT5M2R.js';
5
5
  export { CredentialStoreType, MCPTransportType } from './chunk-YFHT5M2R.js';
6
6
  import { z } from 'zod';
@@ -1,7 +1,7 @@
1
1
  import 'drizzle-orm';
2
2
  import 'drizzle-orm/sqlite-core';
3
- import '../utility-usOTNbMG.cjs';
4
- export { E as agentRelations, H as agentToolRelationsRelations, a as agents, w as apiKeys, G as apiKeysRelations, j as artifactComponents, M as artifactComponentsRelations, b as contextCache, C as contextCacheRelations, c as contextConfigs, B as contextConfigsRelations, r as conversations, K as conversationsRelations, x as credentialReferences, I as credentialReferencesRelations, h as dataComponents, O as dataComponentsRelations, f as externalAgents, F as externalAgentsRelations, m as functionTools, T as functionToolsRelations, n as functions, R as functionsRelations, v as ledgerArtifacts, Q as ledgerArtifactsRelations, u as messages, L as messagesRelations, p as projects, z as projectsRelations, k as subAgentArtifactComponents, N as subAgentArtifactComponentsRelations, i as subAgentDataComponents, P as subAgentDataComponentsRelations, q as subAgentFunctionToolRelations, U as subAgentFunctionToolRelationsRelations, e as subAgentRelations, S as subAgentRelationsRelations, o as subAgentToolRelations, d as subAgents, D as subAgentsRelations, g as taskRelations, A as taskRelationsRelations, t as tasks, y as tasksRelations, l as tools, J as toolsRelations } from '../schema-HuJ7Qh0C.cjs';
3
+ import '../utility-mGrlR4Ta.cjs';
4
+ export { E as agentRelations, H as agentToolRelationsRelations, a as agents, w as apiKeys, G as apiKeysRelations, j as artifactComponents, M as artifactComponentsRelations, b as contextCache, C as contextCacheRelations, c as contextConfigs, B as contextConfigsRelations, r as conversations, K as conversationsRelations, x as credentialReferences, I as credentialReferencesRelations, h as dataComponents, O as dataComponentsRelations, f as externalAgents, F as externalAgentsRelations, m as functionTools, T as functionToolsRelations, n as functions, R as functionsRelations, v as ledgerArtifacts, Q as ledgerArtifactsRelations, u as messages, L as messagesRelations, p as projects, z as projectsRelations, k as subAgentArtifactComponents, N as subAgentArtifactComponentsRelations, i as subAgentDataComponents, P as subAgentDataComponentsRelations, q as subAgentFunctionToolRelations, U as subAgentFunctionToolRelationsRelations, e as subAgentRelations, S as subAgentRelationsRelations, o as subAgentToolRelations, d as subAgents, D as subAgentsRelations, g as taskRelations, A as taskRelationsRelations, t as tasks, y as tasksRelations, l as tools, J as toolsRelations } from '../schema-B8NMPwEM.cjs';
5
5
  import 'zod';
6
6
  import 'drizzle-zod';
7
7
  import '@hono/zod-openapi';