import{s as Ue,n as Fe,o as Ve}from"../chunks/scheduler.0cf4ef2e.js";import{S as je,i as We,e as a,s as r,c as h,h as Be,a as s,d as t,b as i,f as w,g as p,j as d,k as v,l as o,m as l,n as m,t as f,o as _,p as b}from"../chunks/index.abc433bf.js";import{C as ze}from"../chunks/CopyLLMTxtMenu.efc6b005.js";import{D as Q}from"../chunks/Docstring.e4170f41.js";import{H as Te,E as Ye}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.86d448e2.js";function Ke(Le){let C,X,G,Z,T,ee,L,te,k,ke='The <code>huggingface_hub</code> library now includes an <a href="/docs/huggingface_hub/main/en/package_reference/mcp#huggingface_hub.MCPClient">MCPClient</a>, designed to empower Large Language Models (LLMs) with the ability to interact with external Tools via the <a href="https://modelcontextprotocol.io" rel="nofollow">Model Context Protocol</a> (MCP). This client extends an <a href="/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.AsyncInferenceClient">AsyncInferenceClient</a> to seamlessly integrate Tool usage.',ne,A,Ae='The <a href="/docs/huggingface_hub/main/en/package_reference/mcp#huggingface_hub.MCPClient">MCPClient</a> connects to MCP servers (local <code>stdio</code> scripts or remote <code>http</code>/<code>sse</code> services) that expose tools. It feeds these tools to an LLM (via <a href="/docs/huggingface_hub/main/en/package_reference/inference_client#huggingface_hub.AsyncInferenceClient">AsyncInferenceClient</a>). If the LLM decides to use a tool, <a href="/docs/huggingface_hub/main/en/package_reference/mcp#huggingface_hub.MCPClient">MCPClient</a> manages the execution request to the MCP server and relays the Tool’s output back to the LLM, often streaming results in real-time.',oe,E,Ee='We also provide a higher-level <a href="/docs/huggingface_hub/main/en/package_reference/mcp#huggingface_hub.Agent">Agent</a> class. This ‘Tiny Agent’ simplifies creating conversational Agents by managing the chat loop and state, acting as a wrapper around <a href="/docs/huggingface_hub/main/en/package_reference/mcp#huggingface_hub.MCPClient">MCPClient</a>.',re,H,ie,c,I,me,j,He="Client for connecting to one or more MCP servers and processing chat completions with tools.",fe,D,Ie="<p>This class is experimental and might be subject to breaking changes in the future without prior notice.</p>",_e,y,S,be,W,De="Connect to an MCP server",ve,$,O,Ce,B,Se="Clean up resources",ye,x,N,$e,z,Oe="Process a query using <code>self.model</code> and available tools, yielding chunks and tool outputs.",ae,q,se,g,R,xe,Y,Ne='Implementation of a Simple Agent, which is a simple while loop built right on top of an <a href="/docs/huggingface_hub/main/en/package_reference/mcp#huggingface_hub.MCPClient">MCPClient</a>.',Me,U,qe="<p>This class is experimental and might be subject to breaking changes in the future without prior notice.</p>",Pe,M,F,we,K,Re="Run the agent with the given user input.",le,V,ce,J,ge;return T=new ze({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),L=new Te({props:{title:"MCP Client",local:"mcp-client",headingTag:"h1"}}),H=new Te({props:{title:"MCP Client",local:"huggingface_hub.MCPClient",headingTag:"h2"}}),I=new Q({props:{name:"class huggingface_hub.MCPClient",anchor:"huggingface_hub.MCPClient",parameters:[{name:"model",val:": typing.Optional[str] = None"},{name:"provider",val:": typing.Union[typing.Literal['black-forest-labs', 'cerebras', 'clarifai', 'cohere', 'fal-ai', 'featherless-ai', 'fireworks-ai', 'groq', 'hf-inference', 'hyperbolic', 'nebius', 'novita', 'nscale', 'openai', 'publicai', 'replicate', 'sambanova', 'scaleway', 'together', 'wavespeed', 'zai-org'], typing.Literal['auto'], NoneType] = None"},{name:"base_url",val:": typing.Optional[str] = None"},{name:"api_key",val:": typing.Optional[str] = None"}],parametersDescription:[{anchor:"huggingface_hub.MCPClient.model",description:`<strong>model</strong> (<code>str</code>, <code>optional</code>) &#x2014;
The model to run inference with. Can be a model id hosted on the Hugging Face Hub, e.g. <code>meta-llama/Meta-Llama-3-8B-Instruct</code>
or a URL to a deployed Inference Endpoint or other local or remote endpoint.`,name:"model"},{anchor:"huggingface_hub.MCPClient.provider",description:`<strong>provider</strong> (<code>str</code>, <em>optional</em>) &#x2014;
Name of the provider to use for inference. Defaults to &#x201C;auto&#x201D; i.e. the first of the providers available for the model, sorted by the user&#x2019;s order in <a href="https://hf.co/settings/inference-providers" rel="nofollow">https://hf.co/settings/inference-providers</a>.
If model is a URL or <code>base_url</code> is passed, then <code>provider</code> is not used.`,name:"provider"},{anchor:"huggingface_hub.MCPClient.base_url",description:`<strong>base_url</strong> (<code>str</code>, <em>optional</em>) &#x2014;
The base URL to run inference. Defaults to None.`,name:"base_url"},{anchor:"huggingface_hub.MCPClient.api_key",description:`<strong>api_key</strong> (<code>str</code>, <code>optional</code>) &#x2014;
Token to use for authentication. Will default to the locally Hugging Face saved token if not provided. You can also use your own provider API key to interact directly with the provider&#x2019;s service.`,name:"api_key"}],source:"https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/inference/_mcp/mcp_client.py#L55"}}),S=new Q({props:{name:"add_mcp_server",anchor:"huggingface_hub.MCPClient.add_mcp_server",parameters:[{name:"type",val:": typing.Literal['stdio', 'sse', 'http']"},{name:"**params",val:": typing.Any"}],parametersDescription:[{anchor:"huggingface_hub.MCPClient.add_mcp_server.type",description:`<strong>type</strong> (<code>str</code>) &#x2014;
Type of the server to connect to. Can be one of:
<ul>
<li>&#x201C;stdio&#x201D;: Standard input/output server (local)</li>
<li>&#x201C;sse&#x201D;: Server-sent events (SSE) server</li>
<li>&#x201C;http&#x201D;: StreamableHTTP server</li>
</ul>`,name:"type"},{anchor:"huggingface_hub.MCPClient.add_mcp_server.*params",description:`*<strong>*params</strong> (<code>dict[str, Any]</code>) &#x2014;
Server parameters that can be either:
<ul>
<li>For stdio servers:
<ul>
<li>command (str): The command to run the MCP server</li>
<li>args (list[str], optional): Arguments for the command</li>
<li>env (dict[str, str], optional): Environment variables for the command</li>
<li>cwd (Union[str, Path, None], optional): Working directory for the command</li>
<li>allowed_tools (list[str], optional): List of tool names to allow from this server</li>
</ul>
</li>
<li>For SSE servers:
<ul>
<li>url (str): The URL of the SSE server</li>
<li>headers (dict[str, Any], optional): Headers for the SSE connection</li>
<li>timeout (float, optional): Connection timeout</li>
<li>sse_read_timeout (float, optional): SSE read timeout</li>
<li>allowed_tools (list[str], optional): List of tool names to allow from this server</li>
</ul>
</li>
<li>For StreamableHTTP servers:
<ul>
<li>url (str): The URL of the StreamableHTTP server</li>
<li>headers (dict[str, Any], optional): Headers for the StreamableHTTP connection</li>
<li>timeout (timedelta, optional): Connection timeout</li>
<li>sse_read_timeout (timedelta, optional): SSE read timeout</li>
<li>terminate_on_close (bool, optional): Whether to terminate on close</li>
<li>allowed_tools (list[str], optional): List of tool names to allow from this server</li>
</ul>
</li>
</ul>`,name:"*params"}],source:"https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/inference/_mcp/mcp_client.py#L123"}}),O=new Q({props:{name:"cleanup",anchor:"huggingface_hub.MCPClient.cleanup",parameters:[],source:"https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/inference/_mcp/mcp_client.py#L109"}}),N=new Q({props:{name:"process_single_turn_with_tools",anchor:"huggingface_hub.MCPClient.process_single_turn_with_tools",parameters:[{name:"messages",val:": list"},{name:"exit_loop_tools",val:": typing.Optional[list[huggingface_hub.inference._generated.types.chat_completion.ChatCompletionInputTool]] = None"},{name:"exit_if_first_chunk_no_tool",val:": bool = False"}],parametersDescription:[{anchor:"huggingface_hub.MCPClient.process_single_turn_with_tools.messages",description:`<strong>messages</strong> (<code>list[dict]</code>) &#x2014;
List of message objects representing the conversation history`,name:"messages"},{anchor:"huggingface_hub.MCPClient.process_single_turn_with_tools.exit_loop_tools",description:`<strong>exit_loop_tools</strong> (<code>list[ChatCompletionInputTool]</code>, <em>optional</em>) &#x2014;
List of tools that should exit the generator when called`,name:"exit_loop_tools"},{anchor:"huggingface_hub.MCPClient.process_single_turn_with_tools.exit_if_first_chunk_no_tool",description:`<strong>exit_if_first_chunk_no_tool</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Exit if no tool is present in the first chunks. Default to False.`,name:"exit_if_first_chunk_no_tool"}],source:"https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/inference/_mcp/mcp_client.py#L248"}}),q=new Te({props:{title:"Agent",local:"huggingface_hub.Agent",headingTag:"h2"}}),R=new Q({props:{name:"class huggingface_hub.Agent",anchor:"huggingface_hub.Agent",parameters:[{name:"model",val:": Optional[str] = None"},{name:"servers",val:": Iterable[ServerConfig]"},{name:"provider",val:": Optional[PROVIDER_OR_POLICY_T] = None"},{name:"base_url",val:": Optional[str] = None"},{name:"api_key",val:": Optional[str] = None"},{name:"prompt",val:": Optional[str] = None"}],parametersDescription:[{anchor:"huggingface_hub.Agent.model",description:`<strong>model</strong> (<code>str</code>, <em>optional</em>) &#x2014;
The model to run inference with. Can be a model id hosted on the Hugging Face Hub, e.g. <code>meta-llama/Meta-Llama-3-8B-Instruct</code>
or a URL to a deployed Inference Endpoint or other local or remote endpoint.`,name:"model"},{anchor:"huggingface_hub.Agent.servers",description:`<strong>servers</strong> (<code>Iterable[dict]</code>) &#x2014;
MCP servers to connect to. Each server is a dictionary containing a <code>type</code> key and a <code>config</code> key. The <code>type</code> key can be <code>&quot;stdio&quot;</code> or <code>&quot;sse&quot;</code>, and the <code>config</code> key is a dictionary of arguments for the server.`,name:"servers"},{anchor:"huggingface_hub.Agent.provider",description:`<strong>provider</strong> (<code>str</code>, <em>optional</em>) &#x2014;
Name of the provider to use for inference. Defaults to &#x201C;auto&#x201D; i.e. the first of the providers available for the model, sorted by the user&#x2019;s order in <a href="https://hf.co/settings/inference-providers" rel="nofollow">https://hf.co/settings/inference-providers</a>.
If model is a URL or <code>base_url</code> is passed, then <code>provider</code> is not used.`,name:"provider"},{anchor:"huggingface_hub.Agent.base_url",description:`<strong>base_url</strong> (<code>str</code>, <em>optional</em>) &#x2014;
The base URL to run inference. Defaults to None.`,name:"base_url"},{anchor:"huggingface_hub.Agent.api_key",description:`<strong>api_key</strong> (<code>str</code>, <em>optional</em>) &#x2014;
Token to use for authentication. Will default to the locally Hugging Face saved token if not provided. You can also use your own provider API key to interact directly with the provider&#x2019;s service.`,name:"api_key"},{anchor:"huggingface_hub.Agent.prompt",description:`<strong>prompt</strong> (<code>str</code>, <em>optional</em>) &#x2014;
The system prompt to use for the agent. Defaults to the default system prompt in <code>constants.py</code>.`,name:"prompt"}],source:"https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/inference/_mcp/agent.py#L13"}}),F=new Q({props:{name:"run",anchor:"huggingface_hub.Agent.run",parameters:[{name:"user_input",val:": str"},{name:"abort_event",val:": Optional[asyncio.Event] = None"}],parametersDescription:[{anchor:"huggingface_hub.Agent.run.user_input",description:`<strong>user_input</strong> (<code>str</code>) &#x2014;
The user input to run the agent with.`,name:"user_input"},{anchor:"huggingface_hub.Agent.run.abort_event",description:`<strong>abort_event</strong> (<code>asyncio.Event</code>, <em>optional</em>) &#x2014;
An event that can be used to abort the agent. If the event is set, the agent will stop running.`,name:"abort_event"}],source:"https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/inference/_mcp/agent.py#L57"}}),V=new Ye({props:{source:"https://github.com/huggingface/huggingface_hub/blob/main/docs/source/en/package_reference/mcp.md"}}),{c(){C=a("meta"),X=r(),G=a("p"),Z=r(),h(T.$$.fragment),ee=r(),h(L.$$.fragment),te=r(),k=a("p"),k.innerHTML=ke,ne=r(),A=a("p"),A.innerHTML=Ae,oe=r(),E=a("p"),E.innerHTML=Ee,re=r(),h(H.$$.fragment),ie=r(),c=a("div"),h(I.$$.fragment),me=r(),j=a("p"),j.textContent=He,fe=r(),D=a("blockquote"),D.innerHTML=Ie,_e=r(),y=a("div"),h(S.$$.fragment),be=r(),W=a("p"),W.textContent=De,ve=r(),$=a("div"),h(O.$$.fragment),Ce=r(),B=a("p"),B.textContent=Se,ye=r(),x=a("div"),h(N.$$.fragment),$e=r(),z=a("p"),z.innerHTML=Oe,ae=r(),h(q.$$.fragment),se=r(),g=a("div"),h(R.$$.fragment),xe=r(),Y=a("p"),Y.innerHTML=Ne,Me=r(),U=a("blockquote"),U.innerHTML=qe,Pe=r(),M=a("div"),h(F.$$.fragment),we=r(),K=a("p"),K.textContent=Re,le=r(),h(V.$$.fragment),ce=r(),J=a("p"),this.h()},l(e){const n=Be("svelte-u9bgzb",document.head);C=s(n,"META",{name:!0,content:!0}),n.forEach(t),X=i(e),G=s(e,"P",{}),w(G).forEach(t),Z=i(e),p(T.$$.fragment,e),ee=i(e),p(L.$$.fragment,e),te=i(e),k=s(e,"P",{"data-svelte-h":!0}),d(k)!=="svelte-13o8nel"&&(k.innerHTML=ke),ne=i(e),A=s(e,"P",{"data-svelte-h":!0}),d(A)!=="svelte-7cdnea"&&(A.innerHTML=Ae),oe=i(e),E=s(e,"P",{"data-svelte-h":!0}),d(E)!=="svelte-1u9ma2q"&&(E.innerHTML=Ee),re=i(e),p(H.$$.fragment,e),ie=i(e),c=s(e,"DIV",{class:!0});var u=w(c);p(I.$$.fragment,u),me=i(u),j=s(u,"P",{"data-svelte-h":!0}),d(j)!=="svelte-s2sl1p"&&(j.textContent=He),fe=i(u),D=s(u,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),d(D)!=="svelte-yc6ocd"&&(D.innerHTML=Ie),_e=i(u),y=s(u,"DIV",{class:!0});var ue=w(y);p(S.$$.fragment,ue),be=i(ue),W=s(ue,"P",{"data-svelte-h":!0}),d(W)!=="svelte-1sfq5nj"&&(W.textContent=De),ue.forEach(t),ve=i(u),$=s(u,"DIV",{class:!0});var he=w($);p(O.$$.fragment,he),Ce=i(he),B=s(he,"P",{"data-svelte-h":!0}),d(B)!=="svelte-nj9nid"&&(B.textContent=Se),he.forEach(t),ye=i(u),x=s(u,"DIV",{class:!0});var pe=w(x);p(N.$$.fragment,pe),$e=i(pe),z=s(pe,"P",{"data-svelte-h":!0}),d(z)!=="svelte-1i4w3kl"&&(z.innerHTML=Oe),pe.forEach(t),u.forEach(t),ae=i(e),p(q.$$.fragment,e),se=i(e),g=s(e,"DIV",{class:!0});var P=w(g);p(R.$$.fragment,P),xe=i(P),Y=s(P,"P",{"data-svelte-h":!0}),d(Y)!=="svelte-10mvlk3"&&(Y.innerHTML=Ne),Me=i(P),U=s(P,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),d(U)!=="svelte-yc6ocd"&&(U.innerHTML=qe),Pe=i(P),M=s(P,"DIV",{class:!0});var de=w(M);p(F.$$.fragment,de),we=i(de),K=s(de,"P",{"data-svelte-h":!0}),d(K)!=="svelte-14cbc44"&&(K.textContent=Re),de.forEach(t),P.forEach(t),le=i(e),p(V.$$.fragment,e),ce=i(e),J=s(e,"P",{}),w(J).forEach(t),this.h()},h(){v(C,"name","hf:doc:metadata"),v(C,"content",Qe),v(D,"class","warning"),v(y,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),v($,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),v(x,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),v(c,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),v(U,"class","warning"),v(M,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),v(g,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(e,n){o(document.head,C),l(e,X,n),l(e,G,n),l(e,Z,n),m(T,e,n),l(e,ee,n),m(L,e,n),l(e,te,n),l(e,k,n),l(e,ne,n),l(e,A,n),l(e,oe,n),l(e,E,n),l(e,re,n),m(H,e,n),l(e,ie,n),l(e,c,n),m(I,c,null),o(c,me),o(c,j),o(c,fe),o(c,D),o(c,_e),o(c,y),m(S,y,null),o(y,be),o(y,W),o(c,ve),o(c,$),m(O,$,null),o($,Ce),o($,B),o(c,ye),o(c,x),m(N,x,null),o(x,$e),o(x,z),l(e,ae,n),m(q,e,n),l(e,se,n),l(e,g,n),m(R,g,null),o(g,xe),o(g,Y),o(g,Me),o(g,U),o(g,Pe),o(g,M),m(F,M,null),o(M,we),o(M,K),l(e,le,n),m(V,e,n),l(e,ce,n),l(e,J,n),ge=!0},p:Fe,i(e){ge||(f(T.$$.fragment,e),f(L.$$.fragment,e),f(H.$$.fragment,e),f(I.$$.fragment,e),f(S.$$.fragment,e),f(O.$$.fragment,e),f(N.$$.fragment,e),f(q.$$.fragment,e),f(R.$$.fragment,e),f(F.$$.fragment,e),f(V.$$.fragment,e),ge=!0)},o(e){_(T.$$.fragment,e),_(L.$$.fragment,e),_(H.$$.fragment,e),_(I.$$.fragment,e),_(S.$$.fragment,e),_(O.$$.fragment,e),_(N.$$.fragment,e),_(q.$$.fragment,e),_(R.$$.fragment,e),_(F.$$.fragment,e),_(V.$$.fragment,e),ge=!1},d(e){e&&(t(X),t(G),t(Z),t(ee),t(te),t(k),t(ne),t(A),t(oe),t(E),t(re),t(ie),t(c),t(ae),t(se),t(g),t(le),t(ce),t(J)),t(C),b(T,e),b(L,e),b(H,e),b(I),b(S),b(O),b(N),b(q,e),b(R),b(F),b(V,e)}}}const Qe='{"title":"MCP Client","local":"mcp-client","sections":[{"title":"MCP Client","local":"huggingface_hub.MCPClient","sections":[],"depth":2},{"title":"Agent","local":"huggingface_hub.Agent","sections":[],"depth":2}],"depth":1}';function Ge(Le){return Ve(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class nt extends je{constructor(C){super(),We(this,C,Ge,Ke,Ue,{})}}export{nt as component};
