Source: smolagents docs: Tools (advanced usage)
smolagents tool tutorial: Tool subclasses, Hub sharing with trust_remote_code, MCPClient and ToolCollection for MCP servers, structured_output for MCP outputSchema, Gradio Spaces and LangChain tools.
Contents
- What: official tutorial
- Author: Hugging Face
- Date: read 2026-11-14 (docs v1.26.0)
- Original: https://huggingface.co/docs/smolagents/tutorials/tools
Summary
Explains that a smolagents tool is a class wrapping a function with metadata the model sees (name, description, typed inputs, output type), and covers every way to get tools into an agent: custom classes, the Hub, MCP servers, Gradio Spaces and LangChain.
Key claims
- A
Toolsubclass definesname,description(goes into the system prompt),inputs(type plus description),output_type, andforward. Allowed types include string, boolean, integer, number, image, audio, array, object, any, null. - Tools pushed to the Hub must be self-contained: imports inside the functions, and
__init__takes onlyself. load_tool(...)/Tool.from_hub(...)requiretrust_remote_code=Truebecause loading runs third-party code.MCPClient(server_parameters)loads tools from stdio (StdioServerParameters) or Streamable HTTP ({"url": ..., "transport": "streamable-http"}) MCP servers, as a context manager or withget_tools()plus explicitdisconnect(); it accepts a list of servers (the multi-server example mixes a stdio server with an SSE URL).MCPClient(..., structured_output=True)uses MCPoutputSchema/structuredContentand adds output JSON schemas to the CodeAgent system prompt. The default is False for now; the docs say it will flip to True later.ToolCollection.from_mcp(..., trust_remote_code=True)(also takesstructured_output) andToolCollection.from_hub(...)load groups of tools (Hub collection tools load lazily, only when called);Tool.from_space(...)wraps a Gradio Space;Tool.from_langchain(...)wraps a LangChain tool.agent.toolsis a plain dict and can be edited after construction. The docs warn that too many tools overwhelm weaker models.- Security warning: stdio MCP servers always run code on your machine; only connect to trusted servers. Remote Streamable HTTP servers do not run code locally but still warrant caution.