Azure OpenAI
MCP サーバー & クライアント (Azure OpenAI & OpenAI 対応)
Model Context Protocol (MCP) と Azure OpenAI を利用した最小限のサーバー/クライアントアプリケーションの実装です。
MCP サーバーは
FastMCPで構築されています。Playwrightは、モダンな Web アプリケーションをテストするための Microsoft 製のオープンソースのエンドツーエンドテストフレームワークです。ツールに関する MCP レスポンスは、OpenAI の関数呼び出し形式に変換されます。
MCP サーバーのレスポンスを OpenAI の関数呼び出し形式に変換するブリッジは、
MCP-LLM Bridge実装をカスタマイズしたものです。安定した接続を確保するため、サーバーオブジェクトはブリッジに直接渡されます。
client_bridgeは、インプロセスおよび外部 (stdio) の両方の MCP サーバー接続をサポートしており、さまざまなクライアント (Claude Code、VS Code、カスタムスクリプトなど) で再利用可能です。
Related MCP server: MCP Server Example
Model Context Protocol (MCP)
Model Context Protocol (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 用の値を.envに入力します。AZURE_OPEN_AI_ENDPOINT= AZURE_OPEN_AI_API_KEY= AZURE_OPEN_AI_DEPLOYMENT_MODEL= AZURE_OPEN_AI_API_VERSION=Python ライブラリ管理のために
uvをインストールします。pip install uv uv syncpython 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 はアプリケーションプロトコル (構造化された通信) です。これらは別個のものですが、プロトコル内では「stdio 上の JSON-RPC」のように、しばしば同義として扱われます。
ツール説明
@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 deployed
Maintenance
Related MCP Connectors
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
Model Context Protocol server for the Apideck Unified API. Connect any MCP-compatible agent framework to 100+ accounting systems, HRIS platforms, file storage providers, and more through one integration. More information https://www.apideck.com/mcp-server
A Model Context Protocol server for Wix AI tools
An MCP server that provides an API to LLMs to manage their JumpCloud resources.
Related MCP Servers
- AlicenseAqualityDmaintenanceA simple MCP server for interacting with OpenAI assistants. This server allows other tools (like Claude Desktop) to create and interact with OpenAI assistants through the Model Context Protocol.939MIT
- AlicenseBqualityDmaintenanceAn educational implementation of a Model Context Protocol server that demonstrates how to build a functional MCP server for integrating with various LLM clients like Claude Desktop.1163MIT
- AlicenseBqualityDmaintenanceAn educational implementation of a Model Context Protocol server that demonstrates how to build a functional MCP server integrating with various LLM clients.2MIT
- FlicenseNot gradedqualityDmaintenanceA basic Model Context Protocol server implementation that demonstrates core functionality including tools and resources for AI chat applications.-