xj0;HdZddlZddlZddlZddlZddlZddlmZddl m Z m Z ddl m Z ddl mZ ddlZ dd lmZdd lmZ ddlZed Zej4d dddZdZdedeeeffdZ ddZ%ejIejLdd !dgfdede edzejNd"d#d$ddd%fde e eejNd&d'!fddfd(Z(ejIejLdd !dfded)e edzejNd*d+d,!fddfd-Z)ejIejLdd !ddggdfded.e edzejNd/d0d1!fde edzejNd"d#d$ddd%fde e eejNd&d'!fd2e e eejNd3d4d5!fd6e edzejNd7d8d9dddd:fddfd;Z*y#e$redej&dY6wxYw#e$red ej&dYOwxYw#e$rdZYXwxYw)?zMCP CLI tools.N)Path) AnnotatedAny) MCPServer)Serverz=Error: typer is required. Install with 'pip install mcp[cli]')claude) get_loggerz7Error: mcp.server is not installed or not in PYTHONPATHclimcpzMCP development toolsFT)namehelpadd_completionno_args_is_helpctjdk(r'dD]!} tj|dgddd|cSyy#tj$rY;wxYw)z5Get the correct npx command for the current platform.win32)znpx.cmdznpx.exenpxz --versionT)checkcapture_outputshellNr)sysplatform subprocessrunCalledProcessError)cmds _/mnt/ssd/data/Dropbox/adrian/sandbox/mcp-query/venv/lib/python3.12/site-packages/mcp/cli/cli.py_get_npx_commandr*sa ||w0 C [1dZ^_    00  s<AAenv_varreturncd|vr.tjd|dtjd|j dd\}}|j |j fS)z6Parse environment variable string in format KEY=VALUE.=z%Invalid environment variable format: z. Must be KEY=VALUEr)loggererrorrexitsplitstrip)rkeyvalues r_parse_env_varr*8sW ' tjd|ddt|itjdYwxYw)zImport an MCP server from a file. Args: file: Path to the file server_object: Optional object name in format "module:object" or just "object" Returns: The server object r server_modulezCould not load modulerFextrarrC object_namec t|tsRtjd|dt |dtdt|t rtj dyy)zHelper function to check that the server object is supported Args: server_object: The server object to check. Returns: True if it's supported. zThe server object z is of type z (expecting z).zSNote that only MCPServer is supported. Low level Server class is not yet supported.FT) isinstancerr#r$typeLowLevelServerwarning)rCrKs r_check_server_objectz,_import_server.._check_server_objectsW-3 LL-k],tMGZF[[ghqgrrtu v-8tur+)r serverappr9zIgnoring object 'z#' as it's not a valid server objectzNo server object found in a . Please either: 1. Use a standard variable name (mcp, server, or app) 2. Specify the object name with file:object syntax3. If the server creates the MCPServer object within main() or another function, refactor the MCPServer object to be a global variable named mcp, server, or app.NzCould not import module ''zServer object 'z ' not found)r5parentrpathinsert importlibutilspec_from_file_locationloaderr#r$r%module_from_spec exec_modulerhasattrgetattrr& import_module ImportError) rFrCfile_dirspecmodulerQr module_namerKrHrRs r_import_serverrfwsE4;;Hsxx 8$ >> 1 1/4 HD t{{ ,VSY4G H  ^^ , ,T 2FKKF#Cc" , -Dvt$+GFD,AdV1TFCSTLL#4TF!D6Ad!efvt,,  -  (/< < 3t9%     m#0#6#6sA#> [ %33K@M]K>F5 ~ m_K 83t9%     6  M)  LL+K=:s4y)   HHQK  s$"H11AI87I8c tjjd}td|y#tjj$r#tdt j dYywxYw)zShow the MCP version.r z MCP version z+MCP version unknown (package not installed)rN)rXmetadataversionprintPackageNotFoundErrorrr%)ris rriris[$$,,U3 WI&'    2 2 ;<  s-0=A0/A0.z2Python file to run, optionally with :object suffix)rr2z-ez?Directory containing pyproject.toml to install in editable mode)rr? file_okay resolve_pathr1zAdditional packages to installc t|\}}tjdt|||r t|nd|d t ||}t |dr!t t||jz}t|||}t}|s*tjdtjdtjdk(}tj |d g|zd |t#t$j&j) } tj| j*y#tj,$r`} tjd t|t| | j*d tj| j*Yd} ~ yd} ~ wt.$r:tjddt|itjdYywxYw)z)Run an MCP server with the MCP Inspector.zStarting dev serverN)rFrCr-r.rI dependencieszbnpx not found. Please ensure Node.js and npm are properly installed and added to your system PATH.rrz@modelcontextprotocol/inspectorT)rrenvzDev server failed)rFr$ returncodeznpx not found. Please ensure Node.js and npm are properly installed and added to your system PATH. You may need to restart your terminal after installation.rF)rEr#debugr5rfr^listsetror7rr$rr%rrrdictosenvironitemsrqrFileNotFoundError) r,r-r.rFrCrRuv_cmdnpx_cmdrprocesses rdevr~s4+95D- LLI*3@S/d*  *m4 6> * ]V5H5H%H!IJM"9m]K#$ LLt  HHQK '.. 7 86 ARZZ%%'(   ##$  ( (  D Qll      "3t9%   s!C1D44G(AF""AG('G( transportz --transportz-tz(Transport protocol to use (stdio or sse)cDt|\}}tjdt|||d t ||}i}|r||d<|j d i|y#t $r:tjddt|itjdYywxYw) aRun an MCP server. The server can be specified in two ways: 1. Module approach: server.py - runs the module directly, expecting a server.run() call. 2. Import approach: server.py:app - imports and runs the specified server object. Note: This command runs the server directly. You are responsible for ensuring all dependencies are available. For dependency management, use `mcp install` or `mcp dev` instead. zRunning server)rFrCrrIrzFailed to run serverrFrN) rEr#rrr5rfr Exception exceptionrr%)r,rrFrCrRkwargss rrr/s2+95D- LLI*" m4 "+F;  V  "D    s'AABB server_namez--namez-nzMCustom name for the server (defaults to server's name attribute or file name)env_varsz --env-varz-vz)Environment variables in KEY=VALUE formatenv_filez --env-filez-fz+Load environment variables from a .env file)rr?rldir_okayrmc t|\}}tjdt||||r t|nd|dt j s*tj dtjd|}d} |s t||} | j}| r t| d gng} | rtt!|| z}d} |s|ri} |rot"r? | t#j$|j'D cic] \} }| | | c}} z} n*tj d tjd|D]}t/|\}}|| |<t j0||||| rtj3d |dytj d|dtjdy#ttf$r9} tjddt| i|j}Yd} ~ cd} ~ wwxYwcc}} w#t(t*f$r.tj-d tjdY wxYw)zInstall an MCP server in the Claude desktop app. Environment variables are preserved once added and only updated if new values are explicitly provided. zInstalling serverN)rFrrCr-r.rIzClaude app not foundrzFCould not import server (likely missing dependencies), using file namer$rozFailed to load .env filez6python-dotenv is not installed. Cannot load .env file.)r-r.rzSuccessfully installed z in Claude appzFailed to install )rEr#rrr5r get_claude_config_pathr$rr%rfr raModuleNotFoundErrorstemr_rsrtdotenv dotenv_valuesrxOSError ValueErrorrr*update_claude_configinfo)r,rr-r.rrrFrCr rRr}server_dependenciesenv_dictkvrr(r)s rinstallrhs+t+95D- LLI&*3@S/d*     ( ( * +,   D F  #D-8F;;DBH'&."=RS1D!DEF '+H8  &2F2Fx2P2V2V2X j$!Q\]\iA jjH  UV   "G'0JC!HSM """ ##   -dV>BC )$~>?  W01  LLXA'  99D  (!k, $$%?@HHQK sBF?'H H  H H?H.HH H9I  I )NN)N)r N)+__doc__importlib.metadatarXimportlib.utilrvrrpathlibrtypingrr mcp.serverrrrOtyperrarjr%mcp.clir &mcp.server.mcpserver.utilities.loggingr rr#TyperrSrr5tupler*rsr7rErfcommandriArgumentOptionr~rrrr+rrs'  ! / A  E ekk    &C&E#s(O&"&&*$;9t# #Y .$$dC$J.>(?$>WWcDjWt#U^^ A  -OO  t   R     O  S  1  !O. /OOd#U^^ A 55  d   ;   5 55p#U^^ A     e}}  d   `   } t   R    }0 S  1  1}> S   <  ?}N t   >   O}f g}}s  IJ CHHQK CD CHHQK  Fs4I I0J I-,I-0JJJ! J!