@withone/mcp 2.4.0 → 2.5.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/README.md CHANGED
@@ -134,6 +134,7 @@ Fine-tune what the MCP server can see and do:
134
134
 
135
135
  ```bash
136
136
  ONE_PERMISSIONS=read
137
+ ONE_APPROVAL=write
137
138
  ONE_CONNECTION_KEYS=conn_key_1,conn_key_2
138
139
  ONE_ACTION_IDS=action_id_1,action_id_2
139
140
  ONE_KNOWLEDGE_AGENT=true
@@ -142,6 +143,7 @@ ONE_KNOWLEDGE_AGENT=true
142
143
  | Variable | Type | Default | Description |
143
144
  |---|---|---|---|
144
145
  | `ONE_PERMISSIONS` | `read` \| `write` \| `admin` | `admin` | Filter actions by One's `access` classification of what each one does, whatever its HTTP method. `read` = `read` actions only, `write` = `read` and `write` actions, `admin` = all actions including `delete`. Below `admin`, an action with no classification is refused |
146
+ | `ONE_APPROVAL` | `off` \| `delete` \| `write` | `off` | Ask the user before an action runs. `delete` asks for `delete` actions, `write` asks for `write` and `delete` actions, and `read` actions never ask. An action with no classification is asked about at both levels. See [Approval](#approval) |
145
147
  | `ONE_CONNECTION_KEYS` | `*` or comma-separated keys | `*` | Restrict visible connections and platforms to specific connection keys |
146
148
  | `ONE_ACTION_IDS` | `*` or comma-separated IDs | `*` | Restrict visible and executable actions to specific action IDs |
147
149
  | `ONE_KNOWLEDGE_AGENT` | `true` \| `false` | `false` | Remove the `execute_one_action` tool entirely, forcing knowledge-only mode. `find_one_actions` then returns each chosen action's whole document with how to call it from code, and an Integration Code Guide (passthrough URL, `x-one-*` headers, `ONE_SECRET` / `ONE_{PLATFORM}_CONNECTION_KEY` env vars, backend-only placement) for writing application code |
@@ -156,6 +158,14 @@ Whatever you configure here is surfaced back to the agent: `list_one_integration
156
158
  | `{ "policy": "levels", "levels": ["read", ...] }` | No action allowlist, but `ONE_PERMISSIONS` is `read`/`write` — only actions classified at these access levels are runnable. |
157
159
  | `{ "policy": "actions", "actions": [{ "actionId", "title", "method" }] }` | `ONE_ACTION_IDS` is set — exactly these actions (the ones on that connection's platform) are runnable, so no search is needed. |
158
160
 
161
+ ### Approval
162
+
163
+ An agent that has just read an email, a web page or another third-party document can be steered by what it read. With `ONE_APPROVAL` set, the person at the MCP client decides whether a change goes ahead, not the agent.
164
+
165
+ Before `execute_one_action` runs an action that needs approval, the server shows a prompt through [MCP elicitation](https://modelcontextprotocol.io/specification/latest/client/elicitation). It names the action, the platform, the connection and what will be sent, and the user ticks a box to run it. Declining, dismissing, leaving the box unticked or not answering within 10 minutes stops the action, and nothing is sent.
166
+
167
+ Your MCP client has to support elicitation. If it doesn't, every action that needs approval is refused, so check your client before turning this on.
168
+
159
169
  ## Manual Configuration
160
170
 
161
171
  If you used `one init`, the configuration below is already done for you. These examples are for reference or manual setups.
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Approval for actions that change data (`ONE_APPROVAL`).
3
+ *
4
+ * With approval on, `execute_one_action` asks the user before it runs a write
5
+ * or delete, through MCP elicitation: the protocol's way for a server to ask
6
+ * the person at the client a question. An agent that has just read
7
+ * third-party content (an email, a web page) can be steered by it, so the
8
+ * person, not the agent, decides whether a change goes ahead. A client that
9
+ * cannot ask is refused rather than run unapproved.
10
+ *
11
+ * @fileoverview When an action needs approval, and how it is asked for
12
+ * @author One
13
+ */
14
+ import { ToolError } from './tool-error.js';
15
+ export const APPROVAL_LEVELS = ['off', 'delete', 'write'];
16
+ /** How long the user has to answer before the action is refused. */
17
+ export const APPROVAL_TIMEOUT_MS = 10 * 60 * 1000;
18
+ /** How much of the request the prompt shows. */
19
+ export const APPROVAL_REQUEST_CHARS = 2_000;
20
+ /**
21
+ * Whether an action at `access` needs approval at `level`. An action with no
22
+ * level, or one this server does not know, is treated as a delete, since
23
+ * nothing says it is safer.
24
+ */
25
+ export function needsApproval(access, level) {
26
+ if (level === 'off')
27
+ return false;
28
+ if (level === 'delete')
29
+ return access !== 'read' && access !== 'write';
30
+ return access !== 'read';
31
+ }
32
+ /**
33
+ * Whether the client can show a form prompt. Per the spec, an `elicitation`
34
+ * capability naming neither mode means form, as clients declared it before
35
+ * modes existed.
36
+ */
37
+ export function supportsFormElicitation(capabilities) {
38
+ const elicitation = capabilities?.elicitation;
39
+ if (!elicitation)
40
+ return false;
41
+ return elicitation.form !== undefined || elicitation.url === undefined;
42
+ }
43
+ /** The form the user answers: one box to tick. */
44
+ export const APPROVAL_SCHEMA = {
45
+ type: 'object',
46
+ properties: {
47
+ approve: {
48
+ type: 'boolean',
49
+ title: 'Run this action',
50
+ description: 'Tick to run it now. Leave it unticked, decline or dismiss to stop it.',
51
+ default: false,
52
+ },
53
+ },
54
+ required: ['approve'],
55
+ };
56
+ /** What the user reads: what will run, where, and with what. */
57
+ export function approvalMessage(request) {
58
+ const kind = request.access === 'read' || request.access === 'write' || request.access === 'delete' ? request.access : 'unclassified';
59
+ const sent = {};
60
+ if (request.pathVariables !== undefined)
61
+ sent.pathVariables = request.pathVariables;
62
+ if (request.queryParams !== undefined)
63
+ sent.queryParams = request.queryParams;
64
+ if (request.data !== undefined)
65
+ sent.data = request.data;
66
+ let body = Object.keys(sent).length > 0 ? JSON.stringify(sent, null, 2) : '(no parameters)';
67
+ if (body.length > APPROVAL_REQUEST_CHARS) {
68
+ body = `${body.slice(0, APPROVAL_REQUEST_CHARS)}\n… (${body.length - APPROVAL_REQUEST_CHARS} more characters not shown)`;
69
+ }
70
+ return [
71
+ `Your AI agent wants to run ${kind === 'unclassified' ? 'an' : 'a'} ${kind} action on ${request.platform}.`,
72
+ '',
73
+ `${request.title}`,
74
+ `${request.method.toUpperCase()} ${request.path}`,
75
+ `Connection: ${request.connectionKey}`,
76
+ '',
77
+ 'Request:',
78
+ body,
79
+ ].join('\n');
80
+ }
81
+ /**
82
+ * Asks the user to approve `request` when `level` calls for it, and returns
83
+ * only once they have. Anything short of an explicit approval refuses.
84
+ * @throws {ToolError} When the user did not approve, or could not be asked
85
+ */
86
+ export async function requireApproval(request, level, deps) {
87
+ if (!needsApproval(request.access, level))
88
+ return;
89
+ if (!supportsFormElicitation(deps.capabilities)) {
90
+ throw new ToolError(`Action "${request.actionId}" was not run: this server asks the user to approve actions like it, and this MCP client cannot show an approval prompt. Tell the user the action needs their approval and their client does not support approval prompts.`);
91
+ }
92
+ let answer;
93
+ try {
94
+ answer = await deps.elicit({ message: approvalMessage(request), requestedSchema: APPROVAL_SCHEMA });
95
+ }
96
+ catch (error) {
97
+ throw new ToolError(`Action "${request.actionId}" was not run: the approval prompt failed or was not answered in time (${error instanceof Error ? error.message : 'unknown error'}). Ask the user whether to try again.`);
98
+ }
99
+ if (answer.action === 'accept' && answer.content?.approve === true)
100
+ return;
101
+ if (answer.action === 'decline' || answer.action === 'accept') {
102
+ throw new ToolError(`Action "${request.actionId}" was not run: the user did not approve it. Do not run it again unless the user asks you to.`);
103
+ }
104
+ throw new ToolError(`Action "${request.actionId}" was not run: the user dismissed the approval prompt. Do not run it again unless the user asks you to.`);
105
+ }
@@ -0,0 +1,125 @@
1
+ import { describe, it } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { APPROVAL_REQUEST_CHARS, APPROVAL_SCHEMA, approvalMessage, needsApproval, requireApproval, supportsFormElicitation, } from './approval.js';
4
+ import { ToolError } from './tool-error.js';
5
+ const request = (overrides = {}) => ({
6
+ actionId: 'act_1',
7
+ title: 'Send Email',
8
+ method: 'post',
9
+ path: '/v1/gmail/send-email',
10
+ platform: 'gmail',
11
+ connectionKey: 'live::gmail::default::k',
12
+ access: 'write',
13
+ data: { to: 'a@example.com', subject: 'Hi' },
14
+ ...overrides,
15
+ });
16
+ /** A session that answers `answer`, recording every prompt it was asked to show. */
17
+ function session(answer, ...declared) {
18
+ const capabilities = declared.length > 0 ? declared[0] : { elicitation: {} };
19
+ const asked = [];
20
+ const deps = {
21
+ capabilities,
22
+ async elicit(params) {
23
+ asked.push(params);
24
+ if (answer instanceof Error)
25
+ throw answer;
26
+ return answer;
27
+ },
28
+ };
29
+ return { deps, asked };
30
+ }
31
+ describe('needsApproval', () => {
32
+ const cases = [
33
+ ['read', 'off', false],
34
+ ['write', 'off', false],
35
+ ['delete', 'off', false],
36
+ [undefined, 'off', false],
37
+ ['read', 'delete', false],
38
+ ['write', 'delete', false],
39
+ ['delete', 'delete', true],
40
+ [undefined, 'delete', true],
41
+ ['execute', 'delete', true],
42
+ ['read', 'write', false],
43
+ ['write', 'write', true],
44
+ ['delete', 'write', true],
45
+ [undefined, 'write', true],
46
+ ];
47
+ for (const [access, level, expected] of cases) {
48
+ it(`${String(access)} at ${level} ${expected ? 'asks' : 'does not ask'}`, () => {
49
+ assert.equal(needsApproval(access, level), expected);
50
+ });
51
+ }
52
+ });
53
+ describe('supportsFormElicitation', () => {
54
+ it('reads an empty elicitation capability as form, and needs form when modes are named', () => {
55
+ assert.equal(supportsFormElicitation(undefined), false);
56
+ assert.equal(supportsFormElicitation({}), false);
57
+ assert.equal(supportsFormElicitation({ elicitation: {} }), true);
58
+ assert.equal(supportsFormElicitation({ elicitation: { form: {} } }), true);
59
+ assert.equal(supportsFormElicitation({ elicitation: { form: {}, url: {} } }), true);
60
+ assert.equal(supportsFormElicitation({ elicitation: { url: {} } }), false);
61
+ });
62
+ });
63
+ describe('requireApproval', () => {
64
+ it('runs a read without asking, even with approval on', async () => {
65
+ const s = session(new Error('should not ask'));
66
+ await requireApproval(request({ access: 'read' }), 'write', s.deps);
67
+ assert.equal(s.asked.length, 0);
68
+ });
69
+ it('runs anything without asking when approval is off', async () => {
70
+ const s = session(new Error('should not ask'), undefined);
71
+ await requireApproval(request({ access: 'delete' }), 'off', s.deps);
72
+ assert.equal(s.asked.length, 0);
73
+ });
74
+ it('runs once the user ticks the box', async () => {
75
+ const s = session({ action: 'accept', content: { approve: true } });
76
+ await requireApproval(request(), 'write', s.deps);
77
+ assert.equal(s.asked.length, 1);
78
+ assert.deepEqual(s.asked[0].requestedSchema, APPROVAL_SCHEMA);
79
+ });
80
+ for (const [label, answer] of [
81
+ ['declined', { action: 'decline' }],
82
+ ['accepted without ticking the box', { action: 'accept', content: { approve: false } }],
83
+ ['accepted with no content', { action: 'accept' }],
84
+ ['accepted with a truthy non-boolean', { action: 'accept', content: { approve: 'yes' } }],
85
+ ['dismissed', { action: 'cancel' }],
86
+ ]) {
87
+ it(`refuses when the prompt is ${label}`, async () => {
88
+ const s = session(answer);
89
+ await assert.rejects(requireApproval(request(), 'write', s.deps), (e) => e instanceof ToolError && /was not run/.test(e.message));
90
+ });
91
+ }
92
+ it('refuses when the prompt fails or times out', async () => {
93
+ const s = session(new Error('Request timed out'));
94
+ await assert.rejects(requireApproval(request({ access: 'delete' }), 'delete', s.deps), (e) => e instanceof ToolError && /Request timed out/.test(e.message));
95
+ });
96
+ it('refuses without asking when the client cannot show a prompt', async () => {
97
+ for (const capabilities of [undefined, {}, { elicitation: { url: {} } }]) {
98
+ const s = session({ action: 'accept', content: { approve: true } }, capabilities);
99
+ await assert.rejects(requireApproval(request(), 'write', s.deps), (e) => e instanceof ToolError && /cannot show an approval prompt/.test(e.message));
100
+ assert.equal(s.asked.length, 0);
101
+ }
102
+ });
103
+ it('asks for an unclassified action at the delete level', async () => {
104
+ const s = session({ action: 'accept', content: { approve: true } });
105
+ await requireApproval(request({ access: undefined }), 'delete', s.deps);
106
+ assert.ok(s.asked[0].message.includes('wants to run an unclassified action'));
107
+ });
108
+ });
109
+ describe('approvalMessage', () => {
110
+ it('names the action, where it runs and what it sends', () => {
111
+ const text = approvalMessage(request({ pathVariables: { id: '42' }, queryParams: { dry: false } }));
112
+ for (const part of ['write action on gmail', 'Send Email', 'POST /v1/gmail/send-email', 'live::gmail::default::k', '"to": "a@example.com"', '"id": "42"', '"dry": false']) {
113
+ assert.ok(text.includes(part), part);
114
+ }
115
+ });
116
+ it('shortens a large request and says so', () => {
117
+ const text = approvalMessage(request({ data: { body: 'x'.repeat(10_000) } }));
118
+ assert.ok(text.length < APPROVAL_REQUEST_CHARS + 500);
119
+ assert.match(text, /more characters not shown/);
120
+ });
121
+ it('says when there is nothing to send', () => {
122
+ const text = approvalMessage(request({ data: undefined }));
123
+ assert.ok(text.includes('(no parameters)'));
124
+ });
125
+ });
package/build/index.js CHANGED
@@ -9,7 +9,8 @@
9
9
  */
10
10
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
11
11
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
12
- import { ErrorCode, McpError, } from '@modelcontextprotocol/sdk/types.js';
12
+ import { ElicitResultSchema, ErrorCode, McpError, } from '@modelcontextprotocol/sdk/types.js';
13
+ import { APPROVAL_LEVELS, APPROVAL_TIMEOUT_MS, requireApproval } from './approval.js';
13
14
  import { OneClient } from './client.js';
14
15
  import { accessRefusal, isAccessAllowed, isActionAllowed, buildIntegrationsResponse, } from './helpers.js';
15
16
  import { findOneActions } from './find.js';
@@ -32,6 +33,11 @@ if (!["read", "write", "admin"].includes(ONE_PERMISSIONS)) {
32
33
  console.error(`Invalid ONE_PERMISSIONS value: "${ONE_PERMISSIONS}". Must be one of: read, write, admin`);
33
34
  process.exit(1);
34
35
  }
36
+ const ONE_APPROVAL = (process.env.ONE_APPROVAL || "off");
37
+ if (!APPROVAL_LEVELS.includes(ONE_APPROVAL)) {
38
+ console.error(`Invalid ONE_APPROVAL value: "${ONE_APPROVAL}". Must be one of: ${APPROVAL_LEVELS.join(", ")}`);
39
+ process.exit(1);
40
+ }
35
41
  const ONE_CONNECTION_KEYS = process.env.ONE_CONNECTION_KEYS
36
42
  ? process.env.ONE_CONNECTION_KEYS.split(",").map(s => s.trim()).filter(Boolean)
37
43
  : ["*"];
@@ -93,11 +99,11 @@ server.registerTool("find_one_actions", findOneActionsToolConfig, async (args) =
93
99
  return await handleFindOneActions(args);
94
100
  });
95
101
  if (!ONE_KNOWLEDGE_AGENT) {
96
- server.registerTool("execute_one_action", executeOneActionToolConfig, async (args) => {
102
+ server.registerTool("execute_one_action", executeOneActionToolConfig, async (args, extra) => {
97
103
  if (NODE_REFUSAL)
98
104
  return toolErrorResult(new ToolError(NODE_REFUSAL));
99
105
  await initializeOne();
100
- return await handleExecuteOneAction(args);
106
+ return await handleExecuteOneAction(args, extra);
101
107
  });
102
108
  }
103
109
  async function handleGetIntegrations(args) {
@@ -158,7 +164,7 @@ async function handleFindOneActions(args) {
158
164
  throw new McpError(ErrorCode.InternalError, `Failed to find actions: ${error instanceof Error ? error.message : 'Unknown error'}`);
159
165
  }
160
166
  }
161
- async function handleExecuteOneAction(args) {
167
+ async function handleExecuteOneAction(args, extra) {
162
168
  try {
163
169
  if (!isActionAllowed(args.actionId, ONE_ACTION_IDS)) {
164
170
  throw new ToolError(`Action "${args.actionId}" is not one this server may run. Use an action listed in list_one_integrations or returned by find_one_actions.`);
@@ -168,6 +174,28 @@ async function handleExecuteOneAction(args) {
168
174
  if (!isAccessAllowed(actionDetails.access, ONE_PERMISSIONS)) {
169
175
  throw new ToolError(accessRefusal(args.actionId, actionDetails.access, ONE_PERMISSIONS));
170
176
  }
177
+ await requireApproval({
178
+ actionId: args.actionId,
179
+ title: actionDetails.title,
180
+ method: actionDetails.method,
181
+ path: actionDetails.path,
182
+ platform: actionDetails.connectionPlatform ?? args.platform,
183
+ connectionKey: args.connectionKey,
184
+ access: actionDetails.access,
185
+ pathVariables: args.pathVariables,
186
+ queryParams: args.queryParams,
187
+ data: args.data,
188
+ }, ONE_APPROVAL, {
189
+ capabilities: server.server.getClientCapabilities(),
190
+ // Sent as a plain form request, not through elicitInput, which
191
+ // refuses clients that declare elicitation without naming a mode.
192
+ // Tied to the tool call so it travels on the same stream.
193
+ elicit: (params) => server.server.request({ method: "elicitation/create", params }, ElicitResultSchema, {
194
+ timeout: APPROVAL_TIMEOUT_MS,
195
+ relatedRequestId: extra.requestId,
196
+ signal: extra.signal,
197
+ }),
198
+ });
171
199
  const result = await oneClient.executePassthroughRequest(args, actionDetails);
172
200
  return {
173
201
  content: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@withone/mcp",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "A Model Context Protocol Server for One",
5
5
  "type": "module",
6
6
  "bin": {
@@ -17,7 +17,7 @@
17
17
  "inspector": "npx @modelcontextprotocol/inspector build/index.js"
18
18
  },
19
19
  "dependencies": {
20
- "@modelcontextprotocol/sdk": "^1.12.1",
20
+ "@modelcontextprotocol/sdk": "^1.32.2",
21
21
  "axios": "^1.20.0",
22
22
  "form-data": "^4.0.3",
23
23
  "zod": "^3.23.0"