MCP Client

  • 2025/03/16
  • smolagents MCP clients Docker

I was going through Model Context Protocol (MCP), Smolagents documentation and trying the samples included.

With Smolagents, tools provided by MCP servers can be added to agents. https://huggingface.co/docs/smolagents/tutorials/tools#tool-collection-from-any-mcp-server

from mcp import StdioServerParameters  
from smolagents import ToolCollection, CodeAgent, LiteLLMModel  
  
server_parameters = StdioServerParameters(  
    command="docker",  
    args=["run", "-i", "--rm", "mcp/time-zone-converter"]  
)  
  
model = LiteLLMModel(model_id="anthropic/claude-3-5-sonnet-latest")  
  
with ToolCollection.from_mcp(server_parameters) as tool_collection:  
    agent = CodeAgent(tools=[*tool_collection.tools], model=model, add_base_tools=True,  
                      additional_authorized_imports=["json"], )  
    result = agent.run("What is the time in Melbourne now.")  
    print(result)  
  
    result = agent.run("Convert Current time to Poland time.")  
    print(result)

I thought how an agent can know what tools are provided by a MCP server, and the required arguments to use when calling a tool.

There is a sample MCP client available here - https://modelcontextprotocol.io/quickstart/client. I updated it a little to include run MCP servers using Docker. It is available here.

One nice feature of uv is that, a script's dependencies can be specified in the script itself without using other approaches like using requirements.txt, etc. When running a script with uv run, it creates a virtual environment on the fly and installs the dependencies.

uv run \
    "https://raw.githubusercontent.com/ryandam9/uv_tools/refs/heads/master/mcp_client_to_docker_servers.py" \
    mcp/time-zone-converter
  • mcp/time-zone-converter is the Docker image created from Time MCP Server.

./images/mcp-client-test.png

Links