> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bricks.tools/llms.txt
> Use this file to discover all available pages before exploring further.

# MCP 伺服器

> 透過 Model Context Protocol 連接外部工具伺服器

Model Context Protocol (MCP) 讓您可以將外部工具伺服器連線到 AI 代理。MCP 工具擴充了代理在內建工具以外的能力。

## 內建 MCP 伺服器

bricks-ctor 包含內建的 `bricks-ctor` MCP 伺服器，在 `bun install` 時自動設定。它提供編譯、預覽、搜尋圖示和 Lottie 動畫、選擇 Hugging Face 模型，以及管理媒體資產的工具。

<Card title="bricks-ctor 內建 MCP 伺服器" icon="cube" href="/zh-Hant/ctor-pkg/mcp-server">
  請參閱 bricks-ctor 文件中的完整工具參考。
</Card>

<Info>
  當 `bricks-ctor` 伺服器在 CTOR 內執行時，其 `preview` 工具會被停用，代理改為使用內嵌的[預覽面板](/zh-Hant/ctor/reference/preview)——截圖會與您在面板中看到的內容一致，且同一個模擬器同時供可見預覽與代理截圖使用。其他代理（Claude Code、Codex、CLI）仍照常使用 MCP `preview` 工具。
</Info>

## 設定

MCP 伺服器設定於專案根目錄的 `.mcp.json` 檔案中：

```json theme={null}
{
  "mcpServers": {
    "my-server": {
      "command": "npx",
      "args": ["-y", "some-mcp-server"],
      "env": {
        "API_KEY": "your-api-key"
      }
    }
  }
}
```

## 傳輸類型

### stdio

將 MCP 伺服器生成為子程序，透過標準輸入輸出通訊。

```json theme={null}
{
  "mcpServers": {
    "my-server": {
      "command": "npx",
      "args": ["-y", "some-mcp-server"],
      "env": {}
    }
  }
}
```

| 欄位        | 說明      |
| --------- | ------- |
| `command` | 要執行的指令  |
| `args`    | 指令參數陣列  |
| `env`     | 程序的環境變數 |

### HTTP

透過 HTTP 連線遠端 MCP 伺服器。

```json theme={null}
{
  "mcpServers": {
    "remote-server": {
      "url": "https://mcp.example.com/sse"
    }
  }
}
```

| 欄位    | 說明        |
| ----- | --------- |
| `url` | 伺服器端點 URL |

## 管理 MCP 伺服器

點擊側邊欄中的 **MCP**，開啟 MCP 面板。面板顯示：

* 已設定伺服器的清單及其連線狀態
* **綠點** —已連線，顯示可用工具數量
* **紅點** —已斷線或發生錯誤
* 每個伺服器的可展開工具清單

### 編輯設定

MCP 面板包含設定編輯器，可直接編輯 `.mcp.json`。點擊**儲存**套用變更，點擊**重新連線**重新建立伺服器連線。

## 工具整合

連線後，MCP 工具與內建工具一起顯示。代理可以像使用其他工具一樣探索並呼叫它們。工具呼叫結果支援文字和圖片內容。

MCP 伺服器連線按專案快取，並在應用程式退出時自動清理。
