@mastra/libsql 1.5.0 → 1.6.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/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # @mastra/libsql
2
2
 
3
+ ## 1.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Added MCP server table and CRUD operations to storage adapters, enabling MCP server configurations to be persisted alongside agents and workflows. ([#13357](https://github.com/mastra-ai/mastra/pull/13357))
8
+
9
+ ### Patch Changes
10
+
11
+ - Added storage schema support for processor graphs on stored agents. ([#13357](https://github.com/mastra-ai/mastra/pull/13357))
12
+
13
+ - Storage adapters now return `suggestedContinuation` and `currentTask` fields on Observational Memory activation, enabling agents to maintain conversational context across activation boundaries. ([#13357](https://github.com/mastra-ai/mastra/pull/13357))
14
+
15
+ - Updated dependencies [[`0d9efb4`](https://github.com/mastra-ai/mastra/commit/0d9efb47992c34aa90581c18b9f51f774f6252a5), [`5caa13d`](https://github.com/mastra-ai/mastra/commit/5caa13d1b2a496e2565ab124a11de9a51ad3e3b9), [`940163f`](https://github.com/mastra-ai/mastra/commit/940163fc492401d7562301e6f106ccef4fefe06f), [`47892c8`](https://github.com/mastra-ai/mastra/commit/47892c85708eac348209f99f10f9a5f5267e11c0), [`45bb78b`](https://github.com/mastra-ai/mastra/commit/45bb78b70bd9db29678fe49476cd9f4ed01bfd0b), [`70eef84`](https://github.com/mastra-ai/mastra/commit/70eef84b8f44493598fdafa2980a0e7283415eda), [`d84e52d`](https://github.com/mastra-ai/mastra/commit/d84e52d0f6511283ddd21ed5fe7f945449d0f799), [`24b80af`](https://github.com/mastra-ai/mastra/commit/24b80af87da93bb84d389340181e17b7477fa9ca), [`608e156`](https://github.com/mastra-ai/mastra/commit/608e156def954c9604c5e3f6d9dfce3bcc7aeab0), [`2b2e157`](https://github.com/mastra-ai/mastra/commit/2b2e157a092cd597d9d3f0000d62b8bb4a7348ed), [`59d30b5`](https://github.com/mastra-ai/mastra/commit/59d30b5d0cb44ea7a1c440e7460dfb57eac9a9b5), [`453693b`](https://github.com/mastra-ai/mastra/commit/453693bf9e265ddccecef901d50da6caaea0fbc6), [`78d1c80`](https://github.com/mastra-ai/mastra/commit/78d1c808ad90201897a300af551bcc1d34458a20), [`c204b63`](https://github.com/mastra-ai/mastra/commit/c204b632d19e66acb6d6e19b11c4540dd6ad5380), [`742a417`](https://github.com/mastra-ai/mastra/commit/742a417896088220a3b5560c354c45c5ca6d88b9)]:
16
+ - @mastra/core@1.6.0
17
+
18
+ ## 1.6.0-alpha.0
19
+
20
+ ### Minor Changes
21
+
22
+ - Added MCP server table and CRUD operations to storage adapters, enabling MCP server configurations to be persisted alongside agents and workflows. ([#13357](https://github.com/mastra-ai/mastra/pull/13357))
23
+
24
+ ### Patch Changes
25
+
26
+ - Added storage schema support for processor graphs on stored agents. ([#13357](https://github.com/mastra-ai/mastra/pull/13357))
27
+
28
+ - Storage adapters now return `suggestedContinuation` and `currentTask` fields on Observational Memory activation, enabling agents to maintain conversational context across activation boundaries. ([#13357](https://github.com/mastra-ai/mastra/pull/13357))
29
+
30
+ - Updated dependencies [[`0d9efb4`](https://github.com/mastra-ai/mastra/commit/0d9efb47992c34aa90581c18b9f51f774f6252a5), [`5caa13d`](https://github.com/mastra-ai/mastra/commit/5caa13d1b2a496e2565ab124a11de9a51ad3e3b9), [`940163f`](https://github.com/mastra-ai/mastra/commit/940163fc492401d7562301e6f106ccef4fefe06f), [`b260123`](https://github.com/mastra-ai/mastra/commit/b2601234bd093d358c92081a58f9b0befdae52b3), [`47892c8`](https://github.com/mastra-ai/mastra/commit/47892c85708eac348209f99f10f9a5f5267e11c0), [`45bb78b`](https://github.com/mastra-ai/mastra/commit/45bb78b70bd9db29678fe49476cd9f4ed01bfd0b), [`70eef84`](https://github.com/mastra-ai/mastra/commit/70eef84b8f44493598fdafa2980a0e7283415eda), [`d84e52d`](https://github.com/mastra-ai/mastra/commit/d84e52d0f6511283ddd21ed5fe7f945449d0f799), [`24b80af`](https://github.com/mastra-ai/mastra/commit/24b80af87da93bb84d389340181e17b7477fa9ca), [`608e156`](https://github.com/mastra-ai/mastra/commit/608e156def954c9604c5e3f6d9dfce3bcc7aeab0), [`2b2e157`](https://github.com/mastra-ai/mastra/commit/2b2e157a092cd597d9d3f0000d62b8bb4a7348ed), [`59d30b5`](https://github.com/mastra-ai/mastra/commit/59d30b5d0cb44ea7a1c440e7460dfb57eac9a9b5), [`453693b`](https://github.com/mastra-ai/mastra/commit/453693bf9e265ddccecef901d50da6caaea0fbc6), [`78d1c80`](https://github.com/mastra-ai/mastra/commit/78d1c808ad90201897a300af551bcc1d34458a20), [`c204b63`](https://github.com/mastra-ai/mastra/commit/c204b632d19e66acb6d6e19b11c4540dd6ad5380), [`742a417`](https://github.com/mastra-ai/mastra/commit/742a417896088220a3b5560c354c45c5ca6d88b9)]:
31
+ - @mastra/core@1.6.0-alpha.0
32
+
3
33
  ## 1.5.0
4
34
 
5
35
  ### Minor Changes
@@ -3,7 +3,7 @@ name: mastra-libsql
3
3
  description: Documentation for @mastra/libsql. Use when working with @mastra/libsql APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/libsql"
6
- version: "1.5.0"
6
+ version: "1.6.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.5.0",
2
+ "version": "1.6.0",
3
3
  "package": "@mastra/libsql",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -36,7 +36,7 @@ export const agent = new Agent({
36
36
 
37
37
  ### Options parameters
38
38
 
39
- **lastMessages?:** (`number | false`): Number of most recent messages to retrieve. Set to false to disable. (Default: `10`)
39
+ **lastMessages?:** (`number | false`): Number of most recent messages to include in context. Set to \`false\` to disable loading conversation history into context. Use \`Number.MAX\_SAFE\_INTEGER\` to retrieve all messages with no limit. To prevent saving new messages, use the \`readOnly\` option instead. (Default: `10`)
40
40
 
41
41
  **readOnly?:** (`boolean`): When true, prevents memory from saving new messages and provides working memory as read-only context (without the updateWorkingMemory tool). Useful for read-only operations like previews, internal routing agents, or sub agents that should reference but not modify memory. (Default: `false`)
42
42
 
package/dist/index.cjs CHANGED
@@ -4632,6 +4632,490 @@ var MCPClientsLibSQL = class extends storage.MCPClientsStorage {
4632
4632
  };
4633
4633
  }
4634
4634
  };
4635
+ var MCPServersLibSQL = class extends storage.MCPServersStorage {
4636
+ #db;
4637
+ #client;
4638
+ constructor(config) {
4639
+ super();
4640
+ const client = resolveClient(config);
4641
+ this.#client = client;
4642
+ this.#db = new LibSQLDB({ client, maxRetries: config.maxRetries, initialBackoffMs: config.initialBackoffMs });
4643
+ }
4644
+ async init() {
4645
+ await this.#db.createTable({ tableName: storage.TABLE_MCP_SERVERS, schema: storage.MCP_SERVERS_SCHEMA });
4646
+ await this.#db.createTable({
4647
+ tableName: storage.TABLE_MCP_SERVER_VERSIONS,
4648
+ schema: storage.MCP_SERVER_VERSIONS_SCHEMA
4649
+ });
4650
+ await this.#client.execute(
4651
+ `CREATE UNIQUE INDEX IF NOT EXISTS idx_mcp_server_versions_server_version ON "${storage.TABLE_MCP_SERVER_VERSIONS}" ("mcpServerId", "versionNumber")`
4652
+ );
4653
+ }
4654
+ async dangerouslyClearAll() {
4655
+ await this.#db.deleteData({ tableName: storage.TABLE_MCP_SERVERS });
4656
+ await this.#db.deleteData({ tableName: storage.TABLE_MCP_SERVER_VERSIONS });
4657
+ }
4658
+ // ==========================================================================
4659
+ // MCP Server CRUD
4660
+ // ==========================================================================
4661
+ async getById(id) {
4662
+ try {
4663
+ const result = await this.#client.execute({
4664
+ sql: `SELECT ${buildSelectColumns(storage.TABLE_MCP_SERVERS)} FROM "${storage.TABLE_MCP_SERVERS}" WHERE id = ?`,
4665
+ args: [id]
4666
+ });
4667
+ const row = result.rows?.[0];
4668
+ return row ? this.#parseMCPServerRow(row) : null;
4669
+ } catch (error$1) {
4670
+ if (error$1 instanceof error.MastraError) throw error$1;
4671
+ throw new error.MastraError(
4672
+ {
4673
+ id: storage.createStorageErrorId("LIBSQL", "GET_MCP_SERVER", "FAILED"),
4674
+ domain: error.ErrorDomain.STORAGE,
4675
+ category: error.ErrorCategory.THIRD_PARTY
4676
+ },
4677
+ error$1
4678
+ );
4679
+ }
4680
+ }
4681
+ async create(input) {
4682
+ const { mcpServer } = input;
4683
+ try {
4684
+ const now = /* @__PURE__ */ new Date();
4685
+ await this.#db.insert({
4686
+ tableName: storage.TABLE_MCP_SERVERS,
4687
+ record: {
4688
+ id: mcpServer.id,
4689
+ status: "draft",
4690
+ activeVersionId: null,
4691
+ authorId: mcpServer.authorId ?? null,
4692
+ metadata: mcpServer.metadata ?? null,
4693
+ createdAt: now.toISOString(),
4694
+ updatedAt: now.toISOString()
4695
+ }
4696
+ });
4697
+ const { id: _id, authorId: _authorId, metadata: _metadata, ...snapshotConfig } = mcpServer;
4698
+ const versionId = crypto.randomUUID();
4699
+ try {
4700
+ await this.createVersion({
4701
+ id: versionId,
4702
+ mcpServerId: mcpServer.id,
4703
+ versionNumber: 1,
4704
+ ...snapshotConfig,
4705
+ changedFields: Object.keys(snapshotConfig),
4706
+ changeMessage: "Initial version"
4707
+ });
4708
+ } catch (versionError) {
4709
+ await this.#db.delete({ tableName: storage.TABLE_MCP_SERVERS, keys: { id: mcpServer.id } });
4710
+ throw versionError;
4711
+ }
4712
+ return {
4713
+ id: mcpServer.id,
4714
+ status: "draft",
4715
+ activeVersionId: void 0,
4716
+ authorId: mcpServer.authorId,
4717
+ metadata: mcpServer.metadata,
4718
+ createdAt: now,
4719
+ updatedAt: now
4720
+ };
4721
+ } catch (error$1) {
4722
+ if (error$1 instanceof error.MastraError) throw error$1;
4723
+ throw new error.MastraError(
4724
+ {
4725
+ id: storage.createStorageErrorId("LIBSQL", "CREATE_MCP_SERVER", "FAILED"),
4726
+ domain: error.ErrorDomain.STORAGE,
4727
+ category: error.ErrorCategory.THIRD_PARTY
4728
+ },
4729
+ error$1
4730
+ );
4731
+ }
4732
+ }
4733
+ async update(input) {
4734
+ const { id, ...updates } = input;
4735
+ try {
4736
+ const existing = await this.getById(id);
4737
+ if (!existing) {
4738
+ throw new Error(`MCP server with id ${id} not found`);
4739
+ }
4740
+ const { authorId, activeVersionId, metadata, status } = updates;
4741
+ const updateData = {
4742
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
4743
+ };
4744
+ if (authorId !== void 0) updateData.authorId = authorId;
4745
+ if (activeVersionId !== void 0) updateData.activeVersionId = activeVersionId;
4746
+ if (status !== void 0) updateData.status = status;
4747
+ if (metadata !== void 0) {
4748
+ updateData.metadata = { ...existing.metadata, ...metadata };
4749
+ }
4750
+ await this.#db.update({
4751
+ tableName: storage.TABLE_MCP_SERVERS,
4752
+ keys: { id },
4753
+ data: updateData
4754
+ });
4755
+ const updated = await this.getById(id);
4756
+ if (!updated) {
4757
+ throw new error.MastraError({
4758
+ id: storage.createStorageErrorId("LIBSQL", "UPDATE_MCP_SERVER", "NOT_FOUND_AFTER_UPDATE"),
4759
+ domain: error.ErrorDomain.STORAGE,
4760
+ category: error.ErrorCategory.SYSTEM,
4761
+ text: `MCP server ${id} not found after update`,
4762
+ details: { id }
4763
+ });
4764
+ }
4765
+ return updated;
4766
+ } catch (error$1) {
4767
+ if (error$1 instanceof error.MastraError) throw error$1;
4768
+ throw new error.MastraError(
4769
+ {
4770
+ id: storage.createStorageErrorId("LIBSQL", "UPDATE_MCP_SERVER", "FAILED"),
4771
+ domain: error.ErrorDomain.STORAGE,
4772
+ category: error.ErrorCategory.THIRD_PARTY
4773
+ },
4774
+ error$1
4775
+ );
4776
+ }
4777
+ }
4778
+ async delete(id) {
4779
+ try {
4780
+ await this.deleteVersionsByParentId(id);
4781
+ await this.#client.execute({
4782
+ sql: `DELETE FROM "${storage.TABLE_MCP_SERVERS}" WHERE "id" = ?`,
4783
+ args: [id]
4784
+ });
4785
+ } catch (error$1) {
4786
+ if (error$1 instanceof error.MastraError) throw error$1;
4787
+ throw new error.MastraError(
4788
+ {
4789
+ id: storage.createStorageErrorId("LIBSQL", "DELETE_MCP_SERVER", "FAILED"),
4790
+ domain: error.ErrorDomain.STORAGE,
4791
+ category: error.ErrorCategory.THIRD_PARTY
4792
+ },
4793
+ error$1
4794
+ );
4795
+ }
4796
+ }
4797
+ async list(args) {
4798
+ try {
4799
+ const { page = 0, perPage: perPageInput, orderBy, authorId, metadata, status = "published" } = args || {};
4800
+ const { field, direction } = this.parseOrderBy(orderBy);
4801
+ const conditions = [];
4802
+ const queryParams = [];
4803
+ conditions.push("status = ?");
4804
+ queryParams.push(status);
4805
+ if (authorId !== void 0) {
4806
+ conditions.push("authorId = ?");
4807
+ queryParams.push(authorId);
4808
+ }
4809
+ if (metadata && Object.keys(metadata).length > 0) {
4810
+ for (const [key, value] of Object.entries(metadata)) {
4811
+ if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(key)) {
4812
+ throw new error.MastraError({
4813
+ id: storage.createStorageErrorId("LIBSQL", "LIST_MCP_SERVERS", "INVALID_METADATA_KEY"),
4814
+ domain: error.ErrorDomain.STORAGE,
4815
+ category: error.ErrorCategory.USER,
4816
+ text: `Invalid metadata key: ${key}. Keys must be alphanumeric with underscores.`,
4817
+ details: { key }
4818
+ });
4819
+ }
4820
+ conditions.push(`json_extract(metadata, '$.${key}') = ?`);
4821
+ queryParams.push(typeof value === "string" ? value : JSON.stringify(value));
4822
+ }
4823
+ }
4824
+ const whereClause = `WHERE ${conditions.join(" AND ")}`;
4825
+ const countResult = await this.#client.execute({
4826
+ sql: `SELECT COUNT(*) as count FROM "${storage.TABLE_MCP_SERVERS}" ${whereClause}`,
4827
+ args: queryParams
4828
+ });
4829
+ const total = Number(countResult.rows?.[0]?.count ?? 0);
4830
+ if (total === 0) {
4831
+ return {
4832
+ mcpServers: [],
4833
+ total: 0,
4834
+ page,
4835
+ perPage: perPageInput ?? 100,
4836
+ hasMore: false
4837
+ };
4838
+ }
4839
+ const perPage = storage.normalizePerPage(perPageInput, 100);
4840
+ const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
4841
+ const limitValue = perPageInput === false ? total : perPage;
4842
+ const end = perPageInput === false ? total : start + perPage;
4843
+ const result = await this.#client.execute({
4844
+ sql: `SELECT ${buildSelectColumns(storage.TABLE_MCP_SERVERS)} FROM "${storage.TABLE_MCP_SERVERS}" ${whereClause} ORDER BY ${field} ${direction} LIMIT ? OFFSET ?`,
4845
+ args: [...queryParams, limitValue, start]
4846
+ });
4847
+ const mcpServers = result.rows?.map((row) => this.#parseMCPServerRow(row)) ?? [];
4848
+ return {
4849
+ mcpServers,
4850
+ total,
4851
+ page,
4852
+ perPage: perPageForResponse,
4853
+ hasMore: end < total
4854
+ };
4855
+ } catch (error$1) {
4856
+ if (error$1 instanceof error.MastraError) throw error$1;
4857
+ throw new error.MastraError(
4858
+ {
4859
+ id: storage.createStorageErrorId("LIBSQL", "LIST_MCP_SERVERS", "FAILED"),
4860
+ domain: error.ErrorDomain.STORAGE,
4861
+ category: error.ErrorCategory.THIRD_PARTY
4862
+ },
4863
+ error$1
4864
+ );
4865
+ }
4866
+ }
4867
+ // ==========================================================================
4868
+ // MCP Server Version Methods
4869
+ // ==========================================================================
4870
+ async createVersion(input) {
4871
+ try {
4872
+ const now = /* @__PURE__ */ new Date();
4873
+ await this.#db.insert({
4874
+ tableName: storage.TABLE_MCP_SERVER_VERSIONS,
4875
+ record: {
4876
+ id: input.id,
4877
+ mcpServerId: input.mcpServerId,
4878
+ versionNumber: input.versionNumber,
4879
+ name: input.name,
4880
+ version: input.version,
4881
+ description: input.description ?? null,
4882
+ instructions: input.instructions ?? null,
4883
+ repository: input.repository ?? null,
4884
+ releaseDate: input.releaseDate ?? null,
4885
+ isLatest: input.isLatest ?? null,
4886
+ packageCanonical: input.packageCanonical ?? null,
4887
+ tools: input.tools ?? null,
4888
+ agents: input.agents ?? null,
4889
+ workflows: input.workflows ?? null,
4890
+ changedFields: input.changedFields ?? null,
4891
+ changeMessage: input.changeMessage ?? null,
4892
+ createdAt: now.toISOString()
4893
+ }
4894
+ });
4895
+ return {
4896
+ ...input,
4897
+ createdAt: now
4898
+ };
4899
+ } catch (error$1) {
4900
+ if (error$1 instanceof error.MastraError) throw error$1;
4901
+ throw new error.MastraError(
4902
+ {
4903
+ id: storage.createStorageErrorId("LIBSQL", "CREATE_MCP_SERVER_VERSION", "FAILED"),
4904
+ domain: error.ErrorDomain.STORAGE,
4905
+ category: error.ErrorCategory.THIRD_PARTY
4906
+ },
4907
+ error$1
4908
+ );
4909
+ }
4910
+ }
4911
+ async getVersion(id) {
4912
+ try {
4913
+ const result = await this.#client.execute({
4914
+ sql: `SELECT ${buildSelectColumns(storage.TABLE_MCP_SERVER_VERSIONS)} FROM "${storage.TABLE_MCP_SERVER_VERSIONS}" WHERE id = ?`,
4915
+ args: [id]
4916
+ });
4917
+ const row = result.rows?.[0];
4918
+ return row ? this.#parseVersionRow(row) : null;
4919
+ } catch (error$1) {
4920
+ if (error$1 instanceof error.MastraError) throw error$1;
4921
+ throw new error.MastraError(
4922
+ {
4923
+ id: storage.createStorageErrorId("LIBSQL", "GET_MCP_SERVER_VERSION", "FAILED"),
4924
+ domain: error.ErrorDomain.STORAGE,
4925
+ category: error.ErrorCategory.THIRD_PARTY
4926
+ },
4927
+ error$1
4928
+ );
4929
+ }
4930
+ }
4931
+ async getVersionByNumber(mcpServerId, versionNumber) {
4932
+ try {
4933
+ const result = await this.#client.execute({
4934
+ sql: `SELECT ${buildSelectColumns(storage.TABLE_MCP_SERVER_VERSIONS)} FROM "${storage.TABLE_MCP_SERVER_VERSIONS}" WHERE mcpServerId = ? AND versionNumber = ?`,
4935
+ args: [mcpServerId, versionNumber]
4936
+ });
4937
+ const row = result.rows?.[0];
4938
+ return row ? this.#parseVersionRow(row) : null;
4939
+ } catch (error$1) {
4940
+ if (error$1 instanceof error.MastraError) throw error$1;
4941
+ throw new error.MastraError(
4942
+ {
4943
+ id: storage.createStorageErrorId("LIBSQL", "GET_MCP_SERVER_VERSION_BY_NUMBER", "FAILED"),
4944
+ domain: error.ErrorDomain.STORAGE,
4945
+ category: error.ErrorCategory.THIRD_PARTY
4946
+ },
4947
+ error$1
4948
+ );
4949
+ }
4950
+ }
4951
+ async getLatestVersion(mcpServerId) {
4952
+ try {
4953
+ const result = await this.#client.execute({
4954
+ sql: `SELECT ${buildSelectColumns(storage.TABLE_MCP_SERVER_VERSIONS)} FROM "${storage.TABLE_MCP_SERVER_VERSIONS}" WHERE mcpServerId = ? ORDER BY versionNumber DESC LIMIT 1`,
4955
+ args: [mcpServerId]
4956
+ });
4957
+ const row = result.rows?.[0];
4958
+ return row ? this.#parseVersionRow(row) : null;
4959
+ } catch (error$1) {
4960
+ if (error$1 instanceof error.MastraError) throw error$1;
4961
+ throw new error.MastraError(
4962
+ {
4963
+ id: storage.createStorageErrorId("LIBSQL", "GET_LATEST_MCP_SERVER_VERSION", "FAILED"),
4964
+ domain: error.ErrorDomain.STORAGE,
4965
+ category: error.ErrorCategory.THIRD_PARTY
4966
+ },
4967
+ error$1
4968
+ );
4969
+ }
4970
+ }
4971
+ async listVersions(input) {
4972
+ try {
4973
+ const { mcpServerId, page = 0, perPage: perPageInput, orderBy } = input;
4974
+ const { field, direction } = this.parseVersionOrderBy(orderBy);
4975
+ const countResult = await this.#client.execute({
4976
+ sql: `SELECT COUNT(*) as count FROM "${storage.TABLE_MCP_SERVER_VERSIONS}" WHERE mcpServerId = ?`,
4977
+ args: [mcpServerId]
4978
+ });
4979
+ const total = Number(countResult.rows?.[0]?.count ?? 0);
4980
+ if (total === 0) {
4981
+ return {
4982
+ versions: [],
4983
+ total: 0,
4984
+ page,
4985
+ perPage: perPageInput ?? 20,
4986
+ hasMore: false
4987
+ };
4988
+ }
4989
+ const perPage = storage.normalizePerPage(perPageInput, 20);
4990
+ const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
4991
+ const limitValue = perPageInput === false ? total : perPage;
4992
+ const end = perPageInput === false ? total : start + perPage;
4993
+ const result = await this.#client.execute({
4994
+ sql: `SELECT ${buildSelectColumns(storage.TABLE_MCP_SERVER_VERSIONS)} FROM "${storage.TABLE_MCP_SERVER_VERSIONS}" WHERE mcpServerId = ? ORDER BY ${field} ${direction} LIMIT ? OFFSET ?`,
4995
+ args: [mcpServerId, limitValue, start]
4996
+ });
4997
+ const versions = result.rows?.map((row) => this.#parseVersionRow(row)) ?? [];
4998
+ return {
4999
+ versions,
5000
+ total,
5001
+ page,
5002
+ perPage: perPageForResponse,
5003
+ hasMore: end < total
5004
+ };
5005
+ } catch (error$1) {
5006
+ if (error$1 instanceof error.MastraError) throw error$1;
5007
+ throw new error.MastraError(
5008
+ {
5009
+ id: storage.createStorageErrorId("LIBSQL", "LIST_MCP_SERVER_VERSIONS", "FAILED"),
5010
+ domain: error.ErrorDomain.STORAGE,
5011
+ category: error.ErrorCategory.THIRD_PARTY
5012
+ },
5013
+ error$1
5014
+ );
5015
+ }
5016
+ }
5017
+ async deleteVersion(id) {
5018
+ try {
5019
+ await this.#client.execute({
5020
+ sql: `DELETE FROM "${storage.TABLE_MCP_SERVER_VERSIONS}" WHERE "id" = ?`,
5021
+ args: [id]
5022
+ });
5023
+ } catch (error$1) {
5024
+ if (error$1 instanceof error.MastraError) throw error$1;
5025
+ throw new error.MastraError(
5026
+ {
5027
+ id: storage.createStorageErrorId("LIBSQL", "DELETE_MCP_SERVER_VERSION", "FAILED"),
5028
+ domain: error.ErrorDomain.STORAGE,
5029
+ category: error.ErrorCategory.THIRD_PARTY
5030
+ },
5031
+ error$1
5032
+ );
5033
+ }
5034
+ }
5035
+ async deleteVersionsByParentId(entityId) {
5036
+ try {
5037
+ await this.#client.execute({
5038
+ sql: `DELETE FROM "${storage.TABLE_MCP_SERVER_VERSIONS}" WHERE "mcpServerId" = ?`,
5039
+ args: [entityId]
5040
+ });
5041
+ } catch (error$1) {
5042
+ if (error$1 instanceof error.MastraError) throw error$1;
5043
+ throw new error.MastraError(
5044
+ {
5045
+ id: storage.createStorageErrorId("LIBSQL", "DELETE_MCP_SERVER_VERSIONS_BY_SERVER", "FAILED"),
5046
+ domain: error.ErrorDomain.STORAGE,
5047
+ category: error.ErrorCategory.THIRD_PARTY
5048
+ },
5049
+ error$1
5050
+ );
5051
+ }
5052
+ }
5053
+ async countVersions(mcpServerId) {
5054
+ try {
5055
+ const result = await this.#client.execute({
5056
+ sql: `SELECT COUNT(*) as count FROM "${storage.TABLE_MCP_SERVER_VERSIONS}" WHERE mcpServerId = ?`,
5057
+ args: [mcpServerId]
5058
+ });
5059
+ return Number(result.rows?.[0]?.count ?? 0);
5060
+ } catch (error$1) {
5061
+ if (error$1 instanceof error.MastraError) throw error$1;
5062
+ throw new error.MastraError(
5063
+ {
5064
+ id: storage.createStorageErrorId("LIBSQL", "COUNT_MCP_SERVER_VERSIONS", "FAILED"),
5065
+ domain: error.ErrorDomain.STORAGE,
5066
+ category: error.ErrorCategory.THIRD_PARTY
5067
+ },
5068
+ error$1
5069
+ );
5070
+ }
5071
+ }
5072
+ // ==========================================================================
5073
+ // Private Helpers
5074
+ // ==========================================================================
5075
+ #safeParseJSON(val) {
5076
+ if (val === null || val === void 0) return void 0;
5077
+ if (typeof val === "string") {
5078
+ try {
5079
+ return JSON.parse(val);
5080
+ } catch {
5081
+ return val;
5082
+ }
5083
+ }
5084
+ return val;
5085
+ }
5086
+ #parseMCPServerRow(row) {
5087
+ return {
5088
+ id: row.id,
5089
+ status: row.status ?? "draft",
5090
+ activeVersionId: row.activeVersionId ?? void 0,
5091
+ authorId: row.authorId ?? void 0,
5092
+ metadata: this.#safeParseJSON(row.metadata),
5093
+ createdAt: new Date(row.createdAt),
5094
+ updatedAt: new Date(row.updatedAt)
5095
+ };
5096
+ }
5097
+ #parseVersionRow(row) {
5098
+ return {
5099
+ id: row.id,
5100
+ mcpServerId: row.mcpServerId,
5101
+ versionNumber: Number(row.versionNumber),
5102
+ name: row.name,
5103
+ version: row.version,
5104
+ description: row.description ?? void 0,
5105
+ instructions: row.instructions ?? void 0,
5106
+ repository: this.#safeParseJSON(row.repository),
5107
+ releaseDate: row.releaseDate ?? void 0,
5108
+ isLatest: row.isLatest === null || row.isLatest === void 0 ? void 0 : Boolean(row.isLatest),
5109
+ packageCanonical: row.packageCanonical ?? void 0,
5110
+ tools: this.#safeParseJSON(row.tools),
5111
+ agents: this.#safeParseJSON(row.agents),
5112
+ workflows: this.#safeParseJSON(row.workflows),
5113
+ changedFields: this.#safeParseJSON(row.changedFields),
5114
+ changeMessage: row.changeMessage ?? void 0,
5115
+ createdAt: new Date(row.createdAt)
5116
+ };
5117
+ }
5118
+ };
4635
5119
  var OM_TABLE = "mastra_observational_memory";
4636
5120
  var MemoryLibSQL = class extends storage.MemoryStorage {
4637
5121
  supportsObservationalMemory = true;
@@ -6296,32 +6780,40 @@ var MemoryLibSQL = class extends storage.MemoryStorage {
6296
6780
  const retentionFloor = input.messageTokensThreshold * (1 - input.activationRatio);
6297
6781
  const targetMessageTokens = Math.max(0, input.currentPendingTokens - retentionFloor);
6298
6782
  let cumulativeMessageTokens = 0;
6299
- let bestBoundary = 0;
6300
- let bestBoundaryMessageTokens = 0;
6783
+ let bestOverBoundary = 0;
6784
+ let bestOverTokens = 0;
6785
+ let bestUnderBoundary = 0;
6786
+ let bestUnderTokens = 0;
6301
6787
  for (let i = 0; i < chunks.length; i++) {
6302
6788
  cumulativeMessageTokens += chunks[i].messageTokens ?? 0;
6303
6789
  const boundary = i + 1;
6304
- const isUnder = cumulativeMessageTokens <= targetMessageTokens;
6305
- const bestIsUnder = bestBoundaryMessageTokens <= targetMessageTokens;
6306
- if (bestBoundary === 0) {
6307
- bestBoundary = boundary;
6308
- bestBoundaryMessageTokens = cumulativeMessageTokens;
6309
- } else if (isUnder && !bestIsUnder) {
6310
- bestBoundary = boundary;
6311
- bestBoundaryMessageTokens = cumulativeMessageTokens;
6312
- } else if (isUnder && bestIsUnder) {
6313
- if (cumulativeMessageTokens > bestBoundaryMessageTokens) {
6314
- bestBoundary = boundary;
6315
- bestBoundaryMessageTokens = cumulativeMessageTokens;
6790
+ if (cumulativeMessageTokens >= targetMessageTokens) {
6791
+ if (bestOverBoundary === 0 || cumulativeMessageTokens < bestOverTokens) {
6792
+ bestOverBoundary = boundary;
6793
+ bestOverTokens = cumulativeMessageTokens;
6316
6794
  }
6317
- } else if (!isUnder && !bestIsUnder) {
6318
- if (cumulativeMessageTokens < bestBoundaryMessageTokens) {
6319
- bestBoundary = boundary;
6320
- bestBoundaryMessageTokens = cumulativeMessageTokens;
6795
+ } else {
6796
+ if (cumulativeMessageTokens > bestUnderTokens) {
6797
+ bestUnderBoundary = boundary;
6798
+ bestUnderTokens = cumulativeMessageTokens;
6321
6799
  }
6322
6800
  }
6323
6801
  }
6324
- const chunksToActivate = bestBoundary === 0 ? 1 : bestBoundary;
6802
+ const maxOvershoot = retentionFloor * 0.95;
6803
+ const overshoot = bestOverTokens - targetMessageTokens;
6804
+ const remainingAfterOver = input.currentPendingTokens - bestOverTokens;
6805
+ let chunksToActivate;
6806
+ if (input.forceMaxActivation && bestOverBoundary > 0) {
6807
+ chunksToActivate = bestOverBoundary;
6808
+ } else if (bestOverBoundary > 0 && overshoot <= maxOvershoot && (remainingAfterOver >= 1e3 || retentionFloor === 0)) {
6809
+ chunksToActivate = bestOverBoundary;
6810
+ } else if (bestUnderBoundary > 0) {
6811
+ chunksToActivate = bestUnderBoundary;
6812
+ } else if (bestOverBoundary > 0) {
6813
+ chunksToActivate = bestOverBoundary;
6814
+ } else {
6815
+ chunksToActivate = 1;
6816
+ }
6325
6817
  const activatedChunks = chunks.slice(0, chunksToActivate);
6326
6818
  const remainingChunks = chunks.slice(chunksToActivate);
6327
6819
  const activatedContent = activatedChunks.map((c) => c.observations).join("\n\n");
@@ -6360,6 +6852,7 @@ ${activatedContent}` : activatedContent;
6360
6852
  input.id
6361
6853
  ]
6362
6854
  });
6855
+ const latestChunkHints = activatedChunks[activatedChunks.length - 1];
6363
6856
  return {
6364
6857
  chunksActivated: activatedChunks.length,
6365
6858
  messageTokensActivated: activatedMessageTokens,
@@ -6374,7 +6867,9 @@ ${activatedContent}` : activatedContent;
6374
6867
  observationTokens: c.tokenCount,
6375
6868
  messageCount: c.messageIds.length,
6376
6869
  observations: c.observations
6377
- }))
6870
+ })),
6871
+ suggestedContinuation: latestChunkHints?.suggestedContinuation ?? void 0,
6872
+ currentTask: latestChunkHints?.currentTask ?? void 0
6378
6873
  };
6379
6874
  } catch (error$1) {
6380
6875
  if (error$1 instanceof error.MastraError) {
@@ -9653,6 +10148,7 @@ var LibSQLStore = class extends storage.MastraCompositeStore {
9653
10148
  const promptBlocks = new PromptBlocksLibSQL(domainConfig);
9654
10149
  const scorerDefinitions = new ScorerDefinitionsLibSQL(domainConfig);
9655
10150
  const mcpClients = new MCPClientsLibSQL(domainConfig);
10151
+ const mcpServers = new MCPServersLibSQL(domainConfig);
9656
10152
  const workspaces = new WorkspacesLibSQL(domainConfig);
9657
10153
  const skills = new SkillsLibSQL(domainConfig);
9658
10154
  const blobs = new BlobsLibSQL(domainConfig);
@@ -9667,6 +10163,7 @@ var LibSQLStore = class extends storage.MastraCompositeStore {
9667
10163
  promptBlocks,
9668
10164
  scorerDefinitions,
9669
10165
  mcpClients,
10166
+ mcpServers,
9670
10167
  workspaces,
9671
10168
  skills,
9672
10169
  blobs
@@ -9782,6 +10279,7 @@ exports.LIBSQL_PROMPT = LIBSQL_PROMPT;
9782
10279
  exports.LibSQLStore = LibSQLStore;
9783
10280
  exports.LibSQLVector = LibSQLVector;
9784
10281
  exports.MCPClientsLibSQL = MCPClientsLibSQL;
10282
+ exports.MCPServersLibSQL = MCPServersLibSQL;
9785
10283
  exports.MemoryLibSQL = MemoryLibSQL;
9786
10284
  exports.ObservabilityLibSQL = ObservabilityLibSQL;
9787
10285
  exports.PromptBlocksLibSQL = PromptBlocksLibSQL;