( tx: DbOrTx, serverId: string, excludeToolId?: string )
| 127 | } |
| 128 | |
| 129 | export async function getMcpServerToolMetadataUsageRows( |
| 130 | tx: DbOrTx, |
| 131 | serverId: string, |
| 132 | excludeToolId?: string |
| 133 | ): Promise<McpToolMetadataUsageRow[]> { |
| 134 | const rows = await tx |
| 135 | .select({ |
| 136 | id: workflowMcpTool.id, |
| 137 | toolNameBytes: sql<number>`octet_length(${workflowMcpTool.toolName})`, |
| 138 | toolDescriptionBytes: sql<number>`coalesce(octet_length(${workflowMcpTool.toolDescription}), 0)`, |
| 139 | parameterSchemaBytes: sql<number>`octet_length(${workflowMcpTool.parameterSchema}::text)`, |
| 140 | }) |
| 141 | .from(workflowMcpTool) |
| 142 | .where( |
| 143 | and( |
| 144 | eq(workflowMcpTool.serverId, serverId), |
| 145 | isNull(workflowMcpTool.archivedAt), |
| 146 | excludeToolId ? ne(workflowMcpTool.id, excludeToolId) : undefined |
| 147 | ) |
| 148 | ) |
| 149 | |
| 150 | return rows.map((row) => ({ |
| 151 | id: row.id, |
| 152 | toolNameBytes: Number(row.toolNameBytes) || 0, |
| 153 | toolDescriptionBytes: Number(row.toolDescriptionBytes) || 0, |
| 154 | parameterSchemaBytes: Number(row.parameterSchemaBytes) || 0, |
| 155 | })) |
| 156 | } |
| 157 | |
| 158 | export function validateMcpToolMetadataForStorage(metadata: { |
| 159 | toolName?: string | null |
no test coverage detected