최신 AI 개발은 STDIO, 특히 MCP(모델 컨텍스트 프로토콜) 서버를 통해 통신하는 로컬 도구에 점점 더 의존하고 있습니다. 이러한 서버는 stdin을 통해 JSON-RPC 요청을 수신하고 stdout을 통해 JSON-RPC 응답을 보냅니다. 개발자 프록시를 사용하면 실제 서버 논리를 실행하지 않고도 STDIO 통신을 가로채고 모의하여 AI 클라이언트 애플리케이션을 테스트할 수 있습니다.
필수 조건
Mock MCP 서버 응답
MCP 서버의 응답을 모의하려면 stdio 명령을 MockStdioResponsePlugin와 함께 사용합니다. 플러그 인은 stdin을 가로채 stdout 또는 stderr를 통해 모의 응답을 반환합니다.
1. 개발자 프록시 구성 파일 만들기
다음 콘텐츠가 포함된 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"
}
}
2. 모의 파일 만들기
MCP 서버에 대한 모의 stdio-mocks.json 응답을 사용하여 파일을 만듭니다.
{
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.1.0/mockstdioresponseplugin.schema.json",
"mocks": [
{
"request": {
"bodyFragment": "initialize"
},
"response": {
"stdout": "{\"jsonrpc\":\"2.0\",\"id\":@stdin.body.id,\"result\":{\"protocolVersion\":\"2024-11-05\",\"capabilities\":{\"tools\":{}},\"serverInfo\":{\"name\":\"Mock MCP Server\",\"version\":\"1.0.0\"}}}\n"
}
},
{
"request": {
"bodyFragment": "tools/list"
},
"response": {
"stdout": "{\"jsonrpc\":\"2.0\",\"id\":@stdin.body.id,\"result\":{\"tools\":[{\"name\":\"get_weather\",\"description\":\"Get current weather for a location\",\"inputSchema\":{\"type\":\"object\",\"properties\":{\"location\":{\"type\":\"string\",\"description\":\"City name\"}},\"required\":[\"location\"]}}]}}\n"
}
},
{
"request": {
"bodyFragment": "tools/call"
},
"response": {
"stdout": "{\"jsonrpc\":\"2.0\",\"id\":@stdin.body.id,\"result\":{\"content\":[{\"type\":\"text\",\"text\":\"Mock response from the tool\"}]}}\n"
}
}
]
}
3. 개발 프록시 시작
개발 프록시를 STDIO 명령으로 실행하고, 실행할 명령을 지정하십시오.
devproxy stdio npx -y @modelcontextprotocol/server-filesystem
개발자 프록시는 MCP 서버를 자식 프로세스로 시작하고 모든 stdin/stdout 통신을 차단합니다. stdin에 모의 bodyFragment개체와 일치하는 텍스트가 포함된 경우 개발자 프록시는 요청을 실제 서버로 전달하는 대신 모의 응답을 반환합니다.
동적 응답에 자리 표시자 사용
요청의 값을 포함하는 동적 응답을 만들려면 자리 표시자를 사용합니다 @stdin.body.* .
{
"mocks": [
{
"request": {
"bodyFragment": "echo"
},
"response": {
"stdout": "{\"jsonrpc\":\"2.0\",\"id\":@stdin.body.id,\"result\":{\"message\":\"You said: @stdin.body.params.text\"}}\n"
}
}
]
}
사용 가능한 자리 표시자:
| Placeholder | Description |
|---|---|
@stdin.body.id |
JSON-RPC 요청 ID |
@stdin.body.method |
JSON-RPC 메서드 이름 |
@stdin.body.params.* |
요청 매개 변수에 대한 액세스 |
모의되지 않은 요청 차단
차단되지 않은 요청이 자식 프로세스에 도달하지 못하도록 하려면 다음으로 blockUnmockedRequests설정합니다true.
{
"mockStdioResponsePlugin": {
"mocksFile": "stdio-mocks.json",
"blockUnmockedRequests": true
}
}
실제 논리를 실행하지 않고 MCP 서버를 완전히 모의하려는 경우 방해받지 않는 요청을 차단하는 것이 유용합니다.
파일에서 모의 응답 로드
복잡한 응답의 경우 외부 파일의 콘텐츠를 로드합니다.
{
"mocks": [
{
"request": {
"bodyFragment": "initialize"
},
"response": {
"stdout": "@initialize-response.json"
}
}
]
}
initialize-response.json 파일을 만듭니다.
{"jsonrpc":"2.0","id":1,"result":{"protocolVersion":"2024-11-05","capabilities":{"tools":{}},"serverInfo":{"name":"Mock MCP Server","version":"1.0.0"}}}
DevTools에서 STDIO 트래픽 검사
개발자 프록시를 활성화하면, Chrome DevTools가 열리고 모든 STDIO 통신을 검사할 수 있습니다.
- 네트워크 탭: 모든 stdin/stdout/stderr 메시지 보기
-
URL: 메시지가 다음과 같이 표시됩니다.
stdio://command-name -
메서드: 요청이 다음과 같이 표시됨
stdin -
상태 코드:
stdout200stderr으로, 500으로 표시됨 - 타이밍: 각 요청/응답에 걸린 시간 확인
이 사용 DevToolsPlugin 은 AI 클라이언트와 MCP 서버 간의 통신 문제를 디버깅하는 데 매우 중요합니다.
대기 시간 시뮬레이션
애플리케이션이 느린 MCP 서버 응답을 처리하는 방법을 테스트하려면 다음을 추가합니다 LatencyPlugin.
{
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.1.0/rc.schema.json",
"plugins": [
{
"name": "LatencyPlugin",
"enabled": true,
"pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll",
"configSection": "latencyPlugin"
},
{
"name": "MockStdioResponsePlugin",
"enabled": true,
"pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll",
"configSection": "mockStdioResponsePlugin"
}
],
"latencyPlugin": {
"minMs": 100,
"maxMs": 500
},
"mockStdioResponsePlugin": {
"mocksFile": "stdio-mocks.json"
}
}
다음 단계
STDIO 프록시 기능에 대해 자세히 알아보세요.
Dev Proxy