Skip to content

Commit 209bcfa

Browse files
authored
Merge branch 'main' into patch-2
2 parents ff8e667 + 20defb1 commit 209bcfa

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

units/en/unit1/mcp-clients.mdx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ In the next section, we'll explore the ecosystem of MCP servers available on Hug
219219

220220
## Code Clients
221221

222-
You can also use the MCP Client within code so that the tools are available to the LLM. Let's explore some examples in `smolagents`.
222+
You can also use the MCP Client within code so that the tools are available to the LLM. Let's explore some examples in `smolagents`. To run these examples you will need to add `mcp[cli]`, `smolagents[toolkit]`, and `smolagents[mcp]` to your `uv` virtual environment.
223223

224224
First, let's explore our weather server from the previous page. In `smolagents`, we can use the `ToolCollection` class to automatically discover and register tools from an MCP server. This is done by passing the `StdioServerParameters` or `SSEServerParameters` to the `ToolCollection.from_mcp` method. We can then print the tools to the console.
225225

@@ -307,17 +307,19 @@ We can also connect to an MCP package. Here's an example of connecting to the `p
307307

308308
```python
309309
import os
310-
from smolagents import ToolCollection, CodeAgent
311-
from mcp import StdioServerParameters
310+
from smolagents import ToolCollection, CodeAgent, InferenceClientModel
311+
from mcp.client.stdio import StdioServerParameters
312+
313+
model = InferenceClientModel()
312314

313315
server_parameters = StdioServerParameters(
314-
command="uv",
316+
command="uvx",
315317
args=["--quiet", "[email protected]"],
316318
env={"UV_PYTHON": "3.12", **os.environ},
317319
)
318320

319321
with ToolCollection.from_mcp(server_parameters, trust_remote_code=True) as tool_collection:
320-
agent = CodeAgent(tools=[*tool_collection.tools], add_base_tools=True)
322+
agent = CodeAgent(tools=[*tool_collection.tools], add_base_tools=True, model=model)
321323
agent.run("Please find a remedy for hangover.")
322324
```
323325

0 commit comments

Comments
 (0)