MCP(모델 컨텍스트 프로토콜) 서버와 같은 STDIO 기반 애플리케이션에 대한 응답을 시뮬레이션합니다.
플러그 인 인스턴스 정의
{
"name": "MockStdioResponsePlugin",
"enabled": true,
"pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll",
"configSection": "mockStdioResponsePlugin"
}
구성 예제
{
"$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"
}
],
"mockStdioResponsePlugin": {
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.1.0/mockstdioresponseplugin.schema.json",
"mocksFile": "stdio-mocks.json"
}
}
구성 속성
| 재산 | Description | Default |
|---|---|---|
mocksFile |
STDIO 모의 응답이 포함된 파일의 경로 | stdio-mocks.json |
blockUnmockedRequests |
경우 true, 일치하지 않는 stdin이 자식 프로세스에 도달하지 못하게 합니다. |
false |
명령줄 옵션
| 이름 | Description | Default |
|---|---|---|
--no-stdio-mocks |
STDIO 모의 응답 로드 사용 안 함 | false |
--stdio-mocks-file |
STDIO 모의 응답이 포함된 파일의 경로 | - |
모의 파일 예제
다음은 STDIO 모의 개체의 예입니다.
stdout으로 응답
stdout 응답을 사용하여 특정 텍스트를 포함하는 stdin에 응답합니다.
파일: stdio-mocks.json
{
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.1.0/mockstdioresponseplugin.schema.json",
"mocks": [
{
"request": {
"bodyFragment": "tools/list"
},
"response": {
"stdout": "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":{\"tools\":[]}}\n"
}
}
]
}
stderr로 응답
stderr에 오류 메시지를 표시하여 stdin에 응답합니다.
파일: stdio-mocks.json
{
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.1.0/mockstdioresponseplugin.schema.json",
"mocks": [
{
"request": {
"bodyFragment": "invalid_method"
},
"response": {
"stderr": "Error: Unknown method\n"
}
}
]
}
stdin에서 자리 표시자 사용
자리 표시자를 사용하여 @stdin.body.* 응답에 stdin의 값을 동적으로 포함합니다.
파일: stdio-mocks.json
{
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.1.0/mockstdioresponseplugin.schema.json",
"mocks": [
{
"request": {
"bodyFragment": "tools/list"
},
"response": {
"stdout": "{\"jsonrpc\":\"2.0\",\"id\":@stdin.body.id,\"result\":{\"tools\":[]}}\n"
}
}
]
}
다음 자리 표시자를 사용할 수 있습니다.
| Placeholder | Description |
|---|---|
@stdin.body.id |
요청 ID JSON-RPC |
@stdin.body.method |
JSON-RPC 메서드 이름 |
@stdin.body.params.name |
중첩된 속성 액세스 |
파일에서 응답 로드
구문을 사용하여 @filename 외부 파일에서 모의 응답 콘텐츠를 로드합니다.
파일: 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": "@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"}}}
n번째 발생에 응답
n번째 시간 동안 일치하는 stdin을 가로채는 경우에만 응답합니다.
파일: stdio-mocks.json
{
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.1.0/mockstdioresponseplugin.schema.json",
"mocks": [
{
"request": {
"bodyFragment": "tools/call",
"nth": 2
},
"response": {
"stdout": "{\"jsonrpc\":\"2.0\",\"id\":@stdin.body.id,\"result\":{\"content\":[{\"type\":\"text\",\"text\":\"Operation completed\"}]}}\n"
}
}
]
}
Mocks 파일 속성
| 재산 | Description | 필수 |
|---|---|---|
request |
일치시킬 stdin을 정의하는 요청 개체 | yes |
response |
반환할 응답을 정의하는 응답 개체 | yes |
요청 객체
각 요청에는 다음과 같은 속성이 있습니다.
| 재산 | Description | 필수 | 기본값 | 샘플 값 |
|---|---|---|---|---|
bodyFragment |
stdin에 있어야 하는 문자열 | yes | tools/list |
|
nth |
n번째 시간 동안 요청을 가로채는 경우에만 응답 | no | 2 |
Response 개체
각 응답에는 다음과 같은 속성이 있습니다.
| 재산 | Description | 필수 | 기본값 | 샘플 값 |
|---|---|---|---|---|
stdout |
stdout에 보낼 콘텐츠 | no | empty | {"result": "ok"}\n |
stderr |
stderr에 보낼 콘텐츠 | no | empty | Error: Something went wrong\n |
응답 설명
파일에서 응답 콘텐츠를 로드하려면 모의 stdout 파일에 상대적인 파일 경로 다음에 시작하는 문자열 값으로 @ 설정하거나 stderr 속성을 설정합니다. 예를 들어 모 @response.json 의 파일과 동일한 디렉터리에 있는 파일에 저장된 response.json 콘텐츠를 반환합니다.
응답에 stdin의 값을 동적으로 포함하려면 자리 표시자를 사용합니다 @stdin.body.* . 예를 들어 stdin @stdin.body.id JSON에서 속성 값을 id 반환합니다.
플러그 인 설명
이 플러그 인은 로컬 실행 파일과의 STDIO 통신을 가로채고 모의하는 명령과 함께 stdio 사용하도록 설계되었습니다. MCP(모델 컨텍스트 프로토콜) 서버 및 기타 STDIO 기반 애플리케이션을 테스트하고 디버깅하는 데 유용합니다.
blockUnmockedRequests 모true의 항목과 일치하지 않는 모든 stdin이 사용되며 자식 프로세스로 전달되지 않습니다. 차단되지 않은 요청 차단은 실제 논리를 실행하지 않고 실행 파일의 동작을 완전히 모의하려는 경우에 유용합니다.
다음 단계
Dev Proxy