Skip to main content
Glama
config.cpython-312.pyc5.65 kB
� ���h4��V�dZddlZddlmZmZddlmZmZmZGd�de�Z de fd�Z y) z7Configuration management for MCP Background Job Server.�N)�List�Optional)� BaseModel�Field�field_validatorc�B�eZdZUdZedddd��Zeed<edd d d ��Zeed <ed dd��Z e eed<edddd��Z eed<ee d��Z eeed<edd��Zeed<edd��ed���Zed�ed���Zed!d ��Zy )"�BackgroundJobConfigz,Configuration for the background job server.� z!Maximum number of concurrent jobs��d)�default� description�ge�le�max_concurrent_jobsi�z+Maximum output buffer size per job in bytes�i@�max_output_size_bytesNzDefault job timeout in seconds)r rr�default_job_timeouti,z/Cleanup interval for terminated jobs in secondsi�cleanup_interval_secondsz4List of allowed command patterns (empty = allow all))�default_factoryr�allowed_command_patterns�.z#Working directory for job execution)r r�working_directory�before)�modec��t|t�r>|jd�D�cgc]#}|j�s�|j���%c}S|Scc}w)zBSplit comma-separated command patterns from environment variables.�,)� isinstance�str�split�strip)�cls�v�patterns �V/Users/dylan/Workspace/mcp/servers/mcp-background-job/src/mcp_background_job/config.py�split_command_patternsz*BackgroundJobConfig.split_command_patterns(sD�� �a�� �34�7�7�3�<�S�<��7�=�=�?�G�M�M�O�<�S� S����Ts �A�Ac�@�tjj|�std|����tjj |�std|����tj |tj tjz�std|����|S)z2Ensure working directory exists and is accessible.z"Working directory does not exist: z&Working directory is not a directory: z%Working directory is not accessible: )�os�path�exists� ValueError�isdir�access�R_OK�W_OK)r"r#s r%�validate_working_directoryz.BackgroundJobConfig.validate_working_directory0s}���w�w�~�~�a� ��A�!��E�F� F��w�w�}�}�Q���E�a�S�I�J� J��y�y��B�G�G�b�g�g�-�.��D�Q�C�H�I� I���c��i}tjd�x}rt|�|d<tjd�x}rE|j�j d�rt|dd�dzdz|d<nt|�|d<tjd �x}rt|�|d <tjd �x}rt|�|d <tjd �x}r||d<tjd�x}r||d<|di|��S)a�Load configuration from environment variables. Environment variables: - MCP_BG_MAX_JOBS: Maximum concurrent jobs - MCP_BG_MAX_OUTPUT_SIZE: Maximum output buffer size (supports MB suffix) - MCP_BG_JOB_TIMEOUT: Default job timeout in seconds - MCP_BG_CLEANUP_INTERVAL: Cleanup interval in seconds - MCP_BG_ALLOWED_COMMANDS: Comma-separated allowed command patterns - MCP_BG_WORKING_DIR: Working directory for job execution �MCP_BG_MAX_JOBSr�MCP_BG_MAX_OUTPUT_SIZE�MBN�����rr�MCP_BG_JOB_TIMEOUTr�MCP_BG_CLEANUP_INTERVALr�MCP_BG_ALLOWED_COMMANDSr�MCP_BG_WORKING_DIRr�)r(�getenv�int�upper�endswith)r"� config_data�max_jobs� max_output� job_timeout�cleanup_interval�allowed_commands� working_dirs r%�from_environmentz$BackgroundJobConfig.from_environment<s4��� ��y�y�!2�3� 3�8� 3�14�X��K�-� .����#;�<� <�:� <����!�*�*�4�0�� �3�B��(�4�/�$�6��3�4�8;�:�� �3�4��)�)�$8�9� 9�;� 9�14�[�1A�K�-� .� "�y�y�)B�C� C� � C�69�:J�6K�K�2� 3� "�y�y�)B�C� C� � C�6F�K�2� 3��)�)�$8�9� 9�;� 9�/:�K�+� ,��!�[�!�!r1)�returnr )�__name__� __module__� __qualname__�__doc__rrr=�__annotations__rrrr�listrrrrr� classmethodr&r0rGr;r1r%r r s��6�$�� C��c� ����"'� �A� � � "��3�� */��4� �*���#��� %*��E� � � %��c�� +0��J�+��d�3�i��#��!F���s���/�h�?����@�� �(�)����*���*"��*"r1r rHc��� tj�S#t$rI}ddl}t d|��|j ��t d|j ��t�cYd}~Sd}~wwxYw)zHLoad configuration from environment variables with fallback to defaults.rNz8Warning: Failed to load configuration from environment: )�filezUsing default configuration)r rG� Exception�sys�print�stderr)�erSs r%� load_configrWjs\�� %�"�3�3�5�5�� � %�� �F�q�c� J���� � �+�#�*�*�=�"�$�$�� %�s�� A(�>A#�A(�#A() rLr(�typingrr�pydanticrrrr rWr;r1r%�<module>rZs0��=� �!�6�6�^"�)�^"�B %�(� %r1

Latest Blog Posts

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/dylan-gluck/mcp-background-job'

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