Xj dZddlZddlZddlZddlZddlmZddlmZddl m Z e e Z dZ dedzfdZdefd Zdddd d ed ed edzdeedzdeeefdzdef dZy)z!Claude app integration utilities.N)Path)Any) get_loggerzmcp[cli]returnctjdk(r!ttjddd}ntjdk(r!ttjddd}n`tjj dr@tt j jd tjd z d}ny |jr|Sy ) z2Get the Claude config directory based on platform.win32AppDataRoamingClaudedarwinLibraryzApplication SupportlinuxXDG_CONFIG_HOMEz.configN) sysplatformrhome startswithosenvirongetexists)paths b/mnt/ssd/data/Dropbox/adrian/vault-secondbrain/venv/lib/python3.12/site-packages/mcp/cli/claude.pyget_claude_config_pathrs ||wDIIKIx@  !DIIK,A8L   )BJJNN#4diikI6MNPXY {{} c`tjd}|stjdy|S)z'Get the full path to the uv executable.uvzeuv executable not found in PATH, falling back to 'uv'. Please ensure uv is installed and in your PATH)shutilwhichloggererror)uv_paths r get_uv_pathr#!s,ll4 G  s  Nr) with_editable with_packagesenv_vars file_spec server_namer$r%r&cht}t}|s td|dz }|js |j d tj|j}d|vri|d<||dvr d |d|vr|d|d } |ri| |}n| }d d g} th} |r| jd |Dt| D]} | jd | g|r| jdt|gd|vr4|j!dd\} }t#| j%d|}n"tt#|j%}| jdd |g|| d}|r||d <||d|<|j tj&|dt j)d|ddt|iy#t $r%t jddt|iYywxYw#t $r%t jddt|iYywxYw)aAdd or update a FastMCP server in Claude's configuration. Args: file_spec: Path to the server file, optionally with :object suffix server_name: Name for the server in Claude's config with_editable: Optional directory to install in editable mode with_packages: Optional list of additional packages to install env_vars: Optional dictionary of environment variables. These are merged with any existing variables, with new values taking precedence. Raises: RuntimeError: If Claude Desktop's config directory is not found, indicating Claude Desktop may not be installed or properly set up. zClaude Desktop config directory not found. Please ensure Claude Desktop is installed and has been run at least once to initialize its config.zclaude_desktop_config.jsonz{}z#Failed to create Claude config file config_file)extraF mcpServersenvrunz--frozenc3&K|] }|s| yw)N).0pkgs r z'update_claude_config..ks@CCC@sz--withz--with-editable:mcp)commandargs)indentzAdded server 'z' to Claude configTzFailed to update Claude config)rr# RuntimeErrorr write_text Exceptionr exceptionstrjsonloads read_text MCP_PACKAGEupdatesortedextendrsplitrresolvedumpsinfo)r'r(r$r%r& config_dirr"r*config existing_envr8packagesr2 file_path server_object server_configs rupdate_claude_configrR,s,()JmG  U  ;;K       " "4 (=K1134 v %#%F<  &. .5F<? @ ) '0'7'7Q'? $I} ?2245Q}oFIDO3356I UE9-.4;T(J  #+M% ,9|[)tzz&;< [M); < #k"23  }    5!3{#3    ~  ,s;/  s$G FH+H?H+H10H1)__doc__r@rrrpathlibrtypingr$mcp.server.fastmcp.utilities.loggingr__name__r rCrr?r#listdictboolrRr0rrr[s' ; H   t  S"&&*&* hhh$; h 9t# h 38nt# h hr