Skip to main content
Glama

xigua-MCP

by xiguaxiaome
system.cpython-310.pyc6.6 kB
o &EhB!�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z e�d�ZejdkrLejjdd�ejjdd�dd �Zd e fd d �ZdS) �N)�Path)�FastMCPZ system_tools�win32�utf-8��encodingcCs t��dS)u!获取当前用户的桌面路径ZDesktop)r�home�r r �E:\xiaozhi-mcp\tools\system.py�get_desktop_paths r �mcpcCs�|��dtfdd��}|��ddtdtdtfdd��}|��d tdtfd d ��}|��d tdtfd d ��}|��dtfdd��}|��dtfdd��}|��dtdtfdd��}dS)N�returnc Ss�zUtjdd�}t��}t��}|jd}|jd}|j}t�d�}|jd}|jd}|j} t��} d||d�t |d�t |d�|d�t |d�t |d�| d�d | id �d �WSt yx} zt � d t | ����d t | �d�WYd} ~ Sd} ~ ww)u� 获取服务器状态监控信息。 返回: - 包含CPU、内存、磁盘等使用情况的字典 �)�intervali@�/T)� usage_percentZ core_count�)Ztotal_gbZused_gbr� boot_time)Zcpu�memory�disk�system)�success�resultu获取服务器状态失败: F�r�errorN)�psutil� cpu_percent� cpu_countZvirtual_memory�total�used�percent� disk_usager�round� Exception�loggerr�str) rrrZ memory_totalZ memory_usedZmemory_percentrZ disk_totalZ disk_usedZ disk_percentr�er r r �get_server_statussF      ���������z0register_system_tools.<locals>.get_server_status��text�filenamec Ss2zu|r?t�}||}t|ddd�� }|�|�Wd�n1s!wYt�dt|�g�t�d|���dt|�d�WStj ddd d d d ��}|�|�|j }Wd�n1s\wYt�d|g�t�d |���d|d�WSt y�}zt� dt|����d t|�d�WYd}~Sd}~ww)aM Open Notepad with text and optionally save to a specific file. Args: text: The text to display in Notepad filename: If provided, save to this file on desktop (e.g., "poem.txt") Returns: dict: {"success": bool, "filepath": str (if saved), "error": str (if failed)} �wrrN� notepad.exezOpened Notepad with file: T)r�filepathz.txtFZnotepad_)�moder�suffix�delete�prefixz$Opened Notepad with temporary file: z"Failed to open Notepad with text: r) r �open�write� subprocess�Popenr%r$�info�tempfile�NamedTemporaryFile�namer#r)r)r*Zdesktopr-�fZ temp_pathr&r r r �open_notepad_with_textVs:  �� �  ��z5register_system_tools.<locals>.open_notepad_with_text� program_namec Ss�ddddddddd d � }|��}||vrd d |��d �Sz"|dkr+tj|ddd�nt�||�t�d|���ddiWStyd}zt�d|�dt|����d t|�d �WYd}~Sd}~ww)uw Open common Windows programs. Supported programs: - 'notepad' (记事本) - 'explorer' (文件资源管理器) - 'cmd' (命令提示符) - 'calculator' (计算器) - 'control' (控制面板) - 'taskmgr' (任务管理器) - 'mspaint' (画图) - 'wordpad' (写字板) - 'wechat' (微信) r,z explorer.exezcmd.exezcalc.exez control.exez taskmgr.exe� mspaint.exe� write.exez"D:\\WeChat\\WeChat.exe") �notepadZexplorer�cmd� calculatorZcontrolZtaskmgr�mspaint�wordpad�wechatF�Unsupported program: rrDT)�shellzSuccessfully opened rzFailed to open �: N)�lowerr4r5r$r6r#rr%)r<Zprograms�program_name_lowerr&r r r � open_program|s0�  ��z+register_system_tools.<locals>.open_programc Ss�dddddd�}|��}||vrdd|��d �Sz%||}t�d g�D] }|jd |kr0|��q#t�d |���d d iWStyc}zt�d|�dt|����dt|�d �WYd}~Sd}~ww)z� Close a running program by its process name. Supported programs: 'calculator', 'notepad', 'mspaint', etc. zCalculator.exer,r=r>z WeChat.exe)rAr?rBrCrDFrErr9zSuccessfully closed rTzFailed to close rGN) rHrZ process_iterr6�killr$r#rr%)r<Z process_namesrIZ process_name�procr&r r r � close_program�s,�� ��z,register_system_tools.<locals>.close_programc Sshzt�dd�t�d�ddiWSty3}zt�dt|����dt|�d�WYd }~Sd }~ww) z<Minimize all windows to show the desktop (Win+D equivalent).�win�dzShowing desktoprTzFailed to show desktop: FrN)� pyautoguiZhotkeyr$r6r#rr%�r&r r r � show_desktop�s   ��z+register_system_tools.<locals>.show_desktopc Ssfzt�d�t�d�ddiWSty2}zt�dt|����dt|�d�WYd}~Sd}~ww) z$Lock the Windows screen immediately.z'rundll32.exe user32.dll,LockWorkStationzScreen locked successfullyrTzFailed to lock screen: FrN��osrr$r6r#rr%rQr r r � lock_screen�s   ��z*register_system_tools.<locals>.lock_screen�commandc Ssxzt�d|���t�d|���ddiWSty;}zt�d|�dt|����dt|�d�WYd }~Sd }~ww) z� Run a Windows command or open a specific file/path. Examples: - 'C:\Program Files\MyApp\app.exe' - 'shell:startup' (opens the startup folder) - 'ms-settings:' (opens Windows settings) zstart zExecuted command: rTzFailed to execute command rGFrNrS)rVr&r r r � run_command�s  ��z*register_system_tools.<locals>.run_command)r(N)�tool�dictr%)r r'r;rJrMrRrUrWr r r �register_system_toolss7%)  rZ)�logging�requestsrrT�sysr4Z webbrowserr7�timerP�pathlibr�mcp.server.fastmcpr� getLoggerr$�platform�stderr� reconfigure�stdoutr rZr r r r �<module>s$    

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/xiguaxiaome/xigua-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server