Expand description
Core types, traits, and errors for MCP Code Execution.
This crate provides the foundational types and abstractions used across all other crates in the MCP execution workspace.
§Architecture
The core consists of:
- Strong domain types (
ServerId,ToolName) - Error hierarchy with contextual information
- Server configuration with security validation
- Command validation utilities
§Examples
use mcp_execution_core::{ServerConfig, ServerId};
// Create a server configuration
let config = ServerConfig::builder()
.command("docker".to_string())
.arg("run".to_string())
.env("LOG_LEVEL".to_string(), "debug".to_string())
.build()
.unwrap();
// Server ID
let server_id = ServerId::new("github").unwrap();Modules§
- cli
- CLI-specific types and utilities.
- metadata
- Structured sidecar metadata describing a server’s generated tools.
- provenance
- Generation provenance for the
_meta.jsonsidecar: when, and against what server state, ageneraterun produced its output. - untrusted
- Helpers for safely embedding untrusted MCP-server-supplied metadata into Markdown documents and LLM-facing prompts.
Structs§
- Redacted
Items - Debug-formats a list of strings, replacing every entry wholesale with
REDACTED_PLACEHOLDER. - Redacted
MapValues - Debug-formats a
String-valued map with keys visible and every value replaced byREDACTED_PLACEHOLDER. - Redacted
Url - Debug-formats a URL with userinfo credentials and query string hidden, keeping the scheme, host, and path readable.
- Server
Config - MCP server configuration with command, arguments, and environment.
- Server
Config Builder - Builder for constructing
ServerConfiginstances. - Server
Id - Server identifier (newtype over String).
- Tool
Name - Tool name identifier (newtype over String).
Enums§
- Confinement
Error - Errors from walking and confining a path to a base directory.
- Confinement
Target - The terminal path component a
resolve_confined_pathwalk resolves and confinement-checks but deliberately does not create. - Error
- Main error type for MCP Code Execution.
- Resource
Kind - Identifies which bounded resource a
Error::ResourceLimitExceededrejection concerns. - Server
IdError - Error returned when a candidate string fails the invariant
ServerId::newenforces. - Server
IdSlug Error - Errors returned by
validate_server_id_slug. - Tool
Name Error - Error returned when a candidate string fails the invariant
ToolName::newenforces. - Transport
- Transport-specific configuration for connecting to an MCP server.
Constants§
- MAX_
ARG_ COUNT - Maximum number of positional arguments accepted in a
ServerConfig(denial-of-service protection, CWE-400). - MAX_
ARG_ LEN - Maximum byte length for a single command string, argument, or environment variable name.
- MAX_
ENV_ COUNT - Maximum number of environment variables accepted in a
ServerConfig. - MAX_
ENV_ VALUE_ LEN - Maximum byte length for a single environment variable value.
- MAX_
HEADER_ COUNT - Maximum number of HTTP headers accepted for Http/Sse transport.
- MAX_
HEADER_ VALUE_ LEN - Maximum byte length for a single HTTP header value.
- MAX_
SERVER_ ID_ LENGTH - Maximum length, in bytes, of a slug-shaped server id (see
validate_server_id_slug). - MAX_
URL_ LEN - Maximum byte length for the HTTP/Sse transport
url. - REDACTED_
PLACEHOLDER - Fixed placeholder substituted for every redacted value.
Functions§
- contains_
parent_ dir - Returns
trueifpathcontains a..(parent-directory) component. - env_
name_ charset_ desc - Returns the human-readable description of the environment-variable-name identifier
charset used in this module’s own rejection message (
"[A-Za-z_][A-Za-z0-9_]*"). - env_
name_ charset_ pattern - Returns the environment-variable-name identifier charset as an anchored, JavaScript
RegExp-compatible pattern source. - first_
disallowed_ identifier_ char - Returns the first
charinsthat is not UTS #39Identifier_Status=Allowed, orNoneif every character is Allowed. - forbidden_
chars - Returns the shell metacharacters considered forbidden in a command or argument string.
- forbidden_
env_ names - Returns the exact-match forbidden environment variable names.
- forbidden_
env_ prefix - Returns the environment-variable-name prefix rejected regardless of exact match
(currently
DYLD_, macOS’s dynamic-linker variable family). - open_
confined_ write - Opens
pathfor writing, refusing to follow a pre-existing symlink planted at that exact location. - redact_
urls_ in_ text - Finds every URL-shaped token in
textand redacts each one. - resolve_
confined_ path - Resolves
segment, thenrelative_dirs, thentarget(if any), confining every step tobase_dir/segment. - sanitize_
path_ for_ error - Sanitizes a file path for inclusion in an error message, to prevent information disclosure.
- validate_
path_ segment - Validates that
segmentis a single plain path component: non-empty, and with no.., path separator, or root/prefix component. - validate_
server_ config - Validates a
ServerConfigfor safe execution, dispatching on transport type. - validate_
server_ id_ slug - Validates that
idis a filesystem-safe server id slug: 1-64 lowercase ASCII letters, digits, or hyphens (^[a-z0-9-]+$). - validate_
url_ scheme - Validates that a URL uses the
http://orhttps://scheme. - write_
confined_ file - Writes
contenttopath, refusing to follow a symlink planted atpath’s exact location after a caller’sConfinementTarget::Fileconfinement check but before this call.
Type Aliases§
- Result
- Result type alias for MCP operations.