-
Notifications
You must be signed in to change notification settings - Fork 80
Proxy stdio traffic #1485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Proxy stdio traffic #1485
Conversation
|
Great idea! We might also want to include an optional path to a config file, |
To do:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces a comprehensive stdio proxy feature that enables Dev Proxy to intercept and manipulate stdin/stdout/stderr communication with local executables, particularly targeting Model Context Protocol (MCP) servers. The implementation adds a new stdio command, extends the plugin architecture with IStdioPlugin, and provides stdio support for existing plugins (DevTools, Latency, and a new MockStdioResponse plugin).
Key changes:
- New stdio proxy session management with message interception capabilities
- Plugin architecture extension allowing plugins to participate in both HTTP and stdio scenarios
- DevTools integration for inspecting stdio traffic via Chrome DevTools
- Mock response system for stdio with JSON-RPC placeholder support
Reviewed changes
Copilot reviewed 43 out of 43 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
schemas/v2.1.0/mockstdioresponseplugin.schema.json |
JSON schema for MockStdioResponsePlugin configuration |
schemas/v2.1.0/mockstdioresponseplugin.mocksfile.schema.json |
JSON schema for stdio mock response files |
DevProxy/Stdio/ProxySession.cs |
Core stdio proxy session with stream forwarding and plugin invocation |
DevProxy/Logging/StdioFileLoggerProvider.cs |
File-based logger to avoid interfering with proxied streams |
DevProxy/Commands/StdioCommand.cs |
CLI command for stdio proxy functionality |
DevProxy/Commands/DevProxyCommand.cs |
Integration of stdio command and configuration |
DevProxy/Commands/DevProxyConfigOptions.cs |
Command-line options for stdio subcommand |
DevProxy/Extensions/ILoggingBuilderExtensions.cs |
Logging configuration for stdio mode |
DevProxy/Plugins/PluginServiceExtensions.cs |
Registration of IStdioPlugin instances in DI |
DevProxy.Abstractions/Plugins/IStdioPlugin.cs |
Interface for stdio-aware plugins |
DevProxy.Abstractions/Plugins/BasePlugin.cs |
Default IStdioPlugin implementation for all plugins |
DevProxy.Abstractions/Proxy/StdioEvents.cs |
Event argument classes for stdio operations |
DevProxy.Abstractions/Models/MockStdioResponse.cs |
Model classes for stdio mock responses |
DevProxy.Abstractions/Proxy/IProxyLogger.cs |
Logging context for stdio operations |
DevProxy.Abstractions/Extensions/ILoggerExtensions.cs |
Extension methods for stdio logging |
DevProxy.Plugins/Mocking/MockStdioResponsePlugin.cs |
Plugin for mocking stdio responses with placeholder support |
DevProxy.Plugins/Mocking/MockStdioResponsesLoader.cs |
Loader for stdio mock configuration files |
DevProxy.Plugins/Inspection/DevToolsPlugin.cs |
Extended to support stdio traffic inspection in DevTools |
DevProxy.Plugins/Behavior/LatencyPlugin.cs |
Extended to simulate latency for stdio operations |
DevProxy.Plugins/Inspection/WebSocketServer.cs |
Added client connection event for message buffering |
DevProxy/Proxy/ProxyEngine.cs |
Updated logging context instantiation |
| Multiple plugin files | Updated to use explicit new LoggingContext(e) instead of new(e) |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
this is a breaking change so will need to be released in a new major version
Stdio Proxy Feature
Overview
This PR introduces a new
stdiocommand to Dev Proxy that enables proxying stdin/stdout/stderr of local executables. This is particularly useful for testing and debugging Model Context Protocol (MCP) servers and other stdio-based applications.Why?
Modern AI development increasingly relies on local tools that communicate via stdio, particularly MCP servers. These servers:
Developers need to:
Previously, there was no way to intercept and manipulate stdio traffic like Dev Proxy does for HTTP. This feature fills that gap.
Capabilities
1. Stdio Proxy Command
New command that wraps any executable and proxies its stdio streams:
Example:
2. Plugin Architecture for Stdio
New
IStdioPlugininterface that allows plugins to:BeforeStdinAsync)AfterStdoutAsync)AfterStderrAsync)AfterStdioRequestLogAsync)AfterStdioRecordingStopAsync)Plugins can modify, consume, or mock messages by setting
ResponseState.HasBeenSet = true.3. DevTools Plugin Support
The DevToolsPlugin now works with stdio, allowing you to:
Messages appear as:
stdio://command-nameURLsSTDINmethod for requestsSTDOUT(200) andSTDERR(500) for responses4. Mock Stdio Response Plugin
New
MockStdioResponsePluginfor mocking stdio responses:@stdin.body.propertyPathto reference values from stdin@filenameto load mock content from files5. LatencyPlugin Support
The
LatencyPluginnow works with stdio to simulate network delays.Sample Configurations
Basic Stdio Configuration
devproxyrc.json:{ "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.0.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" } ], "urlsToWatch": [ "https://api.example.com/*" ], "devTools": { "preferredBrowser": "Edge" }, "mockStdioResponsePlugin": { "mocksFile": "stdio-mocks.json" } }Mock File for JSON-RPC/MCP
stdio-mocks.json:{ "mocks": [ { "request": { "bodyFragment": "tools/list" }, "response": { "stdout": "{\"jsonrpc\":\"2.0\",\"id\":@stdin.body.id,\"result\":{\"tools\":[]}}\n" } }, { "request": { "bodyFragment": "GetBestPractices" }, "response": { "stdout": "{\"jsonrpc\":\"2.0\",\"id\":@stdin.body.id,\"result\":{\"content\":[{\"type\":\"text\",\"text\":\"Mock best practices response\"}]}}\n" } } ] }Using File-Based Mock Responses
stdio-mocks.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"}}}Blocking Unmocked Requests
{ "mockStdioResponsePlugin": { "mocksFile": "stdio-mocks.json", "blockUnmockedRequests": true } }With Latency Simulation
{ "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 } }Usage Examples
Testing an MCP Server
Command-Line Options
Placeholder Support
Placeholders allow dynamic values in mock responses by referencing stdin properties:
@stdin.body.id@stdin.body.method@stdin.body.params.nameExample:
{ "response": { "stdout": "{\"jsonrpc\":\"2.0\",\"id\":@stdin.body.id,\"result\":\"Hello @stdin.body.params.name\"}\n" } }Files Changed Summary
New Files
DevProxy/Commands/StdioCommand.cs- CLI command implementationDevProxy/Stdio/ProxySession.cs- Core proxy session managementDevProxy/Logging/StdioFileLoggerProvider.cs- File logging for stdio sessionsDevProxy.Abstractions/Plugins/IStdioPlugin.cs- Plugin interfaceDevProxy.Abstractions/Proxy/StdioEvents.cs- Event args and modelsDevProxy.Abstractions/Models/MockStdioResponse.cs- Mock response modelsDevProxy.Plugins/Mocking/MockStdioResponsePlugin.cs- Mocking pluginDevProxy.Plugins/Mocking/MockStdioResponsesLoader.cs- Mock file loaderModified Files
DevProxy.Plugins/Inspection/DevToolsPlugin.cs- Added stdio supportDevProxy.Plugins/Behavior/LatencyPlugin.cs- Added stdio supportDevProxy.Abstractions/Plugins/BasePlugin.cs- Added default IStdioPlugin implementationsDevProxy/Commands/DevProxyCommand.cs- Integrated stdio commandArchitecture
Plugins are invoked in order: