The article explains how to build a lightweight agent using the Model Context Protocol (MCP) in just 50 lines of TypeScript. MCP provides a standard API for exposing tools that can be hooked to large language models (LLMs). By using Hugging Face’s inference client SDKs, the author shows how to connect to local MCP servers, retrieve tool lists, and run a simple while-loop agent that calls tools and feeds results back to the LLM. The example demonstrates tool usage, parsing, and control flow, and highlights the growing support for function calling in modern LLMs.
Over the past few weeks, I've been diving into MCP ( Model Context Protocol ) to understand what the hype around it was all about.
My TL;DR is that it's fairly simple, but still quite powerful: MCP is a standard API to expose sets of Tools that can be hooked to LLMs.
It is fairly simple to extend an Inference Client – at HF, we have two official client SDKs: @huggingface/inference in JS, and huggingface_hub in Python – to also act as a MCP client and hook the available tools from MCP servers into the LLM inference.
A tool is defined by its name, a description, and a JSONSchema representation of its parameters. In some sense, it is an opaque representation of any function's interface, as seen from the outside (meaning, the LLM does not care how the function is actually implemented).
tool_choice: "auto" is the parameter you pass for the LLM to generate zero, one, or multiple tool calls.
For each MCP server we connect to, we slightly re-format its list of tools and add them to this.availableTools .
Once you have an MCP Client, an Agent is literally just a while loop on top of it.
In this short article, I will walk you through how I implemented it in Typescript (JS), how you can adopt MCP too and how it's going to make Agentic AI way simpler going forward.
You'll see your simple Agent connect to two distinct MCP servers (running locally), loading their tools, then prompting you for a conversation.
By simplifying the integration of tool‑based function calling, MCP lowers the barrier to creating agentic applications, encouraging broader adoption of LLMs in practical workflows.