Hyper-V でセキュアな Claude Desktop x MCP 環境を作る！


以下、Hyper-V でセキュアな Claude Desktop x MCP 環境を作るための手順。


## HyperV で Windows11

クイック作成だと Enterprise Eval になる。お手軽だが、90日間しか使えない。恒久的に使いたい場合は、Proを入れる（プロダクトキー必要）。

### Windows11 Enterprise Eval
https://pc.watch.impress.co.jp/docs/column/win11tec/1381698.html

https://pc.watch.impress.co.jp/docs/column/win11tec/1414193.html

### Windows11 Pro
https://zenn.dev/12morosy/articles/1f07034b0e7a2b

https://itochu-cable-systems.jp/esb/category/useful/other/2023/07/6633/?doing_wp_cron=1744124663.0345530509948730468750

https://nishy-software.com/ja/dev-sw/hyper-v-extended-session-signin/

## 関連ソフトのインストール
### Git for windows
https://git-scm.com/downloads/win

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2631481/1c29f66a-f2dc-49c6-a387-633a0ee9cd63.png)

インストール時は以下を変更

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2631481/b233f67a-4fcd-46f0-bcb6-d68fbef6e74b.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2631481/5ff54123-d905-450b-a871-9c1230c3e4e2.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2631481/c124c77e-4538-4206-b4b2-22a76cc4f4ce.png)

インストール後は、name, email を設定
```powershell
git config --global user.name 'TaroYamada'
```

```powershell
git config --global user.email 'taro.yamada@gmail.com'
```

ページャーを無効化

```powershell
git config --global core.pager ""
```

### FFmpeg（必須でない）

以下から、ダウンロードし解凍
https://ffmpeg.org/download.html
https://github.com/BtbN/FFmpeg-Builds/releases

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2631481/97dec7b8-581d-408b-aa74-008be192616f.png)

Cドライブ直下に解凍したものを配置
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2631481/b7e0899d-a803-46bf-9ed9-4103b1fc4441.png)

最後にシステムの環境変数を変更する
Pathに以下をを追加
```
C:\ffmpeg\bin
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2631481/2c456a15-a299-45e4-8823-7aa9d0726cc6.png)

### Cursor
以下からダウンロード

https://www.cursor.com/

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2631481/ea79378d-e14c-46b6-b0d4-99b464468ed6.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2631481/d10d27e7-5361-4f9d-84c8-c28042e0120f.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2631481/2f0ada1f-3f5b-47f6-a45b-bb2a64c08b07.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2631481/b26dccb5-c6c7-4658-8852-a75a3f88da03.png)

メニューを横から縦に 「Ctrl+Shift+P → Open VSCode Setting → orientation → vertical」
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2631481/0b9b9cba-73df-4124-9d1e-3a4e494141f3.png)

日本語化
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2631481/58fcdb32-6b9a-4dc6-babf-90dddca627ec.png)

必要があればAPIを登録
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2631481/a8f4729e-bea1-4927-ade0-bcb834d24f1a.png)

YOLOをON
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2631481/947576a8-ddf2-4895-95c4-e45bd5460993.png)

### uv

uv のインストール
```powershell
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
```

https://docs.astral.sh/uv/getting-started/installation/

### Volta

volta のインストール
```powershell
winget install Volta.Volta
```

node、pnpm のインストール
```powershell
volta install node
```

```powershell
volta install pnpm
```

https://docs.volta.sh/guide/getting-started

### Docker Desktop

https://docs.docker.com/desktop/setup/install/windows-install/

以下、**ホスト**で実行
```powershell
Set-VMProcessor -VMName "VM Name" -ExposeVirtualizationExtensions $true
```

以下、**VM**で実行

仮想マシン プラットフォームを有効化
```powershell
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
```

必要に応じて Hyper-V 関連を有効化
```powershell
dism.exe /online /enable-feature /featurename:HypervisorPlatform /all /norestart
```

Windows Subsystem for Linux(WSL) 機能を有効化（未有効の場合）
```powershell
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
```

再起動
```powershell
Restart-Computer
```

wsl のアップデート
```powershell
wsl.exe --update
```

### VS Runtime 2015-2022

以下からダウンロードし、インストール

https://learn.microsoft.com/ja-jp/cpp/windows/latest-supported-vc-redist?view=msvc-170#visual-studio-2015-2017-2019-and-2022

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2631481/8ee58854-f9a9-4d79-ae78-371834a3db5d.png)

## MCP Servers の初期設定

### Playwright
`C:/Users/username/mcp_projects` ディレクトリを作成し、そこでターミナルを開く

```powershell
git clone https://github.com/TakanariShimbo/playwright-mcp.git
```

```powershell
cd playwright-mcp
```

```powershell
npm install
```

```powershell
npm run build
```


### Markdownify

`C:/Users/username/mcp_projects` ディレクトリを作成し、そこでターミナルを開く

```powershell
git clone https://github.com/TakanariShimbo/markdownify-mcp.git
```
```powershell
cd markdownify-mcp
```
```powershell
pnpm install --ignore-scripts
```
```powershell
uv sync
```
```powershell
pnpm build
```

### Win-CLI
`C:/Users/username/mcp_projects/win-cli-mcp` で `config.json` を作成。

```json
{
  "security": {
    "maxCommandLength": 2000,
    "blockedCommands": [
      "rm",
      "del",
      "rmdir",
      "format",
      "shutdown",
      "restart",
      "reg",
      "regedit",
      "net",
      "netsh",
      "takeown",
      "icacls"
    ],
    "blockedArguments": [
      "--exec",
      "-e",
      "/c",
      "-enc",
      "-encodedcommand",
      "-command",
      "--interactive",
      "-i",
      "--login",
      "--system"
    ],
    "allowedPaths": ["C:/Users/username"],
    "restrictWorkingDirectory": true,
    "logCommands": true,
    "maxHistorySize": 1000,
    "commandTimeout": 30,
    "enableInjectionProtection": true
  },
  "shells": {
    "powershell": {
      "enabled": true,
      "command": "powershell.exe",
      "args": ["-NoProfile", "-NonInteractive", "-Command"],
      "blockedOperators": ["&", "|", ";", "`"]
    },
    "cmd": {
      "enabled": true,
      "command": "cmd.exe",
      "args": ["/c"],
      "blockedOperators": ["&", "|", ";", "`"]
    },
    "gitbash": {
      "enabled": true,
      "command": "C:/Program Files/Git/bin/bash.exe",
      "args": ["-c"],
      "blockedOperators": ["&", "|", ";", "`"]
    }
  },
  "ssh": {
    "enabled": false,
    "defaultTimeout": 30,
    "maxConcurrentSessions": 5,
    "keepaliveInterval": 10000,
    "keepaliveCountMax": 3,
    "readyTimeout": 20000,
    "connections": {}
  }
}
```
## Cluade Desktop

### インストール
https://claude.ai/download

`開発者モードを有効にする`を選択します。

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2631481/ed3c59f1-0365-4df0-a5e1-c5aaacaf9879.png)

### ツール使用の自動認証設定

Claude Desktop で `Ctrl` + `Shift` + `Alt` + `I` を押し、DevToolsを開き、`Sources` -> `Snippets` から、以下を追加する。

```javascript
// Cooldown tracking
let lastClickTime = 0;
const COOLDOWN_MS = 1000; // 1 second cooldown

const observer = new MutationObserver((mutations) => {
    // Check if we're still in cooldown
    const now = Date.now();
    if (now - lastClickTime < COOLDOWN_MS) {
        console.log('🕒 Still in cooldown period, skipping...');
        return;
    }

    console.log('🔍 Checking mutations...');
    
    const dialog = document.querySelector('[role="dialog"]');
    if (!dialog) return;

    const buttonWithDiv = dialog.querySelector('button div');
    if (!buttonWithDiv) return;

    const toolText = buttonWithDiv.textContent;
    if (!toolText) return;

    console.log('📝 Found tool request:', toolText);
       
    const allowButton = Array.from(dialog.querySelectorAll('button'))
        .find(button => button.textContent.includes('チャット'));
    
    if (allowButton) {
        lastClickTime = now; // Set cooldown
        allowButton.click();
    }
});

// Start observing
console.log('👀 Starting observer for all tools');
observer.observe(document.body, {
    childList: true,
    subtree: true
});

```
※ `チャット`の部分は言語に合わせて設定する。

設定後は右クリックから`Run`を選択すると有効化される。

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2631481/a0d5ddeb-9e33-476d-82ef-aa1b427831d6.png)

以下を参考にした。

https://www.reddit.com/r/ClaudeAI/comments/1h9harx/auto_approve_mcp_tool_calls/

### コンフィグファイル設定

Claude Desktop が MCP Serer をハンドリングできるように設定ファイルを変更します。

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2631481/0597579b-ffd6-4c63-a0d5-2cf00ea56923.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2631481/24cb7b81-8711-4562-99e3-dc937a58a9dd.png)

Claude Desktopの設定ファイル（例: `claude_desktop_config.json`）に以下を追記します。

```json
{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "C:/Users/username"
      ]
    },
    "playwright": {
      "command": "node",
      "args": [
        "C:/Users/username/mcp_projects/playwright-mcp/cli.js"
      ]
    },
    "windows-cli": {
      "command": "npx",
      "args": [
        "-y",
        "@simonb97/server-win-cli",
        "C:/Users/username/mcp_projects/win-cli-mcp/config.json"
      ]
    },
    "markdownify": {
      "command": "node",
      "args": [
        "C:/Users/username/mcp_projects/markdownify-mcp/dist/index.js"
      ],
      "env": {
        "UV_PATH": "C:/Users/username/.local/bin/uv.exe"
      }
    },
    "youtube-transcript": {
      "command": "npx",
      "args": [
        "-y", 
        "@kimtaeyoon83/mcp-server-youtube-transcript"
      ]
    }
  }
}
```