bluetooth_mcp_server.cpython-311.pyc•3.64 kB
�
G�ge
� �" � d dl mZmZ d dlZd dlmZmZmZmZ d dl Z d dl
mZ e� � d dlm
Z
ed� � Z e j dd� � Z e e j d d
� � � � Z e j dd� � � � � dk Ze� � � edefd
edee dedeeef fd�� � Ze� d� � dedeeef fd�� � Zedk re� � � dS dS )� )�FastMCP�ContextN)�List�Dict�Any�Optional)�load_dotenv)�
BluetoothToolzBluetooth MCP Server�BLUETOOTH_API_URLzhttp://localhost:8000�BLUETOOTH_SCAN_DURATIONz5.0�BLUETOOTH_INCLUDE_CLASSIC�true�duration�filter_name�include_classic�returnc � � | ||d�}t j t � d�|�� � }|� � � |� � � S # t j $ r,}dt
|� � � �t
|� � d�cY d}~S d}~ww xY w)u*
Effectue un scan des appareils Bluetooth à proximité.
Args:
duration: Durée du scan en secondes
filter_name: Nom de l'appareil à filtrer
include_classic: Inclure les appareils Bluetooth classiques
Returns:
Résultats du scan Bluetooth
)r r r z/mcp/v1/tools/bluetooth-scan)�jsonzBluetooth scan failed: ��error�detailsN)�requests�postr �raise_for_statusr �RequestException�str)r r r �scan_params�response�es �3F:\DEV\bluetooth-mcp-server\bluetooth_mcp_server.py�bluetooth_scanr! s� � �"
� !�&�.�
�
�� �=�$5�!S�!S�!S�Ze�f�f�f���!�!�#�#�#��}�}������$�
�
�
�7�s�1�v�v�7�7��1�v�v�
�
�
�
�
�
�
�
�����
���s �AA �B �!B�>B �B zbluetooth://{device_id}� device_idc � � t j t � d| � �� � }|� � � |� � � S # t j $ r,}dt
|� � � �t
|� � d�cY d}~S d}~ww xY w)u�
Récupère les informations détaillées d'un appareil Bluetooth spécifique.
Args:
device_id: Identifiant de l'appareil Bluetooth
Returns:
Informations détaillées de l'appareil
z/mcp/v1/devices/z Could not retrieve device info: r N)r �getr r r r r )r"