xj dZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z e e ZddedefdZdedzfd Zdefd Zdddd d ed ededzdeedzdeeefdzdef dZy)z!Claude app integration utilities.N)Path)Any) get_loggerpackagereturnc tjjd}d|vsd|vr|S|d|S#tjj$r|cYSwxYw)uRequirement string pinning spawned environments to the running SDK version. `uv run --with mcp` resolves the requirement in a fresh environment, where an unpinned `mcp` means the latest stable release — not necessarily the version the user installed (pre-releases in particular are never selected without an explicit pin). Source builds carry dev/local version segments that are not published to PyPI, so they fall back to the unpinned form, as does a missing distribution (no metadata to pin from). mcpz.dev+z==) importlibmetadataversionPackageNotFoundError)rr s b/mnt/ssd/data/Dropbox/adrian/sandbox/mcp-query/venv/lib/python3.12/site-packages/mcp/cli/claude.pymcp_requirementrse$$,,U3C7NYb ""    2 2s2AActjdk(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 rget_claude_config_pathr##s ||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,3s,ll4 G  s  Nr$) with_editable with_packagesenv_vars file_spec server_namer-r.r/ct}t}|s td|dz }|js |j d tj|j}d|vri|d<||dvr d |d|vr|d|d } |ri| |}n| }d d g} td h} |r| jd |Dt| D]} | jd| g|r| jdt|gt!|dkDxr|ddk(} d| r|ddn|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 an MCP 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--frozenzmcp[cli]c3&K|] }|s| yw)N).0pkgs r z'update_claude_config..}s@CCC@sz--withz--with-editable:Nr )commandargs)indentzAdded server 'z' to Claude configTzFailed to update Claude config)r#r, RuntimeErrorr! write_text Exceptionr) exceptionstrjsonloads read_textrupdatesortedextendlenrsplitrresolvedumpsinfo)r0r1r-r.r/ config_dirr+r3config existing_envrApackagesr;has_windows_drive file_path server_object server_configs rupdate_claude_configr[>s,()JmG  U  ;;K       " "4 (AK1134 v %#%F<  &. .5F<? @  NQ.F9Q<33F $59QR=9 E'0'7'7Q'? $I} ?2245Q}oFIDO3356I UE9-.4;T(J  #+M% ,9|[)tzz&;< [M); < #k"23  E    5!3{#3    F  ,s;/  s$G6 F+H'6+H$#H$'+II)r )__doc__importlib.metadatar rHrr'rpathlibrtypingr&mcp.server.mcpserver.utilities.loggingr__name__r)rGrr#r,listdictboolr[r9r$rres' = H #S#S#& t  S"&&*&* lll$; l 9t# l 38nt# l lr$