@hibira-io/mcp-approval-gate 0.1.0 → 0.2.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 CHANGED
@@ -1,6 +1,16 @@
1
1
  # Changelog
2
2
 
3
- ## 0.1.0 (unreleased)
3
+ ## 0.2.0
4
+
5
+ - The assistant no longer gets the approval link when the request reaches a
6
+ supervisor by push (`--push-interests`, `--push-users`) or a channel
7
+ (`--channel`), so the person in the chat cannot approve their own change.
8
+ Without either, the link is still shown so you can forward it.
9
+ `--show-link auto|always|never` (`GATE_SHOW_LINK`) controls this.
10
+ - New demo and screenshots: the request reaches the store manager's phone and
11
+ the assistant continues once she approves.
12
+
13
+ ## 0.1.0
4
14
 
5
15
  - First release: an MCP proxy that puts supervisor approval in front of any
6
16
  database MCP server. Reads pass through; writes, schema changes and other
package/README.md CHANGED
@@ -8,7 +8,7 @@ as approved.
8
8
 
9
9
  ![An assistant asks to update an order; the change waits until a supervisor approves it on their phone, then runs once](https://raw.githubusercontent.com/hibira-io/mcp-approval-gate/main/docs/demo.gif)
10
10
 
11
- <sub>A real session: Claude Code asks to mark order 1042 as refunded through DBHub. The `UPDATE` waits, the supervisor approves it on the Hibira page, and the assistant finishes the change. ([MP4](https://raw.githubusercontent.com/hibira-io/mcp-approval-gate/main/docs/demo.mp4))</sub>
11
+ <sub>A real session: Claude Code asks to mark order 1042 as refunded through DBHub. The `UPDATE` waits and the assistant never gets the approval link. The store manager's phone gets the request, she approves it, and the assistant finishes the change. ([MP4](https://raw.githubusercontent.com/hibira-io/mcp-approval-gate/main/docs/demo.mp4))</sub>
12
12
 
13
13
  It works with any MCP server, and is tested with:
14
14
 
@@ -48,17 +48,19 @@ front of them.
48
48
  changes every row", and the full statement.
49
49
 
50
50
  <p>
51
- <img src="https://raw.githubusercontent.com/hibira-io/mcp-approval-gate/main/docs/approval-page.png" width="260" alt="The approval page on a phone: UPDATE on shop-production, with the statement, fingerprint and Approve / Reject buttons">
52
- <img src="https://raw.githubusercontent.com/hibira-io/mcp-approval-gate/main/docs/approval-approved.png" width="260" alt="The same request after the supervisor approved it">
51
+ <img src="https://raw.githubusercontent.com/hibira-io/mcp-approval-gate/main/docs/supervisor-notification.png" width="240" alt="The supervisor's phone gets the request: UPDATE on shop-production">
52
+ <img src="https://raw.githubusercontent.com/hibira-io/mcp-approval-gate/main/docs/approval-page.png" width="240" alt="The approval page: database, kind of change, the full statement and its fingerprint">
53
+ <img src="https://raw.githubusercontent.com/hibira-io/mcp-approval-gate/main/docs/approval-approved.png" width="240" alt="The same request after the supervisor approved it">
53
54
  </p>
54
55
 
55
56
  ## Setup
56
57
 
57
58
  1. Sign in at [hibira.io](https://hibira.io), create an app (Free works), and
58
59
  copy its **App ID, Key and Secret**.
59
- 2. Optional: turn on Push for the app and subscribe the supervisors' devices to
60
- an interest such as `db-approvals`, so requests reach their phones. Without
61
- push, the assistant shows the approval link and you share it.
60
+ 2. Turn on Push for the app and subscribe the supervisors' devices to an
61
+ interest such as `db-approvals`, so requests reach their phones (or pass
62
+ `--channel` to show them in your own approvals inbox). Without either, the
63
+ assistant shows the approval link and you forward it to a supervisor.
62
64
  3. Put the gate in front of your database MCP server in your client's config
63
65
  (below). Everything after `--` is the database server's usual command.
64
66
 
@@ -166,10 +168,18 @@ progress updates so the client does not give up early:
166
168
  saying it was approved.
167
169
  - **Rejected or expired:** an error saying it did not run, with the
168
170
  supervisor's comment if they left one.
169
- - **Still waiting:** a short answer with the approval link and `approval_id`.
170
- The gate adds one tool, `check_approval`: when the person says it is
171
- decided, the assistant calls it with that `approval_id`, and the call runs if
172
- it was approved. Asking for the same call again reuses the same request.
171
+ - **Still waiting:** a short answer saying a supervisor has to approve it,
172
+ with an `approval_id`. The gate adds one tool, `check_approval`: when the
173
+ person says it is decided, the assistant calls it with that `approval_id`,
174
+ and the call runs if it was approved. Asking for the same call again reuses
175
+ the same request.
176
+
177
+ **The assistant does not get the approval link** when the request reaches
178
+ the supervisor another way (`--push-interests`, `--push-users` or
179
+ `--channel`), so the person chatting with it cannot approve their own change
180
+ from the chat. Without any of those, the link is the only way to reach a
181
+ supervisor, so the assistant shows it for you to forward. `--show-link always`
182
+ or `never` overrides this.
173
183
 
174
184
  ## What waits for approval
175
185
 
@@ -207,6 +217,7 @@ user only the rights it needs too.
207
217
  | `--push-interests` | `GATE_PUSH_INTERESTS` | | push the request to these interests |
208
218
  | `--push-users` | `GATE_PUSH_USERS` | | ...or to these user ids |
209
219
  | `--channel` | `GATE_CHANNEL` | | also announce requests on this channel, e.g. for an [approvals inbox](https://github.com/hibira-io/approvals) |
220
+ | `--show-link` | `GATE_SHOW_LINK` | `auto` | give the assistant the approval link: `auto` (only without push or a channel), `always`, `never` |
210
221
  | `--options` | `GATE_OPTIONS` | `Approve,Reject` | answer buttons; the first one approves |
211
222
  | `--wait` | `GATE_WAIT_SECONDS` | `50` | how long a call waits before answering "still waiting" |
212
223
  | `--expires` | `GATE_EXPIRES_MINUTES` | `60` | how long a request stays open (up to 7 days) |
@@ -240,6 +251,7 @@ MIT
240
251
  `@hibira-io/mcp-approval-gate` 套在任何数据库 MCP server(DBHub、postgres-mcp、Supabase MCP 等)外面:**读取直接通过;写入、改表、删除会先停下,等另一个人(主管)在 Hibira 托管的审批页或手机推播上核准**,核准后只按原样执行一次。
241
252
 
242
253
  - 审批绑定这一次调用的完整参数(附指纹),SQL 改了就要重新审批。
254
+ - 设定了推播或频道时,助手拿不到审批链接,只有收到推播的主管能核准。
243
255
  - 看不懂的 SQL、不确定是否只读的工具一律要审批;审批服务连不上就不执行。
244
256
  - Gate 跑在你自己的环境,Hibira 只经手审批内容,不碰数据库密码,也看不到查询结果。
245
257
  - Claude(Desktop / Code / claude.ai)、Cursor、ChatGPT 都能用;网页端用 `--http` 加 `GATE_TOKEN`。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hibira-io/mcp-approval-gate",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "mcpName": "io.hibira/mcp-approval-gate",
5
5
  "description": "Supervisor approval for database MCP servers: wrap DBHub, postgres-mcp or Supabase MCP so reads pass through and writes wait for another person to approve them on a hosted page, with push",
6
6
  "keywords": [
package/src/cli.js CHANGED
@@ -34,6 +34,8 @@ Options (each also as an env var, shown in brackets):
34
34
  --push-users <list> ...or to these user ids [GATE_PUSH_USERS]
35
35
  --channel <name> also announce requests on this channel (approvals inbox) [GATE_CHANNEL]
36
36
  --options <a,b> answer buttons, first one approves (default Approve,Reject) [GATE_OPTIONS]
37
+ --show-link <auto|always|never> give the assistant the approval link; auto (default) only when
38
+ no push or channel delivers it to the supervisor [GATE_SHOW_LINK]
37
39
  --wait <seconds> how long a call waits before answering "pending" (default 50) [GATE_WAIT_SECONDS]
38
40
  --expires <minutes> how long a request stays open (default 60) [GATE_EXPIRES_MINUTES]
39
41
  --upstream-url <url> remote MCP server to wrap [GATE_UPSTREAM_URL]
@@ -89,7 +91,7 @@ export function parse(argv, env) {
89
91
  options: {
90
92
  label: { type: 'string' }, mode: { type: 'string' }, allow: { type: 'string' }, gate: { type: 'string' },
91
93
  'push-interests': { type: 'string' }, 'push-users': { type: 'string' }, channel: { type: 'string' },
92
- options: { type: 'string' }, wait: { type: 'string' }, expires: { type: 'string' },
94
+ options: { type: 'string' }, wait: { type: 'string' }, expires: { type: 'string' }, 'show-link': { type: 'string' },
93
95
  'upstream-url': { type: 'string' }, header: { type: 'string', multiple: true },
94
96
  http: { type: 'boolean' }, port: { type: 'string' }, host: { type: 'string' },
95
97
  version: { type: 'boolean' }, help: { type: 'boolean', short: 'h' },
@@ -127,11 +129,13 @@ export function parse(argv, env) {
127
129
  options: list(values.options ?? env.GATE_OPTIONS),
128
130
  waitSeconds: num(values.wait ?? env.GATE_WAIT_SECONDS, 50, '--wait', 0, 3600),
129
131
  expiresMinutes: num(values.expires ?? env.GATE_EXPIRES_MINUTES, 60, '--expires', 1, 10080),
132
+ showLink: values['show-link'] ?? env.GATE_SHOW_LINK ?? 'auto',
130
133
  http: values.http ?? false,
131
134
  port: num(values.port ?? env.PORT, 8787, '--port', 1, 65535),
132
135
  host: values.host ?? env.GATE_HOST ?? '127.0.0.1',
133
136
  token: env.GATE_TOKEN,
134
137
  };
138
+ if (!['auto', 'always', 'never'].includes(opts.showLink)) throw new Error('--show-link must be auto, always or never');
135
139
  if (opts.pushInterests.length && opts.pushUsers.length) throw new Error('give --push-interests or --push-users, not both');
136
140
  if (!opts.help && !opts.version && !opts.command.length && !opts.upstreamUrl) {
137
141
  throw new Error('give the database MCP server to wrap after -- (or in GATE_COMMAND), or --upstream-url');
package/src/gate.js CHANGED
@@ -16,7 +16,7 @@ import {
16
16
  } from '@modelcontextprotocol/sdk/types.js';
17
17
  import { decide, fingerprint } from './policy.js';
18
18
 
19
- export const VERSION = '0.1.0';
19
+ export const VERSION = '0.2.0';
20
20
  const DETAILS_MAX = 4000;
21
21
 
22
22
  export class Gate {
@@ -51,6 +51,7 @@ export class Gate {
51
51
  this.channel = opts.channel;
52
52
  this.options = opts.options;
53
53
  this.upstreamTimeoutMs = opts.upstreamTimeoutMs ?? 300_000;
54
+ this.showLink = opts.showLink ?? 'auto';
54
55
  this.log = opts.log ?? (() => {});
55
56
  /** fingerprint -> pending call */
56
57
  this.pending = new Map();
@@ -99,7 +100,7 @@ export class Gate {
99
100
  #instructions() {
100
101
  const up = this.upstream.getInstructions?.();
101
102
  const own = `Calls that change the ${this.label} (writes, schema changes, deletes) wait for a supervisor's approval before they run. ` +
102
- `If a call answers that it is waiting, give the person the approval link, and call ${this.checkTool} with the approval_id when they say it is decided. ` +
103
+ `If a call answers that it is waiting, tell the person it waits for a supervisor (share the approval link only if the answer includes one), and call ${this.checkTool} with the approval_id when they say it is decided. ` +
103
104
  'Do not rewrite a declined statement to get around the decision.';
104
105
  return up ? `${up}\n\n${own}` : own;
105
106
  }
@@ -168,14 +169,25 @@ export class Gate {
168
169
  return errorResult(`Could not ask for approval, so nothing ran: ${err.message}`);
169
170
  }
170
171
  entry = { id: created.approval_id, url: created.url, name, args, fp, expiresAt: created.expires_at, pushError: created.push_error };
172
+ entry.showLink = this.#linkVisible(entry);
171
173
  this.pending.set(fp, entry);
172
174
  this.byId.set(entry.id, fp);
173
175
  this.log(`approval ${entry.id} requested for ${name} (${d.reason}): ${entry.url}`);
174
176
  }
175
- await notify(server, extra, `Waiting for supervisor approval: ${entry.url}`);
177
+ await notify(server, extra, entry.showLink ? `Waiting for supervisor approval: ${entry.url}` : 'Waiting for supervisor approval');
176
178
  return this.#await(entry, this.waitSeconds, extra);
177
179
  }
178
180
 
181
+ // The link goes back to the assistant only when nothing else delivers it:
182
+ // with push or a channel, the supervisor gets it and the requester never
183
+ // sees it, so they cannot approve their own change.
184
+ #linkVisible(entry) {
185
+ if (this.showLink === 'always') return true;
186
+ if (this.showLink === 'never') return false;
187
+ const pushed = (this.pushInterests.length || this.pushUsers.length) && !entry.pushError;
188
+ return !(pushed || this.channel);
189
+ }
190
+
179
191
  #approvalBody(name, args, d, fp) {
180
192
  const sql = d.sql;
181
193
  const what = sql?.kinds?.length ? sql.kinds.join(', ') : name;
@@ -297,14 +309,19 @@ function otherArgs(args) {
297
309
  }
298
310
 
299
311
  function pendingResult(entry, checkTool) {
300
- const text = [
312
+ const text = entry.showLink ? [
301
313
  'Waiting for a supervisor to approve this call. Nothing has run yet.',
302
314
  `Approval link: ${entry.url}`,
303
315
  `approval_id: ${entry.id}`,
304
316
  entry.pushError ? `(The push notification failed: ${entry.pushError}. Share the link instead.)` : '',
305
- `Give the person the link. When they say it is decided, call ${checkTool} with this approval_id; it runs the call if it was approved.`,
306
- ].filter(Boolean).join('\n');
307
- return { content: [{ type: 'text', text }], _meta: { 'io.hibira/approval': { approval_id: entry.id, url: entry.url, status: 'pending' } } };
317
+ `Give the link to the person who approves. When they have decided, call ${checkTool} with this approval_id; it runs the call if it was approved.`,
318
+ ].filter(Boolean).join('\n') : [
319
+ 'A supervisor has been notified and must approve this call. Nothing has run yet.',
320
+ `approval_id: ${entry.id}`,
321
+ `When the person says it is decided, call ${checkTool} with this approval_id; it runs the call if it was approved.`,
322
+ ].join('\n');
323
+ const meta = { approval_id: entry.id, status: 'pending', ...(entry.showLink ? { url: entry.url } : {}) };
324
+ return { content: [{ type: 'text', text }], _meta: { 'io.hibira/approval': meta } };
308
325
  }
309
326
 
310
327
  function errorResult(text) {