代理 STDIN/STDOUT/STDERR 與本地執行檔的通訊。 此指令對於測試與除錯模型上下文協定(MCP)伺服器及其他基於 STDIO 的應用程式特別有用。
概要
devproxy stdio [options] <command> [args...]
Description
指令啟動 stdio 子程序,並代理所有 STDIN/STDOUT/STDERR 通訊。 這可讓您:
- 檢查客戶端(如 VS Code)與 MCP 伺服器之間流動的訊息
- 模擬測試客戶端行為的回應,無需實際執行伺服器邏輯
- 使用 Chrome DevTools 除錯通訊問題
- 透過注入模擬回應或阻擋請求來測試錯誤處理
- 模擬 STDIO 通訊的延遲
Usage
devproxy stdio npx -y @modelcontextprotocol/server-filesystem
Arguments
| 名稱 | Description | 為必填項目 |
|---|---|---|
<command> |
執行命令 | yes |
[args...] |
傳遞給指令的參數 | no |
選項
| 名稱 | Description | 允許的值 | 預設 |
|---|---|---|---|
-c, --config-file <configFile> |
配置檔的路徑 | 本機檔案路徑 | devproxyrc.json |
--no-stdio-mocks |
停用載入 STDIO 模擬回應 | n/a | n/a |
--stdio-mocks-file <file> |
包含 STDIO 模擬回應的檔案路徑 | 本機檔案路徑 | - |
--log-level <loglevel> |
要記錄的訊息等級 |
trace、debug、information、warning、error |
information |
-?, -h, --help |
顯示說明與使用資訊 | n/a | n/a |
範例
用開發代理啟動 MCP 伺服器
devproxy stdio npx -y @modelcontextprotocol/server-filesystem
指定自訂設定檔
devproxy stdio --config-file ./my-config.json npx my-server
指定一個自訂的 mocks 檔案
devproxy stdio --stdio-mocks-file ./my-mocks.json npx my-server
停用 stdio 模擬
devproxy stdio --no-stdio-mocks npx my-server
設定範例
若要使用 stdio 該指令搭配插件,請建立一個設定檔:
檔案: devproxyrc.json
{
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.1.0/rc.schema.json",
"plugins": [
{
"name": "MockStdioResponsePlugin",
"enabled": true,
"pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll",
"configSection": "mockStdioResponsePlugin"
},
{
"name": "DevToolsPlugin",
"enabled": true,
"pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll",
"configSection": "devTools"
}
],
"devTools": {
"preferredBrowser": "Edge"
},
"mockStdioResponsePlugin": {
"mocksFile": "stdio-mocks.json"
}
}
支援的外掛程式
以下插件支援 STDIO 攔截:
| 外掛程式 | Description |
|---|---|
| MockStdioResponsePlugin | 模擬STDIN/STDOUT/STDERR回應 |
| DevToolsPlugin | 在 Chrome DevTools 中檢查 STDIO 流量 |
| LatencyPlugin | 在 STDIO 通訊中加入人工延遲 |
Architecture
使用該 stdio 指令時,Dev Proxy 作為父程序(如 VS Code)與子程序(如 MCP 伺服器)之間的中介:
┌─────────────────┐ STDIN ┌──────────────────┐ STDIN ┌─────────────────┐
│ Parent Process │ ─────────────▶ │ Dev Proxy │ ─────────────▶ │ Child Process │
│ (VS Code) │ │ │ │ (MCP Server) │
│ │ ◀───────────── │ ┌────────────┐ │ ◀───────────── │ │
└─────────────────┘ STDOUT │ │ Plugins │ │ STDOUT └─────────────────┘
│ └────────────┘ │
└──────────────────┘
外掛的呼叫順序如下:
-
BeforeStdinAsync- 在將標準資料轉發給孩子之前 -
AfterStdoutAsync- 在孩子出生後 -
AfterStderrAsync- 在孩子接種 stderr 後
DevTools 整合
啟用 DevToolsPlugin 後,可以在 Chrome DevTools 中檢查 STDIO 流量:
- 訊息會以
stdio://command-name網址顯示 - 請求顯示為
STDIN方法 - 回應顯示
STDOUT為(200狀態)或STDERR(500狀態) - 訊息主體在適用時會以 JSON 格式化