Azure OpenAI
MCP 服务器与客户端(使用 Azure OpenAI 和 OpenAI)
一个利用模型上下文协议 (MCP) 和 Azure OpenAI 的最小化服务器/客户端应用程序实现。
MCP 服务器基于
FastMCP构建。Playwright是微软推出的一个开源端到端测试框架,用于测试现代 Web 应用程序。关于工具的 MCP 响应将被转换为 OpenAI 函数调用格式。
将 MCP 服务器响应转换为 OpenAI 函数调用格式的桥接器自定义了
MCP-LLM Bridge的实现。为确保连接稳定,服务器对象被直接传递到桥接器中。
client_bridge支持进程内和外部 (stdio) MCP 服务器连接,从而实现不同客户端(如 Claude Code、VS Code、自定义脚本)的复用。
Related MCP server: MCP Simple OpenAI Assistant
模型上下文协议 (MCP)
模型上下文协议 (MCP) MCP 是一种开放协议,支持 AI 应用程序与本地或远程资源之间进行安全、受控的交互。
官方仓库
社区资源
相关项目
FastMCP:构建 MCP 服务器的快速、Pythonic 方式。
Chat MCP:MCP 客户端
MCP-LLM Bridge:支持 MCP 服务器与兼容 OpenAI 的 LLM 之间通信的 MCP 实现
MCP Playwright
配置
在 2024 年 12 月的开发阶段,Python 项目应使用 'uv' 初始化。其他依赖管理库(如 'pip' 和 'poetry')尚未得到 MCP CLI 的完全支持。
将
.env.template重命名为.env,然后填入 Azure OpenAI 的相关值:AZURE_OPEN_AI_ENDPOINT= AZURE_OPEN_AI_API_KEY= AZURE_OPEN_AI_DEPLOYMENT_MODEL= AZURE_OPEN_AI_API_VERSION=安装
uv以进行 Python 库管理pip install uv uv sync执行
python chatgui.py示例屏幕显示客户端启动浏览器并导航到 URL。
与外部客户端配合使用
MCP 服务器可以通过 mcp.json 配置供外部客户端(Claude Desktop、VS Code、Claude Code 等)使用。
Claude Desktop / Claude Code
添加到你的 claude_desktop_config.json (Claude Desktop) 或 .claude/mcp.json (Claude Code):
{
"mcpServers": {
"browser-navigator": {
"command": "uv",
"args": ["run", "fastmcp", "run", "./server/browser_navigator_server.py:app"],
"cwd": "/path/to/mcp-aoai-web-browsing",
"env": {
"AZURE_OPEN_AI_ENDPOINT": "...",
"AZURE_OPEN_AI_API_KEY": "...",
"AZURE_OPEN_AI_DEPLOYMENT_MODEL": "...",
"AZURE_OPEN_AI_API_VERSION": "..."
}
}
}
}VS Code
添加到工作区中的 .vscode/mcp.json:
{
"servers": {
"browser-navigator": {
"command": "uv",
"args": ["run", "fastmcp", "run", "./server/browser_navigator_server.py:app"],
"cwd": "${workspaceFolder}",
"env": {
"AZURE_OPEN_AI_ENDPOINT": "...",
"AZURE_OPEN_AI_API_KEY": "...",
"AZURE_OPEN_AI_DEPLOYMENT_MODEL": "...",
"AZURE_OPEN_AI_API_VERSION": "..."
}
}
}
}以编程方式使用桥接器 (stdio)
client_bridge 还支持通过 Python 的 stdio 连接到外部 MCP 服务器:
from client_bridge import BridgeConfig, MCPServerConfig, BridgeManager
from client_bridge.llm_config import get_default_llm_config
config = BridgeConfig(
server_config=MCPServerConfig(
command="uv",
args=["run", "fastmcp", "run", "./server/browser_navigator_server.py:app"],
),
llm_config=get_default_llm_config(),
system_prompt="You are a helpful assistant.",
)
async with BridgeManager(config) as bridge:
response = await bridge.process_message("Navigate to https://example.com")使用标准 OpenAI (非 Azure)
from client_bridge.llm_config import get_openai_llm_config
config = BridgeConfig(
mcp=server,
llm_config=get_openai_llm_config(),
)设置环境变量:
OPENAI_API_KEY=sk-...
OPENAI_MODEL=gpt-...直接工具执行
对于自行管理 LLM 循环的客户端,桥接器公开了工具元数据和直接执行功能:
async with BridgeManager(config) as bridge:
tools = bridge.get_tools() # OpenAI function calling format
result = await bridge.execute_tool("playwright_navigate", {"url": "https://example.com"})关于 'stdio'
stdio 是一个传输层(原始数据流),而 JSON-RPC 是一个应用协议(结构化通信)。它们是不同的概念,但经常互换使用,例如协议中的“JSON-RPC over stdio”。
工具描述
@self.mcp.tool()
async def playwright_navigate(url: str, timeout=30000, wait_until="load"):
"""Navigate to a URL.""" -> This comment provides a description, which may be used in a mechanism similar to function calling in LLMs.
# Output
Tool(name='playwright_navigate', description='Navigate to a URL.', inputSchema={'properties': {'url': {'title': 'Url', 'type': 'string'}, 'timeout': {'default': 30000, 'title': 'timeout', 'type': 'string'}提示:uv
uv run: Run a script.
uv venv: Create a new virtual environment. By default, '.venv'.
uv add: Add a dependency to a script
uv remove: Remove a dependency from a script
uv sync: Sync (Install) the project's dependencies with the environment.提示
python.exe 的 taskkill 命令
taskkill /IM python.exe /FVisual Code:Python 调试器:使用 launch.json 进行调试将使用 .vscode/launch.json 中的配置启动调试器。
This server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/kimtth/mcp-aoai-web-browsing'
If you have feedback or need assistance with the MCP directory API, please join our Discord server