@mastra/mongodb 1.3.0 → 1.3.1-alpha.0

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