Skip to content

Commit 2218737

Browse files
committed
feat: emit "MCPHubApprovalWindow(Opened/Closed)" events for custom integrations (rel #236)
1 parent a909574 commit 2218737

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

doc/configuration.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,13 +321,14 @@ require("mcphub").setup({
321321
- `params.action` - Either "use_mcp_tool" or "access_mcp_resource"
322322
- `params.uri` - Resource URI (for resource access)
323323
- `params.is_auto_approved_in_server` - Boolean indicating if tool is configured for auto-approval in servers.json
324-
325324
**Return values:**
326325
- `true` - Auto-approve the call
327326
- `false` - Show confirmation prompt
328327
- `string` - Deny with error message
329328
- `nil` - Show confirmation prompt (same as false)
330329

330+
**Events:** When the confirmation window is shown, MCPHub fires `MCPHubApprovalWindowOpened` and `MCPHubApprovalWindowClosed` events that can be used for sound notifications or other integrations.
331+
331332
#### Server-Level Auto-Approval
332333

333334
For fine-grained control per server or tool, configure auto-approval using the `autoApprove` field in your `servers.json`. You can also toggle auto-approval from the Hub UI using the `a` keymap on individual servers or tools. See [servers.json configuration](/mcp/servers_json#auto-approval-configuration) for detailed examples and configuration options.

lua/mcphub/extensions/shared.lua

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,30 @@ function M.show_mcp_tool_prompt(params)
266266
end
267267
end
268268

269-
return require("mcphub.utils.ui").confirm(lines, {
269+
-- Fire event before showing confirmation window
270+
utils.fire("MCPHubApprovalWindowOpened", {
271+
action = action_name,
272+
server_name = server_name,
273+
tool_name = tool_name,
274+
uri = uri,
275+
arguments = arguments,
276+
})
277+
local confirmed, cancelled = require("mcphub.utils.ui").confirm(lines, {
270278
min_width = 70,
271279
max_width = 100,
272280
})
281+
-- Fire event after user makes decision
282+
utils.fire("MCPHubApprovalWindowClosed", {
283+
action = action_name,
284+
server_name = server_name,
285+
tool_name = tool_name,
286+
uri = uri,
287+
arguments = arguments,
288+
confirmed = confirmed,
289+
cancelled = cancelled,
290+
})
291+
292+
return confirmed, cancelled
273293
end
274294

275295
---@param parsed_params MCPHub.ParsedParams

0 commit comments

Comments
 (0)