@mastra/mcp-docs-server 1.1.49-alpha.1 → 1.2.0-alpha.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.
@@ -0,0 +1,141 @@
1
+ # Tool approvals and permissions
2
+
3
+ The Harness provides a permission system that controls which tools require user approval before execution. You can configure policies at the category level or per-tool, and grant session-wide exceptions for trusted tools. This gives agents with access to destructive or sensitive tools — file writes, command execution, API calls — a human-in-the-loop checkpoint before those tools run.
4
+
5
+ ## Permission policies
6
+
7
+ Three policies control tool behavior:
8
+
9
+ - `allow`: The tool runs without prompting
10
+ - `ask`: The tool pauses and emits a `tool_approval_required` event; the user must approve or decline
11
+ - `deny`: The tool is blocked from execution
12
+
13
+ ### Setting policies
14
+
15
+ Set policies per-category or per-tool. Per-tool policies take precedence over category policies:
16
+
17
+ ```typescript
18
+ // Category-level: all execute tools require approval
19
+ harness.setPermissionForCategory({ category: 'execute', policy: 'ask' })
20
+
21
+ // Tool-level: this specific tool is always blocked
22
+ harness.setPermissionForTool({ toolName: 'dangerous_tool', policy: 'deny' })
23
+ ```
24
+
25
+ ### Tool categories
26
+
27
+ The `toolCategoryResolver` maps tool names to categories. Pass it to the Harness constructor:
28
+
29
+ ```typescript
30
+ const harness = new Harness({
31
+ id: 'my-agent',
32
+ toolCategoryResolver: toolName => {
33
+ if (toolName.includes('write') || toolName.includes('delete')) return 'edit'
34
+ if (toolName.includes('execute')) return 'execute'
35
+ return 'read'
36
+ },
37
+ })
38
+ ```
39
+
40
+ Built-in categories are `read`, `edit`, `execute`, `mcp`, and `other`.
41
+
42
+ ## Responding to approval requests
43
+
44
+ When a tool's policy is `ask`, the Harness emits a `tool_approval_required` event. Your UI should display a prompt and call `session.respondToToolApproval()`:
45
+
46
+ ```typescript
47
+ harness.subscribe(event => {
48
+ if (event.type === 'tool_approval_required') {
49
+ // Show approval UI...
50
+ harness.session.respondToToolApproval({ decision: 'approve' })
51
+ }
52
+ })
53
+ ```
54
+
55
+ The `decision` field accepts `'approve'`, `'decline'`, or `'always_allow_category'`. When `always_allow_category` is used, the tool's category is granted for the rest of the session. Future tools in the same category are auto-approved.
56
+
57
+ ```typescript
58
+ harness.session.respondToToolApproval({ decision: 'always_allow_category' })
59
+ ```
60
+
61
+ ## Session grants
62
+
63
+ The Harness owns permission _policy_ (which categories require approval); the [`Session`](https://mastra.ai/docs/harness/session) owns the _grants_ a user makes during a conversation. Grant a category or tool for the rest of the session so it runs without further prompting:
64
+
65
+ ```typescript
66
+ // Grant all edit tools for this session
67
+ harness.session.grantCategory('edit')
68
+
69
+ // Grant a specific tool
70
+ harness.session.grantTool('mastra_workspace_execute_command')
71
+
72
+ // Check current grants
73
+ const grants = harness.session.getGrants()
74
+ // { categories: ['edit'], tools: ['mastra_workspace_execute_command'] }
75
+ ```
76
+
77
+ ## Tool suspensions
78
+
79
+ Interactive built-in tools (`ask_user`, `submit_plan`) use the native tool-suspension primitive instead of the approval flow. They emit a `tool_suspended` event with `toolCallId`, `toolName`, and `suspendPayload`. Resume with `respondToToolSuspension()`:
80
+
81
+ ```typescript
82
+ harness.subscribe(event => {
83
+ if (event.type === 'tool_suspended' && event.toolName === 'ask_user') {
84
+ const { question } = event.suspendPayload as { question: string }
85
+ // Show question to user, then resume:
86
+ harness.respondToToolSuspension({
87
+ toolCallId: event.toolCallId,
88
+ resumeData: 'User response here',
89
+ })
90
+ }
91
+ })
92
+ ```
93
+
94
+ ### Plan approval
95
+
96
+ The `submit_plan` tool suspends via the same mechanism. Resume with an `action` field:
97
+
98
+ ```typescript
99
+ // Approve the plan
100
+ harness.respondToToolSuspension({
101
+ toolCallId: event.toolCallId,
102
+ resumeData: { action: 'approved' },
103
+ })
104
+
105
+ // Reject with feedback
106
+ harness.respondToToolSuspension({
107
+ toolCallId: event.toolCallId,
108
+ resumeData: { action: 'rejected', feedback: 'Needs more detail' },
109
+ })
110
+ ```
111
+
112
+ ## Built-in tools
113
+
114
+ The Harness provides these built-in tools to agents in every mode:
115
+
116
+ | Tool | Description |
117
+ | --------------- | ------------------------------------------------------------------- |
118
+ | `ask_user` | Ask the user a question (free text, single-select, or multi-select) |
119
+ | `submit_plan` | Submit a plan for user review and approval |
120
+ | `task_write` | Create or replace a structured task list |
121
+ | `task_update` | Update one tracked task by ID |
122
+ | `task_complete` | Mark one tracked task completed |
123
+ | `task_check` | Check task list completion status |
124
+ | `subagent` | Spawn a focused subagent (requires `subagents` config) |
125
+
126
+ Disable specific built-in tools with `disableBuiltinTools`:
127
+
128
+ ```typescript
129
+ const harness = new Harness({
130
+ id: 'no-plans',
131
+ disableBuiltinTools: ['submit_plan'],
132
+ })
133
+ ```
134
+
135
+ ## Related
136
+
137
+ - [Harness overview](https://mastra.ai/docs/harness/overview)
138
+ - [Session](https://mastra.ai/docs/harness/session)
139
+ - [Subagents](https://mastra.ai/docs/harness/subagents)
140
+ - [Agent approval](https://mastra.ai/docs/agents/agent-approval)
141
+ - [API reference](https://mastra.ai/reference/harness/harness-class)