Skip to main content
Glama
VSCODE_SETUP_FIX.md5.94 kB
# VS Code MCP サーバー登録問題の修正 ## 問題の原因 MCPサーバーが**MCP標準プロトコル**を実装していなかったため、VS Codeに登録できませんでした。 ### 具体的な問題点 1. **必須メソッドの欠如** - `initialize` - サーバー初期化(必須) - `tools/list` - 利用可能なツールのリスト(必須) - `tools/call` - ツール実行(必須) 2. **エントリーポイントの問題** - `pyproject.toml`に適切なMCPサーバーエントリーポイントがなかった ## 修正内容 ### 1. MCPプロトコルの実装 (`server.py`) 以下の3つの必須メソッドを追加しました: #### `initialize` メソッド ```python def handle_initialize(self, params: dict[str, Any]) -> dict[str, Any]: return { "protocolVersion": "2024-11-05", "capabilities": {"tools": {}}, "serverInfo": { "name": "python-debug", "version": "0.1.0" } } ``` #### `tools/list` メソッド 5つのデバッグツールをリスト化: - `sessions_create` - デバッグセッション作成 - `sessions_breakpoint` - ブレークポイントまで実行 - `sessions_continue` - 次のブレークポイントへ継続 - `sessions_state` - セッション状態取得 - `sessions_end` - セッション終了 #### `tools/call` メソッド MCPクライアントからのツール呼び出しを各ハンドラーにルーティング ### 2. エントリーポイントの追加 (`pyproject.toml`) ```toml [project.scripts] mcp-debug = "cli.main:app" # CLI用(既存) mcp-debug-server = "mcp_debug_tool.server:main" # MCPサーバー用(新規) ``` ### 3. 設定ファイルの更新 `.vscode/mcp.json` と `mcp-config-example.json`: ```json { "mcpServers": { "python-debug": { "command": "uv", "args": [ "run", "mcp-debug-server", // 新しいエントリーポイントを使用 "--workspace", "${workspaceFolder}" ], "env": { "PYTHONUNBUFFERED": "1" } } } } ``` ## セットアップ手順 ### 1. パッケージの再インストール ```bash cd /path/to/Debug-MCP uv pip install -e ".[dev,cli]" ``` ### 2. VS Codeの設定 #### オプションA: ワークスペース設定(推奨) 1. `.vscode/mcp.json` は既に更新済み 2. VS Codeを再起動 3. コマンドパレット → **"MCP: List Servers"** 4. "python-debug" を選択して **"Start"** #### オプションB: グローバル設定 ```bash # macOS/Linuxの場合 mkdir -p ~/Library/Application\ Support/Code/User/globalStorage/github.copilot-chat ``` `~/Library/Application Support/Code/User/globalStorage/github.copilot-chat/mcp.json` を作成: ```json { "mcpServers": { "python-debug": { "command": "uv", "args": [ "run", "--directory", "/absolute/path/to/Debug-MCP", "mcp-debug-server", "--workspace", "${workspaceFolder}" ], "env": { "PYTHONUNBUFFERED": "1" } } } } ``` ### 3. 動作確認 #### ターミナルでテスト ```bash # initialize echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}' | uv run mcp-debug-server --workspace . # tools/list echo '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}' | uv run mcp-debug-server --workspace . # tools/call (セッション作成) echo '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"sessions_create","arguments":{"entry":"tests/integration/samples/buggy_script.py"}}}' | uv run mcp-debug-server --workspace . ``` すべて正常に応答すればOKです。 #### VS Codeでテスト 1. VS Codeを開く 2. コマンドパレット(`Cmd+Shift+P`) 3. **"MCP: List Servers"** を実行 4. "python-debug" が表示されることを確認 5. 右クリック → **"Start"** 6. ステータスが "Running" になることを確認 7. GitHub Copilot Chatを開く 8. ツールアイコンをクリック 9. "python-debug" のツールが利用可能になっていることを確認: - `sessions_create` - `sessions_breakpoint` - `sessions_continue` - `sessions_state` - `sessions_end` ## トラブルシューティング ### サーバーが起動しない 1. **ログを確認** ```bash # コマンドパレット → "MCP: List Servers" # "python-debug" を選択 → "Show Output" ``` 2. **手動で起動テスト** ```bash uv run mcp-debug-server --workspace . # エラーメッセージを確認 ``` 3. **パッケージの再インストール** ```bash uv pip uninstall mcp-debug-tool uv pip install -e ".[dev,cli]" ``` ### ツールが表示されない 1. サーバーが "Running" 状態か確認 2. VS Codeを再起動 3. Copilot Chatのツール権限を確認 ### パスエラー ```json { "mcpServers": { "python-debug": { "command": "/absolute/path/to/uv", // uvへの絶対パス "args": [ "run", "--directory", "/absolute/path/to/Debug-MCP", // プロジェクトへの絶対パス "mcp-debug-server", "--workspace", "${workspaceFolder}" ] } } } ``` ## 使用例 Copilot Chatで以下のように使用できます: ``` @workspace src/main.py をデバッグしたいです。 sessions_create ツールを使ってセッションを開始してください。 ``` ``` @workspace セッション [session-id] で、src/main.py の42行目まで実行して ローカル変数を確認してください。 ``` ## テスト結果 全134テストが成功: ```bash uv run pytest tests/ -v # =================== 134 passed, 4 warnings in 42.65s ==================== ``` ## 参考資料 - [MCP Specification](https://spec.modelcontextprotocol.io/) - [VS Code Setup Guide](docs/vscode-setup.md) - [Project README](README.md)

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/Kaina3/Debug-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server