Commit aa36be2
# PR 1 of 3 — split of #17224 (v1 ToolProvider backend)
Adds the `tool_provider_connections` storage domain that the v1
ToolProvider runtime (PR 2) and the label PATCH endpoint (PR 3) build
on. No runtime, no server routes, no SDK surface — pure storage.
Also adds a `toolProviders` jsonb column to `AGENT_VERSIONS_SCHEMA` so
stored agents can persist a per-agent ToolProvider config (consumed in
PR 2). Nullable, additive — no migration story for existing rows.
## Scope (18 files, +1135 / -3)
**Core storage domain (new)**
- `packages/core/src/storage/domains/tool-provider-connections/base.ts`
— `ToolProviderConnectionsStorage` abstract class (`getConnectionById`,
`upsertConnection`, `listConnectionsByAuthor`, `deleteConnection`,
`dangerouslyClearAll`)
- `packages/core/src/storage/domains/tool-provider-connections/index.ts`
— barrel
-
`packages/core/src/storage/domains/tool-provider-connections/inmemory.ts`
— in-memory reference impl
-
`packages/core/src/storage/domains/tool-provider-connections/inmemory.test.ts`
— 15 tests covering all CRUD paths
**Core storage wiring**
- `packages/core/src/storage/base.ts` — abstract `toolProviders` getter
- `packages/core/src/storage/constants.ts` —
`TABLE_TOOL_PROVIDER_CONNECTIONS = 'mastra_tool_provider_connections'`;
**`AGENT_VERSIONS_SCHEMA` gains `toolProviders: { type: 'jsonb',
nullable: true }`** so stored agent rows can carry per-agent
ToolProvider config
- `packages/core/src/storage/types.ts` —
`StorageToolProviderConnection`,
`StorageUpsertToolProviderConnectionInput`,
`StorageToolProviderConnectionScope` (union of `'shared' | 'per-author'
| 'caller-supplied'`), `StorageToolProviderConnectionKey`
- `packages/core/src/storage/mock.ts` — mock storage exposes new domain
- `packages/core/src/storage/domains/index.ts` — re-export
- `packages/core/src/storage/domains/inmemory-db.ts` — in-memory table
- `packages/core/src/storage/domains/operations/inmemory.ts` —
operations bind
- `packages/core/src/storage/domains/agents/filesystem.ts` —
`'toolProviders'` added to `PERSISTED_SNAPSHOT_FIELDS` so the filesystem
agent storage round-trips the new column
**libsql adapter**
- `stores/libsql/src/storage/domains/tool-provider-connections/index.ts`
— libsql impl of `ToolProviderConnectionsStorage`
-
`stores/libsql/src/storage/domains/tool-provider-connections/index.test.ts`
— 16 tests
- `stores/libsql/src/storage/domains/agents/index.ts` — schema migration
via `alterTable(... ifNotExists: ['toolProviders'])` for
`TABLE_AGENT_VERSIONS`; read/write/create paths round-trip
`toolProviders` (`parseJson` on read, `?? null` on insert)
- `stores/libsql/src/storage/index.ts` — wire domain into `LibSQLStore`
**Cross-store table-constant recognition (no impl)**
- `stores/clickhouse/src/storage/db/utils.ts` — recognize new table
constant
- `stores/cloudflare/src/kv/storage/types.ts` — recognize new table
constant
- These stores do **not** implement `ToolProviderConnectionsStorage`
yet. Same applies to pg / mssql / mongodb / etc. That is acceptable here
because `StorageDomains.toolProviderConnections` is optional, but it
means PR 2's runtime resolver will silently no-op on those stores until
adapter impls land. PR 2 will flag this — see the "Forward-looking
notes" section below.
**Changeset**
- `.changeset/v1-tp-storage.md`
## Intentionally excluded
- Tool-provider runtime resolver, server routes, `@mastra/client-js`
resource, Composio rewrite — see **PR 2** (stacked on this one).
- `SHARED_BUCKET_ID` constant (used to bucket `scope: 'shared'`
connections under a known authorId) lives in the runtime layer, not
storage — it arrives in PR 2.
- PATCH endpoint to rename connection labels — see **PR 3** (stacked on
PR 2).
## Naming choices in this PR
CRUD methods on the storage class use `getConnectionById` /
`upsertConnection` / `listConnectionsByAuthor` / `deleteConnection` to
match the `verb-Entity[-By-key]` pattern used by sibling storage domains
(channels, favorites, etc.). Bare `get`/`upsert`/`list`/`delete` were
ruled out because they collide with mental models from other domains.
## Forward-looking notes (not blocking this PR)
- **Adapter coverage** — only `libsql` implements
`ToolProviderConnectionsStorage` in this PR. `clickhouse` / `cloudflare`
/ `pg` / `mssql` / `mongodb` only get the table constant added to their
`TABLE_NAMES` union. PR 2 should call this out so reviewers don't expect
Composio/Arcade tool resolution to work on those stores until follow-ups
land, and may want to add an explicit "not implemented" path that throws
rather than silently no-op.
- **Admin cross-author listing** — `listConnectionsByAuthor` with
`authorId` omitted returns rows across all authors (documented admin
path). PR 2 must ensure no unauthenticated server route reaches this
branch.
## Verification
- `pnpm build:core` — clean
- `pnpm --filter ./packages/core test` (focused on
`tool-provider-connections/inmemory.test.ts`) — 15/15 pass
- `pnpm --filter ./stores/libsql build` — clean
- `pnpm --filter ./stores/libsql test` — 721/721 pass (16 new for
tool-provider-connections)
## Stack
1. **PR 1 / 3** (this PR) — storage domain
2. **PR 2 / 3** — runtime + server + client SDK + editor wiring
3. **PR 3 / 3** — PATCH endpoint to rename connection labels
Backup of the original branch lives at `backup/v1-tp-backend-original`
locally for cross-checking; range-diff against the full stack is
functionally identical (whitespace-only delta in one test file).
Replaces #17224.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## ELI5
This PR adds a storage system for remembering how users have connected
to external tools and services. Instead of asking users to
re-authenticate every time they use a tool, the system can now save and
reuse these connections—like remembering a username and password so you
don't have to log in again.
## Overview
Introduces a new `tool_provider_connections` storage domain to enable
stored agents to persist per-agent ToolProvider OAuth-style connection
configurations. This storage-only implementation (no runtime, server
routes, or SDK surface) allows agent runs to resolve connections via
multiple scopes (per-author, shared, or caller-supplied) without
re-prompting for authentication on each run.
## Core Changes
**Storage Domain Contract**
(`packages/core/src/storage/domains/tool-provider-connections/`)
- New abstract `ToolProviderConnectionsStorage` class defining six key
methods: `init()`, `getConnectionById()`, `upsertConnection()`,
`listConnectionsByAuthor()`, `deleteConnection()`, and
`dangerouslyClearAll()`
- In-memory reference implementation
(`InMemoryToolProviderConnectionsStorage`) with 15 passing tests
covering upsert, retrieval, listing with optional filters, deletion, and
scope handling
- Type definitions for `StorageToolProviderConnection`,
`StorageUpsertToolProviderConnectionInput`,
`StorageToolProviderConnectionScope` ('shared' | 'per-author' |
'caller-supplied'), and related input types
**Schema & Type Updates**
- New `TOOL_PROVIDER_CONNECTIONS_SCHEMA` with composite primary key on
`(authorId, providerId, connectionId)`
- `AGENT_VERSIONS_SCHEMA` extended with optional `toolProviders` JSONB
column to persist per-agent ToolProvider configurations (additive,
nullable; no migration required for existing rows)
- New type exports in `StorageAgentSnapshotType` to support agent-level
tool provider configs
- Storage type wiring into `StorageDomains` interface and
`EDITOR_DOMAINS` routing list
**Storage Layer Integration**
- Wired into core `InMemoryStore` and mock storage via shared
`InMemoryDB`
- Updated `InMemoryDB` to track tool-provider connections with composite
key formatting
- Filesystem agent storage updated to persist `toolProviders` field in
snapshots (`PERSISTED_SNAPSHOT_FIELDS` includes `toolProviders`)
- In-memory operations table initialized with new storage table
## LibSQL Adapter
**Domain Implementation**
(`stores/libsql/src/storage/domains/tool-provider-connections/`)
- `ToolProviderConnectionsLibSQL` class extending base storage domain
- `init()` creates table with composite primary key and index for
author-scoped queries
- CRUD operations implemented with parameterized queries, transactional
upsert logic, scope normalization, date conversion, and
MastraError-wrapped errors
- Upsert checks for existing row then UPDATEs or INSERTs with proper
createdAt/updatedAt handling
- 16 passing tests validating insert, update, filtering, deletion, and
cross-author isolation
**Agent Storage Updates** (`stores/libsql/src/storage/domains/agents/`)
- `AgentsLibSQL.init()` altered to add `toolProviders` column if missing
(non-breaking migration)
- Legacy migration copies `toolProviders` from legacy rows
- `createVersion()` now persists `input.toolProviders`
- `parseVersionRow()` parses `toolProviders` from result rows
**Storage Index Wiring** (`stores/libsql/src/storage/index.ts`)
- `ToolProviderConnectionsLibSQL` instantiated and included in
`LibSQLStore.stores` map
## Cross-Store Table Constant Updates
- **ClickHouse** (`stores/clickhouse/src/storage/db/utils.ts`): Added
`TABLE_TOOL_PROVIDER_CONNECTIONS` entry with `ReplacingMergeTree()`
engine config
- **Cloudflare** (`stores/cloudflare/src/kv/storage/types.ts`): Extended
`RecordTypes` mapping to recognize the new table constant and associate
it with `StorageToolProviderConnection`
- Other adapters (Postgres, MSSQL, MongoDB, etc.): table constant
recognized but domain implementation deferred (storage domain optional)
## Changeset & Release Notes
Added changeset documenting minor/patch version bumps for
`@mastra/core`, `@mastra/libsql`, `@mastra/clickhouse`, and
`@mastra/cloudflare`. Notes include usage example for upsert/list
operations and clarify that existing stored agents remain compatible;
runtime integration will follow in subsequent PRs.
## Test Coverage
- Core in-memory: 15 tests (upsert, retrieval, filtering, deletion,
scope behavior, clear-all)
- LibSQL: 16 tests (same coverage plus LibSQL-specific transaction and
date handling)
- Relevant test suites pass for core and libsql
## Intentionally Excluded (Planned for Follow-Up PRs)
- Runtime resolver and server routes (PR 2)
- Client SDK and Composio changes (PR 2)
- PATCH endpoint for label renames and other runtime-facing features (PR
3)
<!-- review_stack_entry_start -->
[](https://app.coderabbit.ai/change-stack/mastra-ai/mastra/pull/17247?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)
<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Mastra Code <noreply@mastra.ai>
Co-authored-by: YJ <yj@example.com>
1 parent 3fce5e7 commit aa36be2
19 files changed
Lines changed: 1188 additions & 3 deletions
File tree
- .changeset
- packages/core/src/storage
- domains
- agents
- operations
- tool-provider-connections
- stores
- clickhouse/src/storage/db
- cloudflare/src/kv/storage
- libsql/src/storage
- domains
- agents
- tool-provider-connections
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| 45 | + | |
44 | 46 | | |
45 | 47 | | |
46 | 48 | | |
| |||
57 | 59 | | |
58 | 60 | | |
59 | 61 | | |
| 62 | + | |
60 | 63 | | |
61 | 64 | | |
62 | 65 | | |
| |||
324 | 327 | | |
325 | 328 | | |
326 | 329 | | |
| 330 | + | |
327 | 331 | | |
328 | 332 | | |
329 | 333 | | |
| |||
450 | 454 | | |
451 | 455 | | |
452 | 456 | | |
| 457 | + | |
453 | 458 | | |
454 | 459 | | |
455 | 460 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
48 | 51 | | |
49 | 52 | | |
50 | 53 | | |
| |||
79 | 82 | | |
80 | 83 | | |
81 | 84 | | |
82 | | - | |
| 85 | + | |
| 86 | + | |
83 | 87 | | |
84 | 88 | | |
85 | 89 | | |
| |||
172 | 176 | | |
173 | 177 | | |
174 | 178 | | |
| 179 | + | |
175 | 180 | | |
176 | 181 | | |
177 | 182 | | |
| |||
338 | 343 | | |
339 | 344 | | |
340 | 345 | | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
341 | 365 | | |
342 | 366 | | |
343 | 367 | | |
| |||
636 | 660 | | |
637 | 661 | | |
638 | 662 | | |
| 663 | + | |
639 | 664 | | |
640 | 665 | | |
641 | 666 | | |
| |||
645 | 670 | | |
646 | 671 | | |
647 | 672 | | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
648 | 677 | | |
649 | 678 | | |
650 | 679 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
99 | 100 | | |
100 | 101 | | |
101 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
102 | 108 | | |
103 | 109 | | |
104 | 110 | | |
| |||
145 | 151 | | |
146 | 152 | | |
147 | 153 | | |
| 154 | + | |
148 | 155 | | |
149 | 156 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| |||
Lines changed: 63 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
0 commit comments