---
title: "Tiny Agents in Python: a MCP-powered agent in ~70 lines of code"
description: "Hugging Face's huggingface_hub Python SDK now includes an MCP client and a minimal Agent class, letting an LLM pull tools from MCP servers (stdio, SSE or streamable HTTP) and call them during inference."
url: "https://swe.quest/articles/tiny-agents-in-python-a-mcp-powered-agent-in-70-lines-of-code-ec89d52eb52d9576"
canonical: "https://huggingface.co/blog/python-tiny-agents"
source: "Hugging Face"
published: "2025-05-23"
difficulty: "medium"
kind: "How-to"
reading_minutes: 16
tags: ["ai-agents","llms","python"]
---

# Tiny Agents in Python: a MCP-powered agent in ~70 lines of code

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2025-05-23, 16 min read, How-to. Original: [https://huggingface.co/blog/python-tiny-agents](https://huggingface.co/blog/python-tiny-agents)

## Summary

Hugging Face's huggingface\_hub Python SDK now includes an MCP client and a minimal Agent class, letting an LLM pull tools from MCP servers (stdio, SSE or streamable HTTP) and call them during inference. Install it with \`pip install "huggingface\_hub\[mcp\]"\`, then run agents from the \`tiny-agents\` CLI, configured by an agent.json that sets model, inference provider and MCP servers, plus an optional PROMPT.md. The MCPClient connects to servers, converts their tool schemas into OpenAI-style function definitions, and streams chat completions while rebuilding tool calls. It then routes each call to the right MCP session. The Agent is essentially a while loop on top of the client, with special exit-loop tools to end a turn.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [AI agents](https://swe.quest/tags/ai-agents.md) (AI & ML)
- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)
- [Python](https://swe.quest/tags/python.md) (Languages)

## Prerequisites

- LLM function calling ([easy posts on LLMs](https://swe.quest/tags/llms.md?difficulty=easy))
- Python asyncio ([easy posts on Python](https://swe.quest/tags/python.md?difficulty=easy))

## Keywords

Model Context Protocol, huggingface\_hub, tiny-agents, InferenceClient, Playwright MCP, Gradio, Qwen2.5-72B-Instruct

## Related posts

- [Tiny Agents: an MCP-powered agent in 50 lines of code](https://swe.quest/articles/tiny-agents-an-mcp-powered-agent-in-50-lines-of-code-6bc1baf5d192d871.md): Hugging Face · 2025-04-25 · Medium · 10 min read · AI agents, LLMs, TypeScript
  An LLM agent built on the Model Context Protocol reduces to a simple while loop around an MCP-aware inference client: connect to MCP servers, convert their tools into OpenAI-style function definitions, pass them to the chat-completion call, execute returned tool calls via the MCP SDK, and feed results back.
- [Implementing MCP Servers in Python: An AI Shopping Assistant with Gradio](https://swe.quest/articles/implementing-mcp-servers-in-python-an-ai-shopping-assistant-with-gradio-21ac8e123355c19a.md): Hugging Face · 2025-07-31 · Medium · 4 min read · AI agents, Python, LLMs
  Gradio's MCP integration turns Python functions into LLM tools: launching an app with mcp\_server=True exposes each endpoint as an MCP tool, with names, descriptions and input schemas generated from function docstrings, plus progress streaming and file upload handling.
- [Tool Use, Unified](https://swe.quest/articles/tool-use-unified-117f148d6f2c2374.md): Hugging Face · 2024-08-12 · Medium · 11 min read · LLMs, AI agents, Python, API design
  Hugging Face Transformers extends Jinja chat templates to cover tool use, giving a single portable API for passing tools to Mistral, Cohere, NousResearch and Llama models.
- [Introducing Agents.js: Give tools to your LLMs using JavaScript](https://swe.quest/articles/introducing-agents-js-give-tools-to-your-llms-using-javascript-690428d96ad96e44.md): Hugging Face · 2023-07-24 · Medium · 4 min read · AI agents, JavaScript, LLMs
  Agents.js is a JavaScript library from huggingface.js that gives LLMs tool access in the browser or on Node.
- [How to build AI agents with MCP: 12 framework comparison (2025)](https://swe.quest/articles/how-to-build-ai-agents-with-mcp-12-framework-comparison-2025-21cb351a1cc659e0.md): ClickHouse · 2025-10-13 · Medium · 27 min read · AI agents, LLMs, Python
  Twelve agent SDKs now support the Model Context Protocol: Claude Agent SDK, OpenAI Agents SDK, Microsoft Agent Framework, Google ADK, CrewAI, Upsonic, mcp-agent, Agno, DSPy, LangChain, LlamaIndex and PydanticAI.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
