pub struct BridgeContext {
pub env_name_charset_desc: String,
pub max_arg_count: usize,
pub max_arg_len: usize,
pub max_env_count: usize,
pub max_env_value_len: usize,
pub max_url_len: usize,
pub max_header_count: usize,
pub max_header_value_len: usize,
/* private fields */
}Expand description
Context for rendering the runtime bridge template.
The forbidden-char/forbidden-env-name/charset-pattern fields are rendered directly from
mcp_execution_core’s canonical lists so the generated bridge’s copies structurally
cannot drift from the Rust source of truth — see BridgeContext::default, the only way
to construct one, which populates them from mcp_execution_core::forbidden_chars/
forbidden_env_names/forbidden_env_prefix/env_name_charset_pattern rather than leaving
them empty. This deliberately does not derive Default: an empty forbidden_chars would
render a bridge whose validateCommandString accepts every shell metacharacter, and an
empty env_name_charset_pattern would render new RegExp(''), which matches every string
(fail-open on exactly the checks these exist to enforce) — so Default is hand-written to
make “always populated” a property of the type rather than a convention callers must
remember to uphold.
Those four fields are private with read-only accessors for the same reason: pub fields
would let BridgeContext { forbidden_chars: vec![], .. } bypass the invariant entirely and
still compile, silently reintroducing the fail-open state Default exists to prevent.
Deserialize is intentionally not derived — nothing in this codebase deserializes a
BridgeContext from external input, and doing so would need to re-validate non-emptiness
rather than trust the wire data.
The remaining fields — the denial-of-service size/count ceilings
(mcp_execution_core::MAX_ARG_COUNT and siblings) and env_name_charset_desc (the
human-readable charset description used only in a rejection message’s text, not in the
enforcement regex above) — are plain pub fields: unlike an emptied list or pattern, a
wrong value here cannot fail open — at worst it makes the rendered bridge reject configs it
should accept (a wrong MAX_*), or emit a confusing-but-still-rejecting error message (a
wrong env_name_charset_desc), never silently accept something it shouldn’t — so the extra
accessor/invariant machinery above would be pure ceremony here.
§Examples
use mcp_execution_codegen::progressive::BridgeContext;
let context = BridgeContext::default();
assert!(!context.forbidden_chars().is_empty());
assert!(context.forbidden_chars().contains(&";".to_string()));
assert!(!context.forbidden_env_prefix().is_empty());
assert!(!context.env_name_charset_pattern().is_empty());
assert!(!context.env_name_charset_desc.is_empty());
assert!(context.max_arg_count > 0);Fields§
§env_name_charset_desc: StringHuman-readable description of the charset above (mcp_execution_core::env_name_charset_desc,
e.g. "[A-Za-z_][A-Za-z0-9_]*"), pre-escaped like env_name_charset_pattern and
rendered into the bridge’s own rejection message so that text isn’t a second
hand-copied literal alongside the pattern.
max_arg_count: usizeMaximum number of positional arguments (mcp_execution_core::MAX_ARG_COUNT).
max_arg_len: usizeMaximum byte length for a command, argument, env-var name, or header name
(mcp_execution_core::MAX_ARG_LEN).
max_env_count: usizeMaximum number of environment variables (mcp_execution_core::MAX_ENV_COUNT).
max_env_value_len: usizeMaximum byte length for a single environment variable value
(mcp_execution_core::MAX_ENV_VALUE_LEN).
max_url_len: usizeMaximum byte length for the Http/Sse transport url
(mcp_execution_core::MAX_URL_LEN).
max_header_count: usizeMaximum number of HTTP headers (mcp_execution_core::MAX_HEADER_COUNT).
max_header_value_len: usizeMaximum byte length for a single HTTP header value
(mcp_execution_core::MAX_HEADER_VALUE_LEN).
Implementations§
Source§impl BridgeContext
impl BridgeContext
Sourcepub fn forbidden_chars(&self) -> &[String]
pub fn forbidden_chars(&self) -> &[String]
Shell metacharacters forbidden in a command or argument string, each pre-escaped for safe embedding inside a single-quoted TypeScript string literal. Never empty.
§Examples
use mcp_execution_codegen::progressive::BridgeContext;
assert!(!BridgeContext::default().forbidden_chars().is_empty());Sourcepub fn forbidden_env_names(&self) -> &[String]
pub fn forbidden_env_names(&self) -> &[String]
Forbidden environment variable names (exact match). Never empty.
§Examples
use mcp_execution_codegen::progressive::BridgeContext;
assert!(!BridgeContext::default().forbidden_env_names().is_empty());Sourcepub fn forbidden_env_prefix(&self) -> &str
pub fn forbidden_env_prefix(&self) -> &str
Environment-variable-name prefix rejected regardless of exact match (e.g. DYLD_).
Never empty.
§Examples
use mcp_execution_codegen::progressive::BridgeContext;
assert!(!BridgeContext::default().forbidden_env_prefix().is_empty());Sourcepub fn env_name_charset_pattern(&self) -> &str
pub fn env_name_charset_pattern(&self) -> &str
POSIX/Windows environment-variable-name identifier charset, as an anchored JavaScript
RegExp-compatible pattern source. Never empty.
§Examples
use mcp_execution_codegen::progressive::BridgeContext;
assert!(!BridgeContext::default().env_name_charset_pattern().is_empty());Trait Implementations§
Source§impl Clone for BridgeContext
impl Clone for BridgeContext
Source§fn clone(&self) -> BridgeContext
fn clone(&self) -> BridgeContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BridgeContext
impl Debug for BridgeContext
Source§impl Default for BridgeContext
impl Default for BridgeContext
Source§fn default() -> Self
fn default() -> Self
Populates the forbidden-char/forbidden-env-name/charset-pattern fields directly from
mcp_execution_core’s canonical lists/constants, so BridgeContext::default() can
never render a bridge with an empty (fail-open) FORBIDDEN_CHARS or
ENV_NAME_CHARSET_REGEX. Each forbidden_chars entry and env_name_charset_pattern
itself are passed through sanitize_ts_string_literal (this crate’s TS-string-literal
escaper) so they render as syntactically valid single-quoted TypeScript string literals
regardless of what the Rust source contains — critique #471/#467 S2: without this, a
future edit introducing a '/\ into the Rust pattern would either break the generated
new RegExp('...') call or silently change what it matches.