mcp-use has a complete MCP Agent implementation for Python.
MCP Agents are AI-powered agents that can use tools from MCP servers to accomplish complex tasks. They reason across multiple steps, selecting and executing tools as needed.
Building such agents is easy with mcp-use, all you need is an LLM and the MCP Client.
pip install mcp-use
Here’s a simple example to get you started for an agent with browser tools support.
import asynciofrom langchain_openai import ChatOpenAI # use your preferred LLM providerfrom mcp_use import MCPAgent, MCPClientasync def main(): # Create MCPClient from configuration object client = MCPClient({ "mcpServers": { "playwright": { "command": "npx", "args": ["@playwright/mcp@latest"], "env": { "DISPLAY": ":1" } } } }) # Create agent with the client agent = MCPAgent( llm=ChatOpenAI(model="gpt-4o"), # use your preferred LLM provider client=client, max_steps=30 ) # Run the query result = await agent.run( "Find the best restaurant in San Francisco USING GOOGLE SEARCH" ) print(f"\nResult: {result}") # Clean up await client.close_all_sessions()if __name__ == "__main__": asyncio.run(main())
mcp-use has a complete MCP Client implementation for Python with full async support.
It supports stdio and HTTP with SSE transports for connecting to any MCP server.
pip install mcp-use
Then create a new MCP Client:
import asynciofrom mcp_use import MCPClientasync def main(): client = MCPClient({ "mcpServers": { "everything": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-everything"] } } }) # Initialize all configured sessions await client.create_all_sessions() # Get the session for a specific server session = client.get_session("everything") # List available tools tools = await session.list_tools() print(f"Available tools: {[t.name for t in tools]}") # Call a specific tool with arguments result = await session.call_tool("add", {"a": 1, "b": 2}) print(f"Result: {result}") # Clean up await client.close_all_sessions()if __name__ == "__main__": asyncio.run(main())
To learn more about the MCP Client, see the MCP Client documentation.
mcp-use has a complete MCP server framework implementation for Python.
It supports all official MCP features including tools, resources, prompts, and middleware.
# Via uvx (from PyPI)uvx --from mcp-use create-mcp-use my-server# Or if mcp-use is installed locallycreate-mcp-use my-server# Start the servercd my-serverpython server.py