@mastra/mongodb 1.3.0 → 1.3.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.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
2
- import { createVectorErrorId, AgentsStorage, TABLE_AGENTS, TABLE_AGENT_VERSIONS, createStorageErrorId, normalizePerPage, calculatePagination, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_RESOURCES, safelyParseJSON, ObservabilityStorage, TABLE_SPANS, listTracesArgsSchema, toTraceSpans, PromptBlocksStorage, TABLE_PROMPT_BLOCKS, TABLE_PROMPT_BLOCK_VERSIONS, ScorerDefinitionsStorage, TABLE_SCORER_DEFINITIONS, TABLE_SCORER_DEFINITION_VERSIONS, ScoresStorage, TABLE_SCORERS, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, MastraCompositeStore, TraceStatus, transformScoreRow as transformScoreRow$1 } from '@mastra/core/storage';
2
+ import { createVectorErrorId, AgentsStorage, TABLE_AGENTS, TABLE_AGENT_VERSIONS, createStorageErrorId, normalizePerPage, calculatePagination, MCPClientsStorage, TABLE_MCP_CLIENTS, TABLE_MCP_CLIENT_VERSIONS, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_RESOURCES, safelyParseJSON, ObservabilityStorage, TABLE_SPANS, listTracesArgsSchema, toTraceSpans, PromptBlocksStorage, TABLE_PROMPT_BLOCKS, TABLE_PROMPT_BLOCK_VERSIONS, ScorerDefinitionsStorage, TABLE_SCORER_DEFINITIONS, TABLE_SCORER_DEFINITION_VERSIONS, ScoresStorage, TABLE_SCORERS, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, MastraCompositeStore, TraceStatus, transformScoreRow as transformScoreRow$1 } from '@mastra/core/storage';
3
3
  import { MastraVector, validateUpsertInput, validateVectorValues } from '@mastra/core/vector';
4
4
  import { MongoClient } from 'mongodb';
5
5
  import { v4 } from 'uuid';
@@ -12,7 +12,7 @@ import { saveScorePayloadSchema } from '@mastra/core/evals';
12
12
 
13
13
  // package.json
14
14
  var package_default = {
15
- version: "1.3.0"};
15
+ version: "1.3.1"};
16
16
  var MongoDBFilterTranslator = class extends BaseFilterTranslator {
17
17
  getSupportedOperators() {
18
18
  return {
@@ -906,7 +906,9 @@ var SNAPSHOT_FIELDS = [
906
906
  "inputProcessors",
907
907
  "outputProcessors",
908
908
  "memory",
909
- "scorers"
909
+ "scorers",
910
+ "mcpClients",
911
+ "requestContextSchema"
910
912
  ];
911
913
  var MongoDBAgentsStorage = class _MongoDBAgentsStorage extends AgentsStorage {
912
914
  #connector;
@@ -1516,6 +1518,584 @@ var MongoDBAgentsStorage = class _MongoDBAgentsStorage extends AgentsStorage {
1516
1518
  return result;
1517
1519
  }
1518
1520
  };
1521
+ var SNAPSHOT_FIELDS2 = ["name", "description", "servers"];
1522
+ var MongoDBMCPClientsStorage = class _MongoDBMCPClientsStorage extends MCPClientsStorage {
1523
+ #connector;
1524
+ #skipDefaultIndexes;
1525
+ #indexes;
1526
+ static MANAGED_COLLECTIONS = [TABLE_MCP_CLIENTS, TABLE_MCP_CLIENT_VERSIONS];
1527
+ constructor(config) {
1528
+ super();
1529
+ this.#connector = resolveMongoDBConfig(config);
1530
+ this.#skipDefaultIndexes = config.skipDefaultIndexes;
1531
+ this.#indexes = config.indexes?.filter(
1532
+ (idx) => _MongoDBMCPClientsStorage.MANAGED_COLLECTIONS.includes(idx.collection)
1533
+ );
1534
+ }
1535
+ async getCollection(name) {
1536
+ return this.#connector.getCollection(name);
1537
+ }
1538
+ getDefaultIndexDefinitions() {
1539
+ return [
1540
+ { collection: TABLE_MCP_CLIENTS, keys: { id: 1 }, options: { unique: true } },
1541
+ { collection: TABLE_MCP_CLIENTS, keys: { createdAt: -1 } },
1542
+ { collection: TABLE_MCP_CLIENTS, keys: { updatedAt: -1 } },
1543
+ { collection: TABLE_MCP_CLIENTS, keys: { authorId: 1 } },
1544
+ { collection: TABLE_MCP_CLIENT_VERSIONS, keys: { id: 1 }, options: { unique: true } },
1545
+ {
1546
+ collection: TABLE_MCP_CLIENT_VERSIONS,
1547
+ keys: { mcpClientId: 1, versionNumber: -1 },
1548
+ options: { unique: true }
1549
+ },
1550
+ { collection: TABLE_MCP_CLIENT_VERSIONS, keys: { mcpClientId: 1, createdAt: -1 } }
1551
+ ];
1552
+ }
1553
+ async createDefaultIndexes() {
1554
+ if (this.#skipDefaultIndexes) {
1555
+ return;
1556
+ }
1557
+ for (const indexDef of this.getDefaultIndexDefinitions()) {
1558
+ try {
1559
+ const collection = await this.getCollection(indexDef.collection);
1560
+ await collection.createIndex(indexDef.keys, indexDef.options);
1561
+ } catch (error) {
1562
+ this.logger?.warn?.(`Failed to create index on ${indexDef.collection}:`, error);
1563
+ }
1564
+ }
1565
+ }
1566
+ async createCustomIndexes() {
1567
+ if (!this.#indexes || this.#indexes.length === 0) {
1568
+ return;
1569
+ }
1570
+ for (const indexDef of this.#indexes) {
1571
+ try {
1572
+ const collection = await this.getCollection(indexDef.collection);
1573
+ await collection.createIndex(indexDef.keys, indexDef.options);
1574
+ } catch (error) {
1575
+ this.logger?.warn?.(`Failed to create custom index on ${indexDef.collection}:`, error);
1576
+ }
1577
+ }
1578
+ }
1579
+ async init() {
1580
+ await this.createDefaultIndexes();
1581
+ await this.createCustomIndexes();
1582
+ }
1583
+ async dangerouslyClearAll() {
1584
+ const versionsCollection = await this.getCollection(TABLE_MCP_CLIENT_VERSIONS);
1585
+ await versionsCollection.deleteMany({});
1586
+ const mcpClientsCollection = await this.getCollection(TABLE_MCP_CLIENTS);
1587
+ await mcpClientsCollection.deleteMany({});
1588
+ }
1589
+ // ==========================================================================
1590
+ // MCP Client CRUD
1591
+ // ==========================================================================
1592
+ async getById(id) {
1593
+ try {
1594
+ const collection = await this.getCollection(TABLE_MCP_CLIENTS);
1595
+ const result = await collection.findOne({ id });
1596
+ if (!result) {
1597
+ return null;
1598
+ }
1599
+ return this.transformMCPClient(result);
1600
+ } catch (error) {
1601
+ throw new MastraError(
1602
+ {
1603
+ id: createStorageErrorId("MONGODB", "GET_MCP_CLIENT_BY_ID", "FAILED"),
1604
+ domain: ErrorDomain.STORAGE,
1605
+ category: ErrorCategory.THIRD_PARTY,
1606
+ details: { id }
1607
+ },
1608
+ error
1609
+ );
1610
+ }
1611
+ }
1612
+ async create(input) {
1613
+ const { mcpClient } = input;
1614
+ try {
1615
+ const collection = await this.getCollection(TABLE_MCP_CLIENTS);
1616
+ const existing = await collection.findOne({ id: mcpClient.id });
1617
+ if (existing) {
1618
+ throw new MastraError({
1619
+ id: createStorageErrorId("MONGODB", "CREATE_MCP_CLIENT", "ALREADY_EXISTS"),
1620
+ domain: ErrorDomain.STORAGE,
1621
+ category: ErrorCategory.USER,
1622
+ details: { id: mcpClient.id },
1623
+ text: `MCP client with id ${mcpClient.id} already exists`
1624
+ });
1625
+ }
1626
+ const now = /* @__PURE__ */ new Date();
1627
+ const newMCPClient = {
1628
+ id: mcpClient.id,
1629
+ status: "draft",
1630
+ activeVersionId: void 0,
1631
+ authorId: mcpClient.authorId,
1632
+ metadata: mcpClient.metadata,
1633
+ createdAt: now,
1634
+ updatedAt: now
1635
+ };
1636
+ await collection.insertOne(this.serializeMCPClient(newMCPClient));
1637
+ const snapshotConfig = {};
1638
+ for (const field of SNAPSHOT_FIELDS2) {
1639
+ if (mcpClient[field] !== void 0) {
1640
+ snapshotConfig[field] = mcpClient[field];
1641
+ }
1642
+ }
1643
+ const versionId = randomUUID();
1644
+ try {
1645
+ await this.createVersion({
1646
+ id: versionId,
1647
+ mcpClientId: mcpClient.id,
1648
+ versionNumber: 1,
1649
+ ...snapshotConfig,
1650
+ changedFields: Object.keys(snapshotConfig),
1651
+ changeMessage: "Initial version"
1652
+ });
1653
+ } catch (versionError) {
1654
+ await collection.deleteOne({ id: mcpClient.id });
1655
+ throw versionError;
1656
+ }
1657
+ return newMCPClient;
1658
+ } catch (error) {
1659
+ if (error instanceof MastraError) {
1660
+ throw error;
1661
+ }
1662
+ throw new MastraError(
1663
+ {
1664
+ id: createStorageErrorId("MONGODB", "CREATE_MCP_CLIENT", "FAILED"),
1665
+ domain: ErrorDomain.STORAGE,
1666
+ category: ErrorCategory.THIRD_PARTY,
1667
+ details: { id: mcpClient.id }
1668
+ },
1669
+ error
1670
+ );
1671
+ }
1672
+ }
1673
+ async update(input) {
1674
+ const { id, ...updates } = input;
1675
+ try {
1676
+ const collection = await this.getCollection(TABLE_MCP_CLIENTS);
1677
+ const existingMCPClient = await collection.findOne({ id });
1678
+ if (!existingMCPClient) {
1679
+ throw new MastraError({
1680
+ id: createStorageErrorId("MONGODB", "UPDATE_MCP_CLIENT", "NOT_FOUND"),
1681
+ domain: ErrorDomain.STORAGE,
1682
+ category: ErrorCategory.USER,
1683
+ details: { id },
1684
+ text: `MCP client with id ${id} not found`
1685
+ });
1686
+ }
1687
+ const updateDoc = {
1688
+ updatedAt: /* @__PURE__ */ new Date()
1689
+ };
1690
+ const metadataFields = {
1691
+ authorId: updates.authorId,
1692
+ activeVersionId: updates.activeVersionId,
1693
+ metadata: updates.metadata,
1694
+ status: updates.status
1695
+ };
1696
+ const configFields = {};
1697
+ for (const field of SNAPSHOT_FIELDS2) {
1698
+ if (updates[field] !== void 0) {
1699
+ configFields[field] = updates[field];
1700
+ }
1701
+ }
1702
+ if (Object.keys(configFields).length > 0) {
1703
+ const latestVersion = await this.getLatestVersion(id);
1704
+ if (!latestVersion) {
1705
+ throw new MastraError({
1706
+ id: createStorageErrorId("MONGODB", "UPDATE_MCP_CLIENT", "NO_VERSION"),
1707
+ domain: ErrorDomain.STORAGE,
1708
+ category: ErrorCategory.USER,
1709
+ text: `Cannot update config fields for MCP client ${id} - no versions exist`,
1710
+ details: { id }
1711
+ });
1712
+ }
1713
+ const existingSnapshot = this.extractSnapshotFields(latestVersion);
1714
+ await this.createVersion({
1715
+ id: randomUUID(),
1716
+ mcpClientId: id,
1717
+ versionNumber: latestVersion.versionNumber + 1,
1718
+ ...existingSnapshot,
1719
+ ...configFields,
1720
+ changedFields: Object.keys(configFields),
1721
+ changeMessage: `Updated: ${Object.keys(configFields).join(", ")}`
1722
+ });
1723
+ }
1724
+ if (metadataFields.authorId !== void 0) updateDoc.authorId = metadataFields.authorId;
1725
+ if (metadataFields.activeVersionId !== void 0) {
1726
+ updateDoc.activeVersionId = metadataFields.activeVersionId;
1727
+ if (metadataFields.status === void 0) {
1728
+ updateDoc.status = "published";
1729
+ }
1730
+ }
1731
+ if (metadataFields.status !== void 0) {
1732
+ updateDoc.status = metadataFields.status;
1733
+ }
1734
+ if (metadataFields.metadata !== void 0) {
1735
+ const existingMetadata = existingMCPClient.metadata || {};
1736
+ updateDoc.metadata = { ...existingMetadata, ...metadataFields.metadata };
1737
+ }
1738
+ await collection.updateOne({ id }, { $set: updateDoc });
1739
+ const updatedMCPClient = await collection.findOne({ id });
1740
+ if (!updatedMCPClient) {
1741
+ throw new MastraError({
1742
+ id: createStorageErrorId("MONGODB", "UPDATE_MCP_CLIENT", "NOT_FOUND_AFTER_UPDATE"),
1743
+ domain: ErrorDomain.STORAGE,
1744
+ category: ErrorCategory.SYSTEM,
1745
+ text: `MCP client with id ${id} was deleted during update`,
1746
+ details: { id }
1747
+ });
1748
+ }
1749
+ return this.transformMCPClient(updatedMCPClient);
1750
+ } catch (error) {
1751
+ if (error instanceof MastraError) {
1752
+ throw error;
1753
+ }
1754
+ throw new MastraError(
1755
+ {
1756
+ id: createStorageErrorId("MONGODB", "UPDATE_MCP_CLIENT", "FAILED"),
1757
+ domain: ErrorDomain.STORAGE,
1758
+ category: ErrorCategory.THIRD_PARTY,
1759
+ details: { id }
1760
+ },
1761
+ error
1762
+ );
1763
+ }
1764
+ }
1765
+ async delete(id) {
1766
+ try {
1767
+ await this.deleteVersionsByParentId(id);
1768
+ const collection = await this.getCollection(TABLE_MCP_CLIENTS);
1769
+ await collection.deleteOne({ id });
1770
+ } catch (error) {
1771
+ throw new MastraError(
1772
+ {
1773
+ id: createStorageErrorId("MONGODB", "DELETE_MCP_CLIENT", "FAILED"),
1774
+ domain: ErrorDomain.STORAGE,
1775
+ category: ErrorCategory.THIRD_PARTY,
1776
+ details: { id }
1777
+ },
1778
+ error
1779
+ );
1780
+ }
1781
+ }
1782
+ async list(args) {
1783
+ try {
1784
+ const { page = 0, perPage: perPageInput, orderBy, authorId, metadata } = args || {};
1785
+ const { field, direction } = this.parseOrderBy(orderBy);
1786
+ if (page < 0) {
1787
+ throw new MastraError(
1788
+ {
1789
+ id: createStorageErrorId("MONGODB", "LIST_MCP_CLIENTS", "INVALID_PAGE"),
1790
+ domain: ErrorDomain.STORAGE,
1791
+ category: ErrorCategory.USER,
1792
+ details: { page }
1793
+ },
1794
+ new Error("page must be >= 0")
1795
+ );
1796
+ }
1797
+ const perPage = normalizePerPage(perPageInput, 100);
1798
+ const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
1799
+ const collection = await this.getCollection(TABLE_MCP_CLIENTS);
1800
+ const filter = {};
1801
+ if (authorId) {
1802
+ filter.authorId = authorId;
1803
+ }
1804
+ if (metadata) {
1805
+ for (const [key, value] of Object.entries(metadata)) {
1806
+ filter[`metadata.${key}`] = value;
1807
+ }
1808
+ }
1809
+ const total = await collection.countDocuments(filter);
1810
+ if (total === 0 || perPage === 0) {
1811
+ return {
1812
+ mcpClients: [],
1813
+ total,
1814
+ page,
1815
+ perPage: perPageForResponse,
1816
+ hasMore: false
1817
+ };
1818
+ }
1819
+ const sortOrder = direction === "ASC" ? 1 : -1;
1820
+ let cursor = collection.find(filter).sort({ [field]: sortOrder }).skip(offset);
1821
+ if (perPageInput !== false) {
1822
+ cursor = cursor.limit(perPage);
1823
+ }
1824
+ const results = await cursor.toArray();
1825
+ const mcpClients = results.map((doc) => this.transformMCPClient(doc));
1826
+ return {
1827
+ mcpClients,
1828
+ total,
1829
+ page,
1830
+ perPage: perPageForResponse,
1831
+ hasMore: perPageInput !== false && offset + perPage < total
1832
+ };
1833
+ } catch (error) {
1834
+ if (error instanceof MastraError) {
1835
+ throw error;
1836
+ }
1837
+ throw new MastraError(
1838
+ {
1839
+ id: createStorageErrorId("MONGODB", "LIST_MCP_CLIENTS", "FAILED"),
1840
+ domain: ErrorDomain.STORAGE,
1841
+ category: ErrorCategory.THIRD_PARTY
1842
+ },
1843
+ error
1844
+ );
1845
+ }
1846
+ }
1847
+ // ==========================================================================
1848
+ // MCP Client Version Methods
1849
+ // ==========================================================================
1850
+ async createVersion(input) {
1851
+ try {
1852
+ const collection = await this.getCollection(TABLE_MCP_CLIENT_VERSIONS);
1853
+ const now = /* @__PURE__ */ new Date();
1854
+ const versionDoc = {
1855
+ id: input.id,
1856
+ mcpClientId: input.mcpClientId,
1857
+ versionNumber: input.versionNumber,
1858
+ changedFields: input.changedFields ?? void 0,
1859
+ changeMessage: input.changeMessage ?? void 0,
1860
+ createdAt: now
1861
+ };
1862
+ for (const field of SNAPSHOT_FIELDS2) {
1863
+ if (input[field] !== void 0) {
1864
+ versionDoc[field] = input[field];
1865
+ }
1866
+ }
1867
+ await collection.insertOne(versionDoc);
1868
+ return {
1869
+ ...input,
1870
+ createdAt: now
1871
+ };
1872
+ } catch (error) {
1873
+ throw new MastraError(
1874
+ {
1875
+ id: createStorageErrorId("MONGODB", "CREATE_MCP_CLIENT_VERSION", "FAILED"),
1876
+ domain: ErrorDomain.STORAGE,
1877
+ category: ErrorCategory.THIRD_PARTY,
1878
+ details: { versionId: input.id, mcpClientId: input.mcpClientId }
1879
+ },
1880
+ error
1881
+ );
1882
+ }
1883
+ }
1884
+ async getVersion(id) {
1885
+ try {
1886
+ const collection = await this.getCollection(TABLE_MCP_CLIENT_VERSIONS);
1887
+ const result = await collection.findOne({ id });
1888
+ if (!result) {
1889
+ return null;
1890
+ }
1891
+ return this.transformVersion(result);
1892
+ } catch (error) {
1893
+ throw new MastraError(
1894
+ {
1895
+ id: createStorageErrorId("MONGODB", "GET_MCP_CLIENT_VERSION", "FAILED"),
1896
+ domain: ErrorDomain.STORAGE,
1897
+ category: ErrorCategory.THIRD_PARTY,
1898
+ details: { versionId: id }
1899
+ },
1900
+ error
1901
+ );
1902
+ }
1903
+ }
1904
+ async getVersionByNumber(mcpClientId, versionNumber) {
1905
+ try {
1906
+ const collection = await this.getCollection(TABLE_MCP_CLIENT_VERSIONS);
1907
+ const result = await collection.findOne({ mcpClientId, versionNumber });
1908
+ if (!result) {
1909
+ return null;
1910
+ }
1911
+ return this.transformVersion(result);
1912
+ } catch (error) {
1913
+ throw new MastraError(
1914
+ {
1915
+ id: createStorageErrorId("MONGODB", "GET_MCP_CLIENT_VERSION_BY_NUMBER", "FAILED"),
1916
+ domain: ErrorDomain.STORAGE,
1917
+ category: ErrorCategory.THIRD_PARTY,
1918
+ details: { mcpClientId, versionNumber }
1919
+ },
1920
+ error
1921
+ );
1922
+ }
1923
+ }
1924
+ async getLatestVersion(mcpClientId) {
1925
+ try {
1926
+ const collection = await this.getCollection(TABLE_MCP_CLIENT_VERSIONS);
1927
+ const result = await collection.find({ mcpClientId }).sort({ versionNumber: -1 }).limit(1).toArray();
1928
+ if (!result || result.length === 0) {
1929
+ return null;
1930
+ }
1931
+ return this.transformVersion(result[0]);
1932
+ } catch (error) {
1933
+ throw new MastraError(
1934
+ {
1935
+ id: createStorageErrorId("MONGODB", "GET_LATEST_MCP_CLIENT_VERSION", "FAILED"),
1936
+ domain: ErrorDomain.STORAGE,
1937
+ category: ErrorCategory.THIRD_PARTY,
1938
+ details: { mcpClientId }
1939
+ },
1940
+ error
1941
+ );
1942
+ }
1943
+ }
1944
+ async listVersions(input) {
1945
+ const { mcpClientId, page = 0, perPage: perPageInput, orderBy } = input;
1946
+ if (page < 0) {
1947
+ throw new MastraError(
1948
+ {
1949
+ id: createStorageErrorId("MONGODB", "LIST_MCP_CLIENT_VERSIONS", "INVALID_PAGE"),
1950
+ domain: ErrorDomain.STORAGE,
1951
+ category: ErrorCategory.USER,
1952
+ details: { page }
1953
+ },
1954
+ new Error("page must be >= 0")
1955
+ );
1956
+ }
1957
+ const perPage = normalizePerPage(perPageInput, 20);
1958
+ const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
1959
+ try {
1960
+ const { field, direction } = this.parseVersionOrderBy(orderBy);
1961
+ const collection = await this.getCollection(TABLE_MCP_CLIENT_VERSIONS);
1962
+ const total = await collection.countDocuments({ mcpClientId });
1963
+ if (total === 0 || perPage === 0) {
1964
+ return {
1965
+ versions: [],
1966
+ total,
1967
+ page,
1968
+ perPage: perPageForResponse,
1969
+ hasMore: false
1970
+ };
1971
+ }
1972
+ const sortOrder = direction === "ASC" ? 1 : -1;
1973
+ let cursor = collection.find({ mcpClientId }).sort({ [field]: sortOrder }).skip(offset);
1974
+ if (perPageInput !== false) {
1975
+ cursor = cursor.limit(perPage);
1976
+ }
1977
+ const results = await cursor.toArray();
1978
+ const versions = results.map((doc) => this.transformVersion(doc));
1979
+ return {
1980
+ versions,
1981
+ total,
1982
+ page,
1983
+ perPage: perPageForResponse,
1984
+ hasMore: perPageInput !== false && offset + perPage < total
1985
+ };
1986
+ } catch (error) {
1987
+ throw new MastraError(
1988
+ {
1989
+ id: createStorageErrorId("MONGODB", "LIST_MCP_CLIENT_VERSIONS", "FAILED"),
1990
+ domain: ErrorDomain.STORAGE,
1991
+ category: ErrorCategory.THIRD_PARTY,
1992
+ details: { mcpClientId }
1993
+ },
1994
+ error
1995
+ );
1996
+ }
1997
+ }
1998
+ async deleteVersion(id) {
1999
+ try {
2000
+ const collection = await this.getCollection(TABLE_MCP_CLIENT_VERSIONS);
2001
+ await collection.deleteOne({ id });
2002
+ } catch (error) {
2003
+ throw new MastraError(
2004
+ {
2005
+ id: createStorageErrorId("MONGODB", "DELETE_MCP_CLIENT_VERSION", "FAILED"),
2006
+ domain: ErrorDomain.STORAGE,
2007
+ category: ErrorCategory.THIRD_PARTY,
2008
+ details: { versionId: id }
2009
+ },
2010
+ error
2011
+ );
2012
+ }
2013
+ }
2014
+ async deleteVersionsByParentId(mcpClientId) {
2015
+ try {
2016
+ const collection = await this.getCollection(TABLE_MCP_CLIENT_VERSIONS);
2017
+ await collection.deleteMany({ mcpClientId });
2018
+ } catch (error) {
2019
+ throw new MastraError(
2020
+ {
2021
+ id: createStorageErrorId("MONGODB", "DELETE_VERSIONS_BY_MCP_CLIENT_ID", "FAILED"),
2022
+ domain: ErrorDomain.STORAGE,
2023
+ category: ErrorCategory.THIRD_PARTY,
2024
+ details: { mcpClientId }
2025
+ },
2026
+ error
2027
+ );
2028
+ }
2029
+ }
2030
+ async countVersions(mcpClientId) {
2031
+ try {
2032
+ const collection = await this.getCollection(TABLE_MCP_CLIENT_VERSIONS);
2033
+ return await collection.countDocuments({ mcpClientId });
2034
+ } catch (error) {
2035
+ throw new MastraError(
2036
+ {
2037
+ id: createStorageErrorId("MONGODB", "COUNT_MCP_CLIENT_VERSIONS", "FAILED"),
2038
+ domain: ErrorDomain.STORAGE,
2039
+ category: ErrorCategory.THIRD_PARTY,
2040
+ details: { mcpClientId }
2041
+ },
2042
+ error
2043
+ );
2044
+ }
2045
+ }
2046
+ // ==========================================================================
2047
+ // Private Helper Methods
2048
+ // ==========================================================================
2049
+ transformMCPClient(doc) {
2050
+ const { _id, ...rest } = doc;
2051
+ return {
2052
+ id: rest.id,
2053
+ status: rest.status,
2054
+ activeVersionId: rest.activeVersionId,
2055
+ authorId: rest.authorId,
2056
+ metadata: rest.metadata,
2057
+ createdAt: rest.createdAt instanceof Date ? rest.createdAt : new Date(rest.createdAt),
2058
+ updatedAt: rest.updatedAt instanceof Date ? rest.updatedAt : new Date(rest.updatedAt)
2059
+ };
2060
+ }
2061
+ serializeMCPClient(mcpClient) {
2062
+ return {
2063
+ id: mcpClient.id,
2064
+ status: mcpClient.status,
2065
+ activeVersionId: mcpClient.activeVersionId,
2066
+ authorId: mcpClient.authorId,
2067
+ metadata: mcpClient.metadata,
2068
+ createdAt: mcpClient.createdAt,
2069
+ updatedAt: mcpClient.updatedAt
2070
+ };
2071
+ }
2072
+ transformVersion(doc) {
2073
+ const { _id, ...version } = doc;
2074
+ const result = {
2075
+ id: version.id,
2076
+ mcpClientId: version.mcpClientId,
2077
+ versionNumber: version.versionNumber,
2078
+ changedFields: version.changedFields,
2079
+ changeMessage: version.changeMessage,
2080
+ createdAt: version.createdAt instanceof Date ? version.createdAt : new Date(version.createdAt)
2081
+ };
2082
+ for (const field of SNAPSHOT_FIELDS2) {
2083
+ if (version[field] !== void 0) {
2084
+ result[field] = version[field];
2085
+ }
2086
+ }
2087
+ return result;
2088
+ }
2089
+ extractSnapshotFields(version) {
2090
+ const result = {};
2091
+ for (const field of SNAPSHOT_FIELDS2) {
2092
+ if (version[field] !== void 0) {
2093
+ result[field] = version[field];
2094
+ }
2095
+ }
2096
+ return result;
2097
+ }
2098
+ };
1519
2099
  function formatDateForMongoDB(date) {
1520
2100
  return typeof date === "string" ? new Date(date) : date;
1521
2101
  }
@@ -3857,7 +4437,7 @@ Note: This migration may take some time for large collections.
3857
4437
  return span;
3858
4438
  }
3859
4439
  };
3860
- var SNAPSHOT_FIELDS2 = ["name", "description", "content", "rules"];
4440
+ var SNAPSHOT_FIELDS3 = ["name", "description", "content", "rules"];
3861
4441
  var MongoDBPromptBlocksStorage = class _MongoDBPromptBlocksStorage extends PromptBlocksStorage {
3862
4442
  #connector;
3863
4443
  #skipDefaultIndexes;
@@ -3974,7 +4554,7 @@ var MongoDBPromptBlocksStorage = class _MongoDBPromptBlocksStorage extends Promp
3974
4554
  };
3975
4555
  await collection.insertOne(this.serializeBlock(newBlock));
3976
4556
  const snapshotConfig = {};
3977
- for (const field of SNAPSHOT_FIELDS2) {
4557
+ for (const field of SNAPSHOT_FIELDS3) {
3978
4558
  if (promptBlock[field] !== void 0) {
3979
4559
  snapshotConfig[field] = promptBlock[field];
3980
4560
  }
@@ -4028,7 +4608,7 @@ var MongoDBPromptBlocksStorage = class _MongoDBPromptBlocksStorage extends Promp
4028
4608
  status: updates.status
4029
4609
  };
4030
4610
  const configFields = {};
4031
- for (const field of SNAPSHOT_FIELDS2) {
4611
+ for (const field of SNAPSHOT_FIELDS3) {
4032
4612
  if (updates[field] !== void 0) {
4033
4613
  configFields[field] = updates[field];
4034
4614
  }
@@ -4193,7 +4773,7 @@ var MongoDBPromptBlocksStorage = class _MongoDBPromptBlocksStorage extends Promp
4193
4773
  changeMessage: input.changeMessage ?? void 0,
4194
4774
  createdAt: now
4195
4775
  };
4196
- for (const field of SNAPSHOT_FIELDS2) {
4776
+ for (const field of SNAPSHOT_FIELDS3) {
4197
4777
  if (input[field] !== void 0) {
4198
4778
  versionDoc[field] = input[field];
4199
4779
  }
@@ -4413,7 +4993,7 @@ var MongoDBPromptBlocksStorage = class _MongoDBPromptBlocksStorage extends Promp
4413
4993
  changeMessage: version.changeMessage,
4414
4994
  createdAt: version.createdAt instanceof Date ? version.createdAt : new Date(version.createdAt)
4415
4995
  };
4416
- for (const field of SNAPSHOT_FIELDS2) {
4996
+ for (const field of SNAPSHOT_FIELDS3) {
4417
4997
  if (version[field] !== void 0) {
4418
4998
  result[field] = version[field];
4419
4999
  }
@@ -4422,7 +5002,7 @@ var MongoDBPromptBlocksStorage = class _MongoDBPromptBlocksStorage extends Promp
4422
5002
  }
4423
5003
  extractSnapshotFields(version) {
4424
5004
  const result = {};
4425
- for (const field of SNAPSHOT_FIELDS2) {
5005
+ for (const field of SNAPSHOT_FIELDS3) {
4426
5006
  if (version[field] !== void 0) {
4427
5007
  result[field] = version[field];
4428
5008
  }
@@ -4430,7 +5010,7 @@ var MongoDBPromptBlocksStorage = class _MongoDBPromptBlocksStorage extends Promp
4430
5010
  return result;
4431
5011
  }
4432
5012
  };
4433
- var SNAPSHOT_FIELDS3 = [
5013
+ var SNAPSHOT_FIELDS4 = [
4434
5014
  "name",
4435
5015
  "description",
4436
5016
  "type",
@@ -4556,7 +5136,7 @@ var MongoDBScorerDefinitionsStorage = class _MongoDBScorerDefinitionsStorage ext
4556
5136
  };
4557
5137
  await collection.insertOne(this.serializeScorerDefinition(newScorerDefinition));
4558
5138
  const snapshotConfig = {};
4559
- for (const field of SNAPSHOT_FIELDS3) {
5139
+ for (const field of SNAPSHOT_FIELDS4) {
4560
5140
  if (scorerDefinition[field] !== void 0) {
4561
5141
  snapshotConfig[field] = scorerDefinition[field];
4562
5142
  }
@@ -4610,7 +5190,7 @@ var MongoDBScorerDefinitionsStorage = class _MongoDBScorerDefinitionsStorage ext
4610
5190
  status: updates.status
4611
5191
  };
4612
5192
  const configFields = {};
4613
- for (const field of SNAPSHOT_FIELDS3) {
5193
+ for (const field of SNAPSHOT_FIELDS4) {
4614
5194
  if (updates[field] !== void 0) {
4615
5195
  configFields[field] = updates[field];
4616
5196
  }
@@ -4775,7 +5355,7 @@ var MongoDBScorerDefinitionsStorage = class _MongoDBScorerDefinitionsStorage ext
4775
5355
  changeMessage: input.changeMessage ?? void 0,
4776
5356
  createdAt: now
4777
5357
  };
4778
- for (const field of SNAPSHOT_FIELDS3) {
5358
+ for (const field of SNAPSHOT_FIELDS4) {
4779
5359
  if (input[field] !== void 0) {
4780
5360
  versionDoc[field] = input[field];
4781
5361
  }
@@ -4995,7 +5575,7 @@ var MongoDBScorerDefinitionsStorage = class _MongoDBScorerDefinitionsStorage ext
4995
5575
  changeMessage: version.changeMessage,
4996
5576
  createdAt: version.createdAt instanceof Date ? version.createdAt : new Date(version.createdAt)
4997
5577
  };
4998
- for (const field of SNAPSHOT_FIELDS3) {
5578
+ for (const field of SNAPSHOT_FIELDS4) {
4999
5579
  if (version[field] !== void 0) {
5000
5580
  result[field] = version[field];
5001
5581
  }
@@ -5004,7 +5584,7 @@ var MongoDBScorerDefinitionsStorage = class _MongoDBScorerDefinitionsStorage ext
5004
5584
  }
5005
5585
  extractSnapshotFields(version) {
5006
5586
  const result = {};
5007
- for (const field of SNAPSHOT_FIELDS3) {
5587
+ for (const field of SNAPSHOT_FIELDS4) {
5008
5588
  if (version[field] !== void 0) {
5009
5589
  result[field] = version[field];
5010
5590
  }
@@ -5678,6 +6258,7 @@ var MongoDBStore = class extends MastraCompositeStore {
5678
6258
  const agents = new MongoDBAgentsStorage(domainConfig);
5679
6259
  const promptBlocks = new MongoDBPromptBlocksStorage(domainConfig);
5680
6260
  const scorerDefinitions = new MongoDBScorerDefinitionsStorage(domainConfig);
6261
+ const mcpClients = new MongoDBMCPClientsStorage(domainConfig);
5681
6262
  this.stores = {
5682
6263
  memory,
5683
6264
  scores,
@@ -5685,7 +6266,8 @@ var MongoDBStore = class extends MastraCompositeStore {
5685
6266
  observability,
5686
6267
  agents,
5687
6268
  promptBlocks,
5688
- scorerDefinitions
6269
+ scorerDefinitions,
6270
+ mcpClients
5689
6271
  };
5690
6272
  }
5691
6273
  /**
@@ -5804,6 +6386,6 @@ Example Complex Query:
5804
6386
  ]
5805
6387
  }`;
5806
6388
 
5807
- export { MONGODB_PROMPT, MemoryStorageMongoDB, MongoDBAgentsStorage, MongoDBPromptBlocksStorage, MongoDBScorerDefinitionsStorage, MongoDBStore, MongoDBVector, ObservabilityMongoDB, ScoresStorageMongoDB, WorkflowsStorageMongoDB };
6389
+ export { MONGODB_PROMPT, MemoryStorageMongoDB, MongoDBAgentsStorage, MongoDBMCPClientsStorage, MongoDBPromptBlocksStorage, MongoDBScorerDefinitionsStorage, MongoDBStore, MongoDBVector, ObservabilityMongoDB, ScoresStorageMongoDB, WorkflowsStorageMongoDB };
5808
6390
  //# sourceMappingURL=index.js.map
5809
6391
  //# sourceMappingURL=index.js.map