import{s as Re,o as qe,n as Oe}from"../chunks/scheduler.6062bdaf.js";import{S as Ue,i as Fe,g as s,s as r,r as d,A as Ve,h as l,f as n,c as a,j as A,u as m,x as C,k as D,y as i,a as c,v as f,d as _,t as b,w as v}from"../chunks/index.4bca734e.js";import{T as Ne}from"../chunks/Tip.b9ac1f03.js";import{D as Z}from"../chunks/Docstring.b6251191.js";import{H as Te,E as je}from"../chunks/getInferenceSnippets.b564dd8b.js";function We(B){let o,$="This class is experimental and might be subject to breaking changes in the future without prior notice.";return{c(){o=s("p"),o.textContent=$},l(g){o=l(g,"P",{"data-svelte-h":!0}),C(o)!=="svelte-1qcb9rb"&&(o.textContent=$)},m(g,y){c(g,o,y)},p:Oe,d(g){g&&n(o)}}}function Ye(B){let o,$="This class is experimental and might be subject to breaking changes in the future without prior notice.";return{c(){o=s("p"),o.textContent=$},l(g){o=l(g,"P",{"data-svelte-h":!0}),C(o)!=="svelte-1qcb9rb"&&(o.textContent=$)},m(g,y){c(g,o,y)},p:Oe,d(g){g&&n(o)}}}function Be(B){let o,$,g,y,I,te,E,we='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,H,Le='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,S,ke='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,N,ae,u,O,de,z,Ae="Client for connecting to one or more MCP servers and processing chat completions with tools.",me,x,fe,P,R,_e,G,De="Connect to an MCP server",be,M,q,ve,J,Ie="Clean up resources",Ce,T,U,$e,K,Ee="Process a query using <code>self.model</code> and available tools, yielding chunks and tool outputs.",ie,F,se,h,V,ye,Q,He='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>.',xe,w,Pe,L,j,Me,X,Se="Run the agent with the given user input.",le,W,ce,ee,ge;return I=new Te({props:{title:"MCP Client",local:"mcp-client",headingTag:"h1"}}),N=new Te({props:{title:"MCP Client",local:"huggingface_hub.MCPClient",headingTag:"h2"}}),O=new Z({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', 'cohere', 'fal-ai', 'featherless-ai', 'fireworks-ai', 'groq', 'hf-inference', 'hyperbolic', 'nebius', 'novita', 'nscale', 'openai', 'replicate', 'sambanova', 'together'], 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"}}),x=new Ne({props:{warning:!0,$$slots:{default:[We]},$$scope:{ctx:B}}}),R=new Z({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>
</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>
</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>
</ul></li>
</ul>`,name:"*params"}],source:"https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/inference/_mcp/mcp_client.py#L126"}}),q=new Z({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#L112"}}),U=new Z({props:{name:"process_single_turn_with_tools",anchor:"huggingface_hub.MCPClient.process_single_turn_with_tools",parameters:[{name:"messages",val:": typing.List[typing.Union[typing.Dict, huggingface_hub.inference._generated.types.chat_completion.ChatCompletionInputMessage]]"},{name:"exit_loop_tools",val:": typing.Optional[typing.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#L236"}}),F=new Te({props:{title:"Agent",local:"huggingface_hub.Agent",headingTag:"h2"}}),V=new Z({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"}}),w=new Ne({props:{warning:!0,$$slots:{default:[Ye]},$$scope:{ctx:B}}}),j=new Z({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#L60"}}),W=new je({props:{source:"https://github.com/huggingface/huggingface_hub/blob/main/docs/source/en/package_reference/mcp.md"}}),{c(){o=s("meta"),$=r(),g=s("p"),y=r(),d(I.$$.fragment),te=r(),E=s("p"),E.innerHTML=we,ne=r(),H=s("p"),H.innerHTML=Le,oe=r(),S=s("p"),S.innerHTML=ke,re=r(),d(N.$$.fragment),ae=r(),u=s("div"),d(O.$$.fragment),de=r(),z=s("p"),z.textContent=Ae,me=r(),d(x.$$.fragment),fe=r(),P=s("div"),d(R.$$.fragment),_e=r(),G=s("p"),G.textContent=De,be=r(),M=s("div"),d(q.$$.fragment),ve=r(),J=s("p"),J.textContent=Ie,Ce=r(),T=s("div"),d(U.$$.fragment),$e=r(),K=s("p"),K.innerHTML=Ee,ie=r(),d(F.$$.fragment),se=r(),h=s("div"),d(V.$$.fragment),ye=r(),Q=s("p"),Q.innerHTML=He,xe=r(),d(w.$$.fragment),Pe=r(),L=s("div"),d(j.$$.fragment),Me=r(),X=s("p"),X.textContent=Se,le=r(),d(W.$$.fragment),ce=r(),ee=s("p"),this.h()},l(e){const t=Ve("svelte-u9bgzb",document.head);o=l(t,"META",{name:!0,content:!0}),t.forEach(n),$=a(e),g=l(e,"P",{}),A(g).forEach(n),y=a(e),m(I.$$.fragment,e),te=a(e),E=l(e,"P",{"data-svelte-h":!0}),C(E)!=="svelte-13o8nel"&&(E.innerHTML=we),ne=a(e),H=l(e,"P",{"data-svelte-h":!0}),C(H)!=="svelte-7cdnea"&&(H.innerHTML=Le),oe=a(e),S=l(e,"P",{"data-svelte-h":!0}),C(S)!=="svelte-1u9ma2q"&&(S.innerHTML=ke),re=a(e),m(N.$$.fragment,e),ae=a(e),u=l(e,"DIV",{class:!0});var p=A(u);m(O.$$.fragment,p),de=a(p),z=l(p,"P",{"data-svelte-h":!0}),C(z)!=="svelte-s2sl1p"&&(z.textContent=Ae),me=a(p),m(x.$$.fragment,p),fe=a(p),P=l(p,"DIV",{class:!0});var Y=A(P);m(R.$$.fragment,Y),_e=a(Y),G=l(Y,"P",{"data-svelte-h":!0}),C(G)!=="svelte-1sfq5nj"&&(G.textContent=De),Y.forEach(n),be=a(p),M=l(p,"DIV",{class:!0});var ue=A(M);m(q.$$.fragment,ue),ve=a(ue),J=l(ue,"P",{"data-svelte-h":!0}),C(J)!=="svelte-nj9nid"&&(J.textContent=Ie),ue.forEach(n),Ce=a(p),T=l(p,"DIV",{class:!0});var pe=A(T);m(U.$$.fragment,pe),$e=a(pe),K=l(pe,"P",{"data-svelte-h":!0}),C(K)!=="svelte-1i4w3kl"&&(K.innerHTML=Ee),pe.forEach(n),p.forEach(n),ie=a(e),m(F.$$.fragment,e),se=a(e),h=l(e,"DIV",{class:!0});var k=A(h);m(V.$$.fragment,k),ye=a(k),Q=l(k,"P",{"data-svelte-h":!0}),C(Q)!=="svelte-10mvlk3"&&(Q.innerHTML=He),xe=a(k),m(w.$$.fragment,k),Pe=a(k),L=l(k,"DIV",{class:!0});var he=A(L);m(j.$$.fragment,he),Me=a(he),X=l(he,"P",{"data-svelte-h":!0}),C(X)!=="svelte-14cbc44"&&(X.textContent=Se),he.forEach(n),k.forEach(n),le=a(e),m(W.$$.fragment,e),ce=a(e),ee=l(e,"P",{}),A(ee).forEach(n),this.h()},h(){D(o,"name","hf:doc:metadata"),D(o,"content",ze),D(P,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),D(M,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),D(T,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),D(u,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),D(L,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),D(h,"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,t){i(document.head,o),c(e,$,t),c(e,g,t),c(e,y,t),f(I,e,t),c(e,te,t),c(e,E,t),c(e,ne,t),c(e,H,t),c(e,oe,t),c(e,S,t),c(e,re,t),f(N,e,t),c(e,ae,t),c(e,u,t),f(O,u,null),i(u,de),i(u,z),i(u,me),f(x,u,null),i(u,fe),i(u,P),f(R,P,null),i(P,_e),i(P,G),i(u,be),i(u,M),f(q,M,null),i(M,ve),i(M,J),i(u,Ce),i(u,T),f(U,T,null),i(T,$e),i(T,K),c(e,ie,t),f(F,e,t),c(e,se,t),c(e,h,t),f(V,h,null),i(h,ye),i(h,Q),i(h,xe),f(w,h,null),i(h,Pe),i(h,L),f(j,L,null),i(L,Me),i(L,X),c(e,le,t),f(W,e,t),c(e,ce,t),c(e,ee,t),ge=!0},p(e,[t]){const p={};t&2&&(p.$$scope={dirty:t,ctx:e}),x.$set(p);const Y={};t&2&&(Y.$$scope={dirty:t,ctx:e}),w.$set(Y)},i(e){ge||(_(I.$$.fragment,e),_(N.$$.fragment,e),_(O.$$.fragment,e),_(x.$$.fragment,e),_(R.$$.fragment,e),_(q.$$.fragment,e),_(U.$$.fragment,e),_(F.$$.fragment,e),_(V.$$.fragment,e),_(w.$$.fragment,e),_(j.$$.fragment,e),_(W.$$.fragment,e),ge=!0)},o(e){b(I.$$.fragment,e),b(N.$$.fragment,e),b(O.$$.fragment,e),b(x.$$.fragment,e),b(R.$$.fragment,e),b(q.$$.fragment,e),b(U.$$.fragment,e),b(F.$$.fragment,e),b(V.$$.fragment,e),b(w.$$.fragment,e),b(j.$$.fragment,e),b(W.$$.fragment,e),ge=!1},d(e){e&&(n($),n(g),n(y),n(te),n(E),n(ne),n(H),n(oe),n(S),n(re),n(ae),n(u),n(ie),n(se),n(h),n(le),n(ce),n(ee)),n(o),v(I,e),v(N,e),v(O),v(x),v(R),v(q),v(U),v(F,e),v(V),v(w),v(j),v(W,e)}}}const ze='{"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(B){return qe(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class et extends Ue{constructor(o){super(),Fe(this,o,Ge,Be,Re,{})}}export{et as component};
