@@ -36,7 +36,7 @@ function M.get()
3636 url = " " ,
3737 headers = {},
3838 env = {},
39- alwaysAllow = true ,
39+ autoApprove = true ,
4040 }
4141end
4242
@@ -89,99 +89,122 @@ function M.get_all_servers()
8989 return formatted_servers
9090end
9191
92- --- Call a tool via hub.
92+ --- Send result back to proxy.js via notification
93+ --- @param request_id string The request ID to respond to
94+ --- @param result table The result to send
95+ local function send_result (request_id , result )
96+ vim .rpcnotify (0 , " mcphub_proxy_result" , request_id , result )
97+ end
98+
99+ --- Async version of call_tool for proxy (uses nice UI)
100+ --- @param request_id string Request ID for async response
93101--- @param server_name string Name of the server
94102--- @param tool_name string Name of the tool
95103--- @param params table Parameters including arguments and caller context
96- --- @return table Result or error
97- function M .call_tool (server_name , tool_name , params )
98- local mcphub = require (" mcphub" )
99- local hub = mcphub .get_hub_instance ()
100-
101- if not hub or not hub :is_ready () then
102- return { error = " Hub is not ready" }
103- end
104-
105- local arguments = params .arguments or {}
106- local caller = params .caller or { type = " proxy" }
107-
108- -- Handle approval flow (synchronous version for RPC context)
109- local parsed_params = shared .parse_params ({
110- server_name = server_name ,
111- tool_name = tool_name ,
112- tool_input = arguments ,
113- }, " use_mcp_tool" )
114-
115- if # parsed_params .errors > 0 then
116- return { error = table.concat (parsed_params .errors , " \n " ) }
117- end
118-
119- local approval = shared .handle_auto_approval_decision_sync (parsed_params )
120- if approval .error then
121- return { error = approval .error }
122- end
123-
124- local result , err = hub :call_tool (server_name , tool_name , arguments , {
125- parse_response = false ,
126- caller = vim .tbl_extend (" force" , caller , { auto_approve = approval .approve }),
127- })
128-
129- if err then
130- return { error = err }
131- elseif result and result .result then
132- return result .result
133- elseif result then
134- return result
135- end
104+ function M .call_tool (request_id , server_name , tool_name , params )
105+ local async = require (" plenary.async" )
106+
107+ async .run (function ()
108+ local mcphub = require (" mcphub" )
109+ local hub = mcphub .get_hub_instance ()
110+
111+ if not hub or not hub :is_ready () then
112+ send_result (request_id , { error = " Hub is not ready" })
113+ return
114+ end
115+
116+ local arguments = params .arguments or {}
117+ local caller = params .caller or { type = " proxy" }
118+
119+ -- Parse and validate params
120+ local parsed_params = shared .parse_params ({
121+ server_name = server_name ,
122+ tool_name = tool_name ,
123+ tool_input = arguments ,
124+ }, " use_mcp_tool" )
125+
126+ if # parsed_params .errors > 0 then
127+ send_result (request_id , { error = table.concat (parsed_params .errors , " \n " ) })
128+ return
129+ end
130+
131+ -- Use the async approval with nice UI!
132+ local approval = shared .handle_auto_approval_decision (parsed_params )
133+ if approval .error then
134+ send_result (request_id , { error = approval .error })
135+ return
136+ end
137+
138+ local result , err = hub :call_tool (server_name , tool_name , arguments , {
139+ parse_response = false ,
140+ caller = vim .tbl_extend (" force" , caller , { auto_approve = approval .approve }),
141+ })
136142
137- return { error = " No result returned from hub" }
143+ if err then
144+ send_result (request_id , { error = err })
145+ elseif result and result .result then
146+ send_result (request_id , result .result )
147+ elseif result then
148+ send_result (request_id , result )
149+ else
150+ send_result (request_id , { error = " No result returned from hub" })
151+ end
152+ end )
138153end
139154
140- --- Access a resource via hub.
155+ --- Async version of access_resource for proxy (uses nice UI)
156+ --- @param request_id string Request ID for async response
141157--- @param server_name string Name of the server
142158--- @param uri string Resource URI
143159--- @param params ? table Optional parameters including caller context
144- --- @return table Result or error
145- function M .access_resource (server_name , uri , params )
146- params = params or {}
147- local mcphub = require (" mcphub" )
148- local hub = mcphub .get_hub_instance ()
149-
150- if not hub or not hub :is_ready () then
151- return { error = " Hub is not ready" }
152- end
153-
154- local caller = params .caller or { type = " proxy" }
155-
156- -- Handle approval flow (same as codecompanion/avante)
157- local parsed_params = shared .parse_params ({
158- server_name = server_name ,
159- uri = uri ,
160- }, " access_mcp_resource" )
161-
162- if # parsed_params .errors > 0 then
163- return { error = table.concat (parsed_params .errors , " \n " ) }
164- end
165-
166- local approval = shared .handle_auto_approval_decision_sync (parsed_params )
167- if approval .error then
168- return { error = approval .error }
169- end
170-
171- local result , err = hub :access_resource (server_name , uri , {
172- parse_response = false ,
173- caller = vim .tbl_extend (" force" , caller , { auto_approve = approval .approve }),
174- })
175-
176- if err then
177- return { error = err }
178- elseif result and result .result then
179- return result .result
180- elseif result then
181- return result
182- end
160+ function M .access_resource (request_id , server_name , uri , params )
161+ local async = require (" plenary.async" )
162+
163+ async .run (function ()
164+ params = params or {}
165+ local mcphub = require (" mcphub" )
166+ local hub = mcphub .get_hub_instance ()
167+
168+ if not hub or not hub :is_ready () then
169+ send_result (request_id , { error = " Hub is not ready" })
170+ return
171+ end
172+
173+ local caller = params .caller or { type = " proxy" }
174+
175+ -- Parse and validate params
176+ local parsed_params = shared .parse_params ({
177+ server_name = server_name ,
178+ uri = uri ,
179+ }, " access_mcp_resource" )
180+
181+ if # parsed_params .errors > 0 then
182+ send_result (request_id , { error = table.concat (parsed_params .errors , " \n " ) })
183+ return
184+ end
185+
186+ -- Use the async approval with nice UI!
187+ local approval = shared .handle_auto_approval_decision (parsed_params )
188+ if approval .error then
189+ send_result (request_id , { error = approval .error })
190+ return
191+ end
192+
193+ local result , err = hub :access_resource (server_name , uri , {
194+ parse_response = false ,
195+ caller = vim .tbl_extend (" force" , caller , { auto_approve = approval .approve }),
196+ })
183197
184- return { error = " No result returned from hub" }
198+ if err then
199+ send_result (request_id , { error = err })
200+ elseif result and result .result then
201+ send_result (request_id , result .result )
202+ elseif result then
203+ send_result (request_id , result )
204+ else
205+ send_result (request_id , { error = " No result returned from hub" })
206+ end
207+ end )
185208end
186209
187210--- Get a prompt via hub.
0 commit comments