+
    Q(i1                       R t ^ RIHt ^ RIt^ RIt^ RIHt ^ RIHtH	t	H
t
HtHt ^ RIHt ^ RIt^ RIHtHtHtHtHt ^ RIHtHt ^ RIHt ^ R	IHt ]'       d   ^ R
IHtHtH t H!t! ^ RI"H#t# R R lt$ ! R R]4      t% ! R R]4      t& ! R R]%]&4      t' ! R R]4      t( ! R R]%](4      t)]']),          t*]&](,          t+]*]+,          t, ! R R]4      t- ! R R]-4      t.R R lt/R# )a  Canonical MCP Configuration Format.

This module defines the standard configuration format for Model Context Protocol (MCP) servers.
It provides a client-agnostic, extensible format that can be used across all MCP implementations.

The configuration format supports both stdio and remote (HTTP/SSE) transports, with comprehensive
field definitions for server metadata, authentication, and execution parameters.

Example configuration:
```json
{
    "mcpServers": {
        "my-server": {
            "command": "npx",
            "args": ["-y", "@my/mcp-server"],
            "env": {"API_KEY": "secret"},
            "timeout": 30000,
            "description": "My MCP server"
        }
    }
}
```
)annotationsN)Path)TYPE_CHECKING	AnnotatedAnyLiteralcast)urlparse)AnyUrl	BaseModel
ConfigDictFieldmodel_validator)Selfoverride)ToolTransformConfig)FastMCPBaseModel)ClientTransportSSETransportStdioTransportStreamableHttpTransport)FastMCPc                    V ^8  d   QhRRRR/# )   urlzstr | AnyUrlreturnzLiteral['http', 'sse'] )formats   "X/Users/agent/.openclaw/workspace/venv/lib/python3.14/site-packages/fastmcp/mcp_config.py__annotate__r   8   s      	    c                    \        V 4      p V P                  R4      '       g   \        RV  24      h\        V 4      pVP                  p\
        P                  ! RV4      '       d   R# R# )z:
Infer the appropriate transport type from the given URL.
httpzInvalid URL: z/sse(/|\?|&|$)sse)str
startswith
ValueErrorr	   pathresearch)r   
parsed_urlr'   s   &  r   infer_transport_type_from_urlr+   8   sZ     c(C>>&!!=.//#J??D 
yy"D))r    c                     a  ] tR t^Lt$ Rt]! ]R7      tR]R&    ]! RRR7      t	R]R	&   ]! RR
R7      t
R]R&   ]! RR7      ]R R l4       4       tRR V 3R llltR R ltRtV ;t# )_TransformingMCPServerMixinzAA mixin that enables wrapping an MCP Server with tool transforms.default_factoryzdict[str, ToolTransformConfig]toolsNz!The tags to include in the proxy.)defaultdescriptionzset[str] | Noneinclude_tagsz!The tags to exclude in the proxy.exclude_tagsbeforemodec                    V ^8  d   QhRRRR/# r   valuesdict[str, Any]r   r   )r   s   "r   r   (_TransformingMCPServerMixin.__annotate__^   s      #	r    c                    \        V\        4      '       dd   \        VP                  R4      4      pVP                  R4      RJpVP                  R4      RJpV'       g   V'       g   V'       g   \	        R4      hV# )zReject if none of the transforming fields are set.

This ensures that plain server configs (without tools, include_tags,
or exclude_tags) fall through to the base server types during union
validation, avoiding unnecessary proxy wrapping.
r0   r3   Nr4   zFAt least one of 'tools', 'include_tags', or 'exclude_tags' is required)
isinstancedictboolgetr&   )clsr:   	has_toolshas_includehas_excludes   &&   r   %_require_at_least_one_transform_fieldA_TransformingMCPServerMixin._require_at_least_one_transform_field\   sh     fd##VZZ01I **^4D@K **^4D@K \  r    c               $    V ^8  d   QhRRRRRR/# )r   server_name
str | Noneclient_namer   z$tuple[FastMCP[Any], ClientTransport]r   )r   s   "r   r   r<   q   s(     !- !-!-  !- 
.	!-r    c                  < ^ RI Hp ^ RIHp ^ RIHp \        S
V `  4       p\        WF4      pV! WbR7      pV! VVR7      pV P                  e   VP                  V P                  RR7       V P                  e   VP                  V P                  R7       V P                  '       d(   ^ R	IHp	 VP!                  V	! V P                  4      4       W3# )
z_Turn the Transforming MCPServer into a FastMCP Server and also return the underlying transport.)Client)r   )create_proxy)	transportname)rP   T)tagsonly)rQ   )ToolTransform)fastmcp.clientrM   fastmcp.client.transportsr   fastmcp.serverrN   superto_transportr   r3   enabler4   disabler0   fastmcp.server.transformsrS   add_transform)selfrI   rK   rM   r   rN   rO   clientwrapped_mcp_serverrS   	__class__s   &&&       r   #_to_server_and_underlying_transport?_TransformingMCPServerMixin._to_server_and_underlying_transportq   s     	*	
 	0%*W%9%;	4	*09*W)

 (%%4+<+<4%H(&&D,=,=&> :::?,,]4::-FG!,,r    c                   V ^8  d   QhRR/# )r   r   r   r   )r   s   "r   r   r<      s     S So Sr    c                J    ^ RI Hp V! V P                  4       ^ ,          R7      # )z2Get the transport for the transforming MCP server.)FastMCPTransport)mcp)rU   re   ra   )r]   re   s   & r   rX   (_TransformingMCPServerMixin.to_transport   s    >D$L$L$Nq$QRRr    r   )NN)__name__
__module____qualname____firstlineno____doc__r   r?   r0   __annotations__r3   r4   r   classmethodrF   ra   rX   __static_attributes____classcell__)r`   s   @r   r-   r-   L   s    K,1$,GE)G9$)7%L/ 
 %*7%L/ 
 (#  $&!- !-FS Sr    r-   c                      ] tR t^t$ RtR]R&   ]! ]R7      tR]R&   ]! ]	R7      t
R]R&   R	tR
]R&   RtR]R&   RtR]R&   RtR]R&   RtR]R&   RtR]R&   RtR]R&   RtR]R&   ]! RR7      tR R ltRtR# )StdioMCPServerzMCP server configuration for stdio transport.

This is the canonical configuration format for MCP servers using stdio transport.
r$   commandr.   z	list[str]argsr;   envstdiozLiteral['stdio']rO   NzLiteral['stdio'] | NonetyperJ   cwd
int | Nonetimeoutzbool | None
keep_aliver2   icondict[str, Any] | Noneauthenticationallowextrac                   V ^8  d   QhRR/# )r   r   r   r   )r   s   "r   r   StdioMCPServer.__annotate__   s     	
 	
n 	
r    c                	    ^ RI Hp V! V P                  V P                  V P                  V P
                  V P                  R7      # )    )r   )rs   rt   ru   rx   r{   )rU   r   rs   rt   ru   rx   r{   )r]   r   s   & r   rX   StdioMCPServer.to_transport   s5    <LL
 	
r    r   )rh   ri   rj   rk   rl   rm   r   listrt   r?   ru   rO   rw   rx   rz   r{   r2   r|   r~   r   model_configrX   ro   r   r    r   rr   rr      s     L D1D)15C5 #*I)$(D
!( CGZ  
 #K"D* -1N)0G,L	
 	
r    rr   c                      ] tR t^tRtRtR# )TransformingStdioMCPServerz$A Stdio server with tool transforms.r   Nrh   ri   rj   rk   rl   ro   r   r    r   r   r      s    .r    r   c                      ] tR t^t$ RtR]R&   RtR]R&   ]! ]R7      t	R]R	&   Rt
R
]R&   RtR]R&   RtR]R&   RtR]R&   RtR]R&   RtR]R&   ]! RRR7      tR R ltRtR# )RemoteMCPServerzMCP server configuration for HTTP/SSE transport.

This is the canonical configuration format for MCP servers using remote transports.
r$   r   Nz0Literal['http', 'streamable-http', 'sse'] | NonerO   r.   zdict[str, str]headerszAnnotated[str | Literal['oauth'] | httpx.Auth | None, Field(description='Either a string representing a Bearer token, the literal "oauth" to use OAuth authentication, or an httpx.Auth instance for custom authentication.')]authz'datetime.timedelta | int | float | Nonesse_read_timeoutry   rz   rJ   r2   r|   r}   r~   r   T)r   arbitrary_types_allowedc                   V ^8  d   QhRR/# )r   r   z&StreamableHttpTransport | SSETransportr   )r   s   "r   r   RemoteMCPServer.__annotate__   s      D r    c                	P   ^ RI HpHp V P                  f   \	        V P
                  4      pMV P                  pVR8X  d5   V! V P
                  V P                  V P                  V P                  R7      # V! V P
                  V P                  V P                  V P                  R7      # )r   )r   r   r#   )r   r   r   )	rU   r   r   rO   r+   r   r   r   r   )r]   r   r   rO   s   &   r   rX   RemoteMCPServer.to_transport   s    S>>!5dhh?IIYY!%!6!6	  +YY!%!6!6	 r    r   )rh   ri   rj   rk   rl   rm   rO   r   r?   r   r   r   rz   r2   r|   r~   r   r   rX   ro   r   r    r   r   r      s     
H CGI?F#D9G^9 	 	   AE=DGZ #K"D* -1N)0tL r    r   c                      ] tR tRtRtRtR# )TransformingRemoteMCPServeri	  z%A Remote server with tool transforms.r   Nr   r   r    r   r   r   	  s    /r    r   c                      ] tR tRt$ Rt]! ]R7      tR]R&   ]	! RR7      t
]! RR	7      ]R
 R l4       4       tR R lt]R R l4       tR R ltR R lt]R R l4       tRtR# )	MCPConfigi  a(  A configuration object for MCP Servers that conforms to the canonical MCP configuration format
while adding additional fields for enabling FastMCP-specific features like tool transformations
and filtering by tags.

For an MCPConfig that is strictly canonical, see the `CanonicalMCPConfig` class.
r.   zdict[str, MCPServerTypes]
mcpServersr   r   r5   r6   c                    V ^8  d   QhRRRR/# r9   r   )r   s   "r   r   MCPConfig.__annotate__"  s      . ^ r    c                    RV9  d]   \         ;QJ d*    R VP                  4        4       F  '       g   K   RM	  RM! R VP                  4        4       4      pV'       d   RV/# V# )zMIf there's no mcpServers key but there are server configs at root, wrap them.r   c              3  v   "   T F/  p\        V\        4      ;'       d    R V9   ;'       g    RV9   x  K1  	  R# 5i)rs   r   N)r>   r?   ).0vs   & r   	<genexpr>1MCPConfig.wrap_servers_at_root.<locals>.<genexpr>&  s9      (A 1d#FFa)E)E5A:F(s   999TF)anyr:   )rB   r:   has_serverss   && r   wrap_servers_at_rootMCPConfig.wrap_servers_at_root   sY     v%# ###  K $f--r    c               $    V ^8  d   QhRRRRRR/# )r   rP   r$   serverMCPServerTypesr   Noner   )r   s   "r   r   r   /  s!     ' 's 'N 't 'r    c                "    W P                   V&   R# z,Add or update a server in the configuration.Nr   r]   rP   r   s   &&&r   
add_serverMCPConfig.add_server/  s     &r    c                    V ^8  d   QhRRRR/# )r   configr;   r   r   r   )r   s   "r   r   r   4  s     * *~ *$ *r    c                $    V P                  V4      # )z/Parse MCP configuration from dictionary format.)model_validate)rB   r   s   &&r   	from_dictMCPConfig.from_dict3  s     !!&))r    c                   V ^8  d   QhRR/# )r   r   r;   r   )r   s   "r   r   r   8  s     2 2 2r    c                &    V P                  RR7      # )z>Convert MCPConfig to dictionary format, preserving all fields.Texclude_none)
model_dump)r]   s   &r   to_dictMCPConfig.to_dict8  s    D11r    c                    V ^8  d   QhRRRR/# )r   	file_pathr   r   r   r   )r   s   "r   r   r   <  s     = =t = =r    c                    VP                   P                  RRR7       VP                  V P                  ^R7      4       R# )z!Write configuration to JSON file.T)parentsexist_ok)indentN)parentmkdir
write_textmodel_dump_json)r]   r   s   &&r   write_to_fileMCPConfig.write_to_file<  s7    td;T111;<r    c                    V ^8  d   QhRRRR/# )r   r   r   r   r   r   )r   s   "r   r   r   B  s     O O$ O4 Or    c                    VP                  4       '       d8   VP                  4       P                  4       ;p'       d   V P                  V4      # \	        RV 24      h)z"Load configuration from JSON file.z&No MCP servers defined in the config: )exists	read_textstripmodel_validate_jsonr&   )rB   r   contents   && r   	from_fileMCPConfig.from_fileA  sS     i.A.A.C.I.I.K#K7#K**733A)MNNr    r   N)rh   ri   rj   rk   rl   r   r?   r   rm   r   r   r   rn   r   r   r   r   r   r   ro   r   r    r   r   r     s{     -2$,GJ)GG,L(#  $' * *2=
 O Or    r   c                  N    ] tR tRt$ Rt]! ]R7      tR]R&   ]	R R l4       t
RtR	# )
CanonicalMCPConfigiJ  zCanonical MCP configuration format.

This defines the standard configuration format for Model Context Protocol servers.
The format is designed to be client-agnostic and extensible for future use cases.
r.   z"dict[str, CanonicalMCPServerTypes]r   c               $    V ^8  d   QhRRRRRR/# )r   rP   r$   r   CanonicalMCPServerTypesr   r   r   )r   s   "r   r   CanonicalMCPConfig.__annotate__T  s"     ' 's ',C ' 'r    c                "    W P                   V&   R# r   r   r   s   &&&r   r   CanonicalMCPConfig.add_serverS  s     !'r    r   N)rh   ri   rj   rk   rl   r   r?   r   rm   r   r   ro   r   r    r   r   r   J  s+     6;45PJ2P' 'r    r   c               (    V ^8  d   QhRRRRRRRR/# )	r   r   r   rI   r$   server_configr   r   r   r   )r   s   "r   r   r   Y  s0     $ $$$ +$ 
	$r    c                L   \         P                  V 4      pVP                  P                  V4      ;p'       dJ   VP	                  4       pVP	                  RR7      pVP                  / VCVC4      pVP                  W4       MVP                  W4       VP                  V 4       R# )zUpdate an MCP configuration file from a server object, preserving existing fields.

This is used for updating the mcpServer configurations of third-party tools so we do not
worry about transforming server objects here.Tr   N)r   r   r   rA   r   r   r   r   )r   rI   r   r   existing_serverexisting_dictnew_dictmerged_configs   &&&     r   update_config_filer   Y  s       +F !++//<<<'224 +++> &445R5R5RS+5+5
#r    )0rl   
__future__r   datetimer(   pathlibr   typingr   r   r   r   r   urllib.parser	   httpxpydanticr
   r   r   r   r   typing_extensionsr   r   fastmcp.tools.tool_transformr   fastmcp.utilities.typesr   rU   r   r   r   r   fastmcp.server.serverr   r+   r-   rr   r   r   r   TransformingMCPServerTypesr   r   r   r   r   r   r    r   <module>r      s   0 #  	  ? ? !   - < 4  .(LS"2 LS^*
Y *
Z/!<n /:i :z0"= 0 8:UU (?: +.EE3O	 3Ol' '$r    