diff --git a/units/en/unit1/mcp-clients.mdx b/units/en/unit1/mcp-clients.mdx index 0095f71..185468e 100644 --- a/units/en/unit1/mcp-clients.mdx +++ b/units/en/unit1/mcp-clients.mdx @@ -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 } } ] @@ -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 ``` - - - -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 ``` + + + +### Connecting to MCP Servers + Now, let's create an agent configuration file `agent.json`. ```json @@ -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 diff --git a/units/en/unit2/gradio-client.mdx b/units/en/unit2/gradio-client.mdx index f77eb25..5587e80 100644 --- a/units/en/unit2/gradio-client.mdx +++ b/units/en/unit2/gradio-client.mdx @@ -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)) + +``` + +
+Output +
+
+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.
+
+
+
+ +### 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 diff --git a/units/vi/unit1/mcp-clients.mdx b/units/vi/unit1/mcp-clients.mdx index 09b2d6e..c6f3bce 100644 --- a/units/vi/unit1/mcp-clients.mdx +++ b/units/vi/unit1/mcp-clients.mdx @@ -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)) @@ -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)) @@ -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! \ No newline at end of file +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!