@inkeep/agents-run-api 0.0.0-dev-20260106234559 → 0.0.0-dev-20260107043750

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.
@@ -50,6 +50,13 @@ async function handleMessageSend(c, agent, request) {
50
50
  try {
51
51
  const params = request.params;
52
52
  const { agentId } = getRequestExecutionContext(c);
53
+ const forwardedHeaders = {};
54
+ const xForwardedCookie = c.req.header("x-forwarded-cookie");
55
+ const authorization = c.req.header("authorization");
56
+ const cookie = c.req.header("cookie");
57
+ if (xForwardedCookie) forwardedHeaders["x-forwarded-cookie"] = xForwardedCookie;
58
+ else if (cookie) forwardedHeaders["x-forwarded-cookie"] = cookie;
59
+ if (authorization) forwardedHeaders.authorization = authorization;
53
60
  const task = {
54
61
  id: generateId(),
55
62
  input: { parts: params.message.parts.map((part) => ({
@@ -62,7 +69,8 @@ async function handleMessageSend(c, agent, request) {
62
69
  metadata: {
63
70
  blocking: params.configuration?.blocking ?? false,
64
71
  custom: { agent_id: agentId || "" },
65
- ...params.message.metadata
72
+ ...params.message.metadata,
73
+ forwardedHeaders: Object.keys(forwardedHeaders).length > 0 ? forwardedHeaders : void 0
66
74
  }
67
75
  }
68
76
  };
@@ -297,6 +305,13 @@ async function handleMessageStream(c, agent, request) {
297
305
  },
298
306
  id: request.id
299
307
  });
308
+ const forwardedHeaders = {};
309
+ const xForwardedCookie = c.req.header("x-forwarded-cookie");
310
+ const authorization = c.req.header("authorization");
311
+ const cookie = c.req.header("cookie");
312
+ if (xForwardedCookie) forwardedHeaders["x-forwarded-cookie"] = xForwardedCookie;
313
+ else if (cookie) forwardedHeaders["x-forwarded-cookie"] = cookie;
314
+ if (authorization) forwardedHeaders.authorization = authorization;
300
315
  const task = {
301
316
  id: generateId(),
302
317
  input: { parts: params.message.parts.map((part) => ({
@@ -308,7 +323,8 @@ async function handleMessageStream(c, agent, request) {
308
323
  conversationId: params.message.contextId,
309
324
  metadata: {
310
325
  blocking: false,
311
- custom: { agent_id: agentId || "" }
326
+ custom: { agent_id: agentId || "" },
327
+ forwardedHeaders: Object.keys(forwardedHeaders).length > 0 ? forwardedHeaders : void 0
312
328
  }
313
329
  }
314
330
  };
@@ -48,6 +48,8 @@ type AgentConfig = {
48
48
  sandboxConfig?: SandboxConfig;
49
49
  /** User ID for user-scoped credential lookup (from temp JWT) */
50
50
  userId?: string;
51
+ /** Headers to forward to MCP servers (e.g., x-forwarded-cookie for user session auth) */
52
+ forwardedHeaders?: Record<string, string>;
51
53
  };
52
54
  type ExternalAgentRelationConfig = {
53
55
  relationId: string;
@@ -539,7 +539,8 @@ var Agent = class {
539
539
  };
540
540
  }
541
541
  async getMcpTool(tool$1) {
542
- const cacheKey = `${this.config.tenantId}-${this.config.projectId}-${tool$1.id}-${tool$1.credentialReferenceId || "no-cred"}`;
542
+ const forwardedHeadersHash = this.config.forwardedHeaders ? Object.keys(this.config.forwardedHeaders).sort().join(",") : "no-fwd";
543
+ const cacheKey = `${this.config.tenantId}-${this.config.projectId}-${tool$1.id}-${tool$1.credentialReferenceId || "no-cred"}-${forwardedHeadersHash}`;
543
544
  const credentialReferenceId = tool$1.credentialReferenceId;
544
545
  const toolRelation = (await getToolsForAgent(dbClient_default)({ scopes: {
545
546
  tenantId: this.config.tenantId,
@@ -626,11 +627,16 @@ var Agent = class {
626
627
  else urlObj.searchParams.set("user_id", `${this.config.tenantId}||${this.config.projectId}`);
627
628
  serverConfig.url = urlObj.toString();
628
629
  }
630
+ if (this.config.forwardedHeaders && Object.keys(this.config.forwardedHeaders).length > 0) serverConfig.headers = {
631
+ ...serverConfig.headers,
632
+ ...this.config.forwardedHeaders
633
+ };
629
634
  logger.info({
630
635
  toolName: tool$1.name,
631
636
  credentialReferenceId,
632
637
  transportType: serverConfig.type,
633
- headers: tool$1.headers
638
+ headers: tool$1.headers,
639
+ hasForwardedHeaders: !!this.config.forwardedHeaders
634
640
  }, "Built MCP server config with credentials");
635
641
  let client = this.mcpClientCache.get(cacheKey);
636
642
  if (client && !client.isConnected()) {
@@ -21,6 +21,7 @@ const createTaskHandler = (config, credentialStoreRegistry) => {
21
21
  },
22
22
  artifacts: []
23
23
  };
24
+ const forwardedHeaders = task.context?.metadata?.forwardedHeaders;
24
25
  const [internalRelations, externalRelations, teamRelations, toolsForAgent, dataComponents, artifactComponents] = await Promise.all([
25
26
  getRelatedAgentsForAgent(dbClient_default)({
26
27
  scopes: {
@@ -322,7 +323,8 @@ const createTaskHandler = (config, credentialStoreRegistry) => {
322
323
  artifactComponents,
323
324
  contextConfigId: config.contextConfigId || void 0,
324
325
  conversationHistoryConfig: config.conversationHistoryConfig,
325
- sandboxConfig: config.sandboxConfig
326
+ sandboxConfig: config.sandboxConfig,
327
+ forwardedHeaders
326
328
  }, credentialStoreRegistry);
327
329
  const artifactStreamRequestId = task.context?.metadata?.streamRequestId;
328
330
  if (artifactStreamRequestId && artifactComponents.length > 0) agentSessionManager.updateArtifactComponents(artifactStreamRequestId, artifactComponents);
@@ -10,6 +10,8 @@ interface ExecutionHandlerParams {
10
10
  requestId: string;
11
11
  sseHelper: StreamHelper;
12
12
  emitOperations?: boolean;
13
+ /** Headers to forward to MCP servers (e.g., x-forwarded-cookie for auth) */
14
+ forwardedHeaders?: Record<string, string>;
13
15
  }
14
16
  interface ExecutionResult {
15
17
  success: boolean;
@@ -32,7 +32,7 @@ var ExecutionHandler = class {
32
32
  * @returns
33
33
  */
34
34
  async execute(params) {
35
- const { executionContext, conversationId, userMessage, initialAgentId, requestId, sseHelper, emitOperations } = params;
35
+ const { executionContext, conversationId, userMessage, initialAgentId, requestId, sseHelper, emitOperations, forwardedHeaders } = params;
36
36
  const { tenantId, projectId, agentId, apiKey, baseUrl } = executionContext;
37
37
  registerStreamHelper(requestId, sseHelper);
38
38
  agentSessionManager.createSession(requestId, agentId, tenantId, projectId, conversationId);
@@ -177,7 +177,8 @@ var ExecutionHandler = class {
177
177
  "x-inkeep-tenant-id": tenantId,
178
178
  "x-inkeep-project-id": projectId,
179
179
  "x-inkeep-agent-id": agentId,
180
- "x-inkeep-sub-agent-id": currentAgentId
180
+ "x-inkeep-sub-agent-id": currentAgentId,
181
+ ...forwardedHeaders || {}
181
182
  } });
182
183
  let messageResponse = null;
183
184
  const messageMetadata = { stream_request_id: requestId };
@@ -250,6 +250,13 @@ app.openapi(chatCompletionsRoute, async (c) => {
250
250
  await sseHelper.writeRole();
251
251
  logger.info({ subAgentId }, "Starting execution");
252
252
  const emitOperations = c.req.header("x-emit-operations") === "true";
253
+ const forwardedHeaders = {};
254
+ const xForwardedCookie = c.req.header("x-forwarded-cookie");
255
+ const authorization = c.req.header("authorization");
256
+ const cookie = c.req.header("cookie");
257
+ if (xForwardedCookie) forwardedHeaders["x-forwarded-cookie"] = xForwardedCookie;
258
+ else if (cookie) forwardedHeaders["x-forwarded-cookie"] = cookie;
259
+ if (authorization) forwardedHeaders.authorization = authorization;
253
260
  const result = await new ExecutionHandler().execute({
254
261
  executionContext,
255
262
  conversationId,
@@ -257,7 +264,8 @@ app.openapi(chatCompletionsRoute, async (c) => {
257
264
  initialAgentId: subAgentId,
258
265
  requestId,
259
266
  sseHelper,
260
- emitOperations
267
+ emitOperations,
268
+ forwardedHeaders
261
269
  });
262
270
  logger.info({ result }, `Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`);
263
271
  if (!result.success) await sseHelper.writeOperation(errorOp("Sorry, I was unable to process your request at this time. Please try again.", "system"));
@@ -75,6 +75,13 @@ app.openapi(chatDataStreamRoute, async (c) => {
75
75
  const targetTenantId = c.req.header("x-target-tenant-id");
76
76
  const targetProjectId = c.req.header("x-target-project-id");
77
77
  const targetAgentId = c.req.header("x-target-agent-id");
78
+ const forwardedHeaders = {};
79
+ const xForwardedCookie = c.req.header("x-forwarded-cookie");
80
+ const authorization = c.req.header("authorization");
81
+ const cookie = c.req.header("cookie");
82
+ if (xForwardedCookie) forwardedHeaders["x-forwarded-cookie"] = xForwardedCookie;
83
+ else if (cookie) forwardedHeaders["x-forwarded-cookie"] = cookie;
84
+ if (authorization) forwardedHeaders.authorization = authorization;
78
85
  const activeSpan = trace.getActiveSpan();
79
86
  if (activeSpan) activeSpan.setAttributes({
80
87
  "conversation.id": conversationId,
@@ -183,7 +190,8 @@ app.openapi(chatDataStreamRoute, async (c) => {
183
190
  initialAgentId: subAgentId,
184
191
  requestId: `chat-${Date.now()}`,
185
192
  sseHelper: bufferingHelper,
186
- emitOperations
193
+ emitOperations,
194
+ forwardedHeaders
187
195
  });
188
196
  const captured = bufferingHelper.getCapturedResponse();
189
197
  return c.json({
@@ -217,7 +225,8 @@ app.openapi(chatDataStreamRoute, async (c) => {
217
225
  initialAgentId: subAgentId,
218
226
  requestId: `chatds-${Date.now()}`,
219
227
  sseHelper: streamHelper,
220
- emitOperations
228
+ emitOperations,
229
+ forwardedHeaders
221
230
  })).success) await streamHelper.writeOperation(errorOp("Unable to process request", "system"));
222
231
  } catch (err) {
223
232
  logger.error({ err }, "Streaming error");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkeep/agents-run-api",
3
- "version": "0.0.0-dev-20260106234559",
3
+ "version": "0.0.0-dev-20260107043750",
4
4
  "description": "Agents Run API for Inkeep Agent Framework - handles chat, agent execution, and streaming",
5
5
  "types": "dist/index.d.ts",
6
6
  "exports": {
@@ -41,7 +41,7 @@
41
41
  "hono": "^4.10.4",
42
42
  "jmespath": "^0.16.0",
43
43
  "llm-info": "^1.0.69",
44
- "@inkeep/agents-core": "^0.0.0-dev-20260106234559"
44
+ "@inkeep/agents-core": "^0.0.0-dev-20260107043750"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@hono/zod-openapi": "^1.1.5",