Building a CLI Client For Model Context Protocol Servers
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. TypeScript code builds this into an interactive CLI with a persisted message history, a chat loop and an entry point that launches the Neon MCP server. The simple version lacks streaming and stops after the first tool call; Neon's published MCP Client CLI handles both.
Related posts
- Tiny Agents: an MCP-powered agent in 50 lines of code
Hugging Face mediumAdeptAn 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.
- What’s MCP all about? Comparing MCP with LLM function calling
Neon mediumAdept
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. A Home Assistant light-control function is implemented both ways. The first version uses OpenAI tool definitions in JSON, with the app parsing tool_calls and executing them itself. The second is an MCP server built with the TypeScript SDK, a Zod schema and stdio transport, registered in Cursor. The takeaway is that function calling leaves discovery and execution to each app, while MCP standardizes them so tools can be reused across agents like Cursor, Windsurf and Claude Desktop.
- How to Build an MCP Server with Gradio
Hugging Face mediumAdeptGradio apps become Model Context Protocol servers by passing mcp_server=True to launch(), which auto-converts each Python function into an MCP tool, using its docstring and type hints to build the description and input schema. The server is exposed over SSE at /gradio_api/mcp/sse. Claude Desktop, which lacks SSE support, can reach it through mcp-remote via npx. Newer features include decorators for MCP resources and prompts, MCP-only functions via gr.api(), automatic file and base64 conversion, per-tool latency and success metrics, and free hosting on Hugging Face Spaces with bearer-token auth for private Spaces.
- Tiny Agents in Python: a MCP-powered agent in ~70 lines of code
Hugging Face mediumAdeptHugging 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.
- Better Rails for Agents: A New Remote MCP and Railway Agent in the CLI
Railway mediumAdeptRailway shipped a remote MCP server at mcp.railway.com, which connects to MCP clients over OAuth with no local install, and a new `railway agent` CLI command for interactive, scripted or CI use with JSON output. The MCP surface is kept deliberately small at 7 tools, because every tool definition costs client context and multi-step operations cost a round-trip each. Questions such as "why is my deploy crashing" go to a `railway-agent` tool that runs the multi-step investigation server-side and returns one answer. Instead of a separate service, the MCP server is a stateless Koa route inside the main backend. It reuses the existing OIDC provider and permission controllers, passes per-request context through AsyncLocalStorage, and wraps tools in a factory that handles auth and errors.