Model Context Protocol(MCP)为智能体提供了一种访问工具的标准方式:GitHub、数据库、文件系统、浏览器。很多 MCP 教程默认你用 Claude 或 GPT,但两者都不是必需的。本文解释为什么 MCP 适用于任何支持工具调用的 OpenAI 兼容模型,如何在开发者实际使用的客户端里配置,以及如何在自己的代码中把 MCP 桥接到开源模型。
为什么 MCP 适用于任何模型?
MCP 位于你的应用和工具服务器之间,而不是你的应用和模型之间。MCP 的架构文档描述了三种角色:
- **宿主(Host):**AI 应用,比如编辑器扩展或你的脚本。
- **客户端(Client):**宿主与每个 MCP 服务器之间保持的一条连接。
- **服务器(Server):**一个暴露工具、资源和提示词的程序,本地通过 stdio 运行,远程通过 Streamable HTTP 访问。
文档写得很明确:MCP “does not dictate how AI applications use LLMs or manage the provided context.”(译文:不规定 AI 应用如何使用大模型,也不规定如何管理所提供的上下文。)宿主用 tools/list 列出每个服务器的工具,合并成一个模型能看到的注册表;当模型请求某个工具时,宿主把 tools/call 发给对应的服务器。
在 OpenAI 兼容 API 上,“模型能看到”的意思就是把工具放进普通的 tools 数组。MCP 工具本来就有名称、描述和 inputSchema,与函数定义一一对应。模型根本不知道背后有 MCP。它需要的只是可靠的工具调用。
MCP 该用哪个模型?
| BroadNet 上的模型 | 是否列出工具调用 | 上下文 | 适合 MCP 吗 |
|---|---|---|---|
| GLM 5.3 | 是 | 1,048,576 | 服务器多时的稳妥默认选择 |
| Qwen3.8 27B | 是 | 262,144 | 适合,且支持图像输入 |
| DeepSeek V4.1 Flash | 未列出 | 1,048,576 | 先测试;支持图像输入 |
| Gemma 4 VL 26B | 未列出 | 32,768 | 不推荐 |
两个支持工具的模型的并排对比,见 GLM 5.3 与 Qwen3.8 27B 对比。上下文比很多人想象的更重要。每个 MCP 工具的 schema 都会随每次调用一起发送。opencode 的文档说:“MCP tools consume model context, so add only the servers you need.”(译文:MCP 工具会占用模型上下文,所以只添加你需要的服务器。)怎么测量见智能体的 token 预算一文。
常用客户端里怎么配置 MCP?
| 客户端 | MCP 服务器配置位置 | 传输方式 | 说明 |
|---|---|---|---|
| Cline | MCP Servers 面板,mcpServers JSON |
stdio、Streamable HTTP、旧版 SSE | 远程类型为 "streamableHttp" |
| Continue | config.yaml 中的 mcpServers 或 .continue/mcpServers/ |
stdio、sse、streamable-http | 仅 Agent 模式 |
| opencode | opencode.jsonc 中的 mcp.servers |
local、remote |
密钥用 {env:NAME} |
| n8n | AI Agent 上的 MCP Client Tool 节点 | 远程服务器端点(其文档描述的是 SSE 端点) | 可选 All、Selected 或 All Except 工具 |
| OpenAI Agents SDK | Agent 上的 mcp_servers=[...] |
stdio、Streamable HTTP、SSE | 不是 HostedMCPTool |
然后把客户端的模型指向你的服务商:Cline、Continue 和 opencode 指南介绍了 BroadNet 这一侧的模型配置。在 Continue 中,别忘了加上 tool_use 能力,否则无法使用 Agent 模式。
Continue 文档中的一个示例:
mcpServers:
- name: SQLite MCP
type: stdio
command: npx
args: ["-y", "mcp-sqlite", "/path/to/your/database.db"]
怎么在 Python 中把 MCP 桥接到开源模型?
如果你在构建自己的智能体,桥接代码很短。下面使用 MCP Python SDK 的 Client(2.0 或更高版本;pip install "mcp>=2"),传入 StdioServerParameters 时它会启动一个 stdio 服务器;再配合指向 BroadNet 的 OpenAI SDK:
import asyncio, json, os
from mcp import Client, StdioServerParameters
from mcp.types import TextContent
from openai import OpenAI
llm = OpenAI(base_url="https://inference.broadnet.ai/v1", api_key=os.environ["BROADNET_API_KEY"])
server = StdioServerParameters(command="npx",
args=["-y", "@modelcontextprotocol/server-filesystem", "."])
async def main(question):
async with Client(server) as mcp:
listed = await mcp.list_tools()
tools = [{"type": "function", "function": {
"name": t.name, "description": t.description or "",
"parameters": t.input_schema}} for t in listed.tools]
messages = [{"role": "user", "content": question}]
for _ in range(8):
r = llm.chat.completions.create(model="broadnet/glm-5.3",
messages=messages, tools=tools, max_tokens=4000)
msg = r.choices[0].message
messages.append(msg.model_dump(exclude_none=True))
if not msg.tool_calls:
return msg.content
for call in msg.tool_calls:
try:
res = await mcp.call_tool(call.function.name,
json.loads(call.function.arguments or "{}"))
text = "\n".join(b.text for b in res.content if isinstance(b, TextContent))
out = f"Error: {text}" if res.is_error else text
except Exception as e:
out = f"Error: {e}"
messages.append({"role": "tool", "tool_call_id": call.id, "content": out})
print(asyncio.run(main("List the Markdown files here and summarize the README.")))
mcp 1.x 中没有 Client 类:需要用 stdio_client(...) 打开服务器,包进 ClientSession,调用 initialize(),并读取驼峰命名的字段 inputSchema 和 isError。有三个细节很重要:
- **错误变成工具结果。**MCP SDK 用
is_error报告工具失败,而不是抛出异常。把它们传回去,让模型调整。校验和重试见我们的工具调用指南。 - **限制循环次数。**这里是八步。返回大量结果的 MCP 服务器会很快填满上下文。
- **过滤工具。**只暴露任务需要的工具。OpenAI Agents SDK 为此提供了
tool_filter,n8n 则有 Selected 和 All Except。
改用 OpenAI Agents SDK?它的 MCPServerStdio 和 MCPServerStreamableHttp 类在你的进程内运行。按我们的 Agents SDK 指南把它们和自定义服务商组合起来即可。它的 HostedMCPTool 在 OpenAI 的 Responses API 内部运行,只适用于 OpenAI 模型。
开源模型用 MCP 时常见哪些问题?
- **工具太多。**模型会选错工具,或者干脆不用工具。让当前启用的工具集保持精简。对于你自己的工具,JSON schema 生成器可以生成干净、扁平的
parametersschema。 - **工具结果太大。**一个返回整张数据库表的服务器可能撑爆上下文窗口。设上限或分页。
- **回复为空或被截断。**GLM 5.3 和 Qwen3.8 27B 会先思考,而思考计入
max_tokens。把它调高。 - **信任问题。**MCP 服务器会在你的机器上运行代码,或者用你的凭据调用服务。只安装你信任的服务器,涉及写入或花钱的操作要先确认。
BroadNet Inference 适合什么场景
BroadNet Inference 负责模型这一侧:GLM 5.3 和 Qwen3.8 27B 列明支持工具调用,采用上面所有 MCP 客户端都能使用的标准 chat completions 格式,并对提示词和输出实行零数据保留。它不会替你运行 MCP 服务器或托管工具;这些由你的客户端完成。两个模型按 token 的价格见价格页面,密钥在 inference.broadnet.ai 获取。
