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, MCPClient
async def main():
# Load environment variables
load_dotenv()
# Create configuration dictionary
config = {
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest"],
"env": {
"DISPLAY": ":1"
}
}
}
}
# Create MCPClient from configuration dictionary
client = MCPClient.from_dict(config)
# Create LLM
llm = ChatOpenAI(model="gpt-4o")
# Create agent with the client
agent = MCPAgent(llm=llm, 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}")
if __name__ == "__main__":
asyncio.run(main())
说明
mcp-use 可以与langchain 集成,很值得尝试下
浙公网安备 33010602011771号