@mastra/cursor 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 +34 -0
- package/README.md +93 -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 +1041 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1039 -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,34 @@
|
|
|
1
|
+
# @mastra/cursor
|
|
2
|
+
|
|
3
|
+
## 0.1.0-alpha.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added `@mastra/cursor`, a package for running Cursor SDK agents through Mastra. ([#16906](https://github.com/mastra-ai/mastra/pull/16906))
|
|
8
|
+
|
|
9
|
+
Create a Cursor SDK agent, register it with Mastra, and call `generate()` or `stream()` with Mastra-compatible outputs. Runs keep Cursor SDK usage and observability data available to Mastra.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { CursorSDKAgent } from '@mastra/cursor';
|
|
13
|
+
|
|
14
|
+
export const cursorAgent = new CursorSDKAgent({
|
|
15
|
+
id: 'cursor-sdk-agent',
|
|
16
|
+
description: 'Use Cursor Agent SDK through Mastra.',
|
|
17
|
+
sdkOptions: {
|
|
18
|
+
apiKey: process.env.CURSOR_API_KEY,
|
|
19
|
+
model: { id: process.env.CURSOR_MODEL_ID! },
|
|
20
|
+
local: {
|
|
21
|
+
cwd: process.cwd(),
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- Updated dependencies:
|
|
30
|
+
- @mastra/core@1.38.0-alpha.7
|
|
31
|
+
|
|
32
|
+
## 0.1.0-alpha.0
|
|
33
|
+
|
|
34
|
+
Initial release.
|
package/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# @mastra/cursor
|
|
2
|
+
|
|
3
|
+
`@mastra/cursor` connects Mastra to the Cursor SDK. Use it when you want to register a Cursor SDK agent with Mastra and call it through Mastra-compatible `generate()` and `stream()` methods.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @mastra/cursor @cursor/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
The package exports `CursorSDKAgent`, a Mastra `Agent` wrapper around a Cursor SDK agent.
|
|
14
|
+
|
|
15
|
+
`CursorSDKAgent` keeps the Cursor SDK run loop in charge. Mastra receives compatible outputs, usage data, and tracing data for the run.
|
|
16
|
+
|
|
17
|
+
## Create a Cursor SDK agent
|
|
18
|
+
|
|
19
|
+
Pass Cursor SDK configuration through `sdkOptions`. `CursorSDKAgent` creates the Cursor SDK agent on first use.
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { CursorSDKAgent } from '@mastra/cursor';
|
|
23
|
+
|
|
24
|
+
export const cursorAgent = new CursorSDKAgent({
|
|
25
|
+
id: 'cursor-sdk-agent',
|
|
26
|
+
name: 'Cursor SDK Agent',
|
|
27
|
+
description: 'Use Cursor Agent SDK through Mastra.',
|
|
28
|
+
sdkOptions: {
|
|
29
|
+
apiKey: process.env.CURSOR_API_KEY,
|
|
30
|
+
model: { id: process.env.CURSOR_MODEL_ID! },
|
|
31
|
+
local: {
|
|
32
|
+
cwd: process.cwd(),
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
You can also pass an existing Cursor SDK agent when your app already creates or owns it.
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { Agent as CursorAgent } from '@cursor/sdk';
|
|
42
|
+
import { CursorSDKAgent } from '@mastra/cursor';
|
|
43
|
+
|
|
44
|
+
export const cursorAgent = new CursorSDKAgent({
|
|
45
|
+
id: 'cursor-sdk-agent',
|
|
46
|
+
description: 'Use Cursor Agent SDK through Mastra.',
|
|
47
|
+
agent: CursorAgent.create({
|
|
48
|
+
apiKey: process.env.CURSOR_API_KEY,
|
|
49
|
+
model: { id: process.env.CURSOR_MODEL_ID! },
|
|
50
|
+
local: {
|
|
51
|
+
cwd: process.cwd(),
|
|
52
|
+
},
|
|
53
|
+
}),
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
You can register the wrapper anywhere Mastra accepts an `Agent`.
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { Mastra } from '@mastra/core/mastra';
|
|
61
|
+
|
|
62
|
+
export const mastra = new Mastra({
|
|
63
|
+
agents: {
|
|
64
|
+
cursorAgent,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Run the agent
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
const result = await cursorAgent.generate('Find and explain the failing test.', {
|
|
73
|
+
runId: 'cursor-run',
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
console.log(result.text);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
const stream = await cursorAgent.stream('Inspect this repository and suggest the smallest fix.');
|
|
81
|
+
|
|
82
|
+
for await (const chunk of stream.fullStream) {
|
|
83
|
+
if (chunk.type === 'text-delta') {
|
|
84
|
+
process.stdout.write(chunk.payload.text);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Configure Cursor
|
|
90
|
+
|
|
91
|
+
`CursorSDKAgent` forwards `sdkOptions` to `CursorAgent.create()` when `agent` is not provided or when `agent` is a factory. These include `apiKey`, `model`, `local`, `cloud`, `mcpServers`, `agents`, `agentId`, `idempotencyKey`, and `platform`.
|
|
92
|
+
|
|
93
|
+
`apiKey` defaults to `process.env.CURSOR_API_KEY` when it is not provided.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: mastra-cursor
|
|
3
|
+
description: Documentation for @mastra/cursor. Use when working with @mastra/cursor APIs, configuration, or implementation.
|
|
4
|
+
metadata:
|
|
5
|
+
package: "@mastra/cursor"
|
|
6
|
+
version: "0.0.0"
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## When to use
|
|
10
|
+
|
|
11
|
+
Use this skill whenever you are working with @mastra/cursor 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)
|