@inkeep/agents-core 0.0.0-dev-20260331194528 → 0.0.0-dev-20260331210432

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.
@@ -23,20 +23,45 @@ import "../../utils/index.js";
23
23
  import { isGithubWorkAppTool } from "../runtime/github-work-app-installations.js";
24
24
  import { getCredentialReference, getUserScopedCredentialReference } from "./credentialReferences.js";
25
25
  import { and, count, desc, eq } from "drizzle-orm";
26
+ import { UnauthorizedError } from "@modelcontextprotocol/sdk/client/auth.js";
27
+ import { StreamableHTTPError } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
26
28
  import { ErrorCode, McpError } from "@modelcontextprotocol/sdk/types.js";
27
29
 
28
30
  //#region src/data-access/manage/tools.ts
29
31
  /**
30
- * Check if an error is a timeout/connection error.
32
+ * Check if an error is a timeout/connection error (transient, not auth-related).
31
33
  * Uses MCP SDK ErrorCode for proper type safety.
32
34
  */
33
35
  function isTimeoutOrConnectionError(error) {
34
- if (error instanceof McpError) return error.code === ErrorCode.RequestTimeout || error.code === ErrorCode.ConnectionClosed;
36
+ if (error instanceof McpError) return error.code === ErrorCode.RequestTimeout || error.code === ErrorCode.ConnectionClosed || error.code === ErrorCode.InternalError;
37
+ if (error instanceof StreamableHTTPError) return error.code !== void 0 && error.code >= 500;
35
38
  if (error instanceof Error) {
36
39
  const message = error.message.toLowerCase();
37
40
  const cause = error.cause;
38
- if (message.includes("timed out") || message.includes("timeout")) return true;
39
- if (cause?.code === "ETIMEDOUT" || cause?.code === "ECONNABORTED" || cause?.code === "ECONNRESET") return true;
41
+ if (message.includes("timed out") || message.includes("timeout") || message.includes("fetch failed")) return true;
42
+ if (cause?.code && [
43
+ "ETIMEDOUT",
44
+ "ECONNABORTED",
45
+ "ECONNRESET",
46
+ "ECONNREFUSED",
47
+ "ENOTFOUND",
48
+ "EHOSTUNREACH",
49
+ "ENETUNREACH",
50
+ "EPIPE"
51
+ ].includes(cause.code)) return true;
52
+ }
53
+ return false;
54
+ }
55
+ /**
56
+ * Check if an error indicates the credential is invalid/expired/revoked.
57
+ * These errors mean the user genuinely needs to re-authenticate.
58
+ */
59
+ function isAuthenticationError(error) {
60
+ if (error instanceof UnauthorizedError) return true;
61
+ if (error instanceof StreamableHTTPError) return error.code === 401 || error.code === 403;
62
+ if (error instanceof Error) {
63
+ const message = error.message.toLowerCase();
64
+ if (message.includes("unauthorized") || message.includes("forbidden") || message.includes("invalid_token") || message.includes("token expired") || message.includes("invalid_grant")) return true;
40
65
  }
41
66
  return false;
42
67
  }
@@ -243,6 +268,18 @@ const dbResultToMcpTool = async (dbResult, dbClient, credentialStoreRegistry, re
243
268
  if (isTimeoutOrConnectionError(error)) {
244
269
  status = "unavailable";
245
270
  lastErrorComputed = `Connection failed - the MCP server may be slow or temporarily unreachable.${error instanceof McpError ? ` (MCP error ${error.code})` : ""} ${errorMessage}`;
271
+ } else if (isAuthenticationError(error)) {
272
+ status = "needs_auth";
273
+ lastErrorComputed = `Authentication required - OAuth login needed. ${errorMessage}`;
274
+ } else if (credentialReference) {
275
+ logger.warn({
276
+ toolId: dbResult.id,
277
+ credentialId: credentialReference.id,
278
+ errorCode: error instanceof McpError ? error.code : void 0,
279
+ errorMessage
280
+ }, "MCP server discovery failed with existing credential — treating as transient");
281
+ status = "unavailable";
282
+ lastErrorComputed = `Server temporarily unavailable. ${errorMessage}`;
246
283
  } else {
247
284
  const toolNeedsAuth = await detectAuthenticationRequired({
248
285
  serverUrl: mcpServerUrl,
@@ -12,10 +12,10 @@ declare const getApiKeyById: (db: AgentsRunDatabaseClient) => (params: {
12
12
  name: string | null;
13
13
  createdAt: string;
14
14
  updatedAt: string;
15
- projectId: string;
15
+ expiresAt: string | null;
16
16
  tenantId: string;
17
17
  agentId: string;
18
- expiresAt: string | null;
18
+ projectId: string;
19
19
  publicId: string;
20
20
  keyHash: string;
21
21
  keyPrefix: string;
@@ -26,10 +26,10 @@ declare const getApiKeyByPublicId: (db: AgentsRunDatabaseClient) => (publicId: s
26
26
  name: string | null;
27
27
  createdAt: string;
28
28
  updatedAt: string;
29
- projectId: string;
29
+ expiresAt: string | null;
30
30
  tenantId: string;
31
31
  agentId: string;
32
- expiresAt: string | null;
32
+ projectId: string;
33
33
  publicId: string;
34
34
  keyHash: string;
35
35
  keyPrefix: string;
@@ -43,10 +43,10 @@ declare const listApiKeys: (db: AgentsRunDatabaseClient) => (params: {
43
43
  name: string | null;
44
44
  createdAt: string;
45
45
  updatedAt: string;
46
- projectId: string;
46
+ expiresAt: string | null;
47
47
  tenantId: string;
48
48
  agentId: string;
49
- expiresAt: string | null;
49
+ projectId: string;
50
50
  publicId: string;
51
51
  keyHash: string;
52
52
  keyPrefix: string;
@@ -70,10 +70,10 @@ declare const createApiKey: (db: AgentsRunDatabaseClient) => (params: ApiKeyInse
70
70
  name: string | null;
71
71
  createdAt: string;
72
72
  updatedAt: string;
73
- projectId: string;
73
+ expiresAt: string | null;
74
74
  tenantId: string;
75
75
  agentId: string;
76
- expiresAt: string | null;
76
+ projectId: string;
77
77
  publicId: string;
78
78
  keyHash: string;
79
79
  keyPrefix: string;
@@ -8,11 +8,11 @@ declare const getAppById: (db: AgentsRunDatabaseClient) => (id: string) => Promi
8
8
  type: AppType;
9
9
  id: string;
10
10
  name: string;
11
- description: string | null;
12
11
  createdAt: string;
13
12
  updatedAt: string;
14
- projectId: string | null;
15
13
  tenantId: string | null;
14
+ description: string | null;
15
+ projectId: string | null;
16
16
  lastUsedAt: string | null;
17
17
  defaultProjectId: string | null;
18
18
  defaultAgentId: string | null;
@@ -67,11 +67,11 @@ declare const createApp: (db: AgentsRunDatabaseClient) => (params: AppInsert) =>
67
67
  type: AppType;
68
68
  id: string;
69
69
  name: string;
70
- description: string | null;
71
70
  createdAt: string;
72
71
  updatedAt: string;
73
- projectId: string | null;
74
72
  tenantId: string | null;
73
+ description: string | null;
74
+ projectId: string | null;
75
75
  lastUsedAt: string | null;
76
76
  defaultProjectId: string | null;
77
77
  defaultAgentId: string | null;
@@ -21,16 +21,16 @@ declare const createConversation: (db: AgentsRunDatabaseClient) => (params: Conv
21
21
  name: string;
22
22
  hash: string;
23
23
  } | null;
24
- title: string | null;
25
24
  createdAt: string;
26
25
  updatedAt: string;
27
- projectId: string;
28
- tenantId: string;
29
26
  userId: string | null;
27
+ metadata: ConversationMetadata | null;
28
+ tenantId: string;
30
29
  agentId: string | null;
31
30
  activeSubAgentId: string;
31
+ title: string | null;
32
32
  lastContextResolution: string | null;
33
- metadata: ConversationMetadata | null;
33
+ projectId: string;
34
34
  }>;
35
35
  declare const updateConversation: (db: AgentsRunDatabaseClient) => (params: {
36
36
  scopes: ProjectScopeConfig;
@@ -90,16 +90,16 @@ declare const getConversation: (db: AgentsRunDatabaseClient) => (params: {
90
90
  name: string;
91
91
  hash: string;
92
92
  } | null;
93
- title: string | null;
94
93
  createdAt: string;
95
94
  updatedAt: string;
96
- projectId: string;
97
- tenantId: string;
98
95
  userId: string | null;
96
+ metadata: ConversationMetadata | null;
97
+ tenantId: string;
99
98
  agentId: string | null;
100
99
  activeSubAgentId: string;
100
+ title: string | null;
101
101
  lastContextResolution: string | null;
102
- metadata: ConversationMetadata | null;
102
+ projectId: string;
103
103
  } | undefined>;
104
104
  declare const createOrGetConversation: (db: AgentsRunDatabaseClient) => (input: ConversationInsert) => Promise<{
105
105
  activeSubAgentId: string;
@@ -126,16 +126,16 @@ declare const createOrGetConversation: (db: AgentsRunDatabaseClient) => (input:
126
126
  name: string;
127
127
  hash: string;
128
128
  } | null;
129
- title: string | null;
130
129
  createdAt: string;
131
130
  updatedAt: string;
132
- projectId: string;
133
- tenantId: string;
134
131
  userId: string | null;
132
+ metadata: ConversationMetadata | null;
133
+ tenantId: string;
135
134
  agentId: string | null;
136
135
  activeSubAgentId: string;
136
+ title: string | null;
137
137
  lastContextResolution: string | null;
138
- metadata: ConversationMetadata | null;
138
+ projectId: string;
139
139
  }>;
140
140
  /**
141
141
  * Get conversation history with filtering and context management
@@ -158,16 +158,16 @@ declare const getActiveAgentForConversation: (db: AgentsRunDatabaseClient) => (p
158
158
  name: string;
159
159
  hash: string;
160
160
  } | null;
161
- title: string | null;
162
161
  createdAt: string;
163
162
  updatedAt: string;
164
- projectId: string;
165
- tenantId: string;
166
163
  userId: string | null;
164
+ metadata: ConversationMetadata | null;
165
+ tenantId: string;
167
166
  agentId: string | null;
168
167
  activeSubAgentId: string;
168
+ title: string | null;
169
169
  lastContextResolution: string | null;
170
- metadata: ConversationMetadata | null;
170
+ projectId: string;
171
171
  } | undefined>;
172
172
  /**
173
173
  * Set active agent for a conversation (upsert operation)
@@ -11,20 +11,20 @@ declare const getMessageById: (db: AgentsRunDatabaseClient) => (params: {
11
11
  messageId: string;
12
12
  }) => Promise<{
13
13
  id: string;
14
- conversationId: string;
15
14
  createdAt: string;
16
15
  updatedAt: string;
17
- projectId: string;
18
- tenantId: string;
19
16
  metadata: MessageMetadata | null;
20
- content: MessageContent;
21
17
  role: string;
18
+ tenantId: string;
19
+ projectId: string;
20
+ conversationId: string;
22
21
  fromSubAgentId: string | null;
23
22
  toSubAgentId: string | null;
24
23
  fromExternalAgentId: string | null;
25
24
  toExternalAgentId: string | null;
26
25
  fromTeamAgentId: string | null;
27
26
  toTeamAgentId: string | null;
27
+ content: MessageContent;
28
28
  visibility: string;
29
29
  messageType: string;
30
30
  taskId: string | null;
@@ -145,20 +145,20 @@ declare const createMessage: (db: AgentsRunDatabaseClient) => (params: {
145
145
  data: Omit<MessageInsert, "tenantId" | "projectId">;
146
146
  }) => Promise<{
147
147
  id: string;
148
- conversationId: string;
149
148
  createdAt: string;
150
149
  updatedAt: string;
151
- projectId: string;
152
- tenantId: string;
153
150
  metadata: MessageMetadata | null;
154
- content: MessageContent;
155
151
  role: string;
152
+ tenantId: string;
153
+ projectId: string;
154
+ conversationId: string;
156
155
  fromSubAgentId: string | null;
157
156
  toSubAgentId: string | null;
158
157
  fromExternalAgentId: string | null;
159
158
  toExternalAgentId: string | null;
160
159
  fromTeamAgentId: string | null;
161
160
  toTeamAgentId: string | null;
161
+ content: MessageContent;
162
162
  visibility: string;
163
163
  messageType: string;
164
164
  taskId: string | null;
@@ -198,20 +198,20 @@ declare const deleteMessage: (db: AgentsRunDatabaseClient) => (params: {
198
198
  messageId: string;
199
199
  }) => Promise<{
200
200
  id: string;
201
- conversationId: string;
202
201
  createdAt: string;
203
202
  updatedAt: string;
204
- projectId: string;
205
- tenantId: string;
206
203
  metadata: MessageMetadata | null;
207
- content: MessageContent;
208
204
  role: string;
205
+ tenantId: string;
206
+ projectId: string;
207
+ conversationId: string;
209
208
  fromSubAgentId: string | null;
210
209
  toSubAgentId: string | null;
211
210
  fromExternalAgentId: string | null;
212
211
  toExternalAgentId: string | null;
213
212
  fromTeamAgentId: string | null;
214
213
  toTeamAgentId: string | null;
214
+ content: MessageContent;
215
215
  visibility: string;
216
216
  messageType: string;
217
217
  taskId: string | null;
@@ -15,13 +15,13 @@ declare const createTask: (db: AgentsRunDatabaseClient) => (params: TaskInsert)
15
15
  } | null;
16
16
  createdAt: string;
17
17
  updatedAt: string;
18
- projectId: string;
19
- tenantId: string;
20
- agentId: string;
21
18
  metadata: TaskMetadataConfig | null;
22
- subAgentId: string;
23
19
  status: string;
20
+ tenantId: string;
21
+ agentId: string;
22
+ projectId: string;
24
23
  contextId: string;
24
+ subAgentId: string;
25
25
  }>;
26
26
  declare const getTask: (db: AgentsRunDatabaseClient) => (params: {
27
27
  id: string;
@@ -1,7 +1,7 @@
1
1
  import { MCPTransportType } from "../types/utility.js";
2
+ import { StreamableHTTPClientTransportOptions } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
2
3
  import { ClientCapabilities } from "@modelcontextprotocol/sdk/types.js";
3
4
  import { SSEClientTransportOptions } from "@modelcontextprotocol/sdk/client/sse.js";
4
- import { StreamableHTTPClientTransportOptions } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
5
5
 
6
6
  //#region src/utils/mcp-client.d.ts
7
7
  declare const activeMcpClients: Set<McpClient>;
@@ -1,10 +1,10 @@
1
1
  import { MCPTransportType } from "../types/utility.js";
2
2
  import { MCP_TOOL_CONNECTION_TIMEOUT_MS, MCP_TOOL_INITIAL_RECONNECTION_DELAY_MS, MCP_TOOL_MAX_RECONNECTION_DELAY_MS, MCP_TOOL_MAX_RETRIES, MCP_TOOL_RECONNECTION_DELAY_GROWTH_FACTOR } from "../constants/execution-limits-shared/index.js";
3
3
  import { z } from "@hono/zod-openapi";
4
+ import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
4
5
  import { CallToolResultSchema } from "@modelcontextprotocol/sdk/types.js";
5
6
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
6
7
  import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
7
- import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
8
8
  import { DEFAULT_REQUEST_TIMEOUT_MSEC } from "@modelcontextprotocol/sdk/shared/protocol.js";
9
9
  import { tool } from "ai";
10
10
  import { asyncExitHook } from "exit-hook";
@@ -1,10 +1,10 @@
1
1
  import { z } from "@hono/zod-openapi";
2
- import * as drizzle_zod1 from "drizzle-zod";
2
+ import * as drizzle_zod365 from "drizzle-zod";
3
3
  import { AnySQLiteTable } from "drizzle-orm/sqlite-core";
4
4
 
5
5
  //#region src/validation/drizzle-schema-helpers.d.ts
6
- declare function createSelectSchemaWithModifiers<T extends AnySQLiteTable>(table: T, overrides?: Partial<Record<keyof T['_']['columns'], (schema: z.ZodTypeAny) => z.ZodTypeAny>>): drizzle_zod1.BuildSchema<"select", T["_"]["columns"], drizzle_zod1.BuildRefine<T["_"]["columns"], undefined>, undefined>;
7
- declare function createInsertSchemaWithModifiers<T extends AnySQLiteTable>(table: T, overrides?: Partial<Record<keyof T['_']['columns'], (schema: z.ZodTypeAny) => z.ZodTypeAny>>): drizzle_zod1.BuildSchema<"insert", T["_"]["columns"], drizzle_zod1.BuildRefine<Pick<T["_"]["columns"], keyof T["$inferInsert"]>, undefined>, undefined>;
6
+ declare function createSelectSchemaWithModifiers<T extends AnySQLiteTable>(table: T, overrides?: Partial<Record<keyof T['_']['columns'], (schema: z.ZodTypeAny) => z.ZodTypeAny>>): drizzle_zod365.BuildSchema<"select", T["_"]["columns"], drizzle_zod365.BuildRefine<T["_"]["columns"], undefined>, undefined>;
7
+ declare function createInsertSchemaWithModifiers<T extends AnySQLiteTable>(table: T, overrides?: Partial<Record<keyof T['_']['columns'], (schema: z.ZodTypeAny) => z.ZodTypeAny>>): drizzle_zod365.BuildSchema<"insert", T["_"]["columns"], drizzle_zod365.BuildRefine<Pick<T["_"]["columns"], keyof T["$inferInsert"]>, undefined>, undefined>;
8
8
  declare const createSelectSchema: typeof createSelectSchemaWithModifiers;
9
9
  declare const createInsertSchema: typeof createInsertSchemaWithModifiers;
10
10
  /**
@@ -337,8 +337,8 @@ declare const SkillFileInsertSchema: z.ZodObject<{
337
337
  }>;
338
338
  declare const SkillInsertSchema: z.ZodObject<{
339
339
  name: z.ZodString;
340
- description: z.ZodString;
341
340
  metadata: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodString>>>;
341
+ description: z.ZodString;
342
342
  content: z.ZodString;
343
343
  }, {
344
344
  out: {};
@@ -353,10 +353,10 @@ declare const SkillUpdateSchema: z.ZodObject<{
353
353
  declare const SkillApiSelectSchema: z.ZodObject<{
354
354
  id: z.ZodString;
355
355
  name: z.ZodString;
356
- description: z.ZodString;
357
356
  createdAt: z.ZodString;
358
357
  updatedAt: z.ZodString;
359
358
  metadata: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodString>>;
359
+ description: z.ZodString;
360
360
  content: z.ZodString;
361
361
  }, z.core.$strip>;
362
362
  declare const SkillApiInsertSchema: z.ZodPipe<z.ZodPipe<z.ZodObject<{
@@ -426,10 +426,10 @@ declare const SkillFileApiUpdateSchema: z.ZodObject<{
426
426
  declare const SkillWithFilesApiSelectSchema: z.ZodObject<{
427
427
  id: z.ZodString;
428
428
  name: z.ZodString;
429
- description: z.ZodString;
430
429
  createdAt: z.ZodString;
431
430
  updatedAt: z.ZodString;
432
431
  metadata: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodString>>;
432
+ description: z.ZodString;
433
433
  content: z.ZodString;
434
434
  files: z.ZodArray<z.ZodObject<{
435
435
  id: z.ZodString;
@@ -516,10 +516,10 @@ declare const SubAgentSkillApiUpdateSchema: z.ZodObject<{
516
516
  declare const SubAgentSkillWithIndexSchema: z.ZodObject<{
517
517
  id: z.ZodString;
518
518
  name: z.ZodString;
519
- description: z.ZodString;
520
519
  createdAt: z.ZodString;
521
520
  updatedAt: z.ZodString;
522
521
  metadata: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodString>>;
522
+ description: z.ZodString;
523
523
  content: z.ZodString;
524
524
  subAgentSkillId: z.ZodString;
525
525
  subAgentId: z.ZodString;
@@ -540,10 +540,10 @@ declare const SkillWithFilesResponse: z.ZodObject<{
540
540
  data: z.ZodObject<{
541
541
  id: z.ZodString;
542
542
  name: z.ZodString;
543
- description: z.ZodString;
544
543
  createdAt: z.ZodString;
545
544
  updatedAt: z.ZodString;
546
545
  metadata: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodString>>;
546
+ description: z.ZodString;
547
547
  content: z.ZodString;
548
548
  files: z.ZodArray<z.ZodObject<{
549
549
  id: z.ZodString;
@@ -559,10 +559,10 @@ declare const SkillListResponse: z.ZodObject<{
559
559
  data: z.ZodArray<z.ZodObject<{
560
560
  id: z.ZodString;
561
561
  name: z.ZodString;
562
- description: z.ZodString;
563
562
  createdAt: z.ZodString;
564
563
  updatedAt: z.ZodString;
565
564
  metadata: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodString>>;
565
+ description: z.ZodString;
566
566
  content: z.ZodString;
567
567
  }, z.core.$strip>>;
568
568
  pagination: z.ZodObject<{
@@ -587,10 +587,10 @@ declare const SubAgentSkillWithIndexArrayResponse: z.ZodObject<{
587
587
  data: z.ZodArray<z.ZodObject<{
588
588
  id: z.ZodString;
589
589
  name: z.ZodString;
590
- description: z.ZodString;
591
590
  createdAt: z.ZodString;
592
591
  updatedAt: z.ZodString;
593
592
  metadata: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodString>>;
593
+ description: z.ZodString;
594
594
  content: z.ZodString;
595
595
  subAgentSkillId: z.ZodString;
596
596
  subAgentId: z.ZodString;