Skip to main content
Glama

qudi MCP Integration

by dirkenglund
qudi_mcp_server.cpython-313.pyc11.5 kB
� �+�h�0��<�SrSSKrSSKrSSKrSSKrSSKrSSKJr SSKJ r J r J r J r J r SSKJr SSKJr SSKJrJr SrS S KJrJr S S KJr S SKJr S SKJ r "SS5r!Sr"\#S:Xa\RH"\""55 gg!\a \"S 5 S rNXf=f)a qudi MCP Server Model Context Protocol server for qudi-iqo-modules integration with Claude Code/Desktop. Enables LLM-driven control of quantum photonics experiments through qudi's modular architecture. Based on instrMCP pattern from https://github.com/caidish/instrMCP �N)�Path)�Any�Dict�List�Optional�Sequence)�Server)� stdio_server)�Tool� TextContentTz=Warning: MCP package not found. Install with: pip install mcpF�)�RunLevel� SafetyChecker)�InstrumentTools)�MeasurementTools)� SafetyToolsc��\rSrSrSrSrS\R4SjrSr S\ S\ \ \ 4S\ \ \ 44S jr S\ \ \ 44S jrS \ S\ \ \ 44S jrS rg)� QudiMCPServer�%zMain qudi MCP Server classc�@�[S5UlUR5Ul[R Ul[5Ul[U5Ul [U5Ul [U5UlSUl0Ul0UlUR%5 g)N�qudi-mcp)r �server�_setup_logging�loggerr�DRY_RUN�runlevelr�safety_checkerr�instrument_toolsr�measurement_toolsr� safety_tools� qudi_station� instruments�measurement_state�_register_handlers��selfs �W/Users/englund/Projects/QPG-MIT/qudi-iqo-modules-QPG/mcp_integration/qudi_mcp_server.py�__init__�QudiMCPServer.__init__(s����Z�(�� ��)�)�+�� � �(�(�� �+�o���!0�� 5���!1�$�!7���'��-���!������!#��� ���!��returnc�J�[R"S5nUR[R5 UR(d\[R "[ R5n[R"S5nURU5 URU5 U$)z Setup logging for the MCP serverrz4%(asctime)s - %(name)s - %(levelname)s - %(message)s) �logging� getLogger�setLevel�INFO�handlers� StreamHandler�sys�stderr� Formatter� setFormatter� addHandler)r&r�handler� formatters r'r�QudiMCPServer._setup_logging:su���"�"�:�.������ � �%�����+�+�C�J�J�7�G��)�)�F��I� � � �� +� � � �g� &�� r*c��^�TRR5S[[4Sj5nTRR 5S[ S[ [[ [4S[4U4Sjj5ng)zRegister MCP handlersr+c ��"# �/nUR[SSS0/S.S9[SSSSS S S .0S/S.S9/5 UR[S S S0/S.S9[SSSSS SS .0S/S.S9[SSSSS SS .0S/S.S9/5 UR[SSS0/S.S9[SSSS SS .SSS .S.SS/S.S9[SSSS S S!S .0S".S9/5 UR[S#S$S0/S.S9[S%S&SS'S /S(QS)S*.0S'/S.S9[S+S,S0/S.S9/5 U$7f)-zList all available MCP tools� station.infoz)Get qudi station configuration and status�object)�type� properties�required)�name� description� inputSchema�station.load_config�Load qudi station configuration� config_path�stringzPath to qudi configuration file)r?rCzinstrument.listz*List available instruments in qudi stationzinstrument.loadz!Load and initialize an instrument�instrument_namezName of instrument to loadzinstrument.get_parametersz,Get instrument parameters and current valueszName of instrumentzmeasurement.list_modulesz"List available measurement moduleszmeasurement.startz-Start a measurement with specified parameterszName of measurement modulezMeasurement parameters)� module_name� parametersrJrKzmeasurement.statusz"Get status of running measurements�measurement_idz5Optional measurement ID to check specific measurement)r?r@zsafety.check_interlocksz-Check all safety interlocks and system statuszsafety.set_runlevelz(Set system runlevel (dry-run, sim, live)r)zdry-run�sim�livezTarget runlevel)r?�enumrCzsystem.emergency_stopz.Emergency stop all operations and measurements)�extendr )�toolss r'�handle_list_tools�;QudiMCPServer._register_handlers.<locals>.handle_list_toolsMs)����E� �L�L��'� K� (�&(�$&�!���.� A� (�)�(0�/P�,�'� &3�O� !� �� �6 �L�L��*� L� (�&(�$&�!���*� C� (�-�(0�/K�0�'� &7�$7� !� ��4� N� (�-�(0�/C�0�'� &7�$7� !� �1&�& �R �L�L��3� D� (�&(�$&�!���,� O� (�)1�/K�,� )1�/G�+� '�&3�L�$A� !��$�-� D� (�,�(0�/f�/�'�!� �9)�) �X �L�L��2� O� (�&(�$&�!���.� J� (�&�(0�(B�/@�)�'�&0�L� !���0� P� (�&(�$&�!��3"�" �H�L�s�D DrB� argumentsc ��># �TRRSUSU35 URS5(a#TRX=(d 05IShv�N nO�URS5(a-TRR X=(d 05IShv�N nO�URS5(a-TR R X=(d 05IShv�N nO`URS5(dURS5(a-TRR X=(d 05IShv�N nOS S U30n[S [R"US S 9S9/$GN N�N�N1![aYnTRRSUSU35 S S[U530n[S [R"US S 9S9/sSnA$SnAff=f7f)zHandle tool callsz Tool called: z with args: zstation.Nz instrument.z measurement.zsafety.zsystem.�errorzUnknown tool: �text�)�indent)r?rWzTool z failed: zTool execution failed: )r�info� startswith�_route_station_toolr� handle_toolrr r �json�dumps� ExceptionrV�str)rBrT�result�e� error_resultr&s �r'�handle_call_tool�:QudiMCPServer._register_handlers.<locals>.handle_call_tool�s�����  [�� � � � �=���l�9�+�!N�O��?�?�:�.�.�#'�#;�#;�D�/�r�#R�R�F��_�_�]�3�3�#'�#8�#8�#D�#D�T�?�XZ�#[�[�F��_�_�^�4�4�#'�#9�#9�#E�#E�d�O�Y[�#\�\�F��_�_�Y�/�/�4�?�?�9�3M�3M�#'�#4�#4�#@�#@���TV�#W�W�F�%���v�'>�?�F�#��d�j�j��PQ�6R�S�T�T�S�[�\�W�� � [�� � �!�!�E�$��y���"<�=� '�+B�3�q�6�(�)K�L� �#��d�j�j��VW�6X�Y�Z�Z�� [�s��G�AE,�E#�AE,�E&�AE,�E(� AE,�8E*�9)E,�"G�#E,�&E,�(E,�*E,�, G�6AG �G�G� G�GN) r� list_toolsrr � call_toolrarrr�CallToolResult)r&rRres` r'r$� QudiMCPServer._register_handlersJs~��� ��� � � !�Y ��d��Y � "�Y �v ��� � � � [�� [�"*�4��S��>�":� [� � [� !� [r*rBrTc��# �US:XaUR5IShv�N $US:XaURUS5IShv�N $SSU30$N-N 7f)zRoute station management toolsr=NrErGrVzUnknown station tool: )�_get_station_info�_load_station_config)r&rBrTs r'r\�!QudiMCPServer._route_station_tools^��� �>� !��/�/�1�1� 1� �*� *��2�2�9�]�3K�L�L� L��5�d�V�<�=� =� 2�L�s�A�A �!A�A � A� Ac��,# �UR[R:XaVSURR[ UR 5[ UR5[ UR5SS.$SURRSSSSS.$7f)z"Get station information and status� dry_run_modez1Running in dry-run mode - no hardware interaction)�statusr�station_loaded�instruments_loaded�active_measurements�message� simulatedFrzqudi station not yet integrated) rrr�value�boolr!�lenr"r#r%s r'rl�QudiMCPServer._get_station_infos���� �=�=�H�,�,� ,�(� �M�M�/�/�"&�t�'8�'8�"9�&)�$�*:�*:�&;�'*�4�+A�+A�'B�N� � �"�� � �+�+�#�"#�#$�8�  � �s�BBrGc���# �[RRU5(dSSU30$UR[R :XaSSU3URR S.$SSU3US.$7f) rFrVzConfiguration file not found: �successz Dry-run: Would load config from )rqrurrvzSimulated loading of )rqrurG)�os�path�existsrrrrw)r&rGs r'rm�"QudiMCPServer._load_station_config&s����w�w�~�~�k�*�*��=�k�]�K�L� L� �=�=�H�,�,� ,�#�=�k�]�K� �M�M�/�/�� �"�.�{�m�<�&� � �s�A0A2) rr"rr#rr!rrr rN)�__name__� __module__� __qualname__�__firstlineno__�__doc__r(r-�Loggerrr$rarrr\rlrm�__static_attributes__�r*r'rr%s���$�"�$����� y[�v>�c�>�d�3��8�n�>�QU�VY�[^�V^�Q_�>� ��c�3�h�� �. �c� �d�3��8�n� r*rc��R# �[(d [S5 g[5n[5IShv�N upURR UUURR 55IShv�N SSS5IShv�N gNTNN !,IShv�N (df  g=f7f)zRun the qudi MCP serverz?ERROR: MCP package not available. Install with: pip install mcpN)� MCP_AVAILABLE�printrr r�run�create_initialization_options)�server_instance� read_stream� write_streams r'�mainr�<sz��� �=� �O�P��#�o�O��~�~�!<�+��$�$�(�(� � � � "� "� @� @� B� � � ��~�~� ��~�~�~�sV�0B'�B�B'�;B �1B �2B �6 B'�B �B'� B � B'� B$�B � B$� B'�__main__)%r��asyncior^r-r}r3�pathlibr�typingrrrrr� mcp.serverr �mcp.server.stdior � mcp.typesr r r�� ImportErrorr��safetyrr�tools.instrument_toolsr�tools.measurement_toolsr�tools.safety_toolsrrr�r�r�r�r*r'�<module>r�s����� �� � ��6�6��!�-�+��M�,�3�5�+�S �S �n �" �z�� �K�K������i �� � I�J��M��s�B�B�B

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/dirkenglund/qudi-mcp-integration'

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