@withone/mcp 2.3.2 → 2.4.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 +4 -4
- package/build/client.js +56 -46
- package/build/client.test.js +175 -1
- package/build/find.js +3 -3
- package/build/find.test.js +27 -1
- package/build/helpers.js +75 -14
- package/build/index.js +7 -12
- package/build/integrations-response.test.js +37 -3
- package/build/path-variables.test.js +18 -0
- package/build/schemas.js +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -60,7 +60,7 @@ The server exposes three MCP tools:
|
|
|
60
60
|
|
|
61
61
|
| Tool | Description |
|
|
62
62
|
|------|-------------|
|
|
63
|
-
| `list_one_integrations` | List available platforms and active connections, each with the `access` it confers (full,
|
|
63
|
+
| `list_one_integrations` | List available platforms and active connections, each with the `access` it confers (full, access levels, or specific actions) |
|
|
64
64
|
| `find_one_actions` | Find the action for every operation a task needs, across platforms, with its documentation, in one call; `load` fetches more of a document or an alternative's |
|
|
65
65
|
| `execute_one_action` | Execute an API action on a connected platform |
|
|
66
66
|
|
|
@@ -126,7 +126,7 @@ ONE_IDENTITY_TYPE=user
|
|
|
126
126
|
| `ONE_IDENTITY` | The identifier for the entity (e.g., user ID, team ID) | Any string |
|
|
127
127
|
| `ONE_IDENTITY_TYPE` | The type of identity | `user`, `team`, `organization`, `project` |
|
|
128
128
|
|
|
129
|
-
When set, the MCP server will only return connections associated with the specified identity. This is useful for multi-tenant applications where you want to scope integrations to specific users or entities.
|
|
129
|
+
When set, the MCP server will only return connections associated with the specified identity, and `execute_one_action` will only run on those connections. This is useful for multi-tenant applications where you want to scope integrations to specific users or entities.
|
|
130
130
|
|
|
131
131
|
### Access Control
|
|
132
132
|
|
|
@@ -141,7 +141,7 @@ ONE_KNOWLEDGE_AGENT=true
|
|
|
141
141
|
|
|
142
142
|
| Variable | Type | Default | Description |
|
|
143
143
|
|---|---|---|---|
|
|
144
|
-
| `ONE_PERMISSIONS` | `read` \| `write` \| `admin` | `admin` | Filter actions by HTTP method. `read` =
|
|
144
|
+
| `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 |
|
|
145
145
|
| `ONE_CONNECTION_KEYS` | `*` or comma-separated keys | `*` | Restrict visible connections and platforms to specific connection keys |
|
|
146
146
|
| `ONE_ACTION_IDS` | `*` or comma-separated IDs | `*` | Restrict visible and executable actions to specific action IDs |
|
|
147
147
|
| `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 |
|
|
@@ -153,7 +153,7 @@ Whatever you configure here is surfaced back to the agent: `list_one_integration
|
|
|
153
153
|
| `access` | When |
|
|
154
154
|
|---|---|
|
|
155
155
|
| `{ "policy": "full" }` | No action allowlist and `ONE_PERMISSIONS=admin` — every action is runnable. |
|
|
156
|
-
| `{ "policy": "
|
|
156
|
+
| `{ "policy": "levels", "levels": ["read", ...] }` | No action allowlist, but `ONE_PERMISSIONS` is `read`/`write` — only actions classified at these access levels are runnable. |
|
|
157
157
|
| `{ "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
158
|
|
|
159
159
|
## Manual Configuration
|
package/build/client.js
CHANGED
|
@@ -9,10 +9,18 @@
|
|
|
9
9
|
import axios from 'axios';
|
|
10
10
|
import FormData from 'form-data';
|
|
11
11
|
import { callerHeaders } from './caller.js';
|
|
12
|
-
import { fetchPaginatedData, replacePathVariables } from './helpers.js';
|
|
12
|
+
import { describeError, fetchPaginatedData, replacePathVariables, summarizeErrorData } from './helpers.js';
|
|
13
13
|
import { ToolError, oneApiError, oneRefusal } from './tool-error.js';
|
|
14
14
|
/** Header names that only the server may set on an outgoing request. */
|
|
15
15
|
const RESERVED_HEADER_PREFIX = 'x-one-';
|
|
16
|
+
/**
|
|
17
|
+
* Headers that control the connection to One rather than describe the request.
|
|
18
|
+
* Node also takes the TLS server name from `Host`, so a caller must not set it
|
|
19
|
+
* on a request carrying the secret.
|
|
20
|
+
*/
|
|
21
|
+
const TRANSPORT_HEADERS = new Set(['host', 'connection', 'content-length', 'transfer-encoding', 'keep-alive', 'proxy-connection', 'te', 'trailer', 'upgrade']);
|
|
22
|
+
/** Headers an upstream may obey as the method in place of the request line. */
|
|
23
|
+
const METHOD_OVERRIDE_HEADERS = new Set(['x-http-method-override', 'x-http-method', 'x-method-override']);
|
|
16
24
|
/** The prefix One renames every upstream response header to, so its presence marks a response the platform gave. */
|
|
17
25
|
const PLATFORM_HEADER_PREFIX = 'x-passthrough-';
|
|
18
26
|
/**
|
|
@@ -24,58 +32,20 @@ export function answeredByPlatform(headers) {
|
|
|
24
32
|
}
|
|
25
33
|
/**
|
|
26
34
|
* Drops any caller-supplied header that One itself controls (`x-one-secret`,
|
|
27
|
-
* `x-one-connection-key`, `x-one-action-id`, ...)
|
|
28
|
-
*
|
|
35
|
+
* `x-one-connection-key`, `x-one-action-id`, ...) or that controls the
|
|
36
|
+
* connection (`Host`, `Content-Length`, ...). Comparison is case-insensitive
|
|
37
|
+
* because HTTP header names are.
|
|
29
38
|
*/
|
|
30
39
|
export function stripReservedHeaders(headers) {
|
|
31
40
|
if (!headers)
|
|
32
41
|
return {};
|
|
33
42
|
return Object.fromEntries(Object.entries(headers)
|
|
34
|
-
.filter(([name]) =>
|
|
43
|
+
.filter(([name]) => {
|
|
44
|
+
const normalized = name.trim().toLowerCase();
|
|
45
|
+
return !normalized.startsWith(RESERVED_HEADER_PREFIX) && !TRANSPORT_HEADERS.has(normalized);
|
|
46
|
+
})
|
|
35
47
|
.map(([name, value]) => [name, String(value)]));
|
|
36
48
|
}
|
|
37
|
-
/**
|
|
38
|
-
* Bounds an upstream error body before it is logged: small payloads pass
|
|
39
|
-
* through, larger ones are truncated to a string, and an unserializable value
|
|
40
|
-
* is replaced with a placeholder. Keeps a huge or odd error response from
|
|
41
|
-
* bloating a single log line.
|
|
42
|
-
*/
|
|
43
|
-
function summarizeErrorData(data) {
|
|
44
|
-
if (data === undefined || data === null)
|
|
45
|
-
return undefined;
|
|
46
|
-
let serialized;
|
|
47
|
-
try {
|
|
48
|
-
serialized = typeof data === 'string' ? data : JSON.stringify(data);
|
|
49
|
-
}
|
|
50
|
-
catch {
|
|
51
|
-
return '[unserializable response body]';
|
|
52
|
-
}
|
|
53
|
-
const MAX = 1000;
|
|
54
|
-
return serialized.length <= MAX ? data : `${serialized.slice(0, MAX)}… (${serialized.length} chars, truncated)`;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* A log-safe summary of a failed request. Axios errors carry the full request
|
|
58
|
-
* config, including the `x-one-secret` header, so they must never be logged
|
|
59
|
-
* whole. Only the status, the upstream message, the route (query stripped), and
|
|
60
|
-
* a bounded copy of the response body are kept.
|
|
61
|
-
*/
|
|
62
|
-
export function describeError(error) {
|
|
63
|
-
if (axios.isAxiosError(error)) {
|
|
64
|
-
const url = error.config?.url;
|
|
65
|
-
return {
|
|
66
|
-
status: error.response?.status,
|
|
67
|
-
statusText: error.response?.statusText,
|
|
68
|
-
method: error.config?.method?.toUpperCase(),
|
|
69
|
-
url: typeof url === 'string' ? url.split('?')[0] : undefined,
|
|
70
|
-
message: error.message,
|
|
71
|
-
data: summarizeErrorData(error.response?.data),
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
if (error instanceof Error) {
|
|
75
|
-
return { name: error.name, message: error.message };
|
|
76
|
-
}
|
|
77
|
-
return { error: String(error) };
|
|
78
|
-
}
|
|
79
49
|
/**
|
|
80
50
|
* Client for interacting with the One API
|
|
81
51
|
*/
|
|
@@ -285,6 +255,7 @@ export class OneClient {
|
|
|
285
255
|
actionId,
|
|
286
256
|
title: action.title,
|
|
287
257
|
method: action.method,
|
|
258
|
+
access: action.access,
|
|
288
259
|
platform: action.connectionPlatform
|
|
289
260
|
};
|
|
290
261
|
}
|
|
@@ -308,6 +279,13 @@ export class OneClient {
|
|
|
308
279
|
const action = preloadedAction ?? await this.getActionDetails(actionId);
|
|
309
280
|
const method = action.method;
|
|
310
281
|
const contentType = isFormData ? 'multipart/form-data' : isFormUrlEncoded ? 'application/x-www-form-urlencoded' : 'application/json';
|
|
282
|
+
// An action's access level describes its declared method, so a request must
|
|
283
|
+
// not ask the platform to perform a different one.
|
|
284
|
+
for (const [name, value] of Object.entries(stripReservedHeaders(headers))) {
|
|
285
|
+
if (METHOD_OVERRIDE_HEADERS.has(name.trim().toLowerCase()) && value.trim().toUpperCase() !== method.toUpperCase()) {
|
|
286
|
+
throw new ToolError(`Header ${name.trim()} asks for ${value.trim()}, but this action is a ${method.toUpperCase()} request. Remove the header, or use an action with that method.`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
311
289
|
// Caller-supplied headers are merged first and may adjust things like
|
|
312
290
|
// Content-Type, but they can never override One's own routing and auth
|
|
313
291
|
// headers. Those are applied last, after the connection and action
|
|
@@ -329,6 +307,11 @@ export class OneClient {
|
|
|
329
307
|
const finalActionPath = replacePathVariables(action.path, pathVariables ?? {});
|
|
330
308
|
const normalizedPath = finalActionPath.startsWith('/') ? finalActionPath : `/${finalActionPath}`;
|
|
331
309
|
const url = `${this.baseUrl}/v1/passthrough${normalizedPath}`;
|
|
310
|
+
// This request carries the secret, and the local filters only describe
|
|
311
|
+
// passthrough, so it must not resolve to any other route of the One API.
|
|
312
|
+
if (!new URL(url).pathname.startsWith(new URL(`${this.baseUrl}/v1/passthrough/`).pathname)) {
|
|
313
|
+
throw new ToolError(`Action path ${action.path} does not stay on One's passthrough route, so it was not sent.`);
|
|
314
|
+
}
|
|
332
315
|
let requestData = data;
|
|
333
316
|
if (typeof requestData === 'string') {
|
|
334
317
|
try {
|
|
@@ -425,6 +408,33 @@ export class OneClient {
|
|
|
425
408
|
getUserConnections() {
|
|
426
409
|
return [...this.connections];
|
|
427
410
|
}
|
|
411
|
+
/**
|
|
412
|
+
* Refuses a connection key outside this server's scope, set by
|
|
413
|
+
* `ONE_CONNECTION_KEYS` or `ONE_IDENTITY`. The list is loaded once per
|
|
414
|
+
* process, so a key it lacks is checked against a fresh copy before being
|
|
415
|
+
* refused: it may be a connection made since, or the first load may have failed.
|
|
416
|
+
* @param connectionKey - The key the caller asked to run on
|
|
417
|
+
* @throws {ToolError} If the key is out of scope, or the list cannot be read
|
|
418
|
+
*/
|
|
419
|
+
async ensureConnectionInScope(connectionKey) {
|
|
420
|
+
const keysRestricted = this.connectionKeys !== undefined && !this.connectionKeys.includes('*');
|
|
421
|
+
if (!keysRestricted && !this.identity)
|
|
422
|
+
return;
|
|
423
|
+
const isLoaded = () => this.connections.some((c) => c.key === connectionKey);
|
|
424
|
+
if (isLoaded())
|
|
425
|
+
return;
|
|
426
|
+
const loaded = this.connections;
|
|
427
|
+
try {
|
|
428
|
+
await this.fetchConnections();
|
|
429
|
+
}
|
|
430
|
+
catch (error) {
|
|
431
|
+
this.connections = loaded;
|
|
432
|
+
throw oneApiError('Could not confirm this connection is available to this server', error);
|
|
433
|
+
}
|
|
434
|
+
if (!isLoaded()) {
|
|
435
|
+
throw new ToolError(`Connection key "${connectionKey}" is not one this server may use. Use a connection key from list_one_integrations.`);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
428
438
|
/**
|
|
429
439
|
* Gets available connectors/platforms
|
|
430
440
|
* @returns Array of available connection definitions
|
package/build/client.test.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { describe, it, before, after, beforeEach } from 'node:test';
|
|
2
2
|
import assert from 'node:assert/strict';
|
|
3
3
|
import http from 'node:http';
|
|
4
|
-
import {
|
|
4
|
+
import { inspect } from 'node:util';
|
|
5
|
+
import { OneClient, stripReservedHeaders, answeredByPlatform } from './client.js';
|
|
6
|
+
import { describeError, fetchPaginatedData } from './helpers.js';
|
|
5
7
|
import { ToolError } from './tool-error.js';
|
|
6
8
|
// A passthrough call must never let the caller override One's own routing/auth
|
|
7
9
|
// headers (the scoping bypass), and a failed call must never log the secret.
|
|
@@ -56,6 +58,31 @@ describe("executePassthroughRequest keeps One's headers authoritative", () => {
|
|
|
56
58
|
assert.equal(h['x-custom-trace'], 't-1', 'a non-reserved custom header still passes through');
|
|
57
59
|
assert.equal(h['content-type'], 'application/json', 'the default content type is kept');
|
|
58
60
|
});
|
|
61
|
+
it('a caller cannot set the headers that control the connection', async () => {
|
|
62
|
+
const client = new OneClient(SECRET, base);
|
|
63
|
+
await client.executePassthroughRequest(exec({
|
|
64
|
+
data: { a: 1 },
|
|
65
|
+
headers: { Host: 'attacker.example', 'Content-Length': '1', Connection: 'close', 'x-custom-trace': 't-1' },
|
|
66
|
+
}), { ...ACTION, method: 'POST' });
|
|
67
|
+
const h = received[0].headers;
|
|
68
|
+
assert.equal(h.host, new URL(base).host);
|
|
69
|
+
assert.equal(h['content-length'], '7', 'the length comes from the body that is sent');
|
|
70
|
+
assert.notEqual(h.connection, 'close');
|
|
71
|
+
assert.equal(h['x-custom-trace'], 't-1', 'a custom header still passes through');
|
|
72
|
+
});
|
|
73
|
+
it('sends nothing when a method override differs from the action method', async () => {
|
|
74
|
+
const client = new OneClient(SECRET, base);
|
|
75
|
+
const post = { ...ACTION, method: 'POST' };
|
|
76
|
+
for (const name of ['X-HTTP-Method-Override', 'x-http-method', 'X-Method-Override', ' x-http-method-override ']) {
|
|
77
|
+
await assert.rejects(client.executePassthroughRequest(exec({ headers: { [name]: 'DELETE' } }), post), (e) => e instanceof ToolError && /DELETE/.test(e.message) && /POST/.test(e.message), name);
|
|
78
|
+
}
|
|
79
|
+
assert.equal(received.length, 0, 'nothing is sent upstream');
|
|
80
|
+
});
|
|
81
|
+
it('allows a method override that matches the action method, in any casing', async () => {
|
|
82
|
+
const client = new OneClient(SECRET, base);
|
|
83
|
+
await client.executePassthroughRequest(exec({ headers: { 'X-HTTP-Method-Override': ' post ' } }), { ...ACTION, method: 'POST' });
|
|
84
|
+
assert.equal(received.length, 1);
|
|
85
|
+
});
|
|
59
86
|
it('names the expected path variables instead of sending an unfilled template', async () => {
|
|
60
87
|
const client = new OneClient(SECRET, base);
|
|
61
88
|
const templated = { ...ACTION, path: '/v1/things/{{thingId}}' };
|
|
@@ -64,6 +91,23 @@ describe("executePassthroughRequest keeps One's headers authoritative", () => {
|
|
|
64
91
|
await client.executePassthroughRequest(exec({ pathVariables: { thing_id: 7 } }), templated);
|
|
65
92
|
assert.equal(received.length, 1);
|
|
66
93
|
});
|
|
94
|
+
it('sends nothing when a path variable would leave the action route', async () => {
|
|
95
|
+
const client = new OneClient(SECRET, base);
|
|
96
|
+
const templated = { ...ACTION, path: '/v0/{{a}}/{{b}}/{{c}}' };
|
|
97
|
+
await assert.rejects(client.executePassthroughRequest(exec({ pathVariables: { a: '..', b: '..', c: 'connections' } }), templated), ToolError);
|
|
98
|
+
assert.equal(received.length, 0, 'nothing is sent upstream');
|
|
99
|
+
});
|
|
100
|
+
it('sends nothing when an action path resolves outside passthrough', async () => {
|
|
101
|
+
const client = new OneClient(SECRET, base);
|
|
102
|
+
const encoded = { ...ACTION, path: '/%2e%2e/%2E%2e/connections' };
|
|
103
|
+
await assert.rejects(client.executePassthroughRequest(exec({}), encoded), ToolError);
|
|
104
|
+
assert.equal(received.length, 0, 'nothing is sent upstream');
|
|
105
|
+
});
|
|
106
|
+
it('keeps ordinary paths working under a base URL with a path prefix', async () => {
|
|
107
|
+
const client = new OneClient(SECRET, `${base}/prefix`);
|
|
108
|
+
await client.executePassthroughRequest(exec({}), ACTION);
|
|
109
|
+
assert.equal(received.length, 1);
|
|
110
|
+
});
|
|
67
111
|
it('a caller may still set Content-Type, in any casing', async () => {
|
|
68
112
|
const client = new OneClient(SECRET, base);
|
|
69
113
|
await client.executePassthroughRequest(exec({ headers: { 'content-type': 'text/plain' } }), ACTION);
|
|
@@ -127,6 +171,128 @@ describe("executePassthroughRequest keeps One's headers authoritative", () => {
|
|
|
127
171
|
assert.ok(message.includes('422') && message.includes('upstream said no'), "the tool error carries the status and One's reason");
|
|
128
172
|
});
|
|
129
173
|
});
|
|
174
|
+
describe('ensureConnectionInScope', () => {
|
|
175
|
+
let server;
|
|
176
|
+
let base = '';
|
|
177
|
+
let rows = [];
|
|
178
|
+
let listQueries = [];
|
|
179
|
+
let failLists = false;
|
|
180
|
+
const client = (options = {}) => new OneClient({ secret: SECRET, baseUrl: base, fetchConnectors: false, ...options });
|
|
181
|
+
before(async () => {
|
|
182
|
+
server = http.createServer((req, res) => {
|
|
183
|
+
listQueries.push(new URL(req.url ?? '', 'http://x').searchParams);
|
|
184
|
+
res.writeHead(failLists ? 500 : 200, { 'Content-Type': 'application/json' });
|
|
185
|
+
res.end(JSON.stringify(failLists ? { message: 'boom' } : { rows: rows.map((key) => ({ key, platform: 'test' })), total: rows.length }));
|
|
186
|
+
});
|
|
187
|
+
await new Promise((resolve) => server.listen(0, '127.0.0.1', () => resolve()));
|
|
188
|
+
base = `http://127.0.0.1:${server.address().port}`;
|
|
189
|
+
});
|
|
190
|
+
after(() => {
|
|
191
|
+
server.close();
|
|
192
|
+
});
|
|
193
|
+
beforeEach(() => {
|
|
194
|
+
rows = ['key_a'];
|
|
195
|
+
listQueries = [];
|
|
196
|
+
failLists = false;
|
|
197
|
+
});
|
|
198
|
+
it('allows any key when the server has no scope, without listing', async () => {
|
|
199
|
+
const c = client();
|
|
200
|
+
await c.ensureConnectionInScope('key_b');
|
|
201
|
+
assert.equal(listQueries.length, 0);
|
|
202
|
+
});
|
|
203
|
+
it("allows the identity's own key without listing again", async () => {
|
|
204
|
+
const c = client({ identity: 'user_a' });
|
|
205
|
+
await c.initialize();
|
|
206
|
+
await c.ensureConnectionInScope('key_a');
|
|
207
|
+
assert.equal(listQueries.length, 1);
|
|
208
|
+
});
|
|
209
|
+
it("refuses another identity's key, using the identity-filtered list", async () => {
|
|
210
|
+
const c = client({ identity: 'user_a' });
|
|
211
|
+
await c.initialize();
|
|
212
|
+
await assert.rejects(c.ensureConnectionInScope('key_b'), (e) => e instanceof ToolError && /is not one this server may use/.test(e.message));
|
|
213
|
+
assert.equal(listQueries.at(-1)?.get('identity'), 'user_a', 'the check reads the same filtered list');
|
|
214
|
+
});
|
|
215
|
+
it('allows a connection made after the list was loaded', async () => {
|
|
216
|
+
const c = client({ identity: 'user_a' });
|
|
217
|
+
await c.initialize();
|
|
218
|
+
rows = ['key_a', 'key_new'];
|
|
219
|
+
await c.ensureConnectionInScope('key_new');
|
|
220
|
+
assert.deepEqual(c.getUserConnections().map((x) => x.key), ['key_a', 'key_new']);
|
|
221
|
+
});
|
|
222
|
+
const silenced = async (run) => {
|
|
223
|
+
const original = console.error;
|
|
224
|
+
console.error = () => { };
|
|
225
|
+
try {
|
|
226
|
+
return await run();
|
|
227
|
+
}
|
|
228
|
+
finally {
|
|
229
|
+
console.error = original;
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
it('recovers when the first load failed', async () => {
|
|
233
|
+
const c = client({ identity: 'user_a' });
|
|
234
|
+
failLists = true;
|
|
235
|
+
await silenced(() => c.initialize());
|
|
236
|
+
failLists = false;
|
|
237
|
+
await c.ensureConnectionInScope('key_a');
|
|
238
|
+
});
|
|
239
|
+
it('refuses when the list cannot be read, and keeps the loaded list', async () => {
|
|
240
|
+
const c = client({ identity: 'user_a' });
|
|
241
|
+
await c.initialize();
|
|
242
|
+
failLists = true;
|
|
243
|
+
await silenced(() => assert.rejects(c.ensureConnectionInScope('key_b'), (e) => e instanceof ToolError && /Could not confirm/.test(e.message)));
|
|
244
|
+
assert.deepEqual(c.getUserConnections().map((x) => x.key), ['key_a']);
|
|
245
|
+
});
|
|
246
|
+
it('still applies ONE_CONNECTION_KEYS', async () => {
|
|
247
|
+
const c = client({ connectionKeys: ['key_a'] });
|
|
248
|
+
await c.initialize();
|
|
249
|
+
await assert.rejects(c.ensureConnectionInScope('key_b'), ToolError);
|
|
250
|
+
await c.ensureConnectionInScope('key_a');
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
describe('a failed paginated fetch', () => {
|
|
254
|
+
// Rendered the way console.error renders its arguments, which is what prints
|
|
255
|
+
// a whole axios error's request headers.
|
|
256
|
+
const captureLog = async (run) => {
|
|
257
|
+
const logged = [];
|
|
258
|
+
const original = console.error;
|
|
259
|
+
console.error = (...args) => {
|
|
260
|
+
logged.push(args.map((a) => (typeof a === 'string' ? a : inspect(a, { depth: null }))).join(' '));
|
|
261
|
+
};
|
|
262
|
+
try {
|
|
263
|
+
await assert.rejects(run());
|
|
264
|
+
}
|
|
265
|
+
finally {
|
|
266
|
+
console.error = original;
|
|
267
|
+
}
|
|
268
|
+
return logged.join('\n');
|
|
269
|
+
};
|
|
270
|
+
it('never logs the secret when One answers with an error', async () => {
|
|
271
|
+
const server = http.createServer((_req, res) => {
|
|
272
|
+
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
273
|
+
res.end(JSON.stringify({ message: 'upstream said no' }));
|
|
274
|
+
});
|
|
275
|
+
await new Promise((resolve) => server.listen(0, '127.0.0.1', () => resolve()));
|
|
276
|
+
const url = `http://127.0.0.1:${server.address().port}/v1/vault/connections`;
|
|
277
|
+
try {
|
|
278
|
+
const log = await captureLog(() => fetchPaginatedData(url, { 'x-one-secret': SECRET }));
|
|
279
|
+
assert.ok(!log.includes(SECRET), 'the secret never reaches the log');
|
|
280
|
+
assert.ok(log.includes('500') && log.includes('upstream said no'), 'the log still says what failed');
|
|
281
|
+
}
|
|
282
|
+
finally {
|
|
283
|
+
server.close();
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
it('never logs the secret when One cannot be reached', async () => {
|
|
287
|
+
const closed = http.createServer();
|
|
288
|
+
await new Promise((resolve) => closed.listen(0, '127.0.0.1', () => resolve()));
|
|
289
|
+
const port = closed.address().port;
|
|
290
|
+
await new Promise((resolve) => closed.close(() => resolve()));
|
|
291
|
+
const log = await captureLog(() => fetchPaginatedData(`http://127.0.0.1:${port}/v1/vault/connections`, { 'x-one-secret': SECRET }));
|
|
292
|
+
assert.ok(!log.includes(SECRET), 'the secret never reaches the log');
|
|
293
|
+
assert.ok(log.includes('ECONNREFUSED'), 'the log still says what failed');
|
|
294
|
+
});
|
|
295
|
+
});
|
|
130
296
|
describe('answeredByPlatform', () => {
|
|
131
297
|
it('reads a renamed upstream header, in any casing, as the platform answering', () => {
|
|
132
298
|
assert.equal(answeredByPlatform({ 'x-passthrough-content-type': 'application/json' }), true);
|
|
@@ -140,6 +306,14 @@ describe('stripReservedHeaders', () => {
|
|
|
140
306
|
assert.deepEqual(stripReservedHeaders({ n: 5 }), { n: '5' });
|
|
141
307
|
assert.deepEqual(stripReservedHeaders(undefined), {});
|
|
142
308
|
});
|
|
309
|
+
it('drops connection-level headers case-insensitively', () => {
|
|
310
|
+
for (const name of ['Host', 'host', 'CONNECTION', 'Content-Length', 'Transfer-Encoding', 'Keep-Alive', 'Proxy-Connection', 'TE', 'Trailer', 'Upgrade']) {
|
|
311
|
+
assert.deepEqual(stripReservedHeaders({ [name]: 'x', Accept: 'y' }), { Accept: 'y' }, name);
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
it('ignores surrounding whitespace in a header name', () => {
|
|
315
|
+
assert.deepEqual(stripReservedHeaders({ 'Host ': 'a', ' host': 'b', ' x-one-secret': 'c', Accept: 'y' }), { Accept: 'y' });
|
|
316
|
+
});
|
|
143
317
|
});
|
|
144
318
|
describe('describeError', () => {
|
|
145
319
|
it('summarizes a plain error to its name and message', () => {
|
package/build/find.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* @author One
|
|
14
14
|
*/
|
|
15
15
|
import { ToolError } from './tool-error.js';
|
|
16
|
-
import { buildKnowledgeResponse,
|
|
16
|
+
import { buildKnowledgeResponse, isAccessAllowed, isActionAllowed, platformEnvSegment } from './helpers.js';
|
|
17
17
|
/** How many intents one find answers. Core enforces the same cap. */
|
|
18
18
|
export const FIND_MAX_INTENTS = 10;
|
|
19
19
|
/** How many documents one load returns. */
|
|
@@ -47,7 +47,7 @@ export function actionHeading(title, method, path, actionId) {
|
|
|
47
47
|
return `${title} · \`${method.toUpperCase()} ${path}\` · actionId: \`${actionId}\``;
|
|
48
48
|
}
|
|
49
49
|
function allows(settings, action) {
|
|
50
|
-
return isActionAllowed(action.systemId, settings.actionIds) &&
|
|
50
|
+
return isActionAllowed(action.systemId, settings.actionIds) && isAccessAllowed(action.access, settings.permissions);
|
|
51
51
|
}
|
|
52
52
|
function reaches(settings, platform) {
|
|
53
53
|
return settings.platforms === null || (platform !== undefined && settings.platforms.includes(platform));
|
|
@@ -278,7 +278,7 @@ async function load(loads, deps, settings) {
|
|
|
278
278
|
catch {
|
|
279
279
|
return refused;
|
|
280
280
|
}
|
|
281
|
-
if (!
|
|
281
|
+
if (!isAccessAllowed(details.access, settings.permissions) || !reaches(settings, details.connectionPlatform)) {
|
|
282
282
|
return refused;
|
|
283
283
|
}
|
|
284
284
|
const text = renderAction({
|
package/build/find.test.js
CHANGED
|
@@ -9,13 +9,14 @@ const LARGE = [
|
|
|
9
9
|
'## Request Body\n### Required Request Body Fields\n- to: string',
|
|
10
10
|
`## Response Fields\n${Array.from({ length: 400 }, (_, i) => `- field ${i}: a described response field`).join('\n')}`,
|
|
11
11
|
].join('\n\n');
|
|
12
|
-
const action = (id, method = 'POST', tags = []) => ({
|
|
12
|
+
const action = (id, method = 'POST', tags = [], access = method === 'GET' ? 'read' : 'write') => ({
|
|
13
13
|
systemId: id,
|
|
14
14
|
title: `Action ${id}`,
|
|
15
15
|
key: `key-${id}`,
|
|
16
16
|
method,
|
|
17
17
|
path: `/v1/${id}`,
|
|
18
18
|
tags,
|
|
19
|
+
access,
|
|
19
20
|
knowledge: 'a digest core rendered for its own route',
|
|
20
21
|
});
|
|
21
22
|
const answer = (overrides = {}) => ({
|
|
@@ -54,6 +55,7 @@ function deps(answers, knowledge = {}) {
|
|
|
54
55
|
_id: id,
|
|
55
56
|
title: `Action ${id}`,
|
|
56
57
|
method: id === 'c' ? 'GET' : 'POST',
|
|
58
|
+
access: id === 'unclassified' ? undefined : id === 'c' ? 'read' : id === 'gone' ? 'delete' : 'write',
|
|
57
59
|
path: `/v1/${id}`,
|
|
58
60
|
tags: id === 'custom' ? ['custom'] : [],
|
|
59
61
|
knowledge: knowledge[id] ?? `# Action ${id}\n\nSmall doc for ${id}.`,
|
|
@@ -100,6 +102,30 @@ describe('find_one_actions', () => {
|
|
|
100
102
|
assert.ok(text.indexOf('actionId: `d`') < text.indexOf('actionId: `c`'), 'the runner-up stands in first, the companion after it');
|
|
101
103
|
assert.ok(!text.includes('use this one instead'), 'the promoted runner-up is not also offered as a substitute');
|
|
102
104
|
});
|
|
105
|
+
it('judges an action by its access level, not its HTTP method', async () => {
|
|
106
|
+
const text = await findOneActions({ requests: intent }, deps([answer({ selected: [action('post-read', 'POST', [], 'read')], alternatives: [action('get-write', 'GET', [], 'write')] })]), settings({ permissions: 'read' }));
|
|
107
|
+
assert.ok(text.includes('actionId: `post-read`'), 'a POST that only reads is offered at the read level');
|
|
108
|
+
assert.ok(!text.includes('actionId: `get-write`'), 'a GET that writes is not');
|
|
109
|
+
});
|
|
110
|
+
it('keeps delete actions from the write level, whatever their method', async () => {
|
|
111
|
+
const text = await findOneActions({ requests: intent }, deps([answer({ selected: [action('post-delete', 'POST', [], 'delete')], alternatives: [action('delete-write', 'DELETE', [], 'write')] })]), settings({ permissions: 'write' }));
|
|
112
|
+
assert.ok(!text.includes('actionId: `post-delete`'));
|
|
113
|
+
assert.ok(text.includes('actionId: `delete-write`'));
|
|
114
|
+
});
|
|
115
|
+
it('offers an action with no access level only at the admin level', async () => {
|
|
116
|
+
const unclassified = () => answer({ selected: [action('none', 'GET', [], null)], alternatives: [] });
|
|
117
|
+
const refused = await findOneActions({ requests: intent }, deps([unclassified()]), settings({ permissions: 'read' }));
|
|
118
|
+
assert.ok(!refused.includes('actionId: `none`'));
|
|
119
|
+
const offered = await findOneActions({ requests: intent }, deps([unclassified()]), settings());
|
|
120
|
+
assert.ok(offered.includes('actionId: `none`'));
|
|
121
|
+
});
|
|
122
|
+
it('refuses a load by access level, the same as an action it does not know', async () => {
|
|
123
|
+
const text = await findOneActions({ load: [{ action_id: 'c' }, { action_id: 'a' }, { action_id: 'unclassified' }, { action_id: 'missing' }] }, deps([]), settings({ permissions: 'read' }));
|
|
124
|
+
assert.ok(text.includes('Small doc for c.'));
|
|
125
|
+
for (const id of ['a', 'unclassified', 'missing']) {
|
|
126
|
+
assert.ok(text.includes(`\`${id}\`: ${REFUSED_LOAD}`), id);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
103
129
|
it('serves the first document a load actually returns, however large, even after a refused entry', async () => {
|
|
104
130
|
const huge = `# Huge\n\n${'x'.repeat(450_000)}`;
|
|
105
131
|
const text = await findOneActions({ load: [{ action_id: 'missing' }, { action_id: 'a', full: true }] }, deps([], { a: huge }), settings());
|
package/build/helpers.js
CHANGED
|
@@ -9,6 +9,48 @@
|
|
|
9
9
|
import axios from 'axios';
|
|
10
10
|
import { ToolError } from './tool-error.js';
|
|
11
11
|
import { parseSections, buildDigest, renderDigestBanner, renderDigestNotice, selectSections, flattenSections, parseSectionFlag, collapseSections, omittedSections, } from './knowledge-sections.js';
|
|
12
|
+
/**
|
|
13
|
+
* Bounds an upstream error body before it is logged: small payloads pass
|
|
14
|
+
* through, larger ones are truncated to a string, and an unserializable value
|
|
15
|
+
* is replaced with a placeholder. Keeps a huge or odd error response from
|
|
16
|
+
* bloating a single log line.
|
|
17
|
+
*/
|
|
18
|
+
export function summarizeErrorData(data) {
|
|
19
|
+
if (data === undefined || data === null)
|
|
20
|
+
return undefined;
|
|
21
|
+
let serialized;
|
|
22
|
+
try {
|
|
23
|
+
serialized = typeof data === 'string' ? data : JSON.stringify(data);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return '[unserializable response body]';
|
|
27
|
+
}
|
|
28
|
+
const MAX = 1000;
|
|
29
|
+
return serialized.length <= MAX ? data : `${serialized.slice(0, MAX)}… (${serialized.length} chars, truncated)`;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A log-safe summary of a failed request. Axios errors carry the full request
|
|
33
|
+
* config, including the `x-one-secret` header, so they must never be logged
|
|
34
|
+
* whole. Only the status, the upstream message, the route (query stripped), and
|
|
35
|
+
* a bounded copy of the response body are kept.
|
|
36
|
+
*/
|
|
37
|
+
export function describeError(error) {
|
|
38
|
+
if (axios.isAxiosError(error)) {
|
|
39
|
+
const url = error.config?.url;
|
|
40
|
+
return {
|
|
41
|
+
status: error.response?.status,
|
|
42
|
+
statusText: error.response?.statusText,
|
|
43
|
+
method: error.config?.method?.toUpperCase(),
|
|
44
|
+
url: typeof url === 'string' ? url.split('?')[0] : undefined,
|
|
45
|
+
message: error.message,
|
|
46
|
+
data: summarizeErrorData(error.response?.data),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
if (error instanceof Error) {
|
|
50
|
+
return { name: error.name, message: error.message };
|
|
51
|
+
}
|
|
52
|
+
return { error: String(error) };
|
|
53
|
+
}
|
|
12
54
|
/**
|
|
13
55
|
* Paginates through API results by repeatedly calling a fetch function until all data is retrieved.
|
|
14
56
|
* @param fetchFn - Function that fetches paginated data, takes skip and limit parameters
|
|
@@ -30,7 +72,7 @@ export async function paginateResults(fetchFn, limit = 100) {
|
|
|
30
72
|
return allResults;
|
|
31
73
|
}
|
|
32
74
|
catch (error) {
|
|
33
|
-
console.error("Error in pagination:", error);
|
|
75
|
+
console.error("Error in pagination:", describeError(error));
|
|
34
76
|
throw error;
|
|
35
77
|
}
|
|
36
78
|
}
|
|
@@ -56,7 +98,7 @@ export async function fetchPaginatedData(baseUrl, headers, additionalParams) {
|
|
|
56
98
|
return response.data;
|
|
57
99
|
}
|
|
58
100
|
catch (error) {
|
|
59
|
-
console.error(`Failed to fetch from ${baseUrl}:`, error);
|
|
101
|
+
console.error(`Failed to fetch from ${baseUrl}:`, describeError(error));
|
|
60
102
|
throw error;
|
|
61
103
|
}
|
|
62
104
|
};
|
|
@@ -209,18 +251,37 @@ export function replacePathVariables(path, variables) {
|
|
|
209
251
|
return encodeURIComponent(value.toString());
|
|
210
252
|
};
|
|
211
253
|
// Double brackets first, so {{name}} is not read as {name} wrapped in braces.
|
|
212
|
-
|
|
254
|
+
const filled = path.replace(/\{\{([^}]+)\}\}/g, (_match, variable) => lookup(variable)).replace(/\{([^}]+)\}/g, (_match, variable) => lookup(variable));
|
|
255
|
+
// encodeURIComponent leaves dots alone, and a dot segment would move the
|
|
256
|
+
// request off the action's route. Checked on the filled path because
|
|
257
|
+
// adjacent variables can assemble one.
|
|
258
|
+
const route = filled.split(/[?#]/, 1)[0];
|
|
259
|
+
if (route.split('/').some((segment) => segment === '.' || segment === '..')) {
|
|
260
|
+
throw new ToolError(`Invalid pathVariables for ${path}: a path segment cannot be "." or "..".`);
|
|
261
|
+
}
|
|
262
|
+
return filled;
|
|
213
263
|
}
|
|
214
|
-
const
|
|
215
|
-
read: ["
|
|
216
|
-
write: ["
|
|
264
|
+
const PERMISSION_LEVELS = {
|
|
265
|
+
read: ["read"],
|
|
266
|
+
write: ["read", "write"],
|
|
217
267
|
admin: null,
|
|
218
268
|
};
|
|
219
|
-
|
|
220
|
-
|
|
269
|
+
/**
|
|
270
|
+
* Whether the permission level allows an action classified at `access`. Below
|
|
271
|
+
* `admin`, an action with no level or one this server does not know is refused,
|
|
272
|
+
* since nothing says it is safe at that level.
|
|
273
|
+
*/
|
|
274
|
+
export function isAccessAllowed(access, permissions) {
|
|
275
|
+
const allowed = PERMISSION_LEVELS[permissions];
|
|
221
276
|
if (allowed === null)
|
|
222
277
|
return true;
|
|
223
|
-
return allowed.includes(
|
|
278
|
+
return allowed.includes(access);
|
|
279
|
+
}
|
|
280
|
+
/** What an agent is told when the permission level refuses an action. */
|
|
281
|
+
export function accessRefusal(actionId, access, permissions) {
|
|
282
|
+
return access
|
|
283
|
+
? `Action "${actionId}" is classified as ${access}, which this server's "${permissions}" permission level does not allow, so it cannot be run here.`
|
|
284
|
+
: `Action "${actionId}" has no access level, so this server's "${permissions}" permission level does not allow it and it cannot be run here.`;
|
|
224
285
|
}
|
|
225
286
|
export function isActionAllowed(actionId, allowedActionIds) {
|
|
226
287
|
return allowedActionIds.includes("*") || allowedActionIds.includes(actionId);
|
|
@@ -230,9 +291,9 @@ export function isActionAllowed(actionId, allowedActionIds) {
|
|
|
230
291
|
* `platform`, so `list_one_integrations` can surface it without a search.
|
|
231
292
|
* Mirrors the One core `resolve_connection_access` precedence:
|
|
232
293
|
* an action allowlist wins (report the enumerated actions on this platform),
|
|
233
|
-
* else a non-`admin` permission level reports its
|
|
294
|
+
* else a non-`admin` permission level reports its access levels, else full.
|
|
234
295
|
* `resolvedAllowed` is the allowlisted actions already resolved to their
|
|
235
|
-
* metadata and
|
|
296
|
+
* metadata and filtered by the permission level.
|
|
236
297
|
*/
|
|
237
298
|
export function computeConnectionAccess(platform, permissions, allowedActionIds, resolvedAllowed) {
|
|
238
299
|
if (!allowedActionIds.includes("*")) {
|
|
@@ -241,9 +302,9 @@ export function computeConnectionAccess(platform, permissions, allowedActionIds,
|
|
|
241
302
|
.map(({ actionId, title, method }) => ({ actionId, title, method }));
|
|
242
303
|
return { policy: "actions", actions };
|
|
243
304
|
}
|
|
244
|
-
const
|
|
245
|
-
if (
|
|
246
|
-
return { policy: "
|
|
305
|
+
const levels = PERMISSION_LEVELS[permissions];
|
|
306
|
+
if (levels !== null) {
|
|
307
|
+
return { policy: "levels", levels };
|
|
247
308
|
}
|
|
248
309
|
return { policy: "full" };
|
|
249
310
|
}
|
package/build/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
|
11
11
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
12
12
|
import { ErrorCode, McpError, } from '@modelcontextprotocol/sdk/types.js';
|
|
13
13
|
import { OneClient } from './client.js';
|
|
14
|
-
import {
|
|
14
|
+
import { accessRefusal, isAccessAllowed, isActionAllowed, buildIntegrationsResponse, } from './helpers.js';
|
|
15
15
|
import { findOneActions } from './find.js';
|
|
16
16
|
import { ToolError, toolErrorResult } from './tool-error.js';
|
|
17
17
|
import { unpatchedNodeRefusal } from './node-check.js';
|
|
@@ -102,11 +102,11 @@ if (!ONE_KNOWLEDGE_AGENT) {
|
|
|
102
102
|
}
|
|
103
103
|
async function handleGetIntegrations(args) {
|
|
104
104
|
try {
|
|
105
|
-
// Resolve the action allowlist to per-platform metadata (
|
|
106
|
-
//
|
|
105
|
+
// Resolve the action allowlist to per-platform metadata (filtered by the
|
|
106
|
+
// permission level) once, so each connection can report the exact
|
|
107
107
|
// actions it may run. Only needed when an action allowlist is set.
|
|
108
108
|
const resolvedAllowed = (await oneClient.resolveAllowedActions(ONE_ACTION_IDS))
|
|
109
|
-
.filter(action =>
|
|
109
|
+
.filter(action => isAccessAllowed(action.access, ONE_PERMISSIONS));
|
|
110
110
|
// Execute mode lists only connections: every connection carries its
|
|
111
111
|
// access, and the full catalog (1000+ platforms) would sit in the agent's
|
|
112
112
|
// context for the rest of the session. Knowledge/code-gen mode also lists
|
|
@@ -163,15 +163,10 @@ async function handleExecuteOneAction(args) {
|
|
|
163
163
|
if (!isActionAllowed(args.actionId, ONE_ACTION_IDS)) {
|
|
164
164
|
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.`);
|
|
165
165
|
}
|
|
166
|
-
|
|
167
|
-
const allowedKeys = oneClient.getUserConnections().map(c => c.key);
|
|
168
|
-
if (!allowedKeys.includes(args.connectionKey)) {
|
|
169
|
-
throw new ToolError(`Connection key "${args.connectionKey}" is not one this server may use. Use a connection key from list_one_integrations.`);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
166
|
+
await oneClient.ensureConnectionInScope(args.connectionKey);
|
|
172
167
|
const actionDetails = await oneClient.getActionDetails(args.actionId);
|
|
173
|
-
if (!
|
|
174
|
-
throw new ToolError(
|
|
168
|
+
if (!isAccessAllowed(actionDetails.access, ONE_PERMISSIONS)) {
|
|
169
|
+
throw new ToolError(accessRefusal(args.actionId, actionDetails.access, ONE_PERMISSIONS));
|
|
175
170
|
}
|
|
176
171
|
const result = await oneClient.executePassthroughRequest(args, actionDetails);
|
|
177
172
|
return {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, it } from 'node:test';
|
|
2
2
|
import assert from 'node:assert/strict';
|
|
3
|
-
import { buildIntegrationsResponse } from './helpers.js';
|
|
3
|
+
import { accessRefusal, buildIntegrationsResponse, isAccessAllowed } from './helpers.js';
|
|
4
4
|
const conn = (platform, active = true) => ({ key: `live::${platform}::default::k`, platform, tags: [], active });
|
|
5
5
|
const def = (platform, extra = {}) => ({ platform, name: platform.toUpperCase(), category: 'Test', active: true, deprecated: false, ...extra });
|
|
6
6
|
const FULL = { permissions: 'admin', actionIds: ['*'], resolvedAllowed: [] };
|
|
@@ -13,11 +13,13 @@ describe('buildIntegrationsResponse', () => {
|
|
|
13
13
|
});
|
|
14
14
|
it('keeps the per-connection access', () => {
|
|
15
15
|
const r = buildIntegrationsResponse([conn('gmail')], { permissions: 'read', actionIds: ['*'], resolvedAllowed: [] });
|
|
16
|
-
assert.deepEqual(r.connections[0].access, { policy: '
|
|
16
|
+
assert.deepEqual(r.connections[0].access, { policy: 'levels', levels: ['read'] });
|
|
17
|
+
const writer = buildIntegrationsResponse([conn('gmail')], { permissions: 'write', actionIds: ['*'], resolvedAllowed: [] });
|
|
18
|
+
assert.deepEqual(writer.connections[0].access, { policy: 'levels', levels: ['read', 'write'] });
|
|
17
19
|
const scoped = buildIntegrationsResponse([conn('gmail')], {
|
|
18
20
|
permissions: 'admin',
|
|
19
21
|
actionIds: ['act_1'],
|
|
20
|
-
resolvedAllowed: [{ actionId: 'act_1', title: 'Send Email', method: 'POST', platform: 'gmail' }],
|
|
22
|
+
resolvedAllowed: [{ actionId: 'act_1', title: 'Send Email', method: 'POST', access: 'write', platform: 'gmail' }],
|
|
21
23
|
});
|
|
22
24
|
assert.deepEqual(scoped.connections[0].access, {
|
|
23
25
|
policy: 'actions',
|
|
@@ -38,3 +40,35 @@ describe('buildIntegrationsResponse', () => {
|
|
|
38
40
|
assert.deepEqual(r.summary, { connectedCount: 1, availableCount: 2 });
|
|
39
41
|
});
|
|
40
42
|
});
|
|
43
|
+
describe('isAccessAllowed', () => {
|
|
44
|
+
const cases = [
|
|
45
|
+
['read', 'read', true],
|
|
46
|
+
['write', 'read', false],
|
|
47
|
+
['delete', 'read', false],
|
|
48
|
+
['read', 'write', true],
|
|
49
|
+
['write', 'write', true],
|
|
50
|
+
['delete', 'write', false],
|
|
51
|
+
['read', 'admin', true],
|
|
52
|
+
['write', 'admin', true],
|
|
53
|
+
['delete', 'admin', true],
|
|
54
|
+
[undefined, 'read', false],
|
|
55
|
+
[undefined, 'write', false],
|
|
56
|
+
[null, 'write', false],
|
|
57
|
+
['READ', 'read', false],
|
|
58
|
+
['execute', 'write', false],
|
|
59
|
+
[undefined, 'admin', true],
|
|
60
|
+
];
|
|
61
|
+
for (const [access, level, expected] of cases) {
|
|
62
|
+
it(`${String(access)} at ${level} is ${expected ? 'allowed' : 'refused'}`, () => {
|
|
63
|
+
assert.equal(isAccessAllowed(access, level), expected);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
describe('accessRefusal', () => {
|
|
68
|
+
it('names the action, its level and the server level', () => {
|
|
69
|
+
assert.equal(accessRefusal('act_1', 'delete', 'write'), `Action "act_1" is classified as delete, which this server's "write" permission level does not allow, so it cannot be run here.`);
|
|
70
|
+
});
|
|
71
|
+
it('says so when the action has no level', () => {
|
|
72
|
+
assert.equal(accessRefusal('act_1', undefined, 'read'), `Action "act_1" has no access level, so this server's "read" permission level does not allow it and it cannot be run here.`);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { describe, it } from 'node:test';
|
|
2
2
|
import assert from 'node:assert/strict';
|
|
3
3
|
import { replacePathVariables } from './helpers.js';
|
|
4
|
+
import { ToolError } from './tool-error.js';
|
|
4
5
|
describe('replacePathVariables', () => {
|
|
5
6
|
it('fills exact names in both bracket styles', () => {
|
|
6
7
|
assert.equal(replacePathVariables('/tickets/{{ticketId}}/comments/{id}', { ticketId: 42, id: 'c 1' }), '/tickets/42/comments/c%201');
|
|
@@ -23,4 +24,21 @@ describe('replacePathVariables', () => {
|
|
|
23
24
|
it('rejects empty values', () => {
|
|
24
25
|
assert.throws(() => replacePathVariables('/x/{{id}}', { id: '' }), /Missing value for path variable: id/);
|
|
25
26
|
});
|
|
27
|
+
it('refuses a value that would become a dot segment', () => {
|
|
28
|
+
for (const value of ['.', '..']) {
|
|
29
|
+
assert.throws(() => replacePathVariables('/a/{{id}}/b', { id: value }), ToolError, value);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
it('refuses dot segments assembled from adjacent variables', () => {
|
|
33
|
+
assert.throws(() => replacePathVariables('/a/{{x}}{{y}}/b', { x: '.', y: '.' }), ToolError);
|
|
34
|
+
});
|
|
35
|
+
it('keeps values that only contain dots', () => {
|
|
36
|
+
assert.equal(replacePathVariables('/a/{{x}}/{{y}}/{{z}}', { x: '...', y: '..hidden', z: 'file.txt' }), '/a/.../..hidden/file.txt');
|
|
37
|
+
});
|
|
38
|
+
it('keeps a value with a slash inside one encoded segment', () => {
|
|
39
|
+
assert.equal(replacePathVariables('/a/{{x}}', { x: '../..' }), '/a/..%2F..');
|
|
40
|
+
});
|
|
41
|
+
it('allows dots in a variable after the query separator', () => {
|
|
42
|
+
assert.equal(replacePathVariables('/a?q={{q}}', { q: '..' }), '/a?q=..');
|
|
43
|
+
});
|
|
26
44
|
});
|
package/build/schemas.js
CHANGED
|
@@ -67,8 +67,8 @@ const connectionAccessSchema = z.union([
|
|
|
67
67
|
policy: z.literal("full")
|
|
68
68
|
}),
|
|
69
69
|
z.object({
|
|
70
|
-
policy: z.literal("
|
|
71
|
-
|
|
70
|
+
policy: z.literal("levels"),
|
|
71
|
+
levels: z.array(z.enum(["read", "write", "delete"]))
|
|
72
72
|
}),
|
|
73
73
|
z.object({
|
|
74
74
|
policy: z.literal("actions"),
|
|
@@ -78,7 +78,7 @@ const connectionAccessSchema = z.union([
|
|
|
78
78
|
method: z.string()
|
|
79
79
|
}))
|
|
80
80
|
})
|
|
81
|
-
]).describe("What the access config lets you run on this connection: `full`,
|
|
81
|
+
]).describe("What the access config lets you run on this connection: `full`, the access `levels` you may run (`read`, `write`, `delete`), or a specific `actions` list. When `actions`, those are exactly what may run, so no search is needed.");
|
|
82
82
|
export const listOneIntegrationsOutputSchema = {
|
|
83
83
|
connections: z.array(z.object({
|
|
84
84
|
platform: z.string(),
|
|
@@ -111,7 +111,7 @@ const READ_ONLY_ANNOTATIONS = {
|
|
|
111
111
|
*/
|
|
112
112
|
export const listOneIntegrationsToolConfig = {
|
|
113
113
|
title: "List One Integrations",
|
|
114
|
-
description: "List the platforms the user has connected on One. ALWAYS call this tool first in any workflow. Each connection has the kebab-case `platform` name (e.g., 'ship-station', 'shopify') and the `key` (the connectionKey for execute_one_action) you'll need for subsequent tool calls. Each connection carries an `access` field describing what you may run on it: `full`, a set of allowed
|
|
114
|
+
description: "List the platforms the user has connected on One. ALWAYS call this tool first in any workflow. Each connection has the kebab-case `platform` name (e.g., 'ship-station', 'shopify') and the `key` (the connectionKey for execute_one_action) you'll need for subsequent tool calls. Each connection carries an `access` field describing what you may run on it: `full`, a set of allowed access `levels` (`read`, `write`, `delete`), or a specific list of `actions` (each with `actionId`, `title`, `method`). When a connection is action-scoped, its `actions` are exactly what may run, so you need not search.",
|
|
115
115
|
inputSchema: listOneIntegrationsInputSchema,
|
|
116
116
|
outputSchema: listOneIntegrationsOutputSchema,
|
|
117
117
|
annotations: READ_ONLY_ANNOTATIONS
|