Token导航 LogoToken导航TokenDH.com
MCP Server Blender logo
AI代理stdio官方级别未说明来源级核验

MCP Server Blender

MCP Server

MCP-Use是一个开源库,允许开发者将任何大型语言模型(LLM)连接到MCP服务器,构建具有工具访问权限的自定义代理。

工具数

0

提示词数

0

GitHub Stars

1

资源数

0
PythonClaudeAI代理Claude

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

Gyan-max

提供方

Gyan-max

最后核验

2026/5/17 20:21

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

pip install mcp-use

详细介绍

Unified MCP Client Library

![](https://pypi.org/project/mcp_use/) ](https://pypi.org/project/mcp_use/) ](https://pypi.org/project/mcp_use/) ](https://pypi.org/project/mcp_use/) ![Documentation](https://docs.mcp-use.io) ![Website](https://mcp-use.io) ![License](https://github.com/pietrozullo/mcp-use/blob/main/LICENSE) ![Code style: Ruff](https://github.com/astral-sh/ruff) ](https://github.com/pietrozullo/mcp-use/stargazers) ![Twitter Follow](https://x.com/pietrozullo)

🌐 MCP Use是一种开源的连接方式 任何LLM到任何MCP服务器 并构建具有工具访问权限的自定义代理,而无需使用闭源或应用程序客户端。

💡 让开发人员轻松地将任何LLM连接到web浏览、文件操作等工具。

特性

✨ 主要特点

特性描述
🔄 易用性创建您的第一个支持MCP的代理,您只需要6行代码
🤖 LLM灵活性适用于任何支持工具调用的语言链支持的LLM(OpenAI、Anthropic、Groq、LLama等)
🌐 代码生成器探索MCP功能,并使用交互式生成入门代码 代码生成器.
🔗 HTTP支持直接连接到在特定HTTP端口上运行的MCP服务器
⚙️ 动态服务器选择代理可以从可用池中为给定任务动态选择最合适的MCP服务器
🧩 多服务器支持在单个代理中同时使用多个MCP服务器
🛡️ 工具限制限制文件系统或网络访问等潜在危险的工具
🔧 海关代理使用LangChain适配器使用任何框架构建自己的代理,或创建新的适配器

快速启动

使用pip:

pip install mcp-use

或者从源代码安装:

git clone https://github.com/pietrozullo/mcp-use.git
cd mcp-use
pip install -e .

安装LangChain提供程序

mcp_use通过LangChain与各种LLM提供商合作。您需要为您选择的LLM安装相应的LangChain提供程序包。例如:

# For OpenAI
pip install langchain-openai

# For Anthropic
pip install langchain-anthropic

# For other providers, check the [LangChain chat models documentation](https://python.langchain.com/docs/integrations/chat/)

并将您要使用的提供商的API密钥添加到您的 .env 文件。

OPENAI_API_KEY=
ANTHROPIC_API_KEY=
重要:只有具有工具调用功能的模型才能与mcp_use一起使用。确保您选择的模型支持函数调用或工具使用。

启动您的代理:

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())

您还可以从配置文件中添加服务器配置,如下所示:

client = MCPClient.from_config_file(
        os.path.join("browser_mcp.json")
    )

配置文件示例(browser_mcp.json):

{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": ["@playwright/mcp@latest"],
      "env": {
        "DISPLAY": ":1"
      }
    }
  }
}

有关其他设置、型号等信息,请查看文档。

流媒体代理输出

MCP Use支持使用以下命令异步流式传输代理输出 astream 方法on MCPAgent。这允许您接收代理生成的增量结果、工具操作和中间步骤,从而实现实时反馈和进度报告。

如何使用

呼叫 agent.astream(query) 并异步迭代结果:

async for chunk in agent.astream("Find the best restaurant in San Francisco"):
    print(chunk["messages"], end="", flush=True)

每个块都是一个字典,其中包含以下键 actions, steps, messages,以及(在最后一块上) output。这使您能够构建响应式UI或实时记录代理进度。

示例:实践中的流媒体

import asyncio
import os
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
from mcp_use import MCPAgent, MCPClient

async def main():
    load_dotenv()
    client = MCPClient.from_config_file("browser_mcp.json")
    llm = ChatOpenAI(model="gpt-4o")
    agent = MCPAgent(llm=llm, client=client, max_steps=30)
    async for chunk in agent.astream("Look for job at nvidia for machine learning engineer."):
        print(chunk["messages"], end="", flush=True)

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

此流式界面非常适合需要实时更新的应用程序,如聊天机器人、仪表板或交互式笔记本电脑。

示例用例

用Playwright浏览网页

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 MCPClient from config file
    client = MCPClient.from_config_file(
        os.path.join(os.path.dirname(__file__), "browser_mcp.json")
    )

    # Create LLM
    llm = ChatOpenAI(model="gpt-4o")
    # Alternative models:
    # llm = ChatAnthropic(model="claude-3-5-sonnet-20240620")
    # llm = ChatGroq(model="llama3-8b-8192")

    # 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",
        max_steps=30,
    )
    print(f"\nResult: {result}")

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

Airbnb搜索

import asyncio
import os
from dotenv import load_dotenv
from langchain_anthropic import ChatAnthropic
from mcp_use import MCPAgent, MCPClient

async def run_airbnb_example():
    # Load environment variables
    load_dotenv()

    # Create MCPClient with Airbnb configuration
    client = MCPClient.from_config_file(
        os.path.join(os.path.dirname(__file__), "airbnb_mcp.json")
    )

    # Create LLM - you can choose between different models
    llm = ChatAnthropic(model="claude-3-5-sonnet-20240620")

    # Create agent with the client
    agent = MCPAgent(llm=llm, client=client, max_steps=30)

    try:
        # Run a query to search for accommodations
        result = await agent.run(
            "Find me a nice place to stay in Barcelona for 2 adults "
            "for a week in August. I prefer places with a pool and "
            "good reviews. Show me the top 3 options.",
            max_steps=30,
        )
        print(f"\nResult: {result}")
    finally:
        # Ensure we clean up resources properly
        if client.sessions:
            await client.close_all_sessions()

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

配置文件示例(airbnb_mcp.json):

{
  "mcpServers": {
    "airbnb": {
      "command": "npx",
      "args": ["-y", "@openbnb/mcp-server-airbnb"]
    }
  }
}

Blender 3D创建

import asyncio
from dotenv import load_dotenv
from langchain_anthropic import ChatAnthropic
from mcp_use import MCPAgent, MCPClient

async def run_blender_example():
    # Load environment variables
    load_dotenv()

    # Create MCPClient with Blender MCP configuration
    config = {"mcpServers": {"blender": {"command": "uvx", "args": ["blender-mcp"]}}}
    client = MCPClient.from_dict(config)

    # Create LLM
    llm = ChatAnthropic(model="claude-3-5-sonnet-20240620")

    # Create agent with the client
    agent = MCPAgent(llm=llm, client=client, max_steps=30)

    try:
        # Run the query
        result = await agent.run(
            "Create an inflatable cube with soft material and a plane as ground.",
            max_steps=30,
        )
        print(f"\nResult: {result}")
    finally:
        # Ensure we clean up resources properly
        if client.sessions:
            await client.close_all_sessions()

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

配置文件支持

MCP Use支持从配置文件初始化,使管理和切换不同的MCP服务器设置变得容易:

import asyncio
from mcp_use import create_session_from_config

async def main():
    # Create an MCP session from a config file
    session = create_session_from_config("mcp-config.json")

    # Initialize the session
    await session.initialize()

    # Use the session...

    # Disconnect when done
    await session.disconnect()

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

HTTP连接示例

MCP Use支持HTTP连接,允许您连接到在特定HTTP端口上运行的MCP服务器。此功能对于与基于web的MCP服务器集成特别有用。

以下是一个如何使用HTTP连接功能的示例:

import asyncio
import os
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
from mcp_use import MCPAgent, MCPClient

async def main():
    """Run the example using a configuration file."""
    # Load environment variables
    load_dotenv()

    config = {
        "mcpServers": {
            "http": {
                "url": "http://localhost:8931/sse"
            }
        }
    }

    # Create MCPClient from config file
    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",
        max_steps=30,
    )
    print(f"\nResult: {result}")

if __name__ == "__main__":
    # Run the appropriate example
    asyncio.run(main())

此示例演示了如何连接到在特定HTTP端口上运行的MCP服务器。请确保在运行此示例之前启动MCP服务器。

多服务器支持

MCP使用允许使用 MCPClient这使得需要来自不同服务器的工具的复杂工作流程成为可能,例如与文件操作或3D建模相结合的网页浏览。

配置

您可以在配置文件中配置多个服务器:

{
  "mcpServers": {
    "airbnb": {
      "command": "npx",
      "args": ["-y", "@openbnb/mcp-server-airbnb", "--ignore-robots-txt"]
    },
    "playwright": {
      "command": "npx",
      "args": ["@playwright/mcp@latest"],
      "env": {
        "DISPLAY": ":1"
      }
    }
  }
}

用法

MCPClient 类提供了管理多个服务器连接的方法。创建时 MCPAgent,您可以提供 MCPClient 配置有多个服务器。

默认情况下,代理将可以从所有配置的服务器访问工具。如果需要为特定任务定位特定服务器,可以指定 server_name 当呼叫 agent.run() 方法。

# Example: Manually selecting a server for a specific task
result = await agent.run(
    "Search for Airbnb listings in Barcelona",
    server_name="airbnb" # Explicitly use the airbnb server
)

result_google = await agent.run(
    "Find restaurants near the first result using Google Search",
    server_name="playwright" # Explicitly use the playwright server
)

动态服务器选择(服务器管理器)

为了提高效率,并在处理来自不同服务器的许多工具时减少潜在的代理混淆,您可以通过设置启用服务器管理器 use_server_manager=True 在...期间 MCPAgent 初始化。

启用后,代理将根据LLM为特定步骤选择的工具智能地选择正确的MCP服务器。这最大限度地减少了不必要的连接,并确保代理为任务使用适当的工具。

import asyncio
from mcp_use import MCPClient, MCPAgent
from langchain_anthropic import ChatAnthropic

async def main():
    # Create client with multiple servers
    client = MCPClient.from_config_file("multi_server_config.json")

    # Create agent with the client
    agent = MCPAgent(
        llm=ChatAnthropic(model="claude-3-5-sonnet-20240620"),
        client=client,
        use_server_manager=True  # Enable the Server Manager
    )

    try:
        # Run a query that uses tools from multiple servers
        result = await agent.run(
            "Search for a nice place to stay in Barcelona on Airbnb, "
            "then use Google to find nearby restaurants and attractions."
        )
        print(result)
    finally:
        # Clean up all sessions
        await client.close_all_sessions()

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

工具访问控制

MCP使用允许您限制代理可用的工具,从而提供更好的安全性和对代理功能的控制:

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

async def main():
    # Create client
    client = MCPClient.from_config_file("config.json")

    # Create agent with restricted tools
    agent = MCPAgent(
        llm=ChatOpenAI(model="gpt-4"),
        client=client,
        disallowed_tools=["file_system", "network"]  # Restrict potentially dangerous tools
    )

    # Run a query with restricted tool access
    result = await agent.run(
        "Find the best restaurant in San Francisco"
    )
    print(result)

    # Clean up
    await client.close_all_sessions()

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

构建自定义代理:

您还可以使用LangChain适配器构建自己的自定义代理:

import asyncio
from langchain_openai import ChatOpenAI
from mcp_use.client import MCPClient
from mcp_use.adapters.langchain_adapter import LangChainAdapter
from dotenv import load_dotenv

load_dotenv()

async def main():
    # Initialize MCP client
    client = MCPClient.from_config_file("examples/browser_mcp.json")
    llm = ChatOpenAI(model="gpt-4o")

    # Create adapter instance
    adapter = LangChainAdapter()
    # Get LangChain tools with a single line
    tools = await adapter.create_tools(client)

    # Create a custom LangChain agent
    llm_with_tools = llm.bind_tools(tools)
    result = await llm_with_tools.ainvoke("What tools do you have avilable ? ")
    print(result)

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

调试

MCP Use提供了一种内置的调试模式,可以增加日志的详细程度,并帮助诊断代理实现中的问题。

启用调试模式

启用调试模式有两种主要方法:

1.环境变量(建议一次性运行)

使用以下命令运行脚本 DEBUG 将环境变量设置为所需级别:

# Level 1: Show INFO level messages
DEBUG=1 python3.11 examples/browser_use.py

# Level 2: Show DEBUG level messages (full verbose output)
DEBUG=2 python3.11 examples/browser_use.py

这仅在特定Python进程的持续时间内设置调试级别。

或者,您可以将以下环境变量设置为所需的日志记录级别:

export MCP_USE_DEBUG=1 # or 2

2.以编程方式设置调试标志

您可以直接在代码中设置全局调试标志:

import mcp_use

mcp_use.set_debug(1)  # INFO level
# or
mcp_use.set_debug(2)  # DEBUG level (full verbose output)

3.代理人特有的冗长

如果您只想查看代理的调试信息,而不启用完整的调试日志记录,则可以设置 verbose 创建MCPAgent时的参数:

# Create agent with increased verbosity
agent = MCPAgent(
    llm=your_llm,
    client=your_client,
    verbose=True  # Only shows debug messages from the agent
)

当您只需要查看代理的步骤和决策过程,而不需要查看其他组件的所有低级调试信息时,这很有用。

路线图

[x] Multiple Servers at once

[x] Test remote connectors (http, ws)

[ ] ...

明星历史

![Star History Chart](https://www.star-history.com/#pietrozullo/mcp-use&Date)

贡献

我们热爱贡献!对于bug或功能请求,请随时打开问题。看 贡献.md 作为指导方针。

需求

  • Python 3.11+
  • MCP实现(如Playwright MCP)
  • LangChain和适当的模型库(OpenAI、Anthropic等)

引用

如果您在研究或项目中使用MCP use,请引用:

@software{mcp_use2025,
  author = {Zullo, Pietro},
  title = {MCP-Use: MCP Library for Python},
  year = {2025},
  publisher = {GitHub},
  url = {https://github.com/pietrozullo/mcp-use}
}

许可证

麻省理工学院

目录标签

目录标签

PythonClaudeAI代理LLM集成本地部署工具访问多服务器支持自定义代理开源库

支持客户端

Claude

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

session

工具数量(toolCount,工具数)

0

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdiosession部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP