Skip to content

Commit 981d39a

Browse files
feat(acp): support remote HTTP MCP servers
Signed-off-by: custard-pirate <[email protected]>
1 parent b6b3d11 commit 981d39a

7 files changed

Lines changed: 620 additions & 120 deletions

File tree

‎Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crates/buzz-acp/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ tracing-subscriber = { workspace = true }
6262
# Error handling
6363
thiserror = { workspace = true }
6464
anyhow = { workspace = true }
65+
zeroize = { workspace = true }
6566

6667
# CLI
6768
clap = { version = "4", features = ["derive", "env"] }

‎crates/buzz-acp/README.md‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ All configuration is via environment variables (or CLI flags — every env var h
111111
| `BUZZ_ACP_AGENT_COMMAND` | no | `goose` | Agent binary to spawn. |
112112
| `BUZZ_ACP_AGENT_ARGS` | no | `acp` | Agent arguments (comma-separated). |
113113
| `BUZZ_ACP_MCP_COMMAND` | no | `""` (empty) | Path to an optional MCP server binary to provide to the agent subprocess. |
114-
| `BUZZ_ACP_MCP_CONFIG` | no | `""` (empty) | Path to a version 1 JSON file defining additional stdio MCP servers. |
114+
| `BUZZ_ACP_MCP_CONFIG` | no | `""` (empty) | Path to a version 1 JSON file defining additional stdio and Streamable HTTP MCP servers. |
115115
| `BUZZ_ACP_IDLE_TIMEOUT` | no | `620` | Idle timeout: max seconds of silence before cancelling a turn. Resets on any agent stdout activity. |
116116
| `BUZZ_ACP_MAX_TURN_DURATION` | no | `7200` | Absolute wall-clock cap per turn (safety valve). |
117117
| `BUZZ_API_TOKEN` | no | — | API token (required if relay enforces token auth). |
@@ -122,8 +122,8 @@ All configuration is via environment variables (or CLI flags — every env var h
122122

123123
### Multiple MCP servers
124124

125-
Use `--mcp-config <path>` or `BUZZ_ACP_MCP_CONFIG` to add named stdio MCP
126-
servers:
125+
Use `--mcp-config <path>` or `BUZZ_ACP_MCP_CONFIG` to add named local and
126+
remote MCP servers:
127127

128128
```json
129129
{
@@ -137,15 +137,32 @@ servers:
137137
"env": {
138138
"ANALYTICS_TOKEN": "replace-me"
139139
}
140+
},
141+
{
142+
"name": "hosted-context",
143+
"transport": "http",
144+
"url": "https://mcp.example.test/mcp",
145+
"headers": [
146+
{
147+
"name": "Authorization",
148+
"env_file": "/run/secrets/hosted-context.env",
149+
"env_name": "MCP_TOKEN",
150+
"value_prefix": "Bearer "
151+
}
152+
]
140153
}
141154
]
142155
}
143156
```
144157

145158
The JSON is strict. The only top-level fields are `version` and `servers`.
146-
Each server has `name`, `transport`, `command`, `args`, and `env`. Version 1
147-
supports the `stdio` transport. Server names must be unique, contain 1 to 128
148-
ASCII bytes using only letters, digits, `_`, or `-`, and cannot contain `__`.
159+
Each server has a `name` and tagged `transport`. A `stdio` entry contains
160+
`command`, `args`, and `env`; an `http` entry contains a URL and optional
161+
headers. URLs and header values can be literal, loaded from protected files,
162+
or selected by name from protected environment files. Public endpoints require
163+
HTTPS; plain HTTP is limited to literal private IP addresses. Server names must
164+
be unique, contain 1 to 128 ASCII bytes using only letters, digits, `_`, or `-`,
165+
and cannot contain `__`.
149166
Names are checked across both structured entries and the legacy server.
150167

151168
The config file is limited to 64 KiB. A harness can have at most 16 MCP

‎crates/buzz-acp/src/acp.rs‎

Lines changed: 135 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::borrow::Cow;
1414
use tokio::io::AsyncWriteExt;
1515
use tokio::process::{Child, ChildStdin, ChildStdout};
1616
use tokio_util::codec::{FramedRead, LinesCodec, LinesCodecError};
17+
use zeroize::Zeroizing;
1718

1819
use crate::observer::{ObserverContext, ObserverHandle};
1920
use crate::usage::{TurnUsage, UsageTracker};
@@ -26,20 +27,67 @@ const REDACTED_ENV_VALUE: &str = "[REDACTED]";
2627

2728
/// An MCP server configuration passed to `session/new`.
2829
///
29-
/// Corresponds to the `McpServerStdio` variant in the ACP schema.
30-
/// All four fields are **required** by the schema (`args` and `env` may be empty arrays).
30+
/// ACP models stdio servers as an untagged object and HTTP servers as an
31+
/// object tagged with `type: "http"`, so the outer enum is untagged.
3132
#[derive(Clone, serde::Serialize)]
32-
pub struct McpServer {
33+
#[serde(untagged)]
34+
pub enum McpServer {
35+
Stdio(McpServerStdio),
36+
Http(McpServerHttp),
37+
}
38+
39+
impl McpServer {
40+
pub fn name(&self) -> &str {
41+
match self {
42+
Self::Stdio(server) => &server.name,
43+
Self::Http(server) => &server.name,
44+
}
45+
}
46+
47+
pub fn is_http(&self) -> bool {
48+
matches!(self, Self::Http(_))
49+
}
50+
51+
fn sensitive_values(&self) -> Box<dyn Iterator<Item = &String> + '_> {
52+
match self {
53+
Self::Stdio(server) => Box::new(server.env.iter().map(|entry| &entry.value)),
54+
Self::Http(server) => Box::new(
55+
std::iter::once(&server.url).chain(server.headers.iter().map(|entry| &entry.value)),
56+
),
57+
}
58+
}
59+
60+
#[cfg(test)]
61+
pub fn as_stdio(&self) -> Option<&McpServerStdio> {
62+
match self {
63+
Self::Stdio(server) => Some(server),
64+
Self::Http(_) => None,
65+
}
66+
}
67+
}
68+
69+
impl std::fmt::Debug for McpServer {
70+
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
71+
match self {
72+
Self::Stdio(server) => server.fmt(formatter),
73+
Self::Http(server) => server.fmt(formatter),
74+
}
75+
}
76+
}
77+
78+
/// A child-process MCP server.
79+
#[derive(Clone, serde::Serialize)]
80+
pub struct McpServerStdio {
3381
pub name: String,
3482
pub command: String,
3583
pub args: Vec<String>,
3684
pub env: Vec<EnvVar>,
3785
}
3886

39-
impl std::fmt::Debug for McpServer {
87+
impl std::fmt::Debug for McpServerStdio {
4088
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4189
formatter
42-
.debug_struct("McpServer")
90+
.debug_struct("McpServerStdio")
4391
.field("name", &self.name)
4492
.field("command", &self.command)
4593
.field("arg_count", &self.args.len())
@@ -48,6 +96,34 @@ impl std::fmt::Debug for McpServer {
4896
}
4997
}
5098

99+
/// A remote Streamable HTTP MCP server.
100+
#[derive(Clone, serde::Serialize)]
101+
pub struct McpServerHttp {
102+
#[serde(rename = "type")]
103+
pub transport: HttpTransport,
104+
pub name: String,
105+
pub url: String,
106+
pub headers: Vec<EnvVar>,
107+
}
108+
109+
impl std::fmt::Debug for McpServerHttp {
110+
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
111+
formatter
112+
.debug_struct("McpServerHttp")
113+
.field("transport", &self.transport)
114+
.field("name", &self.name)
115+
.field("url", &REDACTED_ENV_VALUE)
116+
.field("headers", &self.headers)
117+
.finish()
118+
}
119+
}
120+
121+
#[derive(Debug, Clone, Copy, serde::Serialize)]
122+
#[serde(rename_all = "lowercase")]
123+
pub enum HttpTransport {
124+
Http,
125+
}
126+
51127
/// A single environment variable for an MCP server.
52128
#[derive(Clone, serde::Serialize)]
53129
pub struct EnvVar {
@@ -181,7 +257,8 @@ fn redact_wire_text<'a>(
181257
sensitive_value_matcher: Option<&AhoCorasick>,
182258
) -> Cow<'a, str> {
183259
let looks_like_serialized_mcp_config = contains_serialized_json_key(text, "mcpServers")
184-
&& contains_serialized_json_key(text, "env")
260+
&& (contains_serialized_json_key(text, "env")
261+
|| contains_serialized_json_key(text, "headers"))
185262
&& contains_serialized_json_key(text, "value");
186263
if looks_like_serialized_mcp_config {
187264
return Cow::Borrowed(REDACTED_ENV_VALUE);
@@ -219,7 +296,7 @@ fn redact_wire_value(
219296
}
220297
serde_json::Value::Object(fields) => {
221298
for (key, value) in fields {
222-
if key == "env" {
299+
if key == "env" || key == "headers" {
223300
if let serde_json::Value::Array(entries) = value {
224301
for entry in entries {
225302
if let serde_json::Value::Object(env_var) = entry {
@@ -719,7 +796,7 @@ impl AcpClient {
719796
let mut changed = false;
720797
for value in servers
721798
.iter()
722-
.flat_map(|server| server.env.iter().map(|entry| &entry.value))
799+
.flat_map(McpServer::sensitive_values)
723800
.filter(|value| !value.is_empty())
724801
{
725802
if !self
@@ -1244,9 +1321,9 @@ impl AcpClient {
12441321
const WRITE_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(30);
12451322
let observed_value = self.redact_wire_value(value);
12461323
tracing::debug!(target: "acp::wire", "→ {observed_value}");
1247-
let line = serde_json::to_string(value)?;
1324+
let line = Zeroizing::new(serde_json::to_vec(value)?);
12481325
tokio::time::timeout(WRITE_TIMEOUT, async {
1249-
self.stdin.write_all(line.as_bytes()).await?;
1326+
self.stdin.write_all(&line).await?;
12501327
self.stdin.write_all(b"\n").await?;
12511328
self.stdin.flush().await?;
12521329
Ok::<(), std::io::Error>(())
@@ -2658,7 +2735,7 @@ mod tests {
26582735
#[test]
26592736
fn session_new_mcp_server_has_required_fields() {
26602737
// Schema requires name, command, args, env — all present, args/env may be empty.
2661-
let server = McpServer {
2738+
let server = McpServer::Stdio(McpServerStdio {
26622739
name: "test-mcp".into(),
26632740
command: "/usr/local/bin/test-mcp-server".into(),
26642741
args: vec![],
@@ -2672,7 +2749,7 @@ mod tests {
26722749
value: "nsec1abc".into(),
26732750
},
26742751
],
2675-
};
2752+
});
26762753
let serialized = serde_json::to_value(&server).unwrap();
26772754
assert_eq!(serialized["name"].as_str(), Some("test-mcp"));
26782755
assert_eq!(
@@ -2695,15 +2772,15 @@ mod tests {
26952772
let arg_secret = "debug-arg-secret-must-not-render";
26962773
let rendered = format!(
26972774
"{:?}",
2698-
McpServer {
2775+
McpServer::Stdio(McpServerStdio {
26992776
name: "analytics".into(),
27002777
command: "analytics-mcp".into(),
27012778
args: vec!["--token".into(), arg_secret.into()],
27022779
env: vec![EnvVar {
27032780
name: "ANALYTICS_TOKEN".into(),
27042781
value: env_secret.into(),
27052782
}],
2706-
}
2783+
})
27072784
);
27082785

27092786
assert!(rendered.contains("ANALYTICS_TOKEN"));
@@ -2808,6 +2885,30 @@ mod tests {
28082885
);
28092886
}
28102887

2888+
#[test]
2889+
fn wire_redaction_covers_http_header_values() {
2890+
let source = serde_json::json!({
2891+
"params": {
2892+
"mcpServers": [{
2893+
"type": "http",
2894+
"name": "hosted-context",
2895+
"url": "https://mcp.example.test/mcp",
2896+
"headers": [{"name": "Authorization", "value": "Bearer secret"}]
2897+
}]
2898+
}
2899+
});
2900+
2901+
let redacted = redact_wire_value(&source, None);
2902+
assert_eq!(
2903+
redacted["params"]["mcpServers"][0]["headers"][0]["value"],
2904+
REDACTED_ENV_VALUE
2905+
);
2906+
assert_eq!(
2907+
source["params"]["mcpServers"][0]["headers"][0]["value"], "Bearer secret",
2908+
"redaction must not mutate the wire payload"
2909+
);
2910+
}
2911+
28112912
#[test]
28122913
fn wire_redaction_suppresses_plain_sensitive_echoes_without_changing_source() {
28132914
let shorter = "token";
@@ -3795,15 +3896,15 @@ mod tests {
37953896
let response = client
37963897
.session_new_full(
37973898
"/tmp",
3798-
vec![McpServer {
3899+
vec![McpServer::Stdio(McpServerStdio {
37993900
name: "analytics".into(),
38003901
command: "analytics-mcp".into(),
38013902
args: vec!["--stdio".into()],
38023903
env: vec![EnvVar {
38033904
name: "ANALYTICS_TOKEN".into(),
38043905
value: secret.into(),
38053906
}],
3806-
}],
3907+
})],
38073908
None,
38083909
None,
38093910
)
@@ -3891,15 +3992,15 @@ mod tests {
38913992
let result = client
38923993
.session_new_full(
38933994
"/tmp",
3894-
vec![McpServer {
3995+
vec![McpServer::Stdio(McpServerStdio {
38953996
name: "analytics".into(),
38963997
command: "analytics-mcp".into(),
38973998
args: vec![],
38983999
env: vec![EnvVar {
38994000
name: "ANALYTICS_TOKEN".into(),
39004001
value: secret.into(),
39014002
}],
3902-
}],
4003+
})],
39034004
None,
39044005
None,
39054006
)
@@ -3956,14 +4057,16 @@ mod tests {
39564057
.await
39574058
.expect("initialize should succeed");
39584059

3959-
let server_with_secret = |value: &str| McpServer {
3960-
name: "analytics".into(),
3961-
command: "analytics-mcp".into(),
3962-
args: vec![],
3963-
env: vec![EnvVar {
3964-
name: "ANALYTICS_TOKEN".into(),
3965-
value: value.into(),
3966-
}],
4060+
let server_with_secret = |value: &str| {
4061+
McpServer::Stdio(McpServerStdio {
4062+
name: "analytics".into(),
4063+
command: "analytics-mcp".into(),
4064+
args: vec![],
4065+
env: vec![EnvVar {
4066+
name: "ANALYTICS_TOKEN".into(),
4067+
value: value.into(),
4068+
}],
4069+
})
39674070
};
39684071

39694072
client
@@ -4050,15 +4153,15 @@ mod tests {
40504153
});
40514154
let mut client = spawn_inert_client().await;
40524155
client
4053-
.register_sensitive_mcp_env_values(&[McpServer {
4156+
.register_sensitive_mcp_env_values(&[McpServer::Stdio(McpServerStdio {
40544157
name: "analytics".into(),
40554158
command: "analytics-mcp".into(),
40564159
args: vec![],
40574160
env: vec![EnvVar {
40584161
name: "ANALYTICS_TOKEN".into(),
40594162
value: secret.into(),
40604163
}],
4061-
}])
4164+
})])
40624165
.expect("credential redactor should initialize");
40634166
let trace = TraceCapture::default();
40644167
let subscriber = tracing_subscriber::fmt()
@@ -4115,21 +4218,21 @@ mod tests {
41154218
sleep 1
41164219
"#;
41174220
let servers = vec![
4118-
McpServer {
4221+
McpServer::Stdio(McpServerStdio {
41194222
name: "analytics".into(),
41204223
command: "/opt/MCP Servers/analytics,prod".into(),
41214224
args: vec!["--stdio".into(), "literal value".into()],
41224225
env: vec![EnvVar {
41234226
name: "ANALYTICS_ENDPOINT".into(),
41244227
value: "https://example.test/a=b".into(),
41254228
}],
4126-
},
4127-
McpServer {
4229+
}),
4230+
McpServer::Stdio(McpServerStdio {
41284231
name: "search".into(),
41294232
command: "/opt/search-mcp".into(),
41304233
args: vec![],
41314234
env: vec![],
4132-
},
4235+
}),
41334236
];
41344237

41354238
for _restart in 0..2 {

0 commit comments

Comments
 (0)