Skip to content

Commit bc9b0e7

Browse files
committed
fix in unit 2
1 parent 884050f commit bc9b0e7

File tree

2 files changed

+37
-62
lines changed

2 files changed

+37
-62
lines changed

units/en/unit2/gradio-client.mdx

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ We'll connect to the MCP server we created in the previous section and use it to
1515
First, we need to install the `smolagents`, gradio and mcp-client libraries, if we haven't already:
1616

1717
```bash
18-
pip install "smolagents[mcp]" "gradio[mcp]" mcp
18+
pip install "smolagents[mcp]" "gradio[mcp]" mcp fastmcp
1919
```
2020

2121
Now, we can import the necessary libraries and create a simple Gradio interface that uses the MCP Client to connect to the MCP Server.
@@ -24,16 +24,15 @@ Now, we can import the necessary libraries and create a simple Gradio interface
2424
```python
2525
import gradio as gr
2626

27-
from mcp.client.stdio import StdioServerParameters
28-
from smolagents import InferenceClientModel, CodeAgent, ToolCollection
29-
from smolagents.mcp_client import MCPClient
27+
from mcp import StdioServerParameters
28+
from smolagents import InferenceClientModel, CodeAgent, ToolCollection, MCPClient
3029
```
3130

3231
Next, we'll connect to the MCP Server and get the tools that we can use to answer questions.
3332

3433
```python
3534
mcp_client = MCPClient(
36-
{"url": "http://localhost:7860/gradio_api/mcp/sse"}
35+
{"url": "http://localhost:7860/gradio_api/mcp/sse"} # This is the MCP Server we created in the previous section
3736
)
3837
tools = mcp_client.get_tools()
3938
```
@@ -77,16 +76,13 @@ Here's the complete example of the MCP Client in Gradio:
7776
```python
7877
import gradio as gr
7978

80-
from mcp.client.stdio import StdioServerParameters
81-
from smolagents import InferenceClientModel, CodeAgent, ToolCollection
82-
from smolagents.mcp_client import MCPClient
79+
from mcp import StdioServerParameters
80+
from smolagents import InferenceClientModel, CodeAgent, ToolCollection, MCPClient
8381

8482

8583
try:
8684
mcp_client = MCPClient(
87-
## Try this working example on the hub:
88-
# {"url": "https://abidlabs-mcp-tools.hf.space/gradio_api/mcp/sse"}
89-
{"url": "http://localhost:7860/gradio_api/mcp/sse"}
85+
{"url": "http://localhost:7860/gradio_api/mcp/sse"} # This is the MCP Server we created in the previous section
9086
)
9187
tools = mcp_client.get_tools()
9288

@@ -119,13 +115,21 @@ To deploy your Gradio MCP client to Hugging Face Spaces:
119115
- Choose "Gradio" as the SDK
120116
- Name your space (e.g., "mcp-client")
121117

122-
2. Create a `requirements.txt` file:
118+
2. Update MCP Server URL in the code:
119+
120+
```python
121+
mcp_client = MCPClient(
122+
{"url": "http://localhost:7860/gradio_api/mcp/sse"} # This is the MCP Server we created in the previous section
123+
)
124+
```
125+
126+
3. Create a `requirements.txt` file:
123127
```txt
124128
gradio[mcp]
125129
smolagents[mcp]
126130
```
127131

128-
3. Push your code to the Space:
132+
4. Push your code to the Space:
129133
```bash
130134
git init
131135
git add server.py requirements.txt

units/en/unit2/tiny-agents.mdx

Lines changed: 20 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -17,52 +17,45 @@ Some MCP Clients, notably Claude Desktop, do not yet support SSE-based MCP Serve
1717

1818
</Tip>
1919

20-
<hfoptions id="tiny-agents">
21-
<hfoption id="typescript">
20+
Tiny Agent can run MCP servers with a command line environment. To do this, we will need to install `npm` and run the server with `npx`. **We'll need these for both Python and JavaScript.**
2221

23-
First, we need to install the `tiny-agents` package.
22+
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).
2423

2524
```bash
26-
npm install @huggingface/tiny-agents
27-
# or
28-
pnpm add @huggingface/tiny-agents
25+
# install npx
26+
npm install -g npx
2927
```
3028

3129
Then, we need to install the `mcp-remote` package.
3230

3331
```bash
3432
npm i mcp-remote
35-
# or
36-
pnpm add mcp-remote
3733
```
3834

39-
</hfoption>
40-
<hfoption id="python">
35+
<hfoptions id="tiny-agents">
36+
<hfoption id="typescript">
4137

42-
First, you need to install the latest version of `huggingface_hub` with the `mcp` extra to get all the necessary components.
38+
For JavaScript, we need to install the `tiny-agents` package.
4339

4440
```bash
45-
pip install "huggingface_hub[mcp]>=0.32.0"
41+
npm install @huggingface/tiny-agents
4642
```
4743

48-
Then, we need to install the `mcp-remote` package.
49-
50-
```bash
51-
npm install mcp-remote
52-
```
44+
</hfoption>
45+
<hfoption id="python">
5346

54-
And we'll need to install `npx` to run the `mcp-remote` command.
47+
For Python, you need to install the latest version of `huggingface_hub` with the `mcp` extra to get all the necessary components.
5548

5649
```bash
57-
npm install -g npx
50+
pip install "huggingface_hub[mcp]>=0.32.0"
5851
```
5952

6053
</hfoption>
6154
</hfoptions>
6255

6356
## Tiny Agents MCP Client in the Command Line
6457

65-
Tiny Agents can create MCP clients from the command line based on JSON configuration files.
58+
Let's repeat the example from [Unit 1](../unit1/mcp-clients.mdx) to create a basic Tiny Agent. Tiny Agents can create MCP clients from the command line based on JSON configuration files.
6659

6760
<hfoptions id="tiny-agents">
6861
<hfoption id="typescript">
@@ -87,7 +80,7 @@ The JSON file will look like this:
8780
"command": "npx",
8881
"args": [
8982
"mcp-remote",
90-
"http://localhost:7860/gradio_api/mcp/sse"
83+
"http://localhost:7860/gradio_api/mcp/sse" // This is the MCP Server we created in the previous section
9184
]
9285
}
9386
}
@@ -109,6 +102,7 @@ Let's setup a project with a basic Tiny Agent.
109102
```bash
110103
mkdir my-agent
111104
touch my-agent/agent.json
105+
cd my-agent
112106
```
113107

114108
The JSON file will look like this:
@@ -135,7 +129,7 @@ The JSON file will look like this:
135129
We can then run the agent with the following command:
136130

137131
```bash
138-
tiny-agents run ./my-agent
132+
tiny-agents run agent.json
139133
```
140134

141135
</hfoption>
@@ -149,10 +143,9 @@ Here we have a basic Tiny Agent that can connect to our Gradio MCP server. It in
149143
| `provider` | The inference provider to use for the agent |
150144
| `servers` | The servers to use for the agent. We'll use the `mcp-remote` server for our Gradio MCP server. |
151145

152-
We could also use an open source model running locally with Tiny Agents.
146+
<Tip>
153147

154-
<hfoptions id="tiny-agents">
155-
<hfoption id="typescript">
148+
We could also use an open source model running locally with Tiny Agents. If we start a local inference server with
156149

157150
```json
158151
{
@@ -173,33 +166,11 @@ We could also use an open source model running locally with Tiny Agents.
173166
}
174167
```
175168

176-
</hfoption>
177-
<hfoption id="python">
178-
179-
```json
180-
{
181-
"model": "Qwen/Qwen3-32B",
182-
"endpoint_url": "http://localhost:1234/v1",
183-
"servers": [
184-
{
185-
"type": "stdio",
186-
"config": {
187-
"command": "npx",
188-
"args": [
189-
"mcp-remote",
190-
"http://localhost:1234/v1/mcp/sse"
191-
]
192-
}
193-
}
194-
]
195-
}
196-
```
197-
198-
</hfoption>
199-
</hfoptions>
200169

201170
Here we have a Tiny Agent that can connect to a local model. It includes a model, endpoint URL (`http://localhost:1234/v1`), and a server configuration. The endpoint should be an OpenAI-compatible endpoint.
202171

172+
</Tip>
173+
203174
## Custom Tiny Agents MCP Client
204175

205176
Now that we understand both Tiny Agents and Gradio MCP servers, let's see how they work together! The beauty of MCP is that it provides a standardized way for agents to interact with any MCP-compatible server, including our Gradio-based sentiment analysis server from earlier sections.

0 commit comments

Comments
 (0)