Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions units/en/unit1/mcp-clients.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ For local servers using stdio transport, the configuration includes the command
"transport": {
"type": "stdio",
"command": "python",
"args": ["/path/to/file_explorer_server.py"]
"args": ["/path/to/file_explorer_server.py"] // This is an example, we'll use a real server in the next unit
}
}
]
Expand Down Expand Up @@ -237,26 +237,32 @@ Tiny Agent can run MCP servers with a command line environment. To do this, we w

Let's install `npx` with `npm`. If you don't have `npm` installed, check out the [npm documentation](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm).

### Setup

First, we will need to install `npx` if you don't have it installed. You can do this with the following command:

```bash
# install npx
npm install -g npx
```

<hfoptions id="language">
<hfoption id="python">

First, install the tiny agents package:
Then, we will need to install the huggingface_hub package with the MCP support. This will allow us to run MCP servers and clients.

```bash
pip install "huggingface_hub[mcp]>=0.32.0"
```

First, let's login to the Hugging Face Hub. You will need a [login token](https://huggingface.co/docs/huggingface_hub/v0.32.3/en/quick-start#authentication) to do this.
Then, we will need to log in to the Hugging Face Hub to access the MCP servers. You can do this with the `huggingface-cli` command line tool. You will need a [login token](https://huggingface.co/docs/huggingface_hub/v0.32.3/en/quick-start#authentication) to do this.

```bash
huggingface-cli login
```

<hfoptions id="language">
<hfoption id="python">

### Connecting to MCP Servers

Now, let's create an agent configuration file `agent.json`.

```json
Expand Down Expand Up @@ -291,6 +297,8 @@ First, install the tiny agents package with [npm](https://docs.npmjs.com/downloa
npm install @huggingface/tiny-agents
```

### Connecting to MCP Servers

Make an agent project directory and create an `agent.json` file.

```bash
Expand Down
33 changes: 32 additions & 1 deletion units/en/unit2/gradio-client.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,38 @@ We'll connect to the MCP server we created in the previous section and use it to

## MCP Client in Gradio

First, we need to install the `smolagents`, gradio and mcp-client libraries, if we haven't already:
### Connect to an example MCP Server

Let's connect to an example MCP Server that is already running on Hugging Face. We'll use [this one](https://huggingface.co/spaces/abidlabs/mcp-tools2) for this example. It's a space that contains a collection of MCP tools.

```python
from smolagents.mcp_client import MCPClient

with MCPClient(
{"url": "https://abidlabs-mcp-tools2.hf.space/gradio_api/mcp/sse"}
) as tools:
# Tools from the remote server are available
print("\n".join(f"{t.name}: {t.description}" for t in tools))

```

<details>
<summary>Output</summary>
<pre>
<code>
prime_factors: Compute the prime factorization of a positive integer.
generate_cheetah_image: Generate a cheetah image.
image_orientation: Returns whether image is portrait or landscape.
sepia: Apply a sepia filter to the input image.
</code>
</pre>
</details>

### Connect to your MCP Server from Gradio

Great, now that you've connected to an example MCP Server, let's connect to your own MCP Server from Gradio.

First, we need to install the `smolagents`, Gradio and mcp-client libraries, if we haven't already:

```bash
pip install "smolagents[mcp]" "gradio[mcp]" mcp fastmcp
Expand Down
6 changes: 3 additions & 3 deletions units/vi/unit1/mcp-clients.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ Chúng ta cũng có thể kết nối đến Server MCP được host trên máy
from smolagents.mcp_client import MCPClient

with MCPClient(
{"url": "https://abidlabs-mcp-tools.hf.space/gradio_api/mcp/sse"}
{"url": "https://abidlabs-mcp-tools2.hf.space/gradio_api/mcp/sse"}
) as tools:
# Tools from the remote server are available
print("\n".join(f"{t.name}: {t.description}" for t in tools))
Expand All @@ -312,7 +312,7 @@ with MCPClient(
from smolagents.mcp_client import MCPClient

with MCPClient(
{"url": "https://abidlabs-mcp-tools.hf.space/gradio_api/mcp/sse"}
{"url": "https://abidlabs-mcp-tools2.hf.space/gradio_api/mcp/sse"}
) as tools:
# Tools from the remote server are available
print("\n".join(f"{t.name}: {t.description}" for t in tools))
Expand Down Expand Up @@ -419,4 +419,4 @@ Giờ bạn đã hiểu về MCP Client, hãy sẵn sàng để:
* Tìm hiểu về cách tạo MCP Client tùy chỉnh
* Đi sâu vào các mẫu tích hợp MCP nâng cao

Hãy tiếp tục hành trình của chúng ta vào thế giới của Giao Thức Ngữ Cảnh Mô Hình!
Hãy tiếp tục hành trình của chúng ta vào thế giới của Giao Thức Ngữ Cảnh Mô Hình!