NM

nituparimi/mcp

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

2 stars 0 forks 质量 48 趋势 8

model context protocol

概览

Open Source MCP CLient Library PyPI Downloads PyPI Version Python Versions Documentation License Code style: Ruff GitHub stars 🌐 MCP-Use is the open source way to connect any LLM to MCP tools and build custom agents that have tool access, without using closed source or application clients. 💡 Let developers easily connect any LLM to tools like web browsing, file operations, and more. Features ✨ Key Features Feature Description 🔄 Ease of use Create your first MCP capable agent you need only 6 lines of code 🤖 LLM Flexibility Works with any langchain supported LLM that supports tool calling (OpenAI, Anthropic, Groq, LLama etc.) 🌐 HTTP Support Direct connection to MCP servers running on specific HTTP ports 🧩 Multi-Server Support Use multiple MCP servers simultaneously in a single agent 🛡️ Tool Restrictions Restrict potentially dangerous tools like file system or network access Quick start With pip: pip install mcp-use Or install from source: git clone https://github.

README

以下为原文 README 节选,完整内容请查看原文。

mcp

model context protocol

Open Source MCP CLient Library PyPI Downloads PyPI Version Python Versions Documentation License Code style: Ruff GitHub stars

🌐 MCP-Use is the open source way to connect any LLM to MCP tools and build custom agents that have tool access, without using closed source or application clients.

💡 Let developers easily connect any LLM to tools like web browsing, file operations, and more.

Features ✨ Key Features Feature Description 🔄 Ease of use Create your first MCP capable agent you need only 6 lines of code 🤖 LLM Flexibility Works with any langchain supported LLM that supports tool calling (OpenAI, Anthropic, Groq, LLama etc.) 🌐 HTTP Support Direct connection to MCP servers running on specific HTTP ports 🧩 Multi-Server Support Use multiple MCP servers simultaneously in a single agent 🛡️ Tool Restrictions Restrict potentially dangerous tools like file system or network access Quick start With pip:

pip install mcp-use Or install from source:

git clone https://github.com/pietrozullo/mcp-use.git cd mcp-use pip install -e . Installing LangChain Providers mcp_use works with various LLM providers through LangChain. You’ll need to install the appropriate LangChain provider package for your chosen LLM. For example:

For OpenAI

pip install langchain-openai

For Anthropic

pip install langchain-anthropic

For other providers, check the LangChain chat models documentation

and add your API keys for the provider you want to use to your .env file.

OPENAI_API_KEY= ANTHROPIC_API_KEY= Important: Only models with tool calling capabilities can be used with mcp_use. Make sure your chosen model supports function calling or tool use.

Spin up your 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",
)
print(f"\nResult: {result}")

if name == “main”: asyncio.run(main()) You can also add the servers configuration from a config file like this:

client = MCPClient.from_config_file( os.path.join(“browser_mcp.json”) ) Example configuration file (browser_mcp.json):

{ “mcpServers”: { “playwright”: { “command”: “npx”, “args”: [“@playwright/mcp@latest”], “env”: {

在 GitHub 查看完整 README

安装

npx @playwright/mcp@latest
新手?先看 mcpskill.org 教程 →