hands-on
Claude Desktop and Cursor rely on external LLMs to leverage MCP capabilities.
When building enterprise-grade solutions, keeping your data on your own servers becomes critical.
This is where learning to build local MCP clients becomes essential.
Let’s learn that today by building a 100% local MCP server and client.
Stack:
- Build a 100% local and secure MCP client using mcp-use.
- Integrate the client with the Stagehand MCP server.
- Use this setup to control and automate the browser.
A quick background before we get into the code.
MCP follows a client-server architecture where:
- Host (Agent/IDE) runs the MCP Client to communicate with MCP Servers.
- MCP Servers expose tools that can perform various actions.
This architecture enables secure and standardized AI tool integration.
With this understanding in mind, let's start building our own MCP servers and clients.
1️⃣ Build a simple MCP server
First, we create a simple MCP server using FastMCP with a tool that adds two numbers.
- Decorate the method with the specified decorator.
- Add a docstring to the method.
- Implement the functionality.
Then create a configuration file that tells any client how to connect to this server.
2️⃣ Create MCP Client
Next, we build a client using mcp-use, powered by locally running LLMs.
It's completely secure and can run on your machine.
Let's integrate the MCP client and server we just created.
Here's a Streamlit UI for better accessibility that wraps the client we created above.
For didactic purposes, we're starting with a very simple server.
Now, let's make this more practical. We're going to build a browser automation MCP server using Stagehand.
With this, we can navigate websites, click buttons, fill out forms, and extract data using natural language commands (full code is in the GitHub repo shared later).
Here is the implementation:
Next, let's interact with the Stagehand MCP server.
In the video below, when asked to find the cheapest flight from one city to another:
- It navigated to Google.
- Typed in the query.
- Scraped the relevant information.
- Returned the results to the agent to generate a response.
That was simple, wasn’t it?
We used mcp-use because you can use it to connect any LLMs to MCP servers & create local MCP clients easily.
- Compatible with Ollama & LangChain
- Stream Agent output async
- Built-in debugging mode, etc
Find the GitHub Repo here →
Find the code for this project on GitHub here →