Skip to main content
Glama
config.cpython-310.pyc5.3 kB
o 0z�g0�@s�dZddlZddlZddlZddlmZddlmZmZm Z ddddd �d d d �d d d d�ddd�d�Z e� e �Z Gdd�d�Ze�ZdS)z� Configuration module for the persistent-code MCP server. Handles loading and saving configuration settings for: - LlamaIndex integration - Embedding models - Storage settings - Logging levels �N)�Path)�Dict�Any�OptionalTz&sentence-transformers/all-MiniLM-L6-v2i�)�enabled�embedding_model� chunk_sizeZ chunk_overlapF)Z use_sqliteZcompress_storage�INFOZlogs)�levelZ file_loggingZ log_directoryi��)�max_tokens_per_component�similarity_top_k)� llama_index�storage�logging�advancedc @s�eZdZdZddeefdd�Zdeeeffdd�Z dd eeeefddfd d �Z dd ed ededefdd�Z d ed ededdfdd�Z defdd�Z defdd�Zdefdd�Zdefdd�Zdefdd�ZdS)�Configz9Configuration manager for the persistent-code MCP server.N� config_dircCsH|rt|�|_nt��d|_tj|jdd�|jd|_|��|_dS)z�Initialize configuration. Args: config_dir: Directory for configuration files (default: ~/.persistent_code) z.persistent_codeT)�exist_okz config.jsonN)rr�home�os�makedirs� config_file� load_config�config)�selfr�r�Q/Users/sparshdrolia/Sparsh personal/persistent-code-mcp/persistent_code/config.py�__init__-s   zConfig.__init__�returnc Cs|j��rszNt|jd�� }t�|�}Wd�n1swYt�d|j���t��D]"\}}||vr;|||<q.|��D]\}}|||vrO||||<q?q.|WSt yr}zt� d|�d��t� �WYd}~Sd}~wwt�d|j���t� �}|� |�|S)zwLoad configuration from file or create default. Returns: Configuration dictionary �rNzLoaded configuration from zError loading config: z. Using default configuration.z"Creating default configuration at ) r�exists�open�json�load�logger�info�DEFAULT_CONFIG�items� Exception�warning�copy� save_config)r�fr�section�values�key�value�errrrBs0  �   ���� zConfig.load_configrc Cs�|dur|j}z*t|jd��}tj||dd�Wd�n1s!wYt�d|j���WdStyL}zt�d|���WYd}~dSd}~ww)zSave configuration to file. Args: config: Configuration to save (default: current config) N�w�)�indentzSaved configuration to zError saving config: ) rr#rr$�dumpr&r'r*�error)rrr.r3rrrr-cs���zConfig.save_configr/r1�defaultcCs(z|j||WSty|YSw)z�Get a configuration value. Args: section: Configuration section key: Configuration key default: Default value if not found Returns: Configuration value )r�KeyError)rr/r1r9rrr�getss   �z Config.getr2cCs.||jvr i|j|<||j||<|��dS)z�Set a configuration value. Args: section: Configuration section key: Configuration key value: Value to set N)rr-)rr/r1r2rrr�set�s  z Config.setcC�|�ddtdd�S)zgGet the configured embedding model. Returns: Embedding model name rr�r;r(�rrrr�get_embedding_model�� �zConfig.get_embedding_modelcCr=)z{Check if LlamaIndex integration is enabled. Returns: True if enabled, False otherwise rrr>r?rrr�is_llama_index_enabled�rAzConfig.is_llama_index_enabledcCr=)zhGet the configured logging level. Returns: Logging level as string rr r>r?rrr�get_logging_level�rAzConfig.get_logging_levelcCr=)z}Get the number of similar components to retrieve. Returns: Number of similar components rrr>r?rrr�get_similarity_top_k�rAzConfig.get_similarity_top_kcCr=)z{Get the maximum number of tokens per component. Returns: Maximum tokens per component rr r>r?rrr�get_max_tokens_per_component�rAz#Config.get_max_tokens_per_component)N)�__name__� __module__� __qualname__�__doc__r�strrrrrr-r;r<r@�boolrBrC�intrDrErrrrr*s !    r)rIrr$r�pathlibr�typingrrrr(� getLoggerrFr&rrrrrr�<module>s4  �����  

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/sparshdrolia/Persistent-code-mcp'

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