Skip to main content
Glama

MCP Agent Platform

server.cpython-310.pyc3.13 kB
o ��g;�@sFddlmZmZmZddlmZddlmZddlm Z ddlm Z ddl Z ddl Z ddl Z e�Ze j�e j�e��Ze j�e j�e j�e���Ze j�edd�Ze jed d �e j�edd �Ze jed d �ejd eed �dd�eed �Ze�Zd ae�d�dd��Ze�d�dd��Z e�!d�defdd��Z"de#fdd�Z$dS)�)�FastAPI� WebSocket�WebSocketDisconnect)�Jinja2Templates)� StaticFiles)� HTMLResponse)�RequestNZmcpTest�staticT)�exist_ok� templatesz/static)� directory)�name�startupc���datd�dS)NTzWeb server started��server_running�print�rr�.D:\DeepSeek\MCPAgent\mcpTest\src\web\server.py� startup_event!�� r�shutdownc�r)NFzWeb server shutting downrrrrr�shutdown_event'rrz/ws� websocketc �s �|��IdHt�|�tdtt����z�z�|�t�ddd���IdH z�|��IdH}t� |�}td|���|� d�dkr�z7d d l m }|red|d di|d |d dd�}|� |�IdHntd�ddddid�}t|�IdHWn-ty�}z!td|���ddddt|���id�}t|�IdHWYd}~nd}~wwWnty�}z td|���WYd}~nd}~wwq'Wnty�}z td|���WYd}~nd}~wwW|tvr�t�|�tdtt����dS|tvr�t�|�tdtt����w)Nu,WebSocket连接已建立,当前连接数: �status� connected)�type�contentTu收到客户端消息: r�textr)�brain_instancer� sender_id� receiver_id)rr r!� message_typeu未找到大脑智能体实例Zchat�systemu-大脑智能体未启动,无法处理消息)rr ru处理大脑消息时出错: u处理消息时出错: u 处理WebSocket消息时出错: uWebSocket错误: u,WebSocket连接已关闭,剩余连接数: )�accept�websocket_connections�addr�len� send_text�json�dumps� receive_text�loads�getZsrc.brain.brain_agentrZ_handle_text_message�broadcast_message� Exception�str�remove)r�data�messagerZ brain_message� error_message�errr�websocket_endpoint.sz� �  ���������  ���2��� � r6r3c �s��tsdSd}tt�D]3}z|�t�|��IdHd}Wq ty>}ztd|���|tvr4t�|�WYd}~q d}~ww|S)u$广播消息到所有WebSocket连接FNTu发送消息失败: )r%�listr(r)r*r/rr1)r3Zsuccess� connectionr5rrrr.ws�  ��r.)%�fastapirrr�fastapi.templatingr�fastapi.staticfilesr�fastapi.responsesrr�asyncior)�os�app�path�dirname�abspath�__file__� current_dir�base_dir�join� static_dir�makedirs� templates_dir�mountr �setr%r�on_eventrrrr6�dictr.rrrr�<module>s4       H

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/rolenet/McpAgentRobot'

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