�
��?h| � �N � S r SSKJrJrJr SSKJr SSKJr SSK J
r
S\4S jrg )
zX
Console Handler
Handles console session management and command execution in CML labs.
� )�Dict�Any�List)�FastMCP� )�
get_client)�
check_auth�mcpc �� ^� U R 5 S[ S[ S[ [ [ 4 4S j5 nU R 5 S[ S[ S[ [ [ 4 4S j5 nU R 5 S[ S[ S[ S[ [ [ 4 4S j5 mU R 5 S[ S[ S[ [ S[ [ [ 4 4U4S jj5 nU R 5 SS[ S[ S[ S[ [ [ 4 4U4S jjj5 nU R 5 SS[ S
[ [ [ 4 S[ [ [ 4 4S jj5 ng
)z5Register console management tools with the MCP server�lab_id�node_id�returnc � � # � [ 5 nU( a U$ [ 5 R SSU SU S35 I Sh v�N nUR 5 nSSU 3US.$ N! [ a nS S
[ U5 30s SnA$ SnAff = f7f)z�
Open a console session to a node in the lab
Args:
lab_id: ID of the lab
node_id: ID of the node to access
Returns:
Dictionary with session information
�POST�
/api/v0/labs/�/nodes/�/consoleN�successz Console session opened for node )�status�message�session_info�errorzError opening console session: )r r �request�json� Exception�str)r r
�
auth_check�responser �es �UC:\Users\jscon\Documents\Python_Projects\Claude-Modeling-Labs\src\handlers\console.py�open_console_session�4register_console_tools.<locals>.open_console_session s� � � � �\�
���� I�'�\�1�1�&�M�&��QX�Y`�Xa�ai�:j�k�k�H�#�=�=�?�L�#�=�g�Y�G� ,��
� l�� � I��>�s�1�v�h�G�H�H�� I�sD �B�$A �A�A �B�A �
A?�%A:�4A?�5B�:A?�?Bc � �� # � [ 5 nU( a U$ [ 5 R SSU SU S35 I Sh v�N nSSU 3S.$ N! [ a nS S
[ U5 30s SnA$ SnAff = f7f)z�
Close a console session to a node in the lab
Args:
lab_id: ID of the lab
node_id: ID of the node with an open session
Returns:
Dictionary with operation status
�DELETEr r r Nr z Console session closed for node )r r r zError closing console session: )r r r r r )r r
r r r s r �close_console_session�5register_console_tools.<locals>.close_console_session, s� � � � �\�
���� I�'�\�1�1�(�m�F�8�SZ�[b�Zc�ck�<l�m�m�H�#�=�g�Y�G��
� n��
� I��>�s�1�v�h�G�H�H�� I�sD �A1�$A
�A�A
�A1�A
�
A.�A)�#A.�$A1�)A.�.A1�commandc � �& # � [ 5 nU( a U$ [ 5 R SSU SU S3SU0S9I Sh v�N nUR 5 nSUUR S S
5 US.$ N+! [
a nSS
[
U5 30s SnA$ SnAff = f7f)z�
Send a command to a node console
Args:
lab_id: ID of the lab
node_id: ID of the node
command: Command to send
Returns:
Dictionary with command output
r r r z/console/commandr'