@mastra/claude 0.0.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 +31 -0
- package/README.md +105 -0
- package/dist/docs/SKILL.md +22 -0
- package/dist/docs/assets/SOURCE_MAP.json +6 -0
- package/dist/docs/references/docs-agents-sdk-agents.md +261 -0
- package/dist/index.cjs +1026 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1024 -0
- package/dist/index.js.map +1 -0
- package/dist/utils.d.ts +138 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +65 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# @mastra/claude
|
|
2
|
+
|
|
3
|
+
## 0.1.0-alpha.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added `@mastra/claude`, a package for running Claude Agent SDK agents through Mastra. ([#16906](https://github.com/mastra-ai/mastra/pull/16906))
|
|
8
|
+
|
|
9
|
+
Create a Claude SDK agent, register it with Mastra, and call `generate()` or `stream()` with Mastra-compatible outputs. Runs keep Claude SDK usage, cost estimates, and observability data available to Mastra.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { ClaudeSDKAgent } from '@mastra/claude';
|
|
13
|
+
|
|
14
|
+
export const claudeAgent = new ClaudeSDKAgent({
|
|
15
|
+
id: 'claude-sdk-agent',
|
|
16
|
+
description: 'Use Claude Agent SDK through Mastra.',
|
|
17
|
+
sdkOptions: {
|
|
18
|
+
model: process.env.CLAUDE_CODE_MODEL,
|
|
19
|
+
cwd: process.cwd(),
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- Updated dependencies:
|
|
27
|
+
- @mastra/core@1.38.0-alpha.7
|
|
28
|
+
|
|
29
|
+
## 0.1.0-alpha.0
|
|
30
|
+
|
|
31
|
+
Initial release.
|
package/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# @mastra/claude
|
|
2
|
+
|
|
3
|
+
`@mastra/claude` connects Mastra to the Claude Agent SDK. Use it when you want to register a Claude SDK agent with Mastra and call it through Mastra-compatible `generate()` and `stream()` methods.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @mastra/claude @anthropic-ai/claude-agent-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
The package exports `ClaudeSDKAgent`, a Mastra `Agent` wrapper around the Claude Agent SDK run loop.
|
|
14
|
+
|
|
15
|
+
`ClaudeSDKAgent` keeps the Claude SDK run loop in charge. Mastra receives compatible outputs, usage, cost estimates, and tracing data for the run.
|
|
16
|
+
|
|
17
|
+
## Create a Claude SDK agent
|
|
18
|
+
|
|
19
|
+
Pass Claude SDK configuration through `sdkOptions`.
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { ClaudeSDKAgent } from '@mastra/claude';
|
|
23
|
+
|
|
24
|
+
export const claudeAgent = new ClaudeSDKAgent({
|
|
25
|
+
id: 'claude-sdk-agent',
|
|
26
|
+
name: 'Claude SDK Agent',
|
|
27
|
+
description: 'Use Claude Agent SDK through Mastra.',
|
|
28
|
+
sdkOptions: {
|
|
29
|
+
model: process.env.CLAUDE_CODE_MODEL,
|
|
30
|
+
cwd: process.cwd(),
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
You can register the wrapper anywhere Mastra accepts an `Agent`.
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { Mastra } from '@mastra/core/mastra';
|
|
39
|
+
|
|
40
|
+
export const mastra = new Mastra({
|
|
41
|
+
agents: {
|
|
42
|
+
claudeAgent,
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Run the agent
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
const result = await claudeAgent.generate('Summarize the latest changes in this repository.', {
|
|
51
|
+
runId: 'claude-run',
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
console.log(result.text);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
const stream = await claudeAgent.stream('Review this package for test gaps.');
|
|
59
|
+
|
|
60
|
+
for await (const chunk of stream.fullStream) {
|
|
61
|
+
if (chunk.type === 'text-delta') {
|
|
62
|
+
process.stdout.write(chunk.payload.text);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Configure Claude
|
|
68
|
+
|
|
69
|
+
`ClaudeSDKAgent` forwards `sdkOptions` to the Claude SDK `query()` call on every run.
|
|
70
|
+
|
|
71
|
+
For custom tools, create a Claude SDK MCP server and pass it with `mcpServers`.
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { createSdkMcpServer, tool } from '@anthropic-ai/claude-agent-sdk';
|
|
75
|
+
import { ClaudeSDKAgent } from '@mastra/claude';
|
|
76
|
+
import { z } from 'zod';
|
|
77
|
+
|
|
78
|
+
const weatherServer = createSdkMcpServer({
|
|
79
|
+
name: 'weather',
|
|
80
|
+
version: '1.0.0',
|
|
81
|
+
tools: [
|
|
82
|
+
tool(
|
|
83
|
+
'get_temperature',
|
|
84
|
+
'Get the current temperature.',
|
|
85
|
+
{
|
|
86
|
+
location: z.string(),
|
|
87
|
+
},
|
|
88
|
+
async ({ location }) => ({
|
|
89
|
+
content: [{ type: 'text', text: `Temperature for ${location}: 72F` }],
|
|
90
|
+
}),
|
|
91
|
+
),
|
|
92
|
+
],
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
export const claudeAgent = new ClaudeSDKAgent({
|
|
96
|
+
id: 'claude-sdk-agent',
|
|
97
|
+
description: 'Use Claude with weather tools.',
|
|
98
|
+
sdkOptions: {
|
|
99
|
+
mcpServers: {
|
|
100
|
+
weather: weatherServer,
|
|
101
|
+
},
|
|
102
|
+
allowedTools: ['mcp__weather__get_temperature'],
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
```
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: mastra-claude
|
|
3
|
+
description: Documentation for @mastra/claude. Use when working with @mastra/claude APIs, configuration, or implementation.
|
|
4
|
+
metadata:
|
|
5
|
+
package: "@mastra/claude"
|
|
6
|
+
version: "0.0.0"
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## When to use
|
|
10
|
+
|
|
11
|
+
Use this skill whenever you are working with @mastra/claude to obtain the domain-specific knowledge.
|
|
12
|
+
|
|
13
|
+
## How to use
|
|
14
|
+
|
|
15
|
+
Read the individual reference documents for detailed explanations and code examples.
|
|
16
|
+
|
|
17
|
+
### Docs
|
|
18
|
+
|
|
19
|
+
- [SDK agents](references/docs-agents-sdk-agents.md) - Use Claude Agent SDK and Cursor Agent SDK agents from Mastra.
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
Read [assets/SOURCE_MAP.json](assets/SOURCE_MAP.json) for source code references.
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# SDK agents
|
|
2
|
+
|
|
3
|
+
SDK agents let you use other agent SDK frameworks inside Mastra. Use them to register SDK-backed agents in a Mastra project while the provider SDK keeps its own runtime, tools, permissions, and agent loop.
|
|
4
|
+
|
|
5
|
+
## When to use SDK agents
|
|
6
|
+
|
|
7
|
+
- A vendor SDK already owns the agent loop, tools, permissions, or local runtime.
|
|
8
|
+
- You want to register that SDK-backed agent in a Mastra project.
|
|
9
|
+
- You need Mastra-compatible `generate()` and `stream()` outputs.
|
|
10
|
+
- You want usage, cost, and tool activity from the SDK run to appear in Mastra observability.
|
|
11
|
+
|
|
12
|
+
## Supported SDK agents
|
|
13
|
+
|
|
14
|
+
- [Claude Agent SDK](#claude-agent-sdk): Use `@mastra/claude` to register a Claude SDK agent and call it with Mastra `generate()` and `stream()`.
|
|
15
|
+
- [Cursor Agent SDK](#cursor-agent-sdk): Use `@mastra/cursor` to register a Cursor SDK agent and call it with Mastra `generate()` and `stream()`.
|
|
16
|
+
|
|
17
|
+
## Claude Agent SDK
|
|
18
|
+
|
|
19
|
+
Use `@mastra/claude` for Claude Code runtime configuration, permissions, tools, and agent-loop behavior.
|
|
20
|
+
|
|
21
|
+
### Install Claude packages
|
|
22
|
+
|
|
23
|
+
Install the Mastra package and the Claude Agent SDK peer dependency:
|
|
24
|
+
|
|
25
|
+
**npm**:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install @mastra/claude @anthropic-ai/claude-agent-sdk
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**pnpm**:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pnpm add @mastra/claude @anthropic-ai/claude-agent-sdk
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**Yarn**:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
yarn add @mastra/claude @anthropic-ai/claude-agent-sdk
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Bun**:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
bun add @mastra/claude @anthropic-ai/claude-agent-sdk
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Set the Claude SDK credential:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
export ANTHROPIC_API_KEY="..."
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Create a Claude SDK agent
|
|
56
|
+
|
|
57
|
+
Configure Claude Agent SDK through `sdkOptions`.
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { ClaudeSDKAgent } from '@mastra/claude'
|
|
61
|
+
|
|
62
|
+
export const claudeSDKAgent = new ClaudeSDKAgent({
|
|
63
|
+
id: 'claude-sdk-agent',
|
|
64
|
+
name: 'Claude SDK Agent',
|
|
65
|
+
description: 'Use Claude Agent SDK through Mastra.',
|
|
66
|
+
sdkOptions: {
|
|
67
|
+
model: 'claude-sonnet-4-6',
|
|
68
|
+
cwd: process.cwd(),
|
|
69
|
+
},
|
|
70
|
+
})
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Add Claude SDK tools
|
|
74
|
+
|
|
75
|
+
Claude Agent SDK tools are provided through Claude SDK Model Context Protocol (MCP) servers. Create the server with the Claude SDK, then pass it through `sdkOptions.mcpServers`.
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
import { createSdkMcpServer } from '@anthropic-ai/claude-agent-sdk'
|
|
79
|
+
import { ClaudeSDKAgent } from '@mastra/claude'
|
|
80
|
+
import { getTemperature } from '../tools/get-temperature'
|
|
81
|
+
|
|
82
|
+
const weatherServer = createSdkMcpServer({
|
|
83
|
+
name: 'weather',
|
|
84
|
+
version: '1.0.0',
|
|
85
|
+
tools: [getTemperature],
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
export const claudeSDKAgent = new ClaudeSDKAgent({
|
|
89
|
+
id: 'claude-sdk-agent',
|
|
90
|
+
name: 'Claude SDK Agent',
|
|
91
|
+
description: 'Use Claude Agent SDK through Mastra.',
|
|
92
|
+
sdkOptions: {
|
|
93
|
+
model: 'claude-sonnet-4-6',
|
|
94
|
+
cwd: process.cwd(),
|
|
95
|
+
mcpServers: {
|
|
96
|
+
weather: weatherServer,
|
|
97
|
+
},
|
|
98
|
+
allowedTools: ['mcp__weather__get_temperature'],
|
|
99
|
+
},
|
|
100
|
+
})
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The `allowedTools` value uses Claude Agent SDK MCP tool naming: `mcp__<server name>__<tool name>`.
|
|
104
|
+
|
|
105
|
+
## Cursor Agent SDK
|
|
106
|
+
|
|
107
|
+
Use `@mastra/cursor` to register a Cursor SDK agent in Mastra while keeping Cursor-specific setup in Cursor SDK options.
|
|
108
|
+
|
|
109
|
+
### Install Cursor packages
|
|
110
|
+
|
|
111
|
+
Install the Mastra package and the Cursor SDK peer dependency:
|
|
112
|
+
|
|
113
|
+
**npm**:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
npm install @mastra/cursor @cursor/sdk
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**pnpm**:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
pnpm add @mastra/cursor @cursor/sdk
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**Yarn**:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
yarn add @mastra/cursor @cursor/sdk
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**Bun**:
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
bun add @mastra/cursor @cursor/sdk
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Set the Cursor SDK credential:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
export CURSOR_API_KEY="..."
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Create a Cursor SDK agent
|
|
144
|
+
|
|
145
|
+
Configure Cursor Agent SDK through `sdkOptions`.
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
import { CursorSDKAgent } from '@mastra/cursor'
|
|
149
|
+
|
|
150
|
+
export const cursorSDKAgent = new CursorSDKAgent({
|
|
151
|
+
id: 'cursor-sdk-agent',
|
|
152
|
+
name: 'Cursor SDK Agent',
|
|
153
|
+
description: 'Use Cursor Agent SDK through Mastra.',
|
|
154
|
+
sdkOptions: {
|
|
155
|
+
apiKey: process.env.CURSOR_API_KEY,
|
|
156
|
+
model: {
|
|
157
|
+
id: 'gpt-5.5',
|
|
158
|
+
},
|
|
159
|
+
local: {
|
|
160
|
+
cwd: process.cwd(),
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
})
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Cursor local agents require an explicit model. Set it in `sdkOptions.model`.
|
|
167
|
+
|
|
168
|
+
### Use an existing Cursor SDK agent
|
|
169
|
+
|
|
170
|
+
If your app already creates a Cursor SDK agent, pass that agent to `CursorSDKAgent` instead:
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
import { Agent as CursorAgent } from '@cursor/sdk'
|
|
174
|
+
import { CursorSDKAgent } from '@mastra/cursor'
|
|
175
|
+
|
|
176
|
+
const cursorAgent = CursorAgent.create({
|
|
177
|
+
apiKey: process.env.CURSOR_API_KEY,
|
|
178
|
+
model: {
|
|
179
|
+
id: 'gpt-5.5',
|
|
180
|
+
},
|
|
181
|
+
local: {
|
|
182
|
+
cwd: process.cwd(),
|
|
183
|
+
},
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
export const cursorSDKAgent = new CursorSDKAgent({
|
|
187
|
+
id: 'cursor-sdk-agent',
|
|
188
|
+
name: 'Cursor SDK Agent',
|
|
189
|
+
description: 'Use Cursor Agent SDK through Mastra.',
|
|
190
|
+
agent: cursorAgent,
|
|
191
|
+
})
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Add Cursor SDK tools
|
|
195
|
+
|
|
196
|
+
Cursor Agent SDK tools are configured with Cursor SDK options. Pass Model Context Protocol (MCP) servers through `sdkOptions.mcpServers`:
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
import { CursorSDKAgent } from '@mastra/cursor'
|
|
200
|
+
import { mcpServers } from '../mcp/cursor'
|
|
201
|
+
|
|
202
|
+
export const cursorSDKAgent = new CursorSDKAgent({
|
|
203
|
+
id: 'cursor-sdk-agent',
|
|
204
|
+
name: 'Cursor SDK Agent',
|
|
205
|
+
description: 'Use Cursor Agent SDK through Mastra.',
|
|
206
|
+
sdkOptions: {
|
|
207
|
+
apiKey: process.env.CURSOR_API_KEY,
|
|
208
|
+
model: {
|
|
209
|
+
id: 'gpt-5.5',
|
|
210
|
+
},
|
|
211
|
+
local: {
|
|
212
|
+
cwd: process.cwd(),
|
|
213
|
+
},
|
|
214
|
+
mcpServers,
|
|
215
|
+
},
|
|
216
|
+
})
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Register SDK agents
|
|
220
|
+
|
|
221
|
+
Register SDK agents in the Mastra instance like other agents:
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
import { Mastra } from '@mastra/core'
|
|
225
|
+
import { claudeSDKAgent } from './agents/claude-sdk-agent'
|
|
226
|
+
import { cursorSDKAgent } from './agents/cursor-sdk-agent'
|
|
227
|
+
|
|
228
|
+
export const mastra = new Mastra({
|
|
229
|
+
agents: {
|
|
230
|
+
claudeSDKAgent,
|
|
231
|
+
cursorSDKAgent,
|
|
232
|
+
},
|
|
233
|
+
})
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
After registration, call them with `mastra.getAgentById()`:
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
import { mastra } from './index'
|
|
240
|
+
|
|
241
|
+
const agent = mastra.getAgentById('cursor-sdk-agent')
|
|
242
|
+
const stream = await agent.stream('Inspect this project and describe the test setup.')
|
|
243
|
+
|
|
244
|
+
for await (const chunk of stream.textStream) {
|
|
245
|
+
process.stdout.write(chunk)
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## Observability
|
|
250
|
+
|
|
251
|
+
SDK agents create Mastra agent and model spans for `generate()` and `stream()` calls. Mastra records SDK-provided usage, tool activity, and provider metadata when the vendor SDK exposes those events.
|
|
252
|
+
|
|
253
|
+
Claude SDK runs can include SDK-estimated cost from the Claude result message. Cursor SDK runs include token usage from Cursor interaction updates.
|
|
254
|
+
|
|
255
|
+
For storage and dashboard setup, see [Observability](https://mastra.ai/docs/observability/overview).
|
|
256
|
+
|
|
257
|
+
## Related
|
|
258
|
+
|
|
259
|
+
- [Agents overview](https://mastra.ai/docs/agents/overview)
|
|
260
|
+
- [Tools](https://mastra.ai/docs/agents/using-tools)
|
|
261
|
+
- [Observability](https://mastra.ai/docs/observability/overview)
|