@mastra/pg 1.36.0-alpha.0 → 1.36.0-alpha.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.
@@ -3,7 +3,7 @@ name: mastra-pg
3
3
  description: Documentation for @mastra/pg. Use when working with @mastra/pg APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/pg"
6
- version: "1.36.0-alpha.0"
6
+ version: "1.36.0-alpha.1"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -14,18 +14,11 @@ Use this skill whenever you are working with @mastra/pg to obtain the domain-spe
14
14
 
15
15
  Read the individual reference documents for detailed explanations and code examples.
16
16
 
17
- ### Docs
18
-
19
- - [Workers](references/docs-deployment-workers.md) - Run Mastra workflow orchestration, schedules, and long-running background tasks in dedicated workers to keep API processes responsive under load.
20
- - [Semantic recall](references/docs-memory-semantic-recall.md) - Retrieve relevant messages from past Mastra conversations with semantic recall, vector search, embeddings, metadata filters, and configurable storage.
21
- - [Working memory](references/docs-memory-working-memory.md) - Persist user profiles, preferences, and application data with Mastra working memory using resource- or thread-scoped templates and storage adapters.
22
- - [Storage](references/docs-storage.md) - Configure Mastra storage to persist memory, workflow state, observability data, evals, schedules, and long-running agent state across restarts.
23
-
24
17
  ### Integrations
25
18
 
26
19
  - [ClickHouse Managed Postgres](references/integrations-databases-clickhouse-managed-postgres.md) - Store Mastra application data in ClickHouse Managed Postgres with PostgresStore and verified TLS.
27
20
  - [DynamoDB](references/integrations-databases-dynamodb.md) - Persist Mastra data in Amazon DynamoDB with a single-table ElectroDB design, configurable indexes, TTL support, credentials, and table initialization.
28
- - [Neon Postgres](references/integrations-databases-neon.md) - Connect Mastra to Neon Postgres with PostgresStore, pooled production connections, schema initialization, vector search, and Neon agent skills.
21
+ - [Neon Postgres](references/integrations-databases-neon.md) - Connect Mastra to Neon Postgres with PostgresStore, pooled production connections, schema initialization, vector search, and Neon agent skills, and give agents Neon tools through Mastra Connect.
29
22
  - [PostgreSQL](references/integrations-databases-postgresql.md) - Persist Mastra application data in PostgreSQL with PostgresStore, configure connections and pools, initialize schemas, and enable observability.
30
23
  - [PG](references/integrations-vectors-pg.md) - Run pgvector similarity search inside PostgreSQL from Mastra with HNSW or IVFFlat indexing, metadata filtering, and direct connection pool access.
31
24
 
@@ -38,10 +31,6 @@ Read the individual reference documents for detailed explanations and code examp
38
31
  - [Chunking and embedding documents](references/reference-rag-chunking-and-embedding.md) - Chunk documents with MDocument, generate embeddings through the AI SDK, and prepare text and metadata for vector storage and RAG retrieval.
39
32
  - [Reference: Metadata filters](references/reference-rag-metadata-filters.md) - Mastra provides a unified metadata filtering syntax across all vector stores, based on MongoDB/Sift query syntax.
40
33
  - [RAG (Retrieval-Augmented Generation) in Mastra](references/reference-rag-overview.md) - RAG in Mastra helps you enhance LLM outputs by incorporating relevant context from your own data sources, improving accuracy and grounding responses in real information.
41
- - [Retrieval, semantic search, reranking](references/reference-rag-retrieval.md) - After storing embeddings, you need to retrieve relevant chunks to answer user queries.
42
- - [Storing embeddings in a vector database](references/reference-rag-vector-databases.md) - After generating embeddings, you need to store them in a database that supports vector similarity search.
43
- - [Reference: Composite storage](references/reference-storage-composite.md) - MastraCompositeStore can compose storage domains from different providers. Use it when you need different databases for different purposes.
44
- - [Reference: Storage retention (prune)](references/reference-storage-retention.md) - prune() deletes rows. It caps growth and is safe to run against large tables (batched, bounded, resumable, cancellable).
45
34
  - [Reference: createVectorQueryTool()](references/reference-tools-vector-query-tool.md) - The createVectorQueryTool() function creates a tool for semantic search over vector stores.
46
35
 
47
36
 
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.36.0-alpha.0",
2
+ "version": "1.36.0-alpha.1",
3
3
  "package": "@mastra/pg",
4
4
  "exports": {
5
5
  "AgentsPG": {
@@ -70,17 +70,17 @@
70
70
  "ObservabilityStoragePostgresVNext": {
71
71
  "types": "dist/storage/domains/observability/v-next/index.d.ts",
72
72
  "implementation": "dist/index.js",
73
- "line": 21800
73
+ "line": 21805
74
74
  },
75
75
  "PGVECTOR_PROMPT": {
76
76
  "types": "dist/vector/prompt.d.ts",
77
77
  "implementation": "dist/index.js",
78
- "line": 28464
78
+ "line": 28475
79
79
  },
80
80
  "PgFactoryStorage": {
81
81
  "types": "dist/storage/factory-storage.d.ts",
82
82
  "implementation": "dist/index.js",
83
- "line": 27950
83
+ "line": 27961
84
84
  },
85
85
  "PgVector": {
86
86
  "types": "dist/vector/index.d.ts",
@@ -95,67 +95,67 @@
95
95
  "PostgresStore": {
96
96
  "types": "dist/storage/index.d.ts",
97
97
  "implementation": "dist/index.js",
98
- "line": 28165
98
+ "line": 28176
99
99
  },
100
100
  "PostgresStoreVNext": {
101
101
  "types": "dist/storage/index.d.ts",
102
102
  "implementation": "dist/index.js",
103
- "line": 28383
103
+ "line": 28394
104
104
  },
105
105
  "PromptBlocksPG": {
106
106
  "types": "dist/storage/domains/prompt-blocks/index.d.ts",
107
107
  "implementation": "dist/index.js",
108
- "line": 22242
108
+ "line": 22250
109
109
  },
110
110
  "SchedulesPG": {
111
111
  "types": "dist/storage/domains/schedules/index.d.ts",
112
112
  "implementation": "dist/index.js",
113
- "line": 22869
113
+ "line": 22877
114
114
  },
115
115
  "ScorerDefinitionsPG": {
116
116
  "types": "dist/storage/domains/scorer-definitions/index.d.ts",
117
117
  "implementation": "dist/index.js",
118
- "line": 23190
118
+ "line": 23198
119
119
  },
120
120
  "ScoresPG": {
121
121
  "types": "dist/storage/domains/scores/index.d.ts",
122
122
  "implementation": "dist/index.js",
123
- "line": 23813
123
+ "line": 23821
124
124
  },
125
125
  "SkillsPG": {
126
126
  "types": "dist/storage/domains/skills/index.d.ts",
127
127
  "implementation": "dist/index.js",
128
- "line": 24256
128
+ "line": 24264
129
129
  },
130
130
  "ThreadStatePG": {
131
131
  "types": "dist/storage/domains/thread-state/index.d.ts",
132
132
  "implementation": "dist/index.js",
133
- "line": 24947
133
+ "line": 24955
134
134
  },
135
135
  "ToolProviderConnectionsPG": {
136
136
  "types": "dist/storage/domains/tool-provider-connections/index.d.ts",
137
137
  "implementation": "dist/index.js",
138
- "line": 25121
138
+ "line": 25129
139
139
  },
140
140
  "WorkflowDefinitionsPG": {
141
141
  "types": "dist/storage/domains/workflow-definitions/index.d.ts",
142
142
  "implementation": "dist/index.js",
143
- "line": 25385
143
+ "line": 25393
144
144
  },
145
145
  "WorkflowsPG": {
146
146
  "types": "dist/storage/domains/workflows/index.d.ts",
147
147
  "implementation": "dist/index.js",
148
- "line": 25768
148
+ "line": 25776
149
149
  },
150
150
  "WorkspacesPG": {
151
151
  "types": "dist/storage/domains/workspaces/index.d.ts",
152
152
  "implementation": "dist/index.js",
153
- "line": 27050
153
+ "line": 27061
154
154
  },
155
155
  "exportSchemas": {
156
156
  "types": "dist/storage/index.d.ts",
157
157
  "implementation": "dist/index.js",
158
- "line": 28132
158
+ "line": 28143
159
159
  }
160
160
  },
161
161
  "modules": {}
@@ -6,6 +6,8 @@
6
6
 
7
7
  [Neon](https://neon.com) is a managed PostgreSQL service. Mastra connects to Neon through [`PostgresStore`](https://mastra.ai/integrations/databases/postgresql), which uses the Node.js `pg` driver. Neon doesn't require a separate Mastra storage package.
8
8
 
9
+ You can also give an agent tools to manage Neon projects and branches, run SQL, and apply schema migrations through [Mastra Connect](#connect).
10
+
9
11
  ## Quickstart
10
12
 
11
13
  Create a Neon project, then copy its [pooled connection string](https://neon.com/docs/connect/connect-from-any-app) into `DATABASE_URL`.
@@ -219,4 +221,38 @@ const vector = new PgVector({
219
221
  })
220
222
  ```
221
223
 
222
- Setting `disableInit: true` prevents the runtime process from creating or changing the extension, tables and indexes.
224
+ Setting `disableInit: true` prevents the runtime process from creating or changing the extension, tables and indexes.
225
+
226
+ ## Connect
227
+
228
+ Before you start, complete the [Connect setup](https://mastra.ai/docs/mastra-platform/connect) to install `@mastra/connect` and configure your platform project.
229
+
230
+ ### Agent tools
231
+
232
+ Give agents tools from Neon's hosted Model Context Protocol (MCP) server to manage projects and branches, run SQL, and plan and apply schema migrations in Neon.
233
+
234
+ Connect an account with the `neon-mcp` provider ID. Run this command from the directory that contains your `.env` file:
235
+
236
+ ```bash
237
+ mastra connect add neon-mcp
238
+ ```
239
+
240
+ Then pass [`tools()`](https://mastra.ai/reference/connect/tools) to the agent and select the provider:
241
+
242
+ ```typescript
243
+ import { Agent } from '@mastra/core/agent'
244
+ import { tools } from '@mastra/connect'
245
+
246
+ export const neonMcpAgent = new Agent({
247
+ id: 'neon-mcp-agent',
248
+ name: 'Neon agent',
249
+ instructions:
250
+ 'You help people manage projects and branches, run SQL, and plan and apply schema migrations in Neon.',
251
+ model: '__GATEWAY_OPENAI_MODEL_LUNA__',
252
+ tools: tools({ providers: ['neon-mcp'] }),
253
+ })
254
+ ```
255
+
256
+ Mastra discovers Neon's tools from its MCP server when the agent runs. The available tools depend on the server and the connected account, not on your `@mastra/connect` version. Tool keys start with `neon-mcp_`.
257
+
258
+ To see which tools Neon provides, read the [Neon MCP server](https://neon.com/docs/ai/neon-mcp-server) documentation. To require approval before a call runs, see [MCP providers](https://mastra.ai/reference/connect/tools) in the `tools()` reference.
@@ -243,6 +243,52 @@ const thread = await memoryStore?.getThreadById({ threadId: '...' })
243
243
 
244
244
  > **Warning:** If `init()` isn't called, tables won't be created and storage operations will fail silently or throw errors.
245
245
 
246
+ ### Managed PostgreSQL and connection poolers
247
+
248
+ `PostgresStore` connects to managed PostgreSQL providers with the connection string they give you. No provider-specific package is required.
249
+
250
+ `init()` runs all schema changes on a single connection, so it works through transaction-mode connection poolers such as PgBouncer. You can use the provider's pooled connection string and let Mastra create the schema on startup.
251
+
252
+ #### Separate schema initialization
253
+
254
+ If the runtime database role can't create tables or indexes, run `init()` once during deployment with a role that can:
255
+
256
+ ```typescript
257
+ import { PostgresStore } from '@mastra/pg'
258
+
259
+ const storage = new PostgresStore({
260
+ id: 'pg-storage-init',
261
+ connectionString: process.env.DATABASE_ADMIN_URL,
262
+ })
263
+
264
+ try {
265
+ await storage.init()
266
+ // Only needed if the application uses Knowledge
267
+ await storage.initKnowledge()
268
+ } finally {
269
+ await storage.close()
270
+ }
271
+ ```
272
+
273
+ The runtime role needs read and write access to the tables this script creates. See [PostgreSQL privileges](https://www.postgresql.org/docs/current/ddl-priv.html).
274
+
275
+ Then set `disableInit: true` on the runtime store so it skips schema creation:
276
+
277
+ ```typescript
278
+ import { Mastra } from '@mastra/core'
279
+ import { PostgresStore } from '@mastra/pg'
280
+
281
+ export const mastra = new Mastra({
282
+ storage: new PostgresStore({
283
+ id: 'pg-storage',
284
+ connectionString: process.env.DATABASE_URL,
285
+ disableInit: true,
286
+ }),
287
+ })
288
+ ```
289
+
290
+ `disableInit: true` also makes explicit `init()` calls a no-op, so leave it off the store in the deployment script.
291
+
246
292
  ### Using an Existing Pool
247
293
 
248
294
  If you already have a `pg.Pool` in your application (e.g., shared with an ORM or for Row Level Security), you can pass it directly to `PostgresStore`:
package/dist/index.cjs CHANGED
@@ -18337,6 +18337,11 @@ async function batchCreateFeedback(client, schema, args, partitioning) {
18337
18337
  const rows = [...new Map(args.feedbacks.map((feedback) => [feedback.feedbackId, feedback])).values()].map(feedbackRecordToRow);
18338
18338
  await insertRows(client, schema, TABLE_FEEDBACK_EVENTS, rows, partitioning, FEEDBACK_UPSERT_CLAUSE);
18339
18339
  }
18340
+ async function getFeedbackById(client, schema, feedbackId) {
18341
+ const row = await client.oneOrNone(`SELECT ${FEEDBACK_SELECT_COLUMNS} FROM ${qualifiedTable(schema, TABLE_FEEDBACK_EVENTS)}
18342
+ WHERE "feedbackId" = $1 ORDER BY "cursorId" DESC LIMIT 1`, [feedbackId]);
18343
+ return row ? rowToFeedbackRecord(row) : null;
18344
+ }
18340
18345
  async function updateFeedbackReviewStatus(client, schema, args) {
18341
18346
  const { feedbackId, reviewStatus } = parseUpdateFeedbackReviewStatusArgs(args);
18342
18347
  const row = await client.oneOrNone(`UPDATE ${qualifiedTable(schema, TABLE_FEEDBACK_EVENTS)}
@@ -22172,6 +22177,9 @@ var ObservabilityStoragePostgresVNext = class ObservabilityStoragePostgresVNext
22172
22177
  async getScoreById(scoreId) {
22173
22178
  return this.#run("GET_SCORE_BY_ID", () => getScoreById(this.#readClient, this.#schema, scoreId), { scoreId });
22174
22179
  }
22180
+ async getFeedbackById(feedbackId) {
22181
+ return this.#run("GET_FEEDBACK_BY_ID", () => getFeedbackById(this.#readClient, this.#schema, feedbackId), { feedbackId });
22182
+ }
22175
22183
  async listFeedback(args) {
22176
22184
  return this.#run("LIST_FEEDBACK", () => listFeedback(this.#readClient, this.#schema, args));
22177
22185
  }
@@ -27012,18 +27020,9 @@ var WorkflowsPG = class WorkflowsPG extends _mastra_core_storage.WorkflowsStorag
27012
27020
  }
27013
27021
  const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
27014
27022
  const v2WhereClause = v2Conditions.length > 0 ? `WHERE ${v2Conditions.join(" AND ")}` : "";
27015
- let total = 0;
27016
27023
  const usePagination = typeof perPage === "number" && typeof page === "number";
27017
- if (usePagination) {
27018
- const countResult = await this.#db.client.one(`SELECT (SELECT COUNT(*) FROM ${getTableName({
27019
- indexName: _mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT,
27020
- schemaName: getSchemaName(this.#schema)
27021
- })} ${whereClause})
27022
- + (SELECT COUNT(*) FROM ${this.#runsTable()} ${v2WhereClause}) AS count`, values);
27023
- total = Number(countResult.count);
27024
- }
27025
27024
  const normalizedPerPage = usePagination ? (0, _mastra_core_storage.normalizePerPage)(perPage, Number.MAX_SAFE_INTEGER) : 0;
27026
- const offset = usePagination ? page * normalizedPerPage : void 0;
27025
+ const offset = usePagination ? page * normalizedPerPage : 0;
27027
27026
  let v1Snapshot = "snapshot";
27028
27027
  if (summary) {
27029
27028
  const snapshotJson = await this.#db.getColumnType(_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT, "snapshot") === "jsonb" ? "snapshot" : `regexp_replace(snapshot::text, '\\\\u(0000|[Dd][89A-Fa-f][0-9A-Fa-f]{2})', '', 'g')::jsonb`;
@@ -27043,6 +27042,18 @@ var WorkflowsPG = class WorkflowsPG extends _mastra_core_storage.WorkflowsStorag
27043
27042
  ] : values;
27044
27043
  const result = await this.#db.client.manyOrNone(query, queryValues);
27045
27044
  const runs = await Promise.all((result || []).map((row) => this.#parseRun(this.#db.client, row)));
27045
+ let total = 0;
27046
+ if (usePagination) {
27047
+ total = offset + runs.length;
27048
+ if (runs.length === normalizedPerPage || runs.length === 0 && offset > 0) {
27049
+ const countResult = await this.#db.client.one(`SELECT (SELECT COUNT(*) FROM ${getTableName({
27050
+ indexName: _mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT,
27051
+ schemaName: getSchemaName(this.#schema)
27052
+ })} ${whereClause})
27053
+ + (SELECT COUNT(*) FROM ${this.#runsTable()} ${v2WhereClause}) AS count`, values);
27054
+ total = Number(countResult.count);
27055
+ }
27056
+ }
27046
27057
  return {
27047
27058
  runs,
27048
27059
  total: total || runs.length