---
title: "Tiny Agents: an MCP-powered agent in 50 lines of code"
description: "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."
url: "https://swe.quest/articles/tiny-agents-an-mcp-powered-agent-in-50-lines-of-code-6bc1baf5d192d871"
canonical: "https://huggingface.co/blog/tiny-agents"
source: "Hugging Face"
published: "2025-04-25"
difficulty: "medium"
kind: "How-to"
reading_minutes: 10
tags: ["ai-agents","llms","typescript"]
---

# Tiny Agents: an MCP-powered agent in 50 lines of code

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

## Summary

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. The TypeScript implementation in huggingface.js extends InferenceClient into an McpClient that holds one session per server and maps tool names to sessions. An Agent class adds a system prompt plus two control-flow tools (task\_complete, ask\_question). The loop alternates tool calls and results until an exit tool is called, the model answers twice without tools, or a turn limit is reached. The default setup uses Qwen2.5-72B on Nebius, and the model, provider and MCP servers can be swapped.

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)
- [TypeScript](https://swe.quest/tags/typescript.md) (Languages)

## Prerequisites

- LLM function calling ([easy posts on LLMs](https://swe.quest/tags/llms.md?difficulty=easy))
- TypeScript async generators ([easy posts on TypeScript](https://swe.quest/tags/typescript.md?difficulty=easy))
- Node.js ([easy posts on JavaScript](https://swe.quest/tags/javascript.md?difficulty=easy))

## Keywords

Model Context Protocol, Tiny Agents, huggingface.js, Playwright MCP, Qwen2.5-72B-Instruct, InferenceClient

## Related posts

- [Tiny Agents in Python: a MCP-powered agent in ~70 lines of code](https://swe.quest/articles/tiny-agents-in-python-a-mcp-powered-agent-in-70-lines-of-code-ec89d52eb52d9576.md): Hugging Face · 2025-05-23 · Medium · 16 min read · AI agents, LLMs, Python
  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.
- [What’s MCP all about? Comparing MCP with LLM function calling](https://swe.quest/articles/what-s-mcp-all-about-comparing-mcp-with-llm-function-calling-fcce1ee01a7d0aed.md): Neon · 2025-03-12 · Medium · 5 min read · AI agents, LLMs, TypeScript
  The Model Context Protocol (MCP) builds on LLM function calling by moving tool definitions and execution out of individual LLM applications into standalone servers that any MCP-compatible client can discover and invoke.
- [You Should Write An Agent](https://swe.quest/articles/you-should-write-an-agent-1b4d0eb48fb350d8.md): Fly.io · 2025-11-06 · Medium · 10 min read · AI agents, LLMs, Python
  An LLM agent is just a loop around a stateless chat API: keep a list of messages, replay it on every call, and when the model emits a function\_call, run the tool and append its output.
- [Building a CLI Client For Model Context Protocol Servers](https://swe.quest/articles/building-a-cli-client-for-model-context-protocol-servers-36e215421e2291e4.md): Neon · 2024-12-20 · Medium · 5 min read · AI agents, LLMs, TypeScript, Developer tools
  A minimal MCP client can run outside Claude Desktop by implementing four pieces: connecting to the server over stdio, listing tools via tools/list, invoking them via tools/call, and looping tool results back into the Anthropic Messages API.
- [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.

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)
