Commit e17e5c1
feat(server,client-js): add stored agent dependents lookup endpoint (#17183)
## Summary
This is PR 1 of 2 split from #17180.
Adds a new server endpoint and client SDK method to look up agents that
reference a given stored agent as a sub-agent. Used to warn before
deleting or unsharing an agent that other agents depend on.
## Scope
- New `GET /stored/agents/:storedAgentId/dependents` endpoint
- Response splits dependents into two buckets:
- `dependents` — caller-readable dependents (public agents and the
caller's own private agents) with `id` + `name`
- `hiddenCount` — cross-workspace dependents the caller cannot read,
aggregated as a count and only surfaced when the target is public
(avoids leaking cross-workspace structure)
- Access mirrors `GET /stored/agents/:storedAgentId` (404 when caller
cannot read target)
- `client.getStoredAgent(id).dependents()` on the client-js SDK
```ts
const { dependents, hiddenCount } = await client.getStoredAgent(id).dependents();
// { dependents: [{ id: 'parent-1', name: 'Triager' }], hiddenCount: 2 }
```
## Intentionally excluded
- The Studio UI warnings that consume this endpoint ship in the
follow-up PR.
## Verification
- Server tests pass (includes 10 dependents tests: static/conditional
references, empty result, self-exclusion, prototype-key handling, 404
for missing/unreadable target, RBAC + `hiddenCount` semantics)
- Server + client-js typecheck clean
- `route-types.generated.ts` and CLI route metadata regenerated,
permissions check passes
- Editor overview docs updated with the new endpoint + SDK method
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## ELI5
This PR adds a way to check which other agents use a particular stored
agent before you delete or unshare it — like seeing which LEGO builds
use a brick before removing it. It provides a server endpoint and a
client-js SDK method so callers can list readable dependents and learn
how many unreadable (hidden) dependents exist.
## Overview
Adds server and client-js support to list stored-agent dependents (used
for delete/unshare warnings). Access control mirrors GET
/stored/agents/:storedAgentId: callers get 404 if they cannot read the
target. For public targets the response includes readable dependents and
an aggregate hiddenCount for unreadable cross-workspace dependents; for
non-public targets hidden dependents are not leaked.
**New public API**
- Server endpoint: GET /stored/agents/:storedAgentId/dependents
- Client SDK method: client.getStoredAgent(id).dependents()
## Changes
### Server
- New route handler: GET_STORED_AGENT_DEPENDENTS_ROUTE
(packages/server/src/server/handlers/stored-agents.ts)
- Scans published stored agents and detects references to the target via
a new referencesTarget(subAgents, targetId) helper that supports both
static object and array-of-conditional-variants snapshots.
- Partitions results into caller-readable dependents (array of { id,
name } — name defaults to id) and an aggregate hiddenCount for
unreadable cross-workspace dependents.
- Only populates hiddenCount when the target agent is public to avoid
leaking cross-workspace structure.
- Enforces read access (404 when caller cannot read target).
- Wires response schema getStoredAgentDependentsResponseSchema.
- Response schema: getStoredAgentDependentsResponseSchema added to
packages/server/src/server/schemas/stored-agents.ts (dependents:
{id,name}[], hiddenCount: nonnegative integer).
- Route registration: Added to STORED_AGENTS_ROUTES before
GET_STORED_AGENT_ROUTE to preserve literal-path matching precedence.
- Tests: Comprehensive tests added in
packages/server/src/server/handlers/stored-agents.test.ts covering
static/conditional references, empty results, self-exclusion, ignoring
prototype keys, 404 for missing/unreadable target, RBAC, and hiddenCount
semantics. Mocks updated (MockStoredAgent.agents widened; listResolved
perPage supports number | false).
### Client-js SDK & Types
- client-sdks/client-js/src/resources/stored-agent.ts:
StoredAgent.dependents(requestContext?) ->
Promise<StoredAgentDependentsResponse>.
- client-sdks/client-js/src/types.ts: Added StoredAgentDependent { id,
name } and StoredAgentDependentsResponse { dependents, hiddenCount }.
- client-sdks/client-js/src/route-types.generated.ts: Generated
route/type definitions for the new endpoint.
### Tooling, Metadata & Docs
- CLI route metadata regenerated:
packages/cli/src/commands/api/route-metadata.generated.ts updated with
the new route entry.
- docs/src/content/en/docs/editor/overview.mdx: Documentation updated to
mention the new endpoint and SDK helper and explain dependents and
hiddenCount.
- Changeset: .changeset/agent-delete-dependents-warning.md marks
`@mastra/server` and `@mastra/client-js` as minor releases.
## Verification
- Server tests pass (10 dependents tests covering the behaviors above).
- Server and client-js typecheck clean.
- route-types.generated.ts and CLI route metadata regenerated;
permissions check passes.
- Studio UI warning integration excluded from this PR (will be shipped
in a follow-up).
## Commit
- Single commit: "chore: harden prototype-key test, document dependents
endpoint"
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: YJ <yj@example.com>
Co-authored-by: Mastra Code (anthropic/claude-opus-4-7) <noreply@mastra.ai>
Co-authored-by: Abhi Aiyer <abhiaiyer91@gmail.com>1 parent c973db4 commit e17e5c1
10 files changed
Lines changed: 454 additions & 7 deletions
File tree
- .changeset
- client-sdks/client-js/src
- resources
- docs/src/content/en/docs/editor
- packages
- cli/src/commands/api
- server/src/server
- handlers
- schemas
- server-adapter/routes
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
90 | 91 | | |
91 | 92 | | |
92 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
93 | 106 | | |
94 | 107 | | |
95 | 108 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25649 | 25649 | | |
25650 | 25650 | | |
25651 | 25651 | | |
| 25652 | + | |
| 25653 | + | |
| 25654 | + | |
| 25655 | + | |
| 25656 | + | |
| 25657 | + | |
| 25658 | + | |
| 25659 | + | |
| 25660 | + | |
| 25661 | + | |
| 25662 | + | |
| 25663 | + | |
| 25664 | + | |
| 25665 | + | |
| 25666 | + | |
| 25667 | + | |
| 25668 | + | |
| 25669 | + | |
| 25670 | + | |
| 25671 | + | |
| 25672 | + | |
| 25673 | + | |
| 25674 | + | |
| 25675 | + | |
| 25676 | + | |
| 25677 | + | |
| 25678 | + | |
| 25679 | + | |
| 25680 | + | |
| 25681 | + | |
| 25682 | + | |
| 25683 | + | |
| 25684 | + | |
25652 | 25685 | | |
25653 | 25686 | | |
25654 | 25687 | | |
| |||
84990 | 85023 | | |
84991 | 85024 | | |
84992 | 85025 | | |
| 85026 | + | |
84993 | 85027 | | |
84994 | 85028 | | |
84995 | 85029 | | |
| |||
85745 | 85779 | | |
85746 | 85780 | | |
85747 | 85781 | | |
| 85782 | + | |
| 85783 | + | |
| 85784 | + | |
85748 | 85785 | | |
85749 | 85786 | | |
85750 | 85787 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1441 | 1441 | | |
1442 | 1442 | | |
1443 | 1443 | | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
1444 | 1464 | | |
1445 | 1465 | | |
1446 | 1466 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| 156 | + | |
156 | 157 | | |
157 | 158 | | |
158 | | - | |
| 159 | + | |
159 | 160 | | |
160 | 161 | | |
161 | 162 | | |
| |||
Lines changed: 15 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3228 | 3228 | | |
3229 | 3229 | | |
3230 | 3230 | | |
| 3231 | + | |
| 3232 | + | |
| 3233 | + | |
| 3234 | + | |
| 3235 | + | |
| 3236 | + | |
| 3237 | + | |
| 3238 | + | |
| 3239 | + | |
| 3240 | + | |
| 3241 | + | |
| 3242 | + | |
| 3243 | + | |
| 3244 | + | |
| 3245 | + | |
3231 | 3246 | | |
3232 | 3247 | | |
3233 | 3248 | | |
| |||
0 commit comments