'use strict'; var chunkSGXBKIPB_cjs = require('./chunk-SGXBKIPB.cjs'); var chunk2XZ2466F_cjs = require('./chunk-2XZ2466F.cjs'); var chunkGZ4HWZWE_cjs = require('./chunk-GZ4HWZWE.cjs'); var chunkZ7LCIYK7_cjs = require('./chunk-Z7LCIYK7.cjs'); var chunkG54X6VE6_cjs = require('./chunk-G54X6VE6.cjs'); var chunk64ITUOXI_cjs = require('./chunk-64ITUOXI.cjs'); // src/server/handlers/mcp-client-versions.ts var LIST_MCP_CLIENT_VERSIONS_ROUTE = chunkG54X6VE6_cjs.createRoute({ method: "GET", path: "/stored/mcp-clients/:mcpClientId/versions", requiresAuth: true, responseType: "json", pathParamSchema: chunkSGXBKIPB_cjs.mcpClientVersionPathParams, queryParamSchema: chunkSGXBKIPB_cjs.listMCPClientVersionsQuerySchema, responseSchema: chunkSGXBKIPB_cjs.listMCPClientVersionsResponseSchema, summary: "List MCP client versions", description: "Returns a paginated list of all versions for a stored MCP client", tags: ["MCP Client Versions"], handler: async ({ mastra, mcpClientId, page, perPage, orderBy, requestContext }) => { try { const storage = mastra.getStorage(); if (!storage) { throw new chunk64ITUOXI_cjs.HTTPException(500, { message: "Storage is not configured" }); } const mcpClientStore = await storage.getStore("mcpClients"); if (!mcpClientStore) { throw new chunk64ITUOXI_cjs.HTTPException(500, { message: "MCP clients storage domain is not available" }); } const mcpClient = await mcpClientStore.getById(mcpClientId); if (!mcpClient) { throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `MCP client with id ${mcpClientId} not found` }); } chunkGZ4HWZWE_cjs.assertStoredResourceScope(mcpClient, await chunkGZ4HWZWE_cjs.getStoredResourceScope(mastra, requestContext)); const result = await mcpClientStore.listVersions({ mcpClientId, page, perPage, orderBy }); return result; } catch (error) { return chunkZ7LCIYK7_cjs.handleError(error, "Error listing MCP client versions"); } } }); var CREATE_MCP_CLIENT_VERSION_ROUTE = chunkG54X6VE6_cjs.createRoute({ method: "POST", path: "/stored/mcp-clients/:mcpClientId/versions", requiresAuth: true, responseType: "json", pathParamSchema: chunkSGXBKIPB_cjs.mcpClientVersionPathParams, bodySchema: chunkSGXBKIPB_cjs.createMCPClientVersionBodySchema, responseSchema: chunkSGXBKIPB_cjs.createMCPClientVersionResponseSchema, summary: "Create MCP client version", description: "Creates a new version snapshot of the current MCP client configuration", tags: ["MCP Client Versions"], handler: async ({ mastra, mcpClientId, changeMessage, requestContext }) => { try { const storage = mastra.getStorage(); if (!storage) { throw new chunk64ITUOXI_cjs.HTTPException(500, { message: "Storage is not configured" }); } const mcpClientStore = await storage.getStore("mcpClients"); if (!mcpClientStore) { throw new chunk64ITUOXI_cjs.HTTPException(500, { message: "MCP clients storage domain is not available" }); } const mcpClient = await mcpClientStore.getById(mcpClientId); if (!mcpClient) { throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `MCP client with id ${mcpClientId} not found` }); } chunkGZ4HWZWE_cjs.assertStoredResourceScope(mcpClient, await chunkGZ4HWZWE_cjs.getStoredResourceScope(mastra, requestContext)); let currentConfig = {}; if (mcpClient.activeVersionId) { const activeVersion = await mcpClientStore.getVersion(mcpClient.activeVersionId); if (activeVersion) { currentConfig = chunk2XZ2466F_cjs.extractConfigFromVersion( activeVersion, chunk2XZ2466F_cjs.MCP_CLIENT_SNAPSHOT_CONFIG_FIELDS ); } } const latestVersion = await mcpClientStore.getLatestVersion(mcpClientId); if (!mcpClient.activeVersionId && latestVersion) { currentConfig = chunk2XZ2466F_cjs.extractConfigFromVersion( latestVersion, chunk2XZ2466F_cjs.MCP_CLIENT_SNAPSHOT_CONFIG_FIELDS ); } const previousConfig = latestVersion ? chunk2XZ2466F_cjs.extractConfigFromVersion( latestVersion, chunk2XZ2466F_cjs.MCP_CLIENT_SNAPSHOT_CONFIG_FIELDS ) : null; const changedFields = chunk2XZ2466F_cjs.calculateChangedFields(previousConfig, currentConfig); const { versionId } = await chunk2XZ2466F_cjs.createVersionWithRetry( mcpClientStore, mcpClientId, "mcpClientId", currentConfig, changedFields, { changeMessage } ); const version = await mcpClientStore.getVersion(versionId); if (!version) { throw new chunk64ITUOXI_cjs.HTTPException(500, { message: "Failed to retrieve created version" }); } await chunk2XZ2466F_cjs.enforceRetentionLimit( mcpClientStore, mcpClientId, "mcpClientId", mcpClient.activeVersionId ); return version; } catch (error) { return chunkZ7LCIYK7_cjs.handleError(error, "Error creating MCP client version"); } } }); var GET_MCP_CLIENT_VERSION_ROUTE = chunkG54X6VE6_cjs.createRoute({ method: "GET", path: "/stored/mcp-clients/:mcpClientId/versions/:versionId", requiresAuth: true, responseType: "json", pathParamSchema: chunkSGXBKIPB_cjs.mcpClientVersionIdPathParams, responseSchema: chunkSGXBKIPB_cjs.getMCPClientVersionResponseSchema, summary: "Get MCP client version", description: "Returns a specific version of an MCP client by its version ID", tags: ["MCP Client Versions"], handler: async ({ mastra, mcpClientId, versionId, requestContext }) => { try { const storage = mastra.getStorage(); if (!storage) { throw new chunk64ITUOXI_cjs.HTTPException(500, { message: "Storage is not configured" }); } const mcpClientStore = await storage.getStore("mcpClients"); if (!mcpClientStore) { throw new chunk64ITUOXI_cjs.HTTPException(500, { message: "MCP clients storage domain is not available" }); } const version = await mcpClientStore.getVersion(versionId); if (!version) { throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Version with id ${versionId} not found` }); } if (version.mcpClientId !== mcpClientId) { throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Version with id ${versionId} not found for MCP client ${mcpClientId}` }); } const mcpClient = await mcpClientStore.getById(mcpClientId); chunkGZ4HWZWE_cjs.assertStoredResourceScope(mcpClient, await chunkGZ4HWZWE_cjs.getStoredResourceScope(mastra, requestContext)); return version; } catch (error) { return chunkZ7LCIYK7_cjs.handleError(error, "Error getting MCP client version"); } } }); var ACTIVATE_MCP_CLIENT_VERSION_ROUTE = chunkG54X6VE6_cjs.createRoute({ method: "POST", path: "/stored/mcp-clients/:mcpClientId/versions/:versionId/activate", requiresAuth: true, responseType: "json", pathParamSchema: chunkSGXBKIPB_cjs.mcpClientVersionIdPathParams, responseSchema: chunkSGXBKIPB_cjs.activateMCPClientVersionResponseSchema, summary: "Activate MCP client version", description: "Sets a specific version as the active version for the MCP client", tags: ["MCP Client Versions"], handler: async ({ mastra, mcpClientId, versionId, requestContext }) => { try { const storage = mastra.getStorage(); if (!storage) { throw new chunk64ITUOXI_cjs.HTTPException(500, { message: "Storage is not configured" }); } const mcpClientStore = await storage.getStore("mcpClients"); if (!mcpClientStore) { throw new chunk64ITUOXI_cjs.HTTPException(500, { message: "MCP clients storage domain is not available" }); } const mcpClient = await mcpClientStore.getById(mcpClientId); if (!mcpClient) { throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `MCP client with id ${mcpClientId} not found` }); } chunkGZ4HWZWE_cjs.assertStoredResourceScope(mcpClient, await chunkGZ4HWZWE_cjs.getStoredResourceScope(mastra, requestContext)); const version = await mcpClientStore.getVersion(versionId); if (!version) { throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Version with id ${versionId} not found` }); } if (version.mcpClientId !== mcpClientId) { throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Version with id ${versionId} not found for MCP client ${mcpClientId}` }); } await mcpClientStore.update({ id: mcpClientId, activeVersionId: versionId, status: "published" }); mastra.getEditor()?.mcp.clearCache(mcpClientId); return { success: true, message: `Version ${version.versionNumber} is now active`, activeVersionId: versionId }; } catch (error) { return chunkZ7LCIYK7_cjs.handleError(error, "Error activating MCP client version"); } } }); var RESTORE_MCP_CLIENT_VERSION_ROUTE = chunkG54X6VE6_cjs.createRoute({ method: "POST", path: "/stored/mcp-clients/:mcpClientId/versions/:versionId/restore", requiresAuth: true, responseType: "json", pathParamSchema: chunkSGXBKIPB_cjs.mcpClientVersionIdPathParams, responseSchema: chunkSGXBKIPB_cjs.restoreMCPClientVersionResponseSchema, summary: "Restore MCP client version", description: "Restores the MCP client configuration from a version, creating a new version", tags: ["MCP Client Versions"], handler: async ({ mastra, mcpClientId, versionId, requestContext }) => { try { const storage = mastra.getStorage(); if (!storage) { throw new chunk64ITUOXI_cjs.HTTPException(500, { message: "Storage is not configured" }); } const mcpClientStore = await storage.getStore("mcpClients"); if (!mcpClientStore) { throw new chunk64ITUOXI_cjs.HTTPException(500, { message: "MCP clients storage domain is not available" }); } const mcpClient = await mcpClientStore.getById(mcpClientId); if (!mcpClient) { throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `MCP client with id ${mcpClientId} not found` }); } chunkGZ4HWZWE_cjs.assertStoredResourceScope(mcpClient, await chunkGZ4HWZWE_cjs.getStoredResourceScope(mastra, requestContext)); const versionToRestore = await mcpClientStore.getVersion(versionId); if (!versionToRestore) { throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Version with id ${versionId} not found` }); } if (versionToRestore.mcpClientId !== mcpClientId) { throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Version with id ${versionId} not found for MCP client ${mcpClientId}` }); } const restoredConfig = chunk2XZ2466F_cjs.extractConfigFromVersion( versionToRestore, chunk2XZ2466F_cjs.MCP_CLIENT_SNAPSHOT_CONFIG_FIELDS ); await mcpClientStore.update({ id: mcpClientId, ...restoredConfig }); const latestVersion = await mcpClientStore.getLatestVersion(mcpClientId); const previousConfig = latestVersion ? chunk2XZ2466F_cjs.extractConfigFromVersion( latestVersion, chunk2XZ2466F_cjs.MCP_CLIENT_SNAPSHOT_CONFIG_FIELDS ) : null; const changedFields = chunk2XZ2466F_cjs.calculateChangedFields(previousConfig, restoredConfig); const { versionId: newVersionId } = await chunk2XZ2466F_cjs.createVersionWithRetry( mcpClientStore, mcpClientId, "mcpClientId", restoredConfig, changedFields, { changeMessage: `Restored from version ${versionToRestore.versionNumber}` } ); const newVersion = await mcpClientStore.getVersion(newVersionId); if (!newVersion) { throw new chunk64ITUOXI_cjs.HTTPException(500, { message: "Failed to retrieve created version" }); } await chunk2XZ2466F_cjs.enforceRetentionLimit( mcpClientStore, mcpClientId, "mcpClientId", mcpClient.activeVersionId ); mastra.getEditor()?.mcp.clearCache(mcpClientId); return newVersion; } catch (error) { return chunkZ7LCIYK7_cjs.handleError(error, "Error restoring MCP client version"); } } }); var DELETE_MCP_CLIENT_VERSION_ROUTE = chunkG54X6VE6_cjs.createRoute({ method: "DELETE", path: "/stored/mcp-clients/:mcpClientId/versions/:versionId", requiresAuth: true, responseType: "json", pathParamSchema: chunkSGXBKIPB_cjs.mcpClientVersionIdPathParams, responseSchema: chunkSGXBKIPB_cjs.deleteMCPClientVersionResponseSchema, summary: "Delete MCP client version", description: "Deletes a specific version (cannot delete the active version)", tags: ["MCP Client Versions"], handler: async ({ mastra, mcpClientId, versionId, requestContext }) => { try { const storage = mastra.getStorage(); if (!storage) { throw new chunk64ITUOXI_cjs.HTTPException(500, { message: "Storage is not configured" }); } const mcpClientStore = await storage.getStore("mcpClients"); if (!mcpClientStore) { throw new chunk64ITUOXI_cjs.HTTPException(500, { message: "MCP clients storage domain is not available" }); } const mcpClient = await mcpClientStore.getById(mcpClientId); if (!mcpClient) { throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `MCP client with id ${mcpClientId} not found` }); } chunkGZ4HWZWE_cjs.assertStoredResourceScope(mcpClient, await chunkGZ4HWZWE_cjs.getStoredResourceScope(mastra, requestContext)); const version = await mcpClientStore.getVersion(versionId); if (!version) { throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Version with id ${versionId} not found` }); } if (version.mcpClientId !== mcpClientId) { throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Version with id ${versionId} not found for MCP client ${mcpClientId}` }); } if (mcpClient.activeVersionId === versionId) { throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Cannot delete the active version. Activate a different version first." }); } await mcpClientStore.deleteVersion(versionId); mastra.getEditor()?.mcp.clearCache(mcpClientId); return { success: true, message: `Version ${version.versionNumber} deleted successfully` }; } catch (error) { return chunkZ7LCIYK7_cjs.handleError(error, "Error deleting MCP client version"); } } }); var COMPARE_MCP_CLIENT_VERSIONS_ROUTE = chunkG54X6VE6_cjs.createRoute({ method: "GET", path: "/stored/mcp-clients/:mcpClientId/versions/compare", requiresAuth: true, responseType: "json", pathParamSchema: chunkSGXBKIPB_cjs.mcpClientVersionPathParams, queryParamSchema: chunkSGXBKIPB_cjs.compareMCPClientVersionsQuerySchema, responseSchema: chunkSGXBKIPB_cjs.compareMCPClientVersionsResponseSchema, summary: "Compare MCP client versions", description: "Compares two versions and returns the differences between them", tags: ["MCP Client Versions"], handler: async ({ mastra, mcpClientId, from, to, requestContext }) => { try { const storage = mastra.getStorage(); if (!storage) { throw new chunk64ITUOXI_cjs.HTTPException(500, { message: "Storage is not configured" }); } const mcpClientStore = await storage.getStore("mcpClients"); if (!mcpClientStore) { throw new chunk64ITUOXI_cjs.HTTPException(500, { message: "MCP clients storage domain is not available" }); } const mcpClient = await mcpClientStore.getById(mcpClientId); chunkGZ4HWZWE_cjs.assertStoredResourceScope(mcpClient, await chunkGZ4HWZWE_cjs.getStoredResourceScope(mastra, requestContext)); const fromVersion = await mcpClientStore.getVersion(from); if (!fromVersion) { throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Version with id ${from} not found` }); } if (fromVersion.mcpClientId !== mcpClientId) { throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Version with id ${from} not found for MCP client ${mcpClientId}` }); } const toVersion = await mcpClientStore.getVersion(to); if (!toVersion) { throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Version with id ${to} not found` }); } if (toVersion.mcpClientId !== mcpClientId) { throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Version with id ${to} not found for MCP client ${mcpClientId}` }); } const fromConfig = chunk2XZ2466F_cjs.extractConfigFromVersion( fromVersion, chunk2XZ2466F_cjs.MCP_CLIENT_SNAPSHOT_CONFIG_FIELDS ); const toConfig = chunk2XZ2466F_cjs.extractConfigFromVersion( toVersion, chunk2XZ2466F_cjs.MCP_CLIENT_SNAPSHOT_CONFIG_FIELDS ); const diffs = chunk2XZ2466F_cjs.computeVersionDiffs(fromConfig, toConfig); return { diffs, fromVersion, toVersion }; } catch (error) { return chunkZ7LCIYK7_cjs.handleError(error, "Error comparing MCP client versions"); } } }); exports.ACTIVATE_MCP_CLIENT_VERSION_ROUTE = ACTIVATE_MCP_CLIENT_VERSION_ROUTE; exports.COMPARE_MCP_CLIENT_VERSIONS_ROUTE = COMPARE_MCP_CLIENT_VERSIONS_ROUTE; exports.CREATE_MCP_CLIENT_VERSION_ROUTE = CREATE_MCP_CLIENT_VERSION_ROUTE; exports.DELETE_MCP_CLIENT_VERSION_ROUTE = DELETE_MCP_CLIENT_VERSION_ROUTE; exports.GET_MCP_CLIENT_VERSION_ROUTE = GET_MCP_CLIENT_VERSION_ROUTE; exports.LIST_MCP_CLIENT_VERSIONS_ROUTE = LIST_MCP_CLIENT_VERSIONS_ROUTE; exports.RESTORE_MCP_CLIENT_VERSION_ROUTE = RESTORE_MCP_CLIENT_VERSION_ROUTE; //# sourceMappingURL=chunk-JZJ3PP2H.cjs.map //# sourceMappingURL=chunk-JZJ3PP2H.cjs.map