@inkeep/agents-manage-api 0.6.6 → 0.7.0

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 (3) hide show
  1. package/dist/index.cjs +66 -623
  2. package/dist/index.js +67 -624
  3. package/package.json +2 -2
package/dist/index.cjs CHANGED
@@ -1469,45 +1469,6 @@ app6.openapi(
1469
1469
  return c.json({ data: agentToolRelation });
1470
1470
  }
1471
1471
  );
1472
- app6.openapi(
1473
- zodOpenapi.createRoute({
1474
- method: "get",
1475
- path: "/agent/{agentId}/tools",
1476
- summary: "Get Tools for Agent",
1477
- operationId: "get-tools-for-agent",
1478
- tags: ["Agent Tool Relations"],
1479
- request: {
1480
- params: agentsCore.TenantProjectGraphParamsSchema.extend({
1481
- agentId: zod.z.string()
1482
- }),
1483
- query: agentsCore.PaginationQueryParamsSchema
1484
- },
1485
- responses: {
1486
- 200: {
1487
- description: "Tools for agent retrieved successfully",
1488
- content: {
1489
- "application/json": {
1490
- schema: agentsCore.ListResponseSchema(agentsCore.AgentToolRelationApiSelectSchema)
1491
- }
1492
- }
1493
- },
1494
- ...agentsCore.commonGetErrorResponses
1495
- }
1496
- }),
1497
- async (c) => {
1498
- const { tenantId, projectId, graphId, agentId } = c.req.valid("param");
1499
- const { page, limit } = c.req.valid("query");
1500
- const dbResult = await agentsCore.getToolsForAgent(dbClient_default)({
1501
- scopes: { tenantId, projectId, graphId, agentId },
1502
- pagination: { page, limit }
1503
- });
1504
- const result = {
1505
- data: dbResult.data,
1506
- pagination: dbResult.pagination
1507
- };
1508
- return c.json(result);
1509
- }
1510
- );
1511
1472
  app6.openapi(
1512
1473
  zodOpenapi.createRoute({
1513
1474
  method: "get",
@@ -3504,274 +3465,7 @@ app14.openapi(
3504
3465
  }
3505
3466
  );
3506
3467
  var projects_default = app14;
3507
- function extractInputSchema(toolDef) {
3508
- if (toolDef.inputSchema) {
3509
- return toolDef.inputSchema;
3510
- }
3511
- if (toolDef.parameters?.properties) {
3512
- return toolDef.parameters.properties;
3513
- }
3514
- if (toolDef.parameters && typeof toolDef.parameters === "object") {
3515
- return toolDef.parameters;
3516
- }
3517
- if (toolDef.schema) {
3518
- return toolDef.schema;
3519
- }
3520
- return {};
3521
- }
3522
- var logger3 = agentsCore.getLogger("tools");
3523
- var convertToMCPToolConfig = (tool) => {
3524
- return {
3525
- id: tool.id,
3526
- name: tool.name,
3527
- description: tool.name,
3528
- // Use name as description fallback
3529
- serverUrl: tool.config.mcp.server.url,
3530
- mcpType: tool.config.mcp.server.url.includes("api.nango.dev") ? agentsCore.MCPServerType.nango : agentsCore.MCPServerType.generic,
3531
- transport: tool.config.mcp.transport,
3532
- headers: tool.headers
3533
- };
3534
- };
3535
- var updateToolHealth = async ({
3536
- tenantId,
3537
- projectId,
3538
- toolId,
3539
- status,
3540
- error
3541
- }) => {
3542
- const now = (/* @__PURE__ */ new Date()).toISOString();
3543
- const updateData = {
3544
- status,
3545
- lastHealthCheck: now,
3546
- updatedAt: now
3547
- };
3548
- if (error !== void 0) {
3549
- updateData.lastError = error;
3550
- }
3551
- const tool = await agentsCore.updateTool(dbClient_default)({
3552
- scopes: { tenantId, projectId },
3553
- toolId,
3554
- data: updateData
3555
- });
3556
- return tool;
3557
- };
3558
- var checkToolHealth = async (tool, credentialStoreRegistry) => {
3559
- try {
3560
- const transportType = tool.config.mcp.transport?.type || agentsCore.MCPTransportType.streamableHttp;
3561
- const baseConfig = {
3562
- url: tool.config.mcp.server.url
3563
- };
3564
- const credentialReferenceId = tool.credentialReferenceId;
3565
- let serverConfig;
3566
- if (credentialReferenceId) {
3567
- const credentialReference = await agentsCore.getCredentialReference(dbClient_default)({
3568
- scopes: { tenantId: tool.tenantId, projectId: tool.projectId },
3569
- id: credentialReferenceId
3570
- });
3571
- if (!credentialReference) {
3572
- throw new Error(`Credential store not found: ${credentialReferenceId}`);
3573
- }
3574
- const storeReference = {
3575
- credentialStoreId: credentialReference.credentialStoreId,
3576
- retrievalParams: credentialReference.retrievalParams || {}
3577
- };
3578
- if (!credentialStoreRegistry) {
3579
- throw new Error("CredentialStoreRegistry is required for authenticated tools");
3580
- }
3581
- const contextResolver = new agentsCore.ContextResolver(
3582
- tool.tenantId,
3583
- tool.projectId,
3584
- dbClient_default,
3585
- credentialStoreRegistry
3586
- );
3587
- const credentialStuffer = new agentsCore.CredentialStuffer(credentialStoreRegistry, contextResolver);
3588
- serverConfig = await credentialStuffer.buildMcpServerConfig(
3589
- { tenantId: tool.tenantId, projectId: tool.projectId },
3590
- convertToMCPToolConfig(tool),
3591
- storeReference
3592
- );
3593
- } else {
3594
- if (transportType === agentsCore.MCPTransportType.sse) {
3595
- serverConfig = {
3596
- type: agentsCore.MCPTransportType.sse,
3597
- url: baseConfig.url,
3598
- activeTools: tool.config.mcp.activeTools,
3599
- eventSourceInit: tool.config.mcp.transport?.eventSourceInit
3600
- };
3601
- } else {
3602
- serverConfig = {
3603
- type: agentsCore.MCPTransportType.streamableHttp,
3604
- url: baseConfig.url,
3605
- activeTools: tool.config.mcp.activeTools,
3606
- requestInit: tool.config.mcp.transport?.requestInit,
3607
- eventSourceInit: tool.config.mcp.transport?.eventSourceInit,
3608
- reconnectionOptions: tool.config.mcp.transport?.reconnectionOptions,
3609
- sessionId: tool.config.mcp.transport?.sessionId
3610
- };
3611
- }
3612
- }
3613
- const client = new agentsCore.McpClient({
3614
- name: tool.name,
3615
- server: serverConfig
3616
- });
3617
- await client.connect();
3618
- await client.tools();
3619
- await client.disconnect();
3620
- return {
3621
- status: "healthy",
3622
- capabilities: {
3623
- tools: true,
3624
- resources: false,
3625
- // Could be enhanced to check actual capabilities
3626
- prompts: false,
3627
- logging: false
3628
- }
3629
- };
3630
- } catch (error) {
3631
- logger3.error({ toolId: tool.id, error }, "Tool health check failed");
3632
- if (error instanceof Error && await agentsCore.detectAuthenticationRequired(tool, error)) {
3633
- return {
3634
- status: "needs_auth",
3635
- error: "Authentication required - OAuth login needed"
3636
- };
3637
- }
3638
- return {
3639
- status: "unhealthy",
3640
- error: error instanceof Error ? error.message : "Unknown error"
3641
- };
3642
- }
3643
- };
3644
- var discoverToolsFromServer = async (tool, credentialStoreRegistry) => {
3645
- try {
3646
- const credentialReferenceId = tool.credentialReferenceId;
3647
- let serverConfig;
3648
- if (credentialReferenceId) {
3649
- const credentialReference = await agentsCore.getCredentialReference(dbClient_default)({
3650
- scopes: { tenantId: tool.tenantId, projectId: tool.projectId },
3651
- id: credentialReferenceId
3652
- });
3653
- if (!credentialReference) {
3654
- throw new Error(`Credential store not found: ${credentialReferenceId}`);
3655
- }
3656
- const storeReference = {
3657
- credentialStoreId: credentialReference.credentialStoreId,
3658
- retrievalParams: credentialReference.retrievalParams || {}
3659
- };
3660
- if (!credentialStoreRegistry) {
3661
- throw new Error("CredentialStoreRegistry is required for authenticated tools");
3662
- }
3663
- const contextResolver = new agentsCore.ContextResolver(
3664
- tool.tenantId,
3665
- tool.projectId,
3666
- dbClient_default,
3667
- credentialStoreRegistry
3668
- );
3669
- const credentialStuffer = new agentsCore.CredentialStuffer(credentialStoreRegistry, contextResolver);
3670
- serverConfig = await credentialStuffer.buildMcpServerConfig(
3671
- { tenantId: tool.tenantId, projectId: tool.projectId },
3672
- convertToMCPToolConfig(tool),
3673
- storeReference
3674
- );
3675
- } else {
3676
- const transportType = tool.config.mcp.transport?.type || agentsCore.MCPTransportType.streamableHttp;
3677
- if (transportType === agentsCore.MCPTransportType.sse) {
3678
- serverConfig = {
3679
- type: agentsCore.MCPTransportType.sse,
3680
- url: tool.config.mcp.server.url,
3681
- activeTools: tool.config.mcp.activeTools,
3682
- eventSourceInit: tool.config.mcp.transport?.eventSourceInit
3683
- };
3684
- } else {
3685
- serverConfig = {
3686
- type: agentsCore.MCPTransportType.streamableHttp,
3687
- url: tool.config.mcp.server.url,
3688
- activeTools: tool.config.mcp.activeTools,
3689
- requestInit: tool.config.mcp.transport?.requestInit,
3690
- eventSourceInit: tool.config.mcp.transport?.eventSourceInit,
3691
- reconnectionOptions: tool.config.mcp.transport?.reconnectionOptions,
3692
- sessionId: tool.config.mcp.transport?.sessionId
3693
- };
3694
- }
3695
- }
3696
- const client = new agentsCore.McpClient({
3697
- name: tool.name,
3698
- server: serverConfig
3699
- });
3700
- await client.connect();
3701
- const serverTools = await client.tools();
3702
- await client.disconnect();
3703
- const toolDefinitions = Object.entries(serverTools).map(
3704
- ([name, toolDef]) => ({
3705
- name,
3706
- description: toolDef.description || "",
3707
- inputSchema: extractInputSchema(toolDef)
3708
- })
3709
- );
3710
- return toolDefinitions;
3711
- } catch (error) {
3712
- logger3.error({ toolId: tool.id, error }, "Tool discovery failed");
3713
- throw error;
3714
- }
3715
- };
3716
- var syncToolDefinitions = async ({
3717
- tenantId,
3718
- projectId,
3719
- toolId,
3720
- credentialStoreRegistry
3721
- }) => {
3722
- const tool = await agentsCore.getToolById(dbClient_default)({ scopes: { tenantId, projectId }, toolId });
3723
- if (!tool) {
3724
- throw new Error(`Tool ${toolId} not found`);
3725
- }
3726
- const mcpTool = agentsCore.dbResultToMcpTool(tool);
3727
- try {
3728
- const availableTools = await discoverToolsFromServer(mcpTool, credentialStoreRegistry);
3729
- const updatedTool = await agentsCore.updateTool(dbClient_default)({
3730
- scopes: { tenantId, projectId },
3731
- toolId,
3732
- data: {
3733
- availableTools,
3734
- lastToolsSync: (/* @__PURE__ */ new Date()).toISOString(),
3735
- status: "healthy",
3736
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
3737
- }
3738
- });
3739
- return updatedTool;
3740
- } catch (error) {
3741
- const toolNeedsAuth = error instanceof Error && await agentsCore.detectAuthenticationRequired(mcpTool, error);
3742
- const now = (/* @__PURE__ */ new Date()).toISOString();
3743
- const updatedTool = await agentsCore.updateTool(dbClient_default)({
3744
- scopes: { tenantId, projectId },
3745
- toolId,
3746
- data: {
3747
- availableTools: [],
3748
- lastToolsSync: (/* @__PURE__ */ new Date()).toISOString(),
3749
- status: toolNeedsAuth ? "needs_auth" : "unhealthy",
3750
- lastError: toolNeedsAuth ? "Authentication required - OAuth login needed" : error instanceof Error ? error.message : "Tool sync failed",
3751
- lastHealthCheck: now,
3752
- updatedAt: now
3753
- }
3754
- });
3755
- return updatedTool;
3756
- }
3757
- };
3758
- var checkAllToolsHealth = async (tenantId, projectId, credentialStoreRegistry) => {
3759
- const toolsList = await agentsCore.listTools(dbClient_default)({ scopes: { tenantId, projectId } });
3760
- const results = await Promise.allSettled(
3761
- toolsList.data.map(async (tool) => {
3762
- const healthResult = await checkToolHealth(agentsCore.dbResultToMcpTool(tool), credentialStoreRegistry);
3763
- return await updateToolHealth({
3764
- tenantId,
3765
- projectId: tool.projectId,
3766
- toolId: tool.id,
3767
- status: healthResult.status,
3768
- error: healthResult.error
3769
- });
3770
- })
3771
- );
3772
- return results;
3773
- };
3774
- var logger4 = agentsCore.getLogger("oauth-service");
3468
+ var logger3 = agentsCore.getLogger("oauth-service");
3775
3469
  var pkceStore = /* @__PURE__ */ new Map();
3776
3470
  function storePKCEVerifier(state, codeVerifier, toolId, tenantId, projectId, clientId) {
3777
3471
  pkceStore.set(state, { codeVerifier, toolId, tenantId, projectId, clientId });
@@ -3806,7 +3500,7 @@ var OAuthService = class {
3806
3500
  */
3807
3501
  async initiateOAuthFlow(params) {
3808
3502
  const { tool, tenantId, projectId, toolId } = params;
3809
- const oAuthConfig = await agentsCore.discoverOAuthEndpoints(tool.config.mcp.server.url, logger4);
3503
+ const oAuthConfig = await agentsCore.discoverOAuthEndpoints(tool.config.mcp.server.url, logger3);
3810
3504
  if (!oAuthConfig) {
3811
3505
  throw new Error("OAuth not supported by this server");
3812
3506
  }
@@ -3829,7 +3523,7 @@ var OAuthService = class {
3829
3523
  resource: tool.config.mcp.server.url
3830
3524
  });
3831
3525
  storePKCEVerifier(state, codeVerifier, toolId, tenantId, projectId, clientId);
3832
- logger4.info({ toolId, oAuthConfig, tenantId, projectId }, "OAuth flow initiated successfully");
3526
+ logger3.info({ toolId, oAuthConfig, tenantId, projectId }, "OAuth flow initiated successfully");
3833
3527
  return {
3834
3528
  redirectUrl: authUrl,
3835
3529
  state
@@ -3840,7 +3534,7 @@ var OAuthService = class {
3840
3534
  */
3841
3535
  async exchangeCodeForTokens(params) {
3842
3536
  const { code, codeVerifier, clientId, tool } = params;
3843
- const oAuthConfig = await agentsCore.discoverOAuthEndpoints(tool.config.mcp.server.url, logger4);
3537
+ const oAuthConfig = await agentsCore.discoverOAuthEndpoints(tool.config.mcp.server.url, logger3);
3844
3538
  if (!oAuthConfig?.tokenUrl) {
3845
3539
  throw new Error("Could not discover OAuth token endpoint");
3846
3540
  }
@@ -3854,9 +3548,9 @@ var OAuthService = class {
3854
3548
  codeVerifier,
3855
3549
  redirectUri
3856
3550
  });
3857
- logger4.info({ tokenType: tokens.token_type }, "Token exchange successful with openid-client");
3551
+ logger3.info({ tokenType: tokens.token_type }, "Token exchange successful with openid-client");
3858
3552
  } catch (error) {
3859
- logger4.warn(
3553
+ logger3.warn(
3860
3554
  { error: error instanceof Error ? error.message : error },
3861
3555
  "openid-client failed, falling back to manual token exchange"
3862
3556
  );
@@ -3867,7 +3561,7 @@ var OAuthService = class {
3867
3561
  codeVerifier,
3868
3562
  redirectUri
3869
3563
  });
3870
- logger4.info({ tokenType: tokens.token_type }, "Manual token exchange successful");
3564
+ logger3.info({ tokenType: tokens.token_type }, "Manual token exchange successful");
3871
3565
  }
3872
3566
  return { tokens, oAuthConfig };
3873
3567
  }
@@ -3875,7 +3569,7 @@ var OAuthService = class {
3875
3569
  * Perform dynamic client registration
3876
3570
  */
3877
3571
  async performDynamicClientRegistration(registrationUrl, redirectUri) {
3878
- logger4.info({ registrationUrl }, "Attempting dynamic client registration");
3572
+ logger3.info({ registrationUrl }, "Attempting dynamic client registration");
3879
3573
  try {
3880
3574
  const registrationResponse = await fetch(registrationUrl, {
3881
3575
  method: "POST",
@@ -3898,11 +3592,11 @@ var OAuthService = class {
3898
3592
  });
3899
3593
  if (registrationResponse.ok) {
3900
3594
  const registration = await registrationResponse.json();
3901
- logger4.info({ clientId: registration.client_id }, "Dynamic client registration successful");
3595
+ logger3.info({ clientId: registration.client_id }, "Dynamic client registration successful");
3902
3596
  return registration.client_id;
3903
3597
  } else {
3904
3598
  const errorText = await registrationResponse.text();
3905
- logger4.warn(
3599
+ logger3.warn(
3906
3600
  {
3907
3601
  status: registrationResponse.status,
3908
3602
  errorText
@@ -3911,7 +3605,7 @@ var OAuthService = class {
3911
3605
  );
3912
3606
  }
3913
3607
  } catch (regError) {
3914
- logger4.warn(
3608
+ logger3.warn(
3915
3609
  { error: regError },
3916
3610
  "Dynamic client registration error, using default client_id"
3917
3611
  );
@@ -3941,7 +3635,7 @@ var OAuthService = class {
3941
3635
  const oauth = await import('openid-client');
3942
3636
  const tokenUrl = new URL(oAuthConfig.tokenUrl);
3943
3637
  const oauthServerUrl = `${tokenUrl.protocol}//${tokenUrl.host}`;
3944
- logger4.info({ oauthServerUrl, clientId }, "Attempting openid-client discovery");
3638
+ logger3.info({ oauthServerUrl, clientId }, "Attempting openid-client discovery");
3945
3639
  const config = await oauth.discovery(
3946
3640
  new URL(oauthServerUrl),
3947
3641
  clientId,
@@ -3973,7 +3667,7 @@ var OAuthService = class {
3973
3667
  */
3974
3668
  async exchangeManually(params) {
3975
3669
  const { oAuthConfig, clientId, code, codeVerifier, redirectUri } = params;
3976
- logger4.info({ tokenUrl: oAuthConfig.tokenUrl }, "Attempting manual token exchange");
3670
+ logger3.info({ tokenUrl: oAuthConfig.tokenUrl }, "Attempting manual token exchange");
3977
3671
  const tokenResponse = await fetch(oAuthConfig.tokenUrl, {
3978
3672
  method: "POST",
3979
3673
  headers: {
@@ -3991,7 +3685,7 @@ var OAuthService = class {
3991
3685
  });
3992
3686
  if (!tokenResponse.ok) {
3993
3687
  const errorText = await tokenResponse.text();
3994
- logger4.error(
3688
+ logger3.error(
3995
3689
  {
3996
3690
  status: tokenResponse.status,
3997
3691
  statusText: tokenResponse.statusText,
@@ -4009,7 +3703,7 @@ var OAuthService = class {
4009
3703
  var oauthService = new OAuthService();
4010
3704
 
4011
3705
  // src/routes/tools.ts
4012
- var logger5 = agentsCore.getLogger("tools");
3706
+ var logger4 = agentsCore.getLogger("tools");
4013
3707
  var app15 = new zodOpenapi.OpenAPIHono();
4014
3708
  app15.openapi(
4015
3709
  zodOpenapi.createRoute({
@@ -4040,16 +3734,19 @@ app15.openapi(
4040
3734
  const { tenantId, projectId } = c.req.valid("param");
4041
3735
  const { page, limit, status } = c.req.valid("query");
4042
3736
  let result;
3737
+ const credentialStores = c.get("credentialStores");
4043
3738
  if (status) {
4044
- const tools = await agentsCore.listToolsByStatus(dbClient_default)({ scopes: { tenantId, projectId }, status });
3739
+ const dbResult = await agentsCore.listTools(dbClient_default)({
3740
+ scopes: { tenantId, projectId },
3741
+ pagination: { page, limit }
3742
+ });
4045
3743
  result = {
4046
- data: tools.map((tool) => agentsCore.dbResultToMcpTool(tool)),
4047
- pagination: {
4048
- page: 1,
4049
- limit: tools.length,
4050
- total: tools.length,
4051
- pages: 1
4052
- }
3744
+ data: (await Promise.all(
3745
+ dbResult.data.map(
3746
+ async (tool) => await agentsCore.dbResultToMcpTool(tool, dbClient_default, credentialStores)
3747
+ )
3748
+ )).filter((tool) => tool.status === status),
3749
+ pagination: dbResult.pagination
4053
3750
  };
4054
3751
  } else {
4055
3752
  const dbResult = await agentsCore.listTools(dbClient_default)({
@@ -4057,7 +3754,11 @@ app15.openapi(
4057
3754
  pagination: { page, limit }
4058
3755
  });
4059
3756
  result = {
4060
- data: dbResult.data.map((tool) => agentsCore.dbResultToMcpTool(tool)),
3757
+ data: await Promise.all(
3758
+ dbResult.data.map(
3759
+ async (tool) => await agentsCore.dbResultToMcpTool(tool, dbClient_default, credentialStores)
3760
+ )
3761
+ ),
4061
3762
  pagination: dbResult.pagination
4062
3763
  };
4063
3764
  }
@@ -4095,8 +3796,9 @@ app15.openapi(
4095
3796
  message: "Tool not found"
4096
3797
  });
4097
3798
  }
3799
+ const credentialStores = c.get("credentialStores");
4098
3800
  return c.json({
4099
- data: agentsCore.dbResultToMcpTool(tool)
3801
+ data: await agentsCore.dbResultToMcpTool(tool, dbClient_default, credentialStores)
4100
3802
  });
4101
3803
  }
4102
3804
  );
@@ -4132,7 +3834,8 @@ app15.openapi(
4132
3834
  async (c) => {
4133
3835
  const { tenantId, projectId } = c.req.valid("param");
4134
3836
  const body = c.req.valid("json");
4135
- logger5.info({ body }, "body");
3837
+ const credentialStores = c.get("credentialStores");
3838
+ logger4.info({ body }, "body");
4136
3839
  const id = body.id || nanoid.nanoid();
4137
3840
  const tool = await agentsCore.createTool(dbClient_default)({
4138
3841
  tenantId,
@@ -4146,7 +3849,7 @@ app15.openapi(
4146
3849
  });
4147
3850
  return c.json(
4148
3851
  {
4149
- data: agentsCore.dbResultToMcpTool(tool)
3852
+ data: await agentsCore.dbResultToMcpTool(tool, dbClient_default, credentialStores)
4150
3853
  },
4151
3854
  201
4152
3855
  );
@@ -4184,6 +3887,7 @@ app15.openapi(
4184
3887
  async (c) => {
4185
3888
  const { tenantId, projectId, id } = c.req.valid("param");
4186
3889
  const body = c.req.valid("json");
3890
+ const credentialStores = c.get("credentialStores");
4187
3891
  if (Object.keys(body).length === 0) {
4188
3892
  throw agentsCore.createApiError({
4189
3893
  code: "bad_request",
@@ -4208,7 +3912,7 @@ app15.openapi(
4208
3912
  });
4209
3913
  }
4210
3914
  return c.json({
4211
- data: agentsCore.dbResultToMcpTool(updatedTool)
3915
+ data: await agentsCore.dbResultToMcpTool(updatedTool, dbClient_default, credentialStores)
4212
3916
  });
4213
3917
  }
4214
3918
  );
@@ -4248,268 +3952,6 @@ app15.openapi(
4248
3952
  return c.body(null, 204);
4249
3953
  }
4250
3954
  );
4251
- app15.openapi(
4252
- zodOpenapi.createRoute({
4253
- method: "post",
4254
- path: "/{id}/health-check",
4255
- summary: "Check Tool Health",
4256
- operationId: "check-tool-health",
4257
- tags: ["Tools"],
4258
- request: {
4259
- params: agentsCore.TenantProjectParamsSchema.extend(agentsCore.IdParamsSchema.shape)
4260
- },
4261
- responses: {
4262
- 200: {
4263
- description: "Tool health check completed",
4264
- content: {
4265
- "application/json": {
4266
- schema: agentsCore.SingleResponseSchema(
4267
- zod.z.object({
4268
- tool: agentsCore.McpToolSchema,
4269
- healthCheck: zod.z.object({
4270
- status: agentsCore.ToolStatusSchema,
4271
- error: zod.z.string().optional()
4272
- })
4273
- })
4274
- )
4275
- }
4276
- }
4277
- },
4278
- ...agentsCore.commonGetErrorResponses
4279
- }
4280
- }),
4281
- async (c) => {
4282
- const { tenantId, projectId, id } = c.req.valid("param");
4283
- const tool = await agentsCore.getToolById(dbClient_default)({ scopes: { tenantId, projectId }, toolId: id });
4284
- if (!tool) {
4285
- throw agentsCore.createApiError({
4286
- code: "not_found",
4287
- message: "Tool not found"
4288
- });
4289
- }
4290
- const credentialStores = c.get("credentialStores");
4291
- const healthResult = await checkToolHealth(agentsCore.dbResultToMcpTool(tool), credentialStores);
4292
- const updatedTool = await updateToolHealth({
4293
- tenantId,
4294
- projectId,
4295
- toolId: id,
4296
- status: healthResult.status,
4297
- error: healthResult.error
4298
- });
4299
- return c.json({
4300
- data: {
4301
- tool: agentsCore.dbResultToMcpTool(updatedTool),
4302
- healthCheck: healthResult
4303
- }
4304
- });
4305
- }
4306
- );
4307
- app15.openapi(
4308
- zodOpenapi.createRoute({
4309
- method: "post",
4310
- path: "/health-check-all",
4311
- summary: "Check All Tools Health",
4312
- operationId: "check-all-tools-health",
4313
- tags: ["Tools"],
4314
- request: {
4315
- params: agentsCore.TenantProjectParamsSchema
4316
- },
4317
- responses: {
4318
- 200: {
4319
- description: "All tools health check completed",
4320
- content: {
4321
- "application/json": {
4322
- schema: agentsCore.SingleResponseSchema(
4323
- zod.z.object({
4324
- total: zod.z.number(),
4325
- successful: zod.z.number(),
4326
- failed: zod.z.number(),
4327
- results: zod.z.array(
4328
- zod.z.object({
4329
- index: zod.z.number(),
4330
- status: zod.z.enum(["fulfilled", "rejected"]),
4331
- data: zod.z.string().optional(),
4332
- error: zod.z.string().optional()
4333
- })
4334
- )
4335
- })
4336
- )
4337
- }
4338
- }
4339
- },
4340
- ...agentsCore.commonGetErrorResponses
4341
- }
4342
- }),
4343
- async (c) => {
4344
- const { tenantId, projectId } = c.req.valid("param");
4345
- const credentialStores = c.get("credentialStores");
4346
- const results = await checkAllToolsHealth(tenantId, projectId, credentialStores);
4347
- const summary = {
4348
- total: results.length,
4349
- successful: results.filter((r) => r.status === "fulfilled").length,
4350
- failed: results.filter((r) => r.status === "rejected").length,
4351
- results: results.map((result, index) => {
4352
- const baseResult = {
4353
- index,
4354
- status: result.status
4355
- };
4356
- if (result.status === "fulfilled") {
4357
- return {
4358
- ...baseResult,
4359
- data: `Tool ${index} health check completed`
4360
- };
4361
- }
4362
- return {
4363
- ...baseResult,
4364
- error: result.reason?.message || "Unknown error"
4365
- };
4366
- })
4367
- };
4368
- return c.json({ data: summary });
4369
- }
4370
- );
4371
- app15.openapi(
4372
- zodOpenapi.createRoute({
4373
- method: "post",
4374
- path: "/{id}/sync",
4375
- summary: "Sync Tool Definitions",
4376
- operationId: "sync-tool-definitions",
4377
- tags: ["Tools"],
4378
- request: {
4379
- params: agentsCore.TenantProjectParamsSchema.extend(agentsCore.IdParamsSchema.shape)
4380
- },
4381
- responses: {
4382
- 200: {
4383
- description: "Tool definitions synchronized successfully",
4384
- content: {
4385
- "application/json": {
4386
- schema: agentsCore.SingleResponseSchema(agentsCore.McpToolSchema)
4387
- }
4388
- }
4389
- },
4390
- ...agentsCore.commonGetErrorResponses
4391
- }
4392
- }),
4393
- async (c) => {
4394
- const { tenantId, projectId, id } = c.req.valid("param");
4395
- const tool = await agentsCore.getToolById(dbClient_default)({ scopes: { tenantId, projectId }, toolId: id });
4396
- if (!tool) {
4397
- throw agentsCore.createApiError({
4398
- code: "not_found",
4399
- message: "Tool not found"
4400
- });
4401
- }
4402
- const credentialStores = c.get("credentialStores");
4403
- const updatedTool = await syncToolDefinitions({
4404
- tenantId,
4405
- projectId,
4406
- toolId: id,
4407
- credentialStoreRegistry: credentialStores
4408
- });
4409
- return c.json({
4410
- data: agentsCore.dbResultToMcpTool(updatedTool),
4411
- message: "Tool definitions synchronized successfully"
4412
- });
4413
- }
4414
- );
4415
- app15.openapi(
4416
- zodOpenapi.createRoute({
4417
- method: "get",
4418
- path: "/{id}/available-tools",
4419
- summary: "Get Available Tools",
4420
- operationId: "get-available-tools",
4421
- tags: ["Tools"],
4422
- request: {
4423
- params: agentsCore.TenantProjectParamsSchema.extend(agentsCore.IdParamsSchema.shape)
4424
- },
4425
- responses: {
4426
- 200: {
4427
- description: "Available tools retrieved successfully",
4428
- content: {
4429
- "application/json": {
4430
- schema: agentsCore.SingleResponseSchema(
4431
- zod.z.object({
4432
- availableTools: zod.z.array(
4433
- zod.z.object({
4434
- name: zod.z.string(),
4435
- description: zod.z.string().optional(),
4436
- inputSchema: zod.z.record(zod.z.string(), zod.z.unknown()).optional()
4437
- })
4438
- ),
4439
- lastSync: zod.z.string().optional(),
4440
- status: agentsCore.ToolStatusSchema
4441
- })
4442
- )
4443
- }
4444
- }
4445
- },
4446
- ...agentsCore.commonGetErrorResponses
4447
- }
4448
- }),
4449
- async (c) => {
4450
- const { tenantId, projectId, id } = c.req.valid("param");
4451
- const tool = await agentsCore.getToolById(dbClient_default)({ scopes: { tenantId, projectId }, toolId: id });
4452
- if (!tool) {
4453
- throw agentsCore.createApiError({
4454
- code: "not_found",
4455
- message: "Tool not found"
4456
- });
4457
- }
4458
- return c.json({
4459
- data: {
4460
- availableTools: tool.availableTools || [],
4461
- lastSync: tool.lastToolsSync || void 0,
4462
- status: tool.status
4463
- }
4464
- });
4465
- }
4466
- );
4467
- app15.openapi(
4468
- zodOpenapi.createRoute({
4469
- method: "patch",
4470
- path: "/{id}/status",
4471
- summary: "Update Tool Status",
4472
- operationId: "update-tool-status",
4473
- tags: ["Tools"],
4474
- request: {
4475
- params: agentsCore.TenantProjectParamsSchema.extend(agentsCore.IdParamsSchema.shape),
4476
- body: {
4477
- content: {
4478
- "application/json": {
4479
- schema: zod.z.object({
4480
- status: agentsCore.ToolStatusSchema
4481
- })
4482
- }
4483
- }
4484
- }
4485
- },
4486
- responses: {
4487
- 200: {
4488
- description: "Tool status updated successfully",
4489
- content: {
4490
- "application/json": {
4491
- schema: agentsCore.SingleResponseSchema(agentsCore.McpToolSchema)
4492
- }
4493
- }
4494
- },
4495
- ...agentsCore.commonGetErrorResponses
4496
- }
4497
- }),
4498
- async (c) => {
4499
- const { tenantId, projectId, id } = c.req.valid("param");
4500
- const { status } = c.req.valid("json");
4501
- const updatedTool = await updateToolHealth({
4502
- tenantId,
4503
- projectId,
4504
- toolId: id,
4505
- status
4506
- });
4507
- return c.json({
4508
- data: agentsCore.dbResultToMcpTool(updatedTool),
4509
- message: `Tool status updated to ${status}`
4510
- });
4511
- }
4512
- );
4513
3955
  app15.openapi(
4514
3956
  zodOpenapi.createRoute({
4515
3957
  method: "get",
@@ -4561,7 +4003,8 @@ app15.openapi(
4561
4003
  message: "Tool not found"
4562
4004
  });
4563
4005
  }
4564
- const mcpTool = agentsCore.dbResultToMcpTool(tool);
4006
+ const credentialStores = c.get("credentialStores");
4007
+ const mcpTool = await agentsCore.dbResultToMcpTool(tool, dbClient_default, credentialStores);
4565
4008
  const { redirectUrl } = await oauthService.initiateOAuthFlow({
4566
4009
  tool: mcpTool,
4567
4010
  tenantId,
@@ -4570,7 +4013,7 @@ app15.openapi(
4570
4013
  });
4571
4014
  return c.redirect(redirectUrl, 302);
4572
4015
  } catch (error) {
4573
- logger5.error({ toolId: id, error }, "OAuth login failed");
4016
+ logger4.error({ toolId: id, error }, "OAuth login failed");
4574
4017
  if (error && typeof error === "object" && "code" in error) {
4575
4018
  const apiError = error;
4576
4019
  return c.json({ error: apiError.message }, apiError.code === "not_found" ? 404 : 400);
@@ -4605,7 +4048,7 @@ app16.route("/projects/:projectId/api-keys", apiKeys_default);
4605
4048
  app16.route("/projects/:projectId/graph", graphFull_default);
4606
4049
  var routes_default = app16;
4607
4050
  var app17 = new zodOpenapi.OpenAPIHono();
4608
- var logger6 = agentsCore.getLogger("oauth-callback");
4051
+ var logger5 = agentsCore.getLogger("oauth-callback");
4609
4052
  var OAuthCallbackQuerySchema = zodOpenapi.z.object({
4610
4053
  code: zodOpenapi.z.string().min(1, "Authorization code is required"),
4611
4054
  state: zodOpenapi.z.string().min(1, "State parameter is required"),
@@ -4648,15 +4091,15 @@ app17.openapi(
4648
4091
  async (c) => {
4649
4092
  try {
4650
4093
  const { code, state, error, error_description } = c.req.valid("query");
4651
- logger6.info({ state, hasCode: !!code }, "OAuth callback received");
4094
+ logger5.info({ state, hasCode: !!code }, "OAuth callback received");
4652
4095
  if (error) {
4653
- logger6.error({ error, error_description }, "OAuth authorization failed");
4096
+ logger5.error({ error, error_description }, "OAuth authorization failed");
4654
4097
  const errorMessage = "OAuth Authorization Failed. Please try again.";
4655
4098
  return c.text(errorMessage, 400);
4656
4099
  }
4657
4100
  const pkceData = retrievePKCEVerifier(state);
4658
4101
  if (!pkceData) {
4659
- logger6.error({ state }, "Invalid or expired OAuth state");
4102
+ logger5.error({ state }, "Invalid or expired OAuth state");
4660
4103
  return c.text(
4661
4104
  "OAuth Session Expired: The OAuth session has expired or is invalid. Please try again.",
4662
4105
  400
@@ -4670,20 +4113,20 @@ app17.openapi(
4670
4113
  if (!tool) {
4671
4114
  throw new Error(`Tool ${toolId} not found`);
4672
4115
  }
4673
- logger6.info({ toolId, tenantId, projectId }, "Processing OAuth callback");
4674
- logger6.info({ toolId }, "Exchanging authorization code for access token");
4675
- const mcpTool = agentsCore.dbResultToMcpTool(tool);
4116
+ logger5.info({ toolId, tenantId, projectId }, "Processing OAuth callback");
4117
+ logger5.info({ toolId }, "Exchanging authorization code for access token");
4118
+ const credentialStores = c.get("credentialStores");
4119
+ const mcpTool = await agentsCore.dbResultToMcpTool(tool, dbClient_default, credentialStores);
4676
4120
  const { tokens } = await oauthService.exchangeCodeForTokens({
4677
4121
  code,
4678
4122
  codeVerifier,
4679
4123
  clientId,
4680
4124
  tool: mcpTool
4681
4125
  });
4682
- logger6.info(
4126
+ logger5.info(
4683
4127
  { toolId, tokenType: tokens.token_type, hasRefresh: !!tokens.refresh_token },
4684
4128
  "Token exchange successful"
4685
4129
  );
4686
- const credentialStores = c.get("credentialStores");
4687
4130
  const keychainStore = credentialStores.get("keychain-default");
4688
4131
  const keychainKey = `oauth_token_${toolId}`;
4689
4132
  await keychainStore?.set(keychainKey, JSON.stringify(tokens));
@@ -4701,14 +4144,14 @@ app17.openapi(
4701
4144
  };
4702
4145
  let credential;
4703
4146
  if (existingCredential) {
4704
- logger6.info({ credentialId: existingCredential.id }, "Updating existing credential");
4147
+ logger5.info({ credentialId: existingCredential.id }, "Updating existing credential");
4705
4148
  credential = await agentsCore.updateCredentialReference(dbClient_default)({
4706
4149
  scopes: { tenantId, projectId },
4707
4150
  id: existingCredential.id,
4708
4151
  data: credentialData
4709
4152
  });
4710
4153
  } else {
4711
- logger6.info({ credentialId }, "Creating new credential");
4154
+ logger5.info({ credentialId }, "Creating new credential");
4712
4155
  credential = await agentsCore.createCredentialReference(dbClient_default)({
4713
4156
  tenantId,
4714
4157
  projectId,
@@ -4726,7 +4169,7 @@ app17.openapi(
4726
4169
  credentialReferenceId: credential.id
4727
4170
  }
4728
4171
  });
4729
- logger6.info({ toolId, credentialId: credential.id }, "OAuth flow completed successfully");
4172
+ logger5.info({ toolId, credentialId: credential.id }, "OAuth flow completed successfully");
4730
4173
  const successPage = `
4731
4174
  <!DOCTYPE html>
4732
4175
  <html>
@@ -4768,14 +4211,14 @@ app17.openapi(
4768
4211
  `;
4769
4212
  return c.html(successPage);
4770
4213
  } catch (error) {
4771
- logger6.error({ error }, "OAuth callback processing failed");
4214
+ logger5.error({ error }, "OAuth callback processing failed");
4772
4215
  const errorMessage = "OAuth Processing Failed. Please try again.";
4773
4216
  return c.text(errorMessage, 500);
4774
4217
  }
4775
4218
  }
4776
4219
  );
4777
4220
  var oauth_default = app17;
4778
- var logger7 = agentsCore.getLogger("projectFull");
4221
+ var logger6 = agentsCore.getLogger("projectFull");
4779
4222
  var app18 = new zodOpenapi.OpenAPIHono();
4780
4223
  var ProjectIdParamsSchema = zod.z.object({
4781
4224
  tenantId: zod.z.string().openapi({
@@ -4836,7 +4279,7 @@ app18.openapi(
4836
4279
  const projectData = c.req.valid("json");
4837
4280
  const validatedProjectData = agentsCore.FullProjectDefinitionSchema.parse(projectData);
4838
4281
  try {
4839
- const createdProject = await agentsCore.createFullProjectServerSide(dbClient_default, logger7)(
4282
+ const createdProject = await agentsCore.createFullProjectServerSide(dbClient_default, logger6)(
4840
4283
  { tenantId, projectId: validatedProjectData.id },
4841
4284
  validatedProjectData
4842
4285
  );
@@ -4880,7 +4323,7 @@ app18.openapi(
4880
4323
  try {
4881
4324
  const project = await agentsCore.getFullProject(
4882
4325
  dbClient_default,
4883
- logger7
4326
+ logger6
4884
4327
  )({
4885
4328
  scopes: { tenantId, projectId }
4886
4329
  });
@@ -4956,15 +4399,15 @@ app18.openapi(
4956
4399
  }
4957
4400
  const existingProject = await agentsCore.getFullProject(
4958
4401
  dbClient_default,
4959
- logger7
4402
+ logger6
4960
4403
  )({
4961
4404
  scopes: { tenantId, projectId }
4962
4405
  });
4963
4406
  const isCreate = !existingProject;
4964
- const updatedProject = isCreate ? await agentsCore.createFullProjectServerSide(dbClient_default, logger7)(
4407
+ const updatedProject = isCreate ? await agentsCore.createFullProjectServerSide(dbClient_default, logger6)(
4965
4408
  { tenantId, projectId },
4966
4409
  validatedProjectData
4967
- ) : await agentsCore.updateFullProjectServerSide(dbClient_default, logger7)(
4410
+ ) : await agentsCore.updateFullProjectServerSide(dbClient_default, logger6)(
4968
4411
  { tenantId, projectId },
4969
4412
  validatedProjectData
4970
4413
  );
@@ -5012,7 +4455,7 @@ app18.openapi(
5012
4455
  try {
5013
4456
  const deleted = await agentsCore.deleteFullProject(
5014
4457
  dbClient_default,
5015
- logger7
4458
+ logger6
5016
4459
  )({
5017
4460
  scopes: { tenantId, projectId }
5018
4461
  });
@@ -5040,8 +4483,8 @@ app18.openapi(
5040
4483
  var projectFull_default = app18;
5041
4484
 
5042
4485
  // src/app.ts
5043
- var logger8 = agentsCore.getLogger("agents-manage-api");
5044
- logger8.info({ logger: logger8.getTransports() }, "Logger initialized");
4486
+ var logger7 = agentsCore.getLogger("agents-manage-api");
4487
+ logger7.info({ logger: logger7.getTransports() }, "Logger initialized");
5045
4488
  function createManagementHono(serverConfig, credentialStores) {
5046
4489
  const app20 = new zodOpenapi.OpenAPIHono();
5047
4490
  app20.use("*", requestId.requestId());
@@ -5096,7 +4539,7 @@ function createManagementHono(serverConfig, credentialStores) {
5096
4539
  if (!isExpectedError) {
5097
4540
  const errorMessage = err instanceof Error ? err.message : String(err);
5098
4541
  const errorStack = err instanceof Error ? err.stack : void 0;
5099
- logger8.error(
4542
+ logger7.error(
5100
4543
  {
5101
4544
  error: err,
5102
4545
  message: errorMessage,
@@ -5107,7 +4550,7 @@ function createManagementHono(serverConfig, credentialStores) {
5107
4550
  "Unexpected server error occurred"
5108
4551
  );
5109
4552
  } else {
5110
- logger8.error(
4553
+ logger7.error(
5111
4554
  {
5112
4555
  error: err,
5113
4556
  path: c.req.path,
@@ -5123,7 +4566,7 @@ function createManagementHono(serverConfig, credentialStores) {
5123
4566
  const response = err.getResponse();
5124
4567
  return response;
5125
4568
  } catch (responseError) {
5126
- logger8.error({ error: responseError }, "Error while handling HTTPException response");
4569
+ logger7.error({ error: responseError }, "Error while handling HTTPException response");
5127
4570
  }
5128
4571
  }
5129
4572
  const { status: respStatus, title, detail, instance } = await agentsCore.handleApiError(err, requestId2);