mcp-use mcp server 交互工具
mcp-use mcp server 交互工具,当然mcp-use 不支持简单的mcp client,还支持agent开发,通过mcp-use 我们可以将llm 与mcp server 集成起来,提升agent 的能力
简单示例
import asyncio
import os
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
from mcp_use import MCPAgent, MCPClientasync def main():# Load environment variablesload_dotenv()# Create configuration dictionaryconfig = {"mcpServers": {"playwright": {"command": "npx","args": ["@playwright/mcp@latest"],"env": {"DISPLAY": ":1"}}}}# Create MCPClient from configuration dictionaryclient = MCPClient.from_dict(config)# Create LLMllm = ChatOpenAI(model="gpt-4o")# Create agent with the clientagent = MCPAgent(llm=llm, client=client, max_steps=30)# Run the queryresult = await agent.run("Find the best restaurant in San Francisco USING GOOGLE SEARCH",)print(f"\nResult: {result}")if __name__ == "__main__":asyncio.run(main())
说明
mcp-use 可以与langchain 集成,很值得尝试下
参考资料
https://github.com/mcp-use/mcp-use
https://docs.mcp-use.com/
https://docs.mcp-use.com/essentials/client-configuration
