MCP-Use LogoMCP-Use

Code Builder

import asyncio
from langchain_openai import ChatOpenAI
from mcp_use import MCPAgent, MCPClient

async def main():
    client = MCPClient(config=
    {
        "mcpServers": {
            "playwright": {
                "command": "npx",
                "args": ["@playwright/mcp@latest"],
                "env": { "DISPLAY": ":1" }
            }
        }
    }
    )
    # Create LLM
    llm = ChatOpenAI(model="gpt-4o", api_key=...)
    # Create agent with tools
    agent = MCPAgent(llm=llm, client=client, max_steps=30)
    # Run the query
    result = await agent.run("Find the best restaurant in San Francisco")

if __name__ == "__main__":
    asyncio.run(main())