
How to Build an MCP Client in Python in 10 Min
You have seen a dozen tutorials on building MCP servers . But how do you actually connect to one from your own code? If you want your Python app or AI agent to discover and call MCP tools programmatically -- not through Claude Desktop or Cursor -- you need a client. Here is how to build one. The server (so you can test end-to-end) Save this as server.py . It exposes a single get_weather tool over stdio: # server.py from mcp.server.fastmcp import FastMCP mcp = FastMCP ( " weather " ) @mcp.tool () def get_weather ( city : str ) -> str : """ Get the current weather for a city. """ # Stub response -- swap in a real API call if you want return f " Sunny, 22C in { city } " if __name__ == " __main__ " : mcp . run ( transport = " stdio " ) That is the server side handled in 10 lines. Now for the interesting part. The client Save this as client.py : # client.py import asyncio from mcp import ClientSession , StdioServerParameters from mcp.client.stdio import stdio_client async def main (): # 1.
Continue reading on Dev.to Tutorial
Opens in a new tab



