
    sj                         d Z ddlZddlmZmZ ddlmZmZ dZ	 	 	 	 dde	d	e	d
e	dee         de	f
dZ
dddddddg ddddddddgddZ ej        dded d           dS )u  Propose an MCP server to the user as an inline card in the desktop chat.

The card (install / enable / authorize + decline) lives in the desktop
renderer, so this tool round-trips through the gateway's blocking-prompt
bridge — the same one ``clarify`` uses: tui_gateway emits
``mcp.setup.request``, the renderer walks the user through the flow via the
existing REST endpoints (catalog install, enable, OAuth), and answers with
``mcp.setup.respond`` once the flow settles. This module is just schema + a
thin dispatcher over the platform-injected callback.

Lives in the ``desktop_ui`` toolset, which the GUI gateway enables only for
desktop-sourced sessions — on every other surface the agent falls back to
``hermes mcp install <name>`` in the terminal.
    N)CallableOptional)registry
tool_error)installenable	authorize r   serveractionreasoncallbackreturnc                    |t          d          S | pd                                }|st          d          S |pd                                                                }|t          vr+t          dd                    t                     d          S 	  ||||pd                                          }n)# t
          $ r}t          d	|           cY d}~S d}~ww xY w|st          j        d
|ddd          S 	 t          j        t          j        |          d          S # t          t          f$ r) t          j        dt          |          dd          cY S w xY w)zFAsk the desktop GUI to run an MCP setup flow; return its JSON outcome.Nzsetup_mcp is only available in the Hermes desktop app. Use the terminal instead: `hermes mcp install <name>` for catalog entries, `hermes mcp login <name>` for OAuth.r
   uD   server is required — the catalog or config name of the MCP server.r   zaction must be one of z, .zMCP setup flow failed: 
unansweredzqThe user did not respond to the setup card. Do not retry immediately; continue without the server or ask in chat.)statusr   noteF)ensure_asciierror)r   detail)r   striplower_ACTIONSjoin	Exceptionjsondumpsloads	TypeError
ValueErrorstr)r   r   r   r   namerawexcs          8/home/agent/.hermes/hermes-agent/tools/setup_mcp_tool.pysetup_mcp_toolr'      s    3
 
 	
 Lb!!D b`aaa!	((**0022FXI499X3F3FIIIJJJ;htVfl%9%9%;%;<< ; ; ;9C99::::::::;  
 z&O	  

 

 

 
	
Wz$*S//>>>>z" W W WzWCAAPUVVVVVVWs0   !B8 8
CCCC>'D& &7E E 	setup_mcpu  Propose an MCP server to the user as an inline consent card in the Hermes desktop chat. The card lets them install a catalog entry, re-enable a disabled server, or run an OAuth login — right there, without opening the Capabilities tab — and blocks until they act or decline. Use when the user asks to add/set up an MCP (e.g. "add the linear mcp"), or when a task clearly needs one that is missing or unauthorized. Never call it twice for the same server after a decline. Returns JSON {status: installed|enabled|authorized|declined|unanswered|error, server, detail?, tools?}. On declined/unanswered, continue without the server. Catalog names: run `hermes mcp catalog` in the terminal to list them.objectstringzaThe server's catalog name (for install) or its name in mcp_servers config (for enable/authorize).)typedescriptionzinstall: add a catalog entry (prompts for any required keys). enable: re-enable a disabled configured server. authorize: run the OAuth browser flow for a configured server. Defaults to install.)r+   enumr,   zrOne short sentence shown on the card: why this server helps right now (e.g. "To read the JIRA ticket you linked").)r   r   r   )r+   
propertiesrequired)r#   r,   
parameters
desktop_uic                     t          |                     dd          |                     dd          |                     dd          |                    d                    S )Nr   r
   r   r   r   r   )r   r   r   r   )r'   get)argskws     r&   <lambda>r6      sW    ~xx"%%xx),,xx"%%
##	          u   🔌)r#   toolsetschemahandleremoji)r
   r   r
   N)__doc__r   typingr   r   tools.registryr   r   r   r"   r'   SETUP_MCP_SCHEMAregister r7   r&   <module>rB      sr     % % % % % % % % / / / / / / / /- #'	.W .W.W.W .W x 	.W
 	.W .W .W .Wd 
	(  !A  !:::3		 	 !! %
 
6 J; . . b  	       r7   