@inkeep/agents-manage-api 0.6.6 → 0.7.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.
- package/dist/index.cjs +66 -623
- package/dist/index.js +67 -624
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { loadEnvironmentFiles, getLogger, createDatabaseClient, commonGetErrorResponses, TenantProjectGraphParamsSchema, ArtifactComponentApiSelectSchema, getArtifactComponentsForAgent, getAgentsUsingArtifactComponent, ErrorResponseSchema, SingleResponseSchema, AgentArtifactComponentApiInsertSchema, AgentArtifactComponentApiSelectSchema, getAgentById, getArtifactComponentById, createApiError, isArtifactComponentAssociatedWithAgent, associateArtifactComponentWithAgent, RemovedResponseSchema, removeArtifactComponentFromAgent, ExistsResponseSchema, DataComponentApiSelectSchema, getDataComponentsForAgent, getAgentsUsingDataComponent, AgentDataComponentApiInsertSchema, AgentDataComponentApiSelectSchema, getDataComponent, isDataComponentAssociatedWithAgent, associateDataComponentWithAgent, removeDataComponentFromAgent, ListResponseSchema, PaginationQueryParamsSchema, TenantProjectParamsSchema, AgentGraphApiSelectSchema, listAgentGraphs, IdParamsSchema, getAgentGraphById, getGraphAgentInfos, FullGraphDefinitionSchema, getFullGraphDefinition, AgentGraphApiInsertSchema, createAgentGraph, AgentGraphApiUpdateSchema, updateAgentGraph, deleteAgentGraph, AgentRelationApiSelectSchema, AgentRelationQuerySchema, getAgentRelationsBySource, getAgentRelationsByTarget, getExternalAgentRelations, listAgentRelations, TenantProjectGraphIdParamsSchema, getAgentRelationById, AgentRelationApiInsertSchema, validateExternalAgent, validateInternalAgent, createAgentRelation, AgentRelationApiUpdateSchema, updateAgentRelation, deleteAgentRelation, AgentApiSelectSchema, listAgentsPaginated, AgentApiInsertSchema, createAgent, AgentApiUpdateSchema, updateAgent, deleteAgent, AgentToolRelationApiSelectSchema, getAgentToolRelationByAgent, getAgentToolRelationByTool, listAgentToolRelations, getAgentToolRelationById,
|
|
1
|
+
import { loadEnvironmentFiles, getLogger, createDatabaseClient, commonGetErrorResponses, TenantProjectGraphParamsSchema, ArtifactComponentApiSelectSchema, getArtifactComponentsForAgent, getAgentsUsingArtifactComponent, ErrorResponseSchema, SingleResponseSchema, AgentArtifactComponentApiInsertSchema, AgentArtifactComponentApiSelectSchema, getAgentById, getArtifactComponentById, createApiError, isArtifactComponentAssociatedWithAgent, associateArtifactComponentWithAgent, RemovedResponseSchema, removeArtifactComponentFromAgent, ExistsResponseSchema, DataComponentApiSelectSchema, getDataComponentsForAgent, getAgentsUsingDataComponent, AgentDataComponentApiInsertSchema, AgentDataComponentApiSelectSchema, getDataComponent, isDataComponentAssociatedWithAgent, associateDataComponentWithAgent, removeDataComponentFromAgent, ListResponseSchema, PaginationQueryParamsSchema, TenantProjectParamsSchema, AgentGraphApiSelectSchema, listAgentGraphs, IdParamsSchema, getAgentGraphById, getGraphAgentInfos, FullGraphDefinitionSchema, getFullGraphDefinition, AgentGraphApiInsertSchema, createAgentGraph, AgentGraphApiUpdateSchema, updateAgentGraph, deleteAgentGraph, AgentRelationApiSelectSchema, AgentRelationQuerySchema, getAgentRelationsBySource, getAgentRelationsByTarget, getExternalAgentRelations, listAgentRelations, TenantProjectGraphIdParamsSchema, getAgentRelationById, AgentRelationApiInsertSchema, validateExternalAgent, validateInternalAgent, createAgentRelation, AgentRelationApiUpdateSchema, updateAgentRelation, deleteAgentRelation, AgentApiSelectSchema, listAgentsPaginated, AgentApiInsertSchema, createAgent, AgentApiUpdateSchema, updateAgent, deleteAgent, AgentToolRelationApiSelectSchema, getAgentToolRelationByAgent, getAgentToolRelationByTool, listAgentToolRelations, getAgentToolRelationById, getAgentsForTool, AgentToolRelationApiInsertSchema, createAgentToolRelation, AgentToolRelationApiUpdateSchema, updateAgentToolRelation, deleteAgentToolRelation, ApiKeyApiSelectSchema, listApiKeysPaginated, getApiKeyById, ApiKeyApiCreationResponseSchema, ApiKeyApiInsertSchema, generateApiKey, createApiKey, ApiKeyApiUpdateSchema, updateApiKey, deleteApiKey, listArtifactComponentsPaginated, ArtifactComponentApiInsertSchema, createArtifactComponent, ArtifactComponentApiUpdateSchema, updateArtifactComponent, deleteArtifactComponent, ContextConfigApiSelectSchema, listContextConfigsPaginated, getContextConfigById, ContextConfigApiInsertSchema, createContextConfig, commonUpdateErrorResponses, ContextConfigApiUpdateSchema, updateContextConfig, commonDeleteErrorResponses, deleteContextConfig, CredentialReferenceApiSelectSchema, listCredentialReferencesPaginated, getCredentialReferenceWithTools, CredentialReferenceApiInsertSchema, createCredentialReference, CredentialReferenceApiUpdateSchema, updateCredentialReference, getCredentialReferenceById, getCredentialStoreLookupKeyFromRetrievalParams, deleteCredentialReference, listDataComponentsPaginated, DataComponentApiInsertSchema, createDataComponent, DataComponentApiUpdateSchema, updateDataComponent, deleteDataComponent, ExternalAgentApiSelectSchema, listExternalAgentsPaginated, getExternalAgent, ExternalAgentApiInsertSchema, createExternalAgent, ExternalAgentApiUpdateSchema, updateExternalAgent, deleteExternalAgent, createFullGraphServerSide, getFullGraph, updateFullGraphServerSide, deleteFullGraph, TenantParamsSchema, ProjectApiSelectSchema, listProjectsPaginated, TenantIdParamsSchema, getProject, ProjectApiInsertSchema, createProject, ProjectApiUpdateSchema, updateProject, deleteProject, McpToolSchema, ToolStatusSchema, listTools, dbResultToMcpTool, getToolById, ToolApiInsertSchema, createTool, ToolApiUpdateSchema, updateTool, deleteTool, getCredentialReference, CredentialStoreType, FullProjectDefinitionSchema, createFullProjectServerSide, getFullProject, updateFullProjectServerSide, deleteFullProject, createDefaultCredentialStores, CredentialStoreRegistry, discoverOAuthEndpoints, handleApiError } from '@inkeep/agents-core';
|
|
2
2
|
import { OpenAPIHono, createRoute, z as z$1 } from '@hono/zod-openapi';
|
|
3
3
|
import { Hono } from 'hono';
|
|
4
4
|
import { cors } from 'hono/cors';
|
|
@@ -1465,45 +1465,6 @@ app6.openapi(
|
|
|
1465
1465
|
return c.json({ data: agentToolRelation });
|
|
1466
1466
|
}
|
|
1467
1467
|
);
|
|
1468
|
-
app6.openapi(
|
|
1469
|
-
createRoute({
|
|
1470
|
-
method: "get",
|
|
1471
|
-
path: "/agent/{agentId}/tools",
|
|
1472
|
-
summary: "Get Tools for Agent",
|
|
1473
|
-
operationId: "get-tools-for-agent",
|
|
1474
|
-
tags: ["Agent Tool Relations"],
|
|
1475
|
-
request: {
|
|
1476
|
-
params: TenantProjectGraphParamsSchema.extend({
|
|
1477
|
-
agentId: z.string()
|
|
1478
|
-
}),
|
|
1479
|
-
query: PaginationQueryParamsSchema
|
|
1480
|
-
},
|
|
1481
|
-
responses: {
|
|
1482
|
-
200: {
|
|
1483
|
-
description: "Tools for agent retrieved successfully",
|
|
1484
|
-
content: {
|
|
1485
|
-
"application/json": {
|
|
1486
|
-
schema: ListResponseSchema(AgentToolRelationApiSelectSchema)
|
|
1487
|
-
}
|
|
1488
|
-
}
|
|
1489
|
-
},
|
|
1490
|
-
...commonGetErrorResponses
|
|
1491
|
-
}
|
|
1492
|
-
}),
|
|
1493
|
-
async (c) => {
|
|
1494
|
-
const { tenantId, projectId, graphId, agentId } = c.req.valid("param");
|
|
1495
|
-
const { page, limit } = c.req.valid("query");
|
|
1496
|
-
const dbResult = await getToolsForAgent(dbClient_default)({
|
|
1497
|
-
scopes: { tenantId, projectId, graphId, agentId },
|
|
1498
|
-
pagination: { page, limit }
|
|
1499
|
-
});
|
|
1500
|
-
const result = {
|
|
1501
|
-
data: dbResult.data,
|
|
1502
|
-
pagination: dbResult.pagination
|
|
1503
|
-
};
|
|
1504
|
-
return c.json(result);
|
|
1505
|
-
}
|
|
1506
|
-
);
|
|
1507
1468
|
app6.openapi(
|
|
1508
1469
|
createRoute({
|
|
1509
1470
|
method: "get",
|
|
@@ -3500,274 +3461,7 @@ app14.openapi(
|
|
|
3500
3461
|
}
|
|
3501
3462
|
);
|
|
3502
3463
|
var projects_default = app14;
|
|
3503
|
-
|
|
3504
|
-
if (toolDef.inputSchema) {
|
|
3505
|
-
return toolDef.inputSchema;
|
|
3506
|
-
}
|
|
3507
|
-
if (toolDef.parameters?.properties) {
|
|
3508
|
-
return toolDef.parameters.properties;
|
|
3509
|
-
}
|
|
3510
|
-
if (toolDef.parameters && typeof toolDef.parameters === "object") {
|
|
3511
|
-
return toolDef.parameters;
|
|
3512
|
-
}
|
|
3513
|
-
if (toolDef.schema) {
|
|
3514
|
-
return toolDef.schema;
|
|
3515
|
-
}
|
|
3516
|
-
return {};
|
|
3517
|
-
}
|
|
3518
|
-
var logger3 = getLogger("tools");
|
|
3519
|
-
var convertToMCPToolConfig = (tool) => {
|
|
3520
|
-
return {
|
|
3521
|
-
id: tool.id,
|
|
3522
|
-
name: tool.name,
|
|
3523
|
-
description: tool.name,
|
|
3524
|
-
// Use name as description fallback
|
|
3525
|
-
serverUrl: tool.config.mcp.server.url,
|
|
3526
|
-
mcpType: tool.config.mcp.server.url.includes("api.nango.dev") ? MCPServerType.nango : MCPServerType.generic,
|
|
3527
|
-
transport: tool.config.mcp.transport,
|
|
3528
|
-
headers: tool.headers
|
|
3529
|
-
};
|
|
3530
|
-
};
|
|
3531
|
-
var updateToolHealth = async ({
|
|
3532
|
-
tenantId,
|
|
3533
|
-
projectId,
|
|
3534
|
-
toolId,
|
|
3535
|
-
status,
|
|
3536
|
-
error
|
|
3537
|
-
}) => {
|
|
3538
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3539
|
-
const updateData = {
|
|
3540
|
-
status,
|
|
3541
|
-
lastHealthCheck: now,
|
|
3542
|
-
updatedAt: now
|
|
3543
|
-
};
|
|
3544
|
-
if (error !== void 0) {
|
|
3545
|
-
updateData.lastError = error;
|
|
3546
|
-
}
|
|
3547
|
-
const tool = await updateTool(dbClient_default)({
|
|
3548
|
-
scopes: { tenantId, projectId },
|
|
3549
|
-
toolId,
|
|
3550
|
-
data: updateData
|
|
3551
|
-
});
|
|
3552
|
-
return tool;
|
|
3553
|
-
};
|
|
3554
|
-
var checkToolHealth = async (tool, credentialStoreRegistry) => {
|
|
3555
|
-
try {
|
|
3556
|
-
const transportType = tool.config.mcp.transport?.type || MCPTransportType.streamableHttp;
|
|
3557
|
-
const baseConfig = {
|
|
3558
|
-
url: tool.config.mcp.server.url
|
|
3559
|
-
};
|
|
3560
|
-
const credentialReferenceId = tool.credentialReferenceId;
|
|
3561
|
-
let serverConfig;
|
|
3562
|
-
if (credentialReferenceId) {
|
|
3563
|
-
const credentialReference = await getCredentialReference(dbClient_default)({
|
|
3564
|
-
scopes: { tenantId: tool.tenantId, projectId: tool.projectId },
|
|
3565
|
-
id: credentialReferenceId
|
|
3566
|
-
});
|
|
3567
|
-
if (!credentialReference) {
|
|
3568
|
-
throw new Error(`Credential store not found: ${credentialReferenceId}`);
|
|
3569
|
-
}
|
|
3570
|
-
const storeReference = {
|
|
3571
|
-
credentialStoreId: credentialReference.credentialStoreId,
|
|
3572
|
-
retrievalParams: credentialReference.retrievalParams || {}
|
|
3573
|
-
};
|
|
3574
|
-
if (!credentialStoreRegistry) {
|
|
3575
|
-
throw new Error("CredentialStoreRegistry is required for authenticated tools");
|
|
3576
|
-
}
|
|
3577
|
-
const contextResolver = new ContextResolver(
|
|
3578
|
-
tool.tenantId,
|
|
3579
|
-
tool.projectId,
|
|
3580
|
-
dbClient_default,
|
|
3581
|
-
credentialStoreRegistry
|
|
3582
|
-
);
|
|
3583
|
-
const credentialStuffer = new CredentialStuffer(credentialStoreRegistry, contextResolver);
|
|
3584
|
-
serverConfig = await credentialStuffer.buildMcpServerConfig(
|
|
3585
|
-
{ tenantId: tool.tenantId, projectId: tool.projectId },
|
|
3586
|
-
convertToMCPToolConfig(tool),
|
|
3587
|
-
storeReference
|
|
3588
|
-
);
|
|
3589
|
-
} else {
|
|
3590
|
-
if (transportType === MCPTransportType.sse) {
|
|
3591
|
-
serverConfig = {
|
|
3592
|
-
type: MCPTransportType.sse,
|
|
3593
|
-
url: baseConfig.url,
|
|
3594
|
-
activeTools: tool.config.mcp.activeTools,
|
|
3595
|
-
eventSourceInit: tool.config.mcp.transport?.eventSourceInit
|
|
3596
|
-
};
|
|
3597
|
-
} else {
|
|
3598
|
-
serverConfig = {
|
|
3599
|
-
type: MCPTransportType.streamableHttp,
|
|
3600
|
-
url: baseConfig.url,
|
|
3601
|
-
activeTools: tool.config.mcp.activeTools,
|
|
3602
|
-
requestInit: tool.config.mcp.transport?.requestInit,
|
|
3603
|
-
eventSourceInit: tool.config.mcp.transport?.eventSourceInit,
|
|
3604
|
-
reconnectionOptions: tool.config.mcp.transport?.reconnectionOptions,
|
|
3605
|
-
sessionId: tool.config.mcp.transport?.sessionId
|
|
3606
|
-
};
|
|
3607
|
-
}
|
|
3608
|
-
}
|
|
3609
|
-
const client = new McpClient({
|
|
3610
|
-
name: tool.name,
|
|
3611
|
-
server: serverConfig
|
|
3612
|
-
});
|
|
3613
|
-
await client.connect();
|
|
3614
|
-
await client.tools();
|
|
3615
|
-
await client.disconnect();
|
|
3616
|
-
return {
|
|
3617
|
-
status: "healthy",
|
|
3618
|
-
capabilities: {
|
|
3619
|
-
tools: true,
|
|
3620
|
-
resources: false,
|
|
3621
|
-
// Could be enhanced to check actual capabilities
|
|
3622
|
-
prompts: false,
|
|
3623
|
-
logging: false
|
|
3624
|
-
}
|
|
3625
|
-
};
|
|
3626
|
-
} catch (error) {
|
|
3627
|
-
logger3.error({ toolId: tool.id, error }, "Tool health check failed");
|
|
3628
|
-
if (error instanceof Error && await detectAuthenticationRequired(tool, error)) {
|
|
3629
|
-
return {
|
|
3630
|
-
status: "needs_auth",
|
|
3631
|
-
error: "Authentication required - OAuth login needed"
|
|
3632
|
-
};
|
|
3633
|
-
}
|
|
3634
|
-
return {
|
|
3635
|
-
status: "unhealthy",
|
|
3636
|
-
error: error instanceof Error ? error.message : "Unknown error"
|
|
3637
|
-
};
|
|
3638
|
-
}
|
|
3639
|
-
};
|
|
3640
|
-
var discoverToolsFromServer = async (tool, credentialStoreRegistry) => {
|
|
3641
|
-
try {
|
|
3642
|
-
const credentialReferenceId = tool.credentialReferenceId;
|
|
3643
|
-
let serverConfig;
|
|
3644
|
-
if (credentialReferenceId) {
|
|
3645
|
-
const credentialReference = await getCredentialReference(dbClient_default)({
|
|
3646
|
-
scopes: { tenantId: tool.tenantId, projectId: tool.projectId },
|
|
3647
|
-
id: credentialReferenceId
|
|
3648
|
-
});
|
|
3649
|
-
if (!credentialReference) {
|
|
3650
|
-
throw new Error(`Credential store not found: ${credentialReferenceId}`);
|
|
3651
|
-
}
|
|
3652
|
-
const storeReference = {
|
|
3653
|
-
credentialStoreId: credentialReference.credentialStoreId,
|
|
3654
|
-
retrievalParams: credentialReference.retrievalParams || {}
|
|
3655
|
-
};
|
|
3656
|
-
if (!credentialStoreRegistry) {
|
|
3657
|
-
throw new Error("CredentialStoreRegistry is required for authenticated tools");
|
|
3658
|
-
}
|
|
3659
|
-
const contextResolver = new ContextResolver(
|
|
3660
|
-
tool.tenantId,
|
|
3661
|
-
tool.projectId,
|
|
3662
|
-
dbClient_default,
|
|
3663
|
-
credentialStoreRegistry
|
|
3664
|
-
);
|
|
3665
|
-
const credentialStuffer = new CredentialStuffer(credentialStoreRegistry, contextResolver);
|
|
3666
|
-
serverConfig = await credentialStuffer.buildMcpServerConfig(
|
|
3667
|
-
{ tenantId: tool.tenantId, projectId: tool.projectId },
|
|
3668
|
-
convertToMCPToolConfig(tool),
|
|
3669
|
-
storeReference
|
|
3670
|
-
);
|
|
3671
|
-
} else {
|
|
3672
|
-
const transportType = tool.config.mcp.transport?.type || MCPTransportType.streamableHttp;
|
|
3673
|
-
if (transportType === MCPTransportType.sse) {
|
|
3674
|
-
serverConfig = {
|
|
3675
|
-
type: MCPTransportType.sse,
|
|
3676
|
-
url: tool.config.mcp.server.url,
|
|
3677
|
-
activeTools: tool.config.mcp.activeTools,
|
|
3678
|
-
eventSourceInit: tool.config.mcp.transport?.eventSourceInit
|
|
3679
|
-
};
|
|
3680
|
-
} else {
|
|
3681
|
-
serverConfig = {
|
|
3682
|
-
type: MCPTransportType.streamableHttp,
|
|
3683
|
-
url: tool.config.mcp.server.url,
|
|
3684
|
-
activeTools: tool.config.mcp.activeTools,
|
|
3685
|
-
requestInit: tool.config.mcp.transport?.requestInit,
|
|
3686
|
-
eventSourceInit: tool.config.mcp.transport?.eventSourceInit,
|
|
3687
|
-
reconnectionOptions: tool.config.mcp.transport?.reconnectionOptions,
|
|
3688
|
-
sessionId: tool.config.mcp.transport?.sessionId
|
|
3689
|
-
};
|
|
3690
|
-
}
|
|
3691
|
-
}
|
|
3692
|
-
const client = new McpClient({
|
|
3693
|
-
name: tool.name,
|
|
3694
|
-
server: serverConfig
|
|
3695
|
-
});
|
|
3696
|
-
await client.connect();
|
|
3697
|
-
const serverTools = await client.tools();
|
|
3698
|
-
await client.disconnect();
|
|
3699
|
-
const toolDefinitions = Object.entries(serverTools).map(
|
|
3700
|
-
([name, toolDef]) => ({
|
|
3701
|
-
name,
|
|
3702
|
-
description: toolDef.description || "",
|
|
3703
|
-
inputSchema: extractInputSchema(toolDef)
|
|
3704
|
-
})
|
|
3705
|
-
);
|
|
3706
|
-
return toolDefinitions;
|
|
3707
|
-
} catch (error) {
|
|
3708
|
-
logger3.error({ toolId: tool.id, error }, "Tool discovery failed");
|
|
3709
|
-
throw error;
|
|
3710
|
-
}
|
|
3711
|
-
};
|
|
3712
|
-
var syncToolDefinitions = async ({
|
|
3713
|
-
tenantId,
|
|
3714
|
-
projectId,
|
|
3715
|
-
toolId,
|
|
3716
|
-
credentialStoreRegistry
|
|
3717
|
-
}) => {
|
|
3718
|
-
const tool = await getToolById(dbClient_default)({ scopes: { tenantId, projectId }, toolId });
|
|
3719
|
-
if (!tool) {
|
|
3720
|
-
throw new Error(`Tool ${toolId} not found`);
|
|
3721
|
-
}
|
|
3722
|
-
const mcpTool = dbResultToMcpTool(tool);
|
|
3723
|
-
try {
|
|
3724
|
-
const availableTools = await discoverToolsFromServer(mcpTool, credentialStoreRegistry);
|
|
3725
|
-
const updatedTool = await updateTool(dbClient_default)({
|
|
3726
|
-
scopes: { tenantId, projectId },
|
|
3727
|
-
toolId,
|
|
3728
|
-
data: {
|
|
3729
|
-
availableTools,
|
|
3730
|
-
lastToolsSync: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3731
|
-
status: "healthy",
|
|
3732
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
3733
|
-
}
|
|
3734
|
-
});
|
|
3735
|
-
return updatedTool;
|
|
3736
|
-
} catch (error) {
|
|
3737
|
-
const toolNeedsAuth = error instanceof Error && await detectAuthenticationRequired(mcpTool, error);
|
|
3738
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3739
|
-
const updatedTool = await updateTool(dbClient_default)({
|
|
3740
|
-
scopes: { tenantId, projectId },
|
|
3741
|
-
toolId,
|
|
3742
|
-
data: {
|
|
3743
|
-
availableTools: [],
|
|
3744
|
-
lastToolsSync: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3745
|
-
status: toolNeedsAuth ? "needs_auth" : "unhealthy",
|
|
3746
|
-
lastError: toolNeedsAuth ? "Authentication required - OAuth login needed" : error instanceof Error ? error.message : "Tool sync failed",
|
|
3747
|
-
lastHealthCheck: now,
|
|
3748
|
-
updatedAt: now
|
|
3749
|
-
}
|
|
3750
|
-
});
|
|
3751
|
-
return updatedTool;
|
|
3752
|
-
}
|
|
3753
|
-
};
|
|
3754
|
-
var checkAllToolsHealth = async (tenantId, projectId, credentialStoreRegistry) => {
|
|
3755
|
-
const toolsList = await listTools(dbClient_default)({ scopes: { tenantId, projectId } });
|
|
3756
|
-
const results = await Promise.allSettled(
|
|
3757
|
-
toolsList.data.map(async (tool) => {
|
|
3758
|
-
const healthResult = await checkToolHealth(dbResultToMcpTool(tool), credentialStoreRegistry);
|
|
3759
|
-
return await updateToolHealth({
|
|
3760
|
-
tenantId,
|
|
3761
|
-
projectId: tool.projectId,
|
|
3762
|
-
toolId: tool.id,
|
|
3763
|
-
status: healthResult.status,
|
|
3764
|
-
error: healthResult.error
|
|
3765
|
-
});
|
|
3766
|
-
})
|
|
3767
|
-
);
|
|
3768
|
-
return results;
|
|
3769
|
-
};
|
|
3770
|
-
var logger4 = getLogger("oauth-service");
|
|
3464
|
+
var logger3 = getLogger("oauth-service");
|
|
3771
3465
|
var pkceStore = /* @__PURE__ */ new Map();
|
|
3772
3466
|
function storePKCEVerifier(state, codeVerifier, toolId, tenantId, projectId, clientId) {
|
|
3773
3467
|
pkceStore.set(state, { codeVerifier, toolId, tenantId, projectId, clientId });
|
|
@@ -3802,7 +3496,7 @@ var OAuthService = class {
|
|
|
3802
3496
|
*/
|
|
3803
3497
|
async initiateOAuthFlow(params) {
|
|
3804
3498
|
const { tool, tenantId, projectId, toolId } = params;
|
|
3805
|
-
const oAuthConfig = await discoverOAuthEndpoints(tool.config.mcp.server.url,
|
|
3499
|
+
const oAuthConfig = await discoverOAuthEndpoints(tool.config.mcp.server.url, logger3);
|
|
3806
3500
|
if (!oAuthConfig) {
|
|
3807
3501
|
throw new Error("OAuth not supported by this server");
|
|
3808
3502
|
}
|
|
@@ -3825,7 +3519,7 @@ var OAuthService = class {
|
|
|
3825
3519
|
resource: tool.config.mcp.server.url
|
|
3826
3520
|
});
|
|
3827
3521
|
storePKCEVerifier(state, codeVerifier, toolId, tenantId, projectId, clientId);
|
|
3828
|
-
|
|
3522
|
+
logger3.info({ toolId, oAuthConfig, tenantId, projectId }, "OAuth flow initiated successfully");
|
|
3829
3523
|
return {
|
|
3830
3524
|
redirectUrl: authUrl,
|
|
3831
3525
|
state
|
|
@@ -3836,7 +3530,7 @@ var OAuthService = class {
|
|
|
3836
3530
|
*/
|
|
3837
3531
|
async exchangeCodeForTokens(params) {
|
|
3838
3532
|
const { code, codeVerifier, clientId, tool } = params;
|
|
3839
|
-
const oAuthConfig = await discoverOAuthEndpoints(tool.config.mcp.server.url,
|
|
3533
|
+
const oAuthConfig = await discoverOAuthEndpoints(tool.config.mcp.server.url, logger3);
|
|
3840
3534
|
if (!oAuthConfig?.tokenUrl) {
|
|
3841
3535
|
throw new Error("Could not discover OAuth token endpoint");
|
|
3842
3536
|
}
|
|
@@ -3850,9 +3544,9 @@ var OAuthService = class {
|
|
|
3850
3544
|
codeVerifier,
|
|
3851
3545
|
redirectUri
|
|
3852
3546
|
});
|
|
3853
|
-
|
|
3547
|
+
logger3.info({ tokenType: tokens.token_type }, "Token exchange successful with openid-client");
|
|
3854
3548
|
} catch (error) {
|
|
3855
|
-
|
|
3549
|
+
logger3.warn(
|
|
3856
3550
|
{ error: error instanceof Error ? error.message : error },
|
|
3857
3551
|
"openid-client failed, falling back to manual token exchange"
|
|
3858
3552
|
);
|
|
@@ -3863,7 +3557,7 @@ var OAuthService = class {
|
|
|
3863
3557
|
codeVerifier,
|
|
3864
3558
|
redirectUri
|
|
3865
3559
|
});
|
|
3866
|
-
|
|
3560
|
+
logger3.info({ tokenType: tokens.token_type }, "Manual token exchange successful");
|
|
3867
3561
|
}
|
|
3868
3562
|
return { tokens, oAuthConfig };
|
|
3869
3563
|
}
|
|
@@ -3871,7 +3565,7 @@ var OAuthService = class {
|
|
|
3871
3565
|
* Perform dynamic client registration
|
|
3872
3566
|
*/
|
|
3873
3567
|
async performDynamicClientRegistration(registrationUrl, redirectUri) {
|
|
3874
|
-
|
|
3568
|
+
logger3.info({ registrationUrl }, "Attempting dynamic client registration");
|
|
3875
3569
|
try {
|
|
3876
3570
|
const registrationResponse = await fetch(registrationUrl, {
|
|
3877
3571
|
method: "POST",
|
|
@@ -3894,11 +3588,11 @@ var OAuthService = class {
|
|
|
3894
3588
|
});
|
|
3895
3589
|
if (registrationResponse.ok) {
|
|
3896
3590
|
const registration = await registrationResponse.json();
|
|
3897
|
-
|
|
3591
|
+
logger3.info({ clientId: registration.client_id }, "Dynamic client registration successful");
|
|
3898
3592
|
return registration.client_id;
|
|
3899
3593
|
} else {
|
|
3900
3594
|
const errorText = await registrationResponse.text();
|
|
3901
|
-
|
|
3595
|
+
logger3.warn(
|
|
3902
3596
|
{
|
|
3903
3597
|
status: registrationResponse.status,
|
|
3904
3598
|
errorText
|
|
@@ -3907,7 +3601,7 @@ var OAuthService = class {
|
|
|
3907
3601
|
);
|
|
3908
3602
|
}
|
|
3909
3603
|
} catch (regError) {
|
|
3910
|
-
|
|
3604
|
+
logger3.warn(
|
|
3911
3605
|
{ error: regError },
|
|
3912
3606
|
"Dynamic client registration error, using default client_id"
|
|
3913
3607
|
);
|
|
@@ -3937,7 +3631,7 @@ var OAuthService = class {
|
|
|
3937
3631
|
const oauth = await import('openid-client');
|
|
3938
3632
|
const tokenUrl = new URL(oAuthConfig.tokenUrl);
|
|
3939
3633
|
const oauthServerUrl = `${tokenUrl.protocol}//${tokenUrl.host}`;
|
|
3940
|
-
|
|
3634
|
+
logger3.info({ oauthServerUrl, clientId }, "Attempting openid-client discovery");
|
|
3941
3635
|
const config = await oauth.discovery(
|
|
3942
3636
|
new URL(oauthServerUrl),
|
|
3943
3637
|
clientId,
|
|
@@ -3969,7 +3663,7 @@ var OAuthService = class {
|
|
|
3969
3663
|
*/
|
|
3970
3664
|
async exchangeManually(params) {
|
|
3971
3665
|
const { oAuthConfig, clientId, code, codeVerifier, redirectUri } = params;
|
|
3972
|
-
|
|
3666
|
+
logger3.info({ tokenUrl: oAuthConfig.tokenUrl }, "Attempting manual token exchange");
|
|
3973
3667
|
const tokenResponse = await fetch(oAuthConfig.tokenUrl, {
|
|
3974
3668
|
method: "POST",
|
|
3975
3669
|
headers: {
|
|
@@ -3987,7 +3681,7 @@ var OAuthService = class {
|
|
|
3987
3681
|
});
|
|
3988
3682
|
if (!tokenResponse.ok) {
|
|
3989
3683
|
const errorText = await tokenResponse.text();
|
|
3990
|
-
|
|
3684
|
+
logger3.error(
|
|
3991
3685
|
{
|
|
3992
3686
|
status: tokenResponse.status,
|
|
3993
3687
|
statusText: tokenResponse.statusText,
|
|
@@ -4005,7 +3699,7 @@ var OAuthService = class {
|
|
|
4005
3699
|
var oauthService = new OAuthService();
|
|
4006
3700
|
|
|
4007
3701
|
// src/routes/tools.ts
|
|
4008
|
-
var
|
|
3702
|
+
var logger4 = getLogger("tools");
|
|
4009
3703
|
var app15 = new OpenAPIHono();
|
|
4010
3704
|
app15.openapi(
|
|
4011
3705
|
createRoute({
|
|
@@ -4036,16 +3730,19 @@ app15.openapi(
|
|
|
4036
3730
|
const { tenantId, projectId } = c.req.valid("param");
|
|
4037
3731
|
const { page, limit, status } = c.req.valid("query");
|
|
4038
3732
|
let result;
|
|
3733
|
+
const credentialStores = c.get("credentialStores");
|
|
4039
3734
|
if (status) {
|
|
4040
|
-
const
|
|
3735
|
+
const dbResult = await listTools(dbClient_default)({
|
|
3736
|
+
scopes: { tenantId, projectId },
|
|
3737
|
+
pagination: { page, limit }
|
|
3738
|
+
});
|
|
4041
3739
|
result = {
|
|
4042
|
-
data:
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
}
|
|
3740
|
+
data: (await Promise.all(
|
|
3741
|
+
dbResult.data.map(
|
|
3742
|
+
async (tool) => await dbResultToMcpTool(tool, dbClient_default, credentialStores)
|
|
3743
|
+
)
|
|
3744
|
+
)).filter((tool) => tool.status === status),
|
|
3745
|
+
pagination: dbResult.pagination
|
|
4049
3746
|
};
|
|
4050
3747
|
} else {
|
|
4051
3748
|
const dbResult = await listTools(dbClient_default)({
|
|
@@ -4053,7 +3750,11 @@ app15.openapi(
|
|
|
4053
3750
|
pagination: { page, limit }
|
|
4054
3751
|
});
|
|
4055
3752
|
result = {
|
|
4056
|
-
data:
|
|
3753
|
+
data: await Promise.all(
|
|
3754
|
+
dbResult.data.map(
|
|
3755
|
+
async (tool) => await dbResultToMcpTool(tool, dbClient_default, credentialStores)
|
|
3756
|
+
)
|
|
3757
|
+
),
|
|
4057
3758
|
pagination: dbResult.pagination
|
|
4058
3759
|
};
|
|
4059
3760
|
}
|
|
@@ -4091,8 +3792,9 @@ app15.openapi(
|
|
|
4091
3792
|
message: "Tool not found"
|
|
4092
3793
|
});
|
|
4093
3794
|
}
|
|
3795
|
+
const credentialStores = c.get("credentialStores");
|
|
4094
3796
|
return c.json({
|
|
4095
|
-
data: dbResultToMcpTool(tool)
|
|
3797
|
+
data: await dbResultToMcpTool(tool, dbClient_default, credentialStores)
|
|
4096
3798
|
});
|
|
4097
3799
|
}
|
|
4098
3800
|
);
|
|
@@ -4128,7 +3830,8 @@ app15.openapi(
|
|
|
4128
3830
|
async (c) => {
|
|
4129
3831
|
const { tenantId, projectId } = c.req.valid("param");
|
|
4130
3832
|
const body = c.req.valid("json");
|
|
4131
|
-
|
|
3833
|
+
const credentialStores = c.get("credentialStores");
|
|
3834
|
+
logger4.info({ body }, "body");
|
|
4132
3835
|
const id = body.id || nanoid();
|
|
4133
3836
|
const tool = await createTool(dbClient_default)({
|
|
4134
3837
|
tenantId,
|
|
@@ -4142,7 +3845,7 @@ app15.openapi(
|
|
|
4142
3845
|
});
|
|
4143
3846
|
return c.json(
|
|
4144
3847
|
{
|
|
4145
|
-
data: dbResultToMcpTool(tool)
|
|
3848
|
+
data: await dbResultToMcpTool(tool, dbClient_default, credentialStores)
|
|
4146
3849
|
},
|
|
4147
3850
|
201
|
|
4148
3851
|
);
|
|
@@ -4180,6 +3883,7 @@ app15.openapi(
|
|
|
4180
3883
|
async (c) => {
|
|
4181
3884
|
const { tenantId, projectId, id } = c.req.valid("param");
|
|
4182
3885
|
const body = c.req.valid("json");
|
|
3886
|
+
const credentialStores = c.get("credentialStores");
|
|
4183
3887
|
if (Object.keys(body).length === 0) {
|
|
4184
3888
|
throw createApiError({
|
|
4185
3889
|
code: "bad_request",
|
|
@@ -4204,7 +3908,7 @@ app15.openapi(
|
|
|
4204
3908
|
});
|
|
4205
3909
|
}
|
|
4206
3910
|
return c.json({
|
|
4207
|
-
data: dbResultToMcpTool(updatedTool)
|
|
3911
|
+
data: await dbResultToMcpTool(updatedTool, dbClient_default, credentialStores)
|
|
4208
3912
|
});
|
|
4209
3913
|
}
|
|
4210
3914
|
);
|
|
@@ -4244,268 +3948,6 @@ app15.openapi(
|
|
|
4244
3948
|
return c.body(null, 204);
|
|
4245
3949
|
}
|
|
4246
3950
|
);
|
|
4247
|
-
app15.openapi(
|
|
4248
|
-
createRoute({
|
|
4249
|
-
method: "post",
|
|
4250
|
-
path: "/{id}/health-check",
|
|
4251
|
-
summary: "Check Tool Health",
|
|
4252
|
-
operationId: "check-tool-health",
|
|
4253
|
-
tags: ["Tools"],
|
|
4254
|
-
request: {
|
|
4255
|
-
params: TenantProjectParamsSchema.extend(IdParamsSchema.shape)
|
|
4256
|
-
},
|
|
4257
|
-
responses: {
|
|
4258
|
-
200: {
|
|
4259
|
-
description: "Tool health check completed",
|
|
4260
|
-
content: {
|
|
4261
|
-
"application/json": {
|
|
4262
|
-
schema: SingleResponseSchema(
|
|
4263
|
-
z.object({
|
|
4264
|
-
tool: McpToolSchema,
|
|
4265
|
-
healthCheck: z.object({
|
|
4266
|
-
status: ToolStatusSchema,
|
|
4267
|
-
error: z.string().optional()
|
|
4268
|
-
})
|
|
4269
|
-
})
|
|
4270
|
-
)
|
|
4271
|
-
}
|
|
4272
|
-
}
|
|
4273
|
-
},
|
|
4274
|
-
...commonGetErrorResponses
|
|
4275
|
-
}
|
|
4276
|
-
}),
|
|
4277
|
-
async (c) => {
|
|
4278
|
-
const { tenantId, projectId, id } = c.req.valid("param");
|
|
4279
|
-
const tool = await getToolById(dbClient_default)({ scopes: { tenantId, projectId }, toolId: id });
|
|
4280
|
-
if (!tool) {
|
|
4281
|
-
throw createApiError({
|
|
4282
|
-
code: "not_found",
|
|
4283
|
-
message: "Tool not found"
|
|
4284
|
-
});
|
|
4285
|
-
}
|
|
4286
|
-
const credentialStores = c.get("credentialStores");
|
|
4287
|
-
const healthResult = await checkToolHealth(dbResultToMcpTool(tool), credentialStores);
|
|
4288
|
-
const updatedTool = await updateToolHealth({
|
|
4289
|
-
tenantId,
|
|
4290
|
-
projectId,
|
|
4291
|
-
toolId: id,
|
|
4292
|
-
status: healthResult.status,
|
|
4293
|
-
error: healthResult.error
|
|
4294
|
-
});
|
|
4295
|
-
return c.json({
|
|
4296
|
-
data: {
|
|
4297
|
-
tool: dbResultToMcpTool(updatedTool),
|
|
4298
|
-
healthCheck: healthResult
|
|
4299
|
-
}
|
|
4300
|
-
});
|
|
4301
|
-
}
|
|
4302
|
-
);
|
|
4303
|
-
app15.openapi(
|
|
4304
|
-
createRoute({
|
|
4305
|
-
method: "post",
|
|
4306
|
-
path: "/health-check-all",
|
|
4307
|
-
summary: "Check All Tools Health",
|
|
4308
|
-
operationId: "check-all-tools-health",
|
|
4309
|
-
tags: ["Tools"],
|
|
4310
|
-
request: {
|
|
4311
|
-
params: TenantProjectParamsSchema
|
|
4312
|
-
},
|
|
4313
|
-
responses: {
|
|
4314
|
-
200: {
|
|
4315
|
-
description: "All tools health check completed",
|
|
4316
|
-
content: {
|
|
4317
|
-
"application/json": {
|
|
4318
|
-
schema: SingleResponseSchema(
|
|
4319
|
-
z.object({
|
|
4320
|
-
total: z.number(),
|
|
4321
|
-
successful: z.number(),
|
|
4322
|
-
failed: z.number(),
|
|
4323
|
-
results: z.array(
|
|
4324
|
-
z.object({
|
|
4325
|
-
index: z.number(),
|
|
4326
|
-
status: z.enum(["fulfilled", "rejected"]),
|
|
4327
|
-
data: z.string().optional(),
|
|
4328
|
-
error: z.string().optional()
|
|
4329
|
-
})
|
|
4330
|
-
)
|
|
4331
|
-
})
|
|
4332
|
-
)
|
|
4333
|
-
}
|
|
4334
|
-
}
|
|
4335
|
-
},
|
|
4336
|
-
...commonGetErrorResponses
|
|
4337
|
-
}
|
|
4338
|
-
}),
|
|
4339
|
-
async (c) => {
|
|
4340
|
-
const { tenantId, projectId } = c.req.valid("param");
|
|
4341
|
-
const credentialStores = c.get("credentialStores");
|
|
4342
|
-
const results = await checkAllToolsHealth(tenantId, projectId, credentialStores);
|
|
4343
|
-
const summary = {
|
|
4344
|
-
total: results.length,
|
|
4345
|
-
successful: results.filter((r) => r.status === "fulfilled").length,
|
|
4346
|
-
failed: results.filter((r) => r.status === "rejected").length,
|
|
4347
|
-
results: results.map((result, index) => {
|
|
4348
|
-
const baseResult = {
|
|
4349
|
-
index,
|
|
4350
|
-
status: result.status
|
|
4351
|
-
};
|
|
4352
|
-
if (result.status === "fulfilled") {
|
|
4353
|
-
return {
|
|
4354
|
-
...baseResult,
|
|
4355
|
-
data: `Tool ${index} health check completed`
|
|
4356
|
-
};
|
|
4357
|
-
}
|
|
4358
|
-
return {
|
|
4359
|
-
...baseResult,
|
|
4360
|
-
error: result.reason?.message || "Unknown error"
|
|
4361
|
-
};
|
|
4362
|
-
})
|
|
4363
|
-
};
|
|
4364
|
-
return c.json({ data: summary });
|
|
4365
|
-
}
|
|
4366
|
-
);
|
|
4367
|
-
app15.openapi(
|
|
4368
|
-
createRoute({
|
|
4369
|
-
method: "post",
|
|
4370
|
-
path: "/{id}/sync",
|
|
4371
|
-
summary: "Sync Tool Definitions",
|
|
4372
|
-
operationId: "sync-tool-definitions",
|
|
4373
|
-
tags: ["Tools"],
|
|
4374
|
-
request: {
|
|
4375
|
-
params: TenantProjectParamsSchema.extend(IdParamsSchema.shape)
|
|
4376
|
-
},
|
|
4377
|
-
responses: {
|
|
4378
|
-
200: {
|
|
4379
|
-
description: "Tool definitions synchronized successfully",
|
|
4380
|
-
content: {
|
|
4381
|
-
"application/json": {
|
|
4382
|
-
schema: SingleResponseSchema(McpToolSchema)
|
|
4383
|
-
}
|
|
4384
|
-
}
|
|
4385
|
-
},
|
|
4386
|
-
...commonGetErrorResponses
|
|
4387
|
-
}
|
|
4388
|
-
}),
|
|
4389
|
-
async (c) => {
|
|
4390
|
-
const { tenantId, projectId, id } = c.req.valid("param");
|
|
4391
|
-
const tool = await getToolById(dbClient_default)({ scopes: { tenantId, projectId }, toolId: id });
|
|
4392
|
-
if (!tool) {
|
|
4393
|
-
throw createApiError({
|
|
4394
|
-
code: "not_found",
|
|
4395
|
-
message: "Tool not found"
|
|
4396
|
-
});
|
|
4397
|
-
}
|
|
4398
|
-
const credentialStores = c.get("credentialStores");
|
|
4399
|
-
const updatedTool = await syncToolDefinitions({
|
|
4400
|
-
tenantId,
|
|
4401
|
-
projectId,
|
|
4402
|
-
toolId: id,
|
|
4403
|
-
credentialStoreRegistry: credentialStores
|
|
4404
|
-
});
|
|
4405
|
-
return c.json({
|
|
4406
|
-
data: dbResultToMcpTool(updatedTool),
|
|
4407
|
-
message: "Tool definitions synchronized successfully"
|
|
4408
|
-
});
|
|
4409
|
-
}
|
|
4410
|
-
);
|
|
4411
|
-
app15.openapi(
|
|
4412
|
-
createRoute({
|
|
4413
|
-
method: "get",
|
|
4414
|
-
path: "/{id}/available-tools",
|
|
4415
|
-
summary: "Get Available Tools",
|
|
4416
|
-
operationId: "get-available-tools",
|
|
4417
|
-
tags: ["Tools"],
|
|
4418
|
-
request: {
|
|
4419
|
-
params: TenantProjectParamsSchema.extend(IdParamsSchema.shape)
|
|
4420
|
-
},
|
|
4421
|
-
responses: {
|
|
4422
|
-
200: {
|
|
4423
|
-
description: "Available tools retrieved successfully",
|
|
4424
|
-
content: {
|
|
4425
|
-
"application/json": {
|
|
4426
|
-
schema: SingleResponseSchema(
|
|
4427
|
-
z.object({
|
|
4428
|
-
availableTools: z.array(
|
|
4429
|
-
z.object({
|
|
4430
|
-
name: z.string(),
|
|
4431
|
-
description: z.string().optional(),
|
|
4432
|
-
inputSchema: z.record(z.string(), z.unknown()).optional()
|
|
4433
|
-
})
|
|
4434
|
-
),
|
|
4435
|
-
lastSync: z.string().optional(),
|
|
4436
|
-
status: ToolStatusSchema
|
|
4437
|
-
})
|
|
4438
|
-
)
|
|
4439
|
-
}
|
|
4440
|
-
}
|
|
4441
|
-
},
|
|
4442
|
-
...commonGetErrorResponses
|
|
4443
|
-
}
|
|
4444
|
-
}),
|
|
4445
|
-
async (c) => {
|
|
4446
|
-
const { tenantId, projectId, id } = c.req.valid("param");
|
|
4447
|
-
const tool = await getToolById(dbClient_default)({ scopes: { tenantId, projectId }, toolId: id });
|
|
4448
|
-
if (!tool) {
|
|
4449
|
-
throw createApiError({
|
|
4450
|
-
code: "not_found",
|
|
4451
|
-
message: "Tool not found"
|
|
4452
|
-
});
|
|
4453
|
-
}
|
|
4454
|
-
return c.json({
|
|
4455
|
-
data: {
|
|
4456
|
-
availableTools: tool.availableTools || [],
|
|
4457
|
-
lastSync: tool.lastToolsSync || void 0,
|
|
4458
|
-
status: tool.status
|
|
4459
|
-
}
|
|
4460
|
-
});
|
|
4461
|
-
}
|
|
4462
|
-
);
|
|
4463
|
-
app15.openapi(
|
|
4464
|
-
createRoute({
|
|
4465
|
-
method: "patch",
|
|
4466
|
-
path: "/{id}/status",
|
|
4467
|
-
summary: "Update Tool Status",
|
|
4468
|
-
operationId: "update-tool-status",
|
|
4469
|
-
tags: ["Tools"],
|
|
4470
|
-
request: {
|
|
4471
|
-
params: TenantProjectParamsSchema.extend(IdParamsSchema.shape),
|
|
4472
|
-
body: {
|
|
4473
|
-
content: {
|
|
4474
|
-
"application/json": {
|
|
4475
|
-
schema: z.object({
|
|
4476
|
-
status: ToolStatusSchema
|
|
4477
|
-
})
|
|
4478
|
-
}
|
|
4479
|
-
}
|
|
4480
|
-
}
|
|
4481
|
-
},
|
|
4482
|
-
responses: {
|
|
4483
|
-
200: {
|
|
4484
|
-
description: "Tool status updated successfully",
|
|
4485
|
-
content: {
|
|
4486
|
-
"application/json": {
|
|
4487
|
-
schema: SingleResponseSchema(McpToolSchema)
|
|
4488
|
-
}
|
|
4489
|
-
}
|
|
4490
|
-
},
|
|
4491
|
-
...commonGetErrorResponses
|
|
4492
|
-
}
|
|
4493
|
-
}),
|
|
4494
|
-
async (c) => {
|
|
4495
|
-
const { tenantId, projectId, id } = c.req.valid("param");
|
|
4496
|
-
const { status } = c.req.valid("json");
|
|
4497
|
-
const updatedTool = await updateToolHealth({
|
|
4498
|
-
tenantId,
|
|
4499
|
-
projectId,
|
|
4500
|
-
toolId: id,
|
|
4501
|
-
status
|
|
4502
|
-
});
|
|
4503
|
-
return c.json({
|
|
4504
|
-
data: dbResultToMcpTool(updatedTool),
|
|
4505
|
-
message: `Tool status updated to ${status}`
|
|
4506
|
-
});
|
|
4507
|
-
}
|
|
4508
|
-
);
|
|
4509
3951
|
app15.openapi(
|
|
4510
3952
|
createRoute({
|
|
4511
3953
|
method: "get",
|
|
@@ -4557,7 +3999,8 @@ app15.openapi(
|
|
|
4557
3999
|
message: "Tool not found"
|
|
4558
4000
|
});
|
|
4559
4001
|
}
|
|
4560
|
-
const
|
|
4002
|
+
const credentialStores = c.get("credentialStores");
|
|
4003
|
+
const mcpTool = await dbResultToMcpTool(tool, dbClient_default, credentialStores);
|
|
4561
4004
|
const { redirectUrl } = await oauthService.initiateOAuthFlow({
|
|
4562
4005
|
tool: mcpTool,
|
|
4563
4006
|
tenantId,
|
|
@@ -4566,7 +4009,7 @@ app15.openapi(
|
|
|
4566
4009
|
});
|
|
4567
4010
|
return c.redirect(redirectUrl, 302);
|
|
4568
4011
|
} catch (error) {
|
|
4569
|
-
|
|
4012
|
+
logger4.error({ toolId: id, error }, "OAuth login failed");
|
|
4570
4013
|
if (error && typeof error === "object" && "code" in error) {
|
|
4571
4014
|
const apiError = error;
|
|
4572
4015
|
return c.json({ error: apiError.message }, apiError.code === "not_found" ? 404 : 400);
|
|
@@ -4601,7 +4044,7 @@ app16.route("/projects/:projectId/api-keys", apiKeys_default);
|
|
|
4601
4044
|
app16.route("/projects/:projectId/graph", graphFull_default);
|
|
4602
4045
|
var routes_default = app16;
|
|
4603
4046
|
var app17 = new OpenAPIHono();
|
|
4604
|
-
var
|
|
4047
|
+
var logger5 = getLogger("oauth-callback");
|
|
4605
4048
|
var OAuthCallbackQuerySchema = z$1.object({
|
|
4606
4049
|
code: z$1.string().min(1, "Authorization code is required"),
|
|
4607
4050
|
state: z$1.string().min(1, "State parameter is required"),
|
|
@@ -4644,15 +4087,15 @@ app17.openapi(
|
|
|
4644
4087
|
async (c) => {
|
|
4645
4088
|
try {
|
|
4646
4089
|
const { code, state, error, error_description } = c.req.valid("query");
|
|
4647
|
-
|
|
4090
|
+
logger5.info({ state, hasCode: !!code }, "OAuth callback received");
|
|
4648
4091
|
if (error) {
|
|
4649
|
-
|
|
4092
|
+
logger5.error({ error, error_description }, "OAuth authorization failed");
|
|
4650
4093
|
const errorMessage = "OAuth Authorization Failed. Please try again.";
|
|
4651
4094
|
return c.text(errorMessage, 400);
|
|
4652
4095
|
}
|
|
4653
4096
|
const pkceData = retrievePKCEVerifier(state);
|
|
4654
4097
|
if (!pkceData) {
|
|
4655
|
-
|
|
4098
|
+
logger5.error({ state }, "Invalid or expired OAuth state");
|
|
4656
4099
|
return c.text(
|
|
4657
4100
|
"OAuth Session Expired: The OAuth session has expired or is invalid. Please try again.",
|
|
4658
4101
|
400
|
|
@@ -4666,20 +4109,20 @@ app17.openapi(
|
|
|
4666
4109
|
if (!tool) {
|
|
4667
4110
|
throw new Error(`Tool ${toolId} not found`);
|
|
4668
4111
|
}
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
const
|
|
4112
|
+
logger5.info({ toolId, tenantId, projectId }, "Processing OAuth callback");
|
|
4113
|
+
logger5.info({ toolId }, "Exchanging authorization code for access token");
|
|
4114
|
+
const credentialStores = c.get("credentialStores");
|
|
4115
|
+
const mcpTool = await dbResultToMcpTool(tool, dbClient_default, credentialStores);
|
|
4672
4116
|
const { tokens } = await oauthService.exchangeCodeForTokens({
|
|
4673
4117
|
code,
|
|
4674
4118
|
codeVerifier,
|
|
4675
4119
|
clientId,
|
|
4676
4120
|
tool: mcpTool
|
|
4677
4121
|
});
|
|
4678
|
-
|
|
4122
|
+
logger5.info(
|
|
4679
4123
|
{ toolId, tokenType: tokens.token_type, hasRefresh: !!tokens.refresh_token },
|
|
4680
4124
|
"Token exchange successful"
|
|
4681
4125
|
);
|
|
4682
|
-
const credentialStores = c.get("credentialStores");
|
|
4683
4126
|
const keychainStore = credentialStores.get("keychain-default");
|
|
4684
4127
|
const keychainKey = `oauth_token_${toolId}`;
|
|
4685
4128
|
await keychainStore?.set(keychainKey, JSON.stringify(tokens));
|
|
@@ -4697,14 +4140,14 @@ app17.openapi(
|
|
|
4697
4140
|
};
|
|
4698
4141
|
let credential;
|
|
4699
4142
|
if (existingCredential) {
|
|
4700
|
-
|
|
4143
|
+
logger5.info({ credentialId: existingCredential.id }, "Updating existing credential");
|
|
4701
4144
|
credential = await updateCredentialReference(dbClient_default)({
|
|
4702
4145
|
scopes: { tenantId, projectId },
|
|
4703
4146
|
id: existingCredential.id,
|
|
4704
4147
|
data: credentialData
|
|
4705
4148
|
});
|
|
4706
4149
|
} else {
|
|
4707
|
-
|
|
4150
|
+
logger5.info({ credentialId }, "Creating new credential");
|
|
4708
4151
|
credential = await createCredentialReference(dbClient_default)({
|
|
4709
4152
|
tenantId,
|
|
4710
4153
|
projectId,
|
|
@@ -4722,7 +4165,7 @@ app17.openapi(
|
|
|
4722
4165
|
credentialReferenceId: credential.id
|
|
4723
4166
|
}
|
|
4724
4167
|
});
|
|
4725
|
-
|
|
4168
|
+
logger5.info({ toolId, credentialId: credential.id }, "OAuth flow completed successfully");
|
|
4726
4169
|
const successPage = `
|
|
4727
4170
|
<!DOCTYPE html>
|
|
4728
4171
|
<html>
|
|
@@ -4764,14 +4207,14 @@ app17.openapi(
|
|
|
4764
4207
|
`;
|
|
4765
4208
|
return c.html(successPage);
|
|
4766
4209
|
} catch (error) {
|
|
4767
|
-
|
|
4210
|
+
logger5.error({ error }, "OAuth callback processing failed");
|
|
4768
4211
|
const errorMessage = "OAuth Processing Failed. Please try again.";
|
|
4769
4212
|
return c.text(errorMessage, 500);
|
|
4770
4213
|
}
|
|
4771
4214
|
}
|
|
4772
4215
|
);
|
|
4773
4216
|
var oauth_default = app17;
|
|
4774
|
-
var
|
|
4217
|
+
var logger6 = getLogger("projectFull");
|
|
4775
4218
|
var app18 = new OpenAPIHono();
|
|
4776
4219
|
var ProjectIdParamsSchema = z.object({
|
|
4777
4220
|
tenantId: z.string().openapi({
|
|
@@ -4832,7 +4275,7 @@ app18.openapi(
|
|
|
4832
4275
|
const projectData = c.req.valid("json");
|
|
4833
4276
|
const validatedProjectData = FullProjectDefinitionSchema.parse(projectData);
|
|
4834
4277
|
try {
|
|
4835
|
-
const createdProject = await createFullProjectServerSide(dbClient_default,
|
|
4278
|
+
const createdProject = await createFullProjectServerSide(dbClient_default, logger6)(
|
|
4836
4279
|
{ tenantId, projectId: validatedProjectData.id },
|
|
4837
4280
|
validatedProjectData
|
|
4838
4281
|
);
|
|
@@ -4876,7 +4319,7 @@ app18.openapi(
|
|
|
4876
4319
|
try {
|
|
4877
4320
|
const project = await getFullProject(
|
|
4878
4321
|
dbClient_default,
|
|
4879
|
-
|
|
4322
|
+
logger6
|
|
4880
4323
|
)({
|
|
4881
4324
|
scopes: { tenantId, projectId }
|
|
4882
4325
|
});
|
|
@@ -4952,15 +4395,15 @@ app18.openapi(
|
|
|
4952
4395
|
}
|
|
4953
4396
|
const existingProject = await getFullProject(
|
|
4954
4397
|
dbClient_default,
|
|
4955
|
-
|
|
4398
|
+
logger6
|
|
4956
4399
|
)({
|
|
4957
4400
|
scopes: { tenantId, projectId }
|
|
4958
4401
|
});
|
|
4959
4402
|
const isCreate = !existingProject;
|
|
4960
|
-
const updatedProject = isCreate ? await createFullProjectServerSide(dbClient_default,
|
|
4403
|
+
const updatedProject = isCreate ? await createFullProjectServerSide(dbClient_default, logger6)(
|
|
4961
4404
|
{ tenantId, projectId },
|
|
4962
4405
|
validatedProjectData
|
|
4963
|
-
) : await updateFullProjectServerSide(dbClient_default,
|
|
4406
|
+
) : await updateFullProjectServerSide(dbClient_default, logger6)(
|
|
4964
4407
|
{ tenantId, projectId },
|
|
4965
4408
|
validatedProjectData
|
|
4966
4409
|
);
|
|
@@ -5008,7 +4451,7 @@ app18.openapi(
|
|
|
5008
4451
|
try {
|
|
5009
4452
|
const deleted = await deleteFullProject(
|
|
5010
4453
|
dbClient_default,
|
|
5011
|
-
|
|
4454
|
+
logger6
|
|
5012
4455
|
)({
|
|
5013
4456
|
scopes: { tenantId, projectId }
|
|
5014
4457
|
});
|
|
@@ -5036,8 +4479,8 @@ app18.openapi(
|
|
|
5036
4479
|
var projectFull_default = app18;
|
|
5037
4480
|
|
|
5038
4481
|
// src/app.ts
|
|
5039
|
-
var
|
|
5040
|
-
|
|
4482
|
+
var logger7 = getLogger("agents-manage-api");
|
|
4483
|
+
logger7.info({ logger: logger7.getTransports() }, "Logger initialized");
|
|
5041
4484
|
function createManagementHono(serverConfig, credentialStores) {
|
|
5042
4485
|
const app20 = new OpenAPIHono();
|
|
5043
4486
|
app20.use("*", requestId());
|
|
@@ -5092,7 +4535,7 @@ function createManagementHono(serverConfig, credentialStores) {
|
|
|
5092
4535
|
if (!isExpectedError) {
|
|
5093
4536
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
5094
4537
|
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
5095
|
-
|
|
4538
|
+
logger7.error(
|
|
5096
4539
|
{
|
|
5097
4540
|
error: err,
|
|
5098
4541
|
message: errorMessage,
|
|
@@ -5103,7 +4546,7 @@ function createManagementHono(serverConfig, credentialStores) {
|
|
|
5103
4546
|
"Unexpected server error occurred"
|
|
5104
4547
|
);
|
|
5105
4548
|
} else {
|
|
5106
|
-
|
|
4549
|
+
logger7.error(
|
|
5107
4550
|
{
|
|
5108
4551
|
error: err,
|
|
5109
4552
|
path: c.req.path,
|
|
@@ -5119,7 +4562,7 @@ function createManagementHono(serverConfig, credentialStores) {
|
|
|
5119
4562
|
const response = err.getResponse();
|
|
5120
4563
|
return response;
|
|
5121
4564
|
} catch (responseError) {
|
|
5122
|
-
|
|
4565
|
+
logger7.error({ error: responseError }, "Error while handling HTTPException response");
|
|
5123
4566
|
}
|
|
5124
4567
|
}
|
|
5125
4568
|
const { status: respStatus, title, detail, instance } = await handleApiError(err, requestId2);
|