mcp-behave
Runtime behavioral auditing and monitoring for Model Context Protocol (MCP) servers.
mcp-behave is a CLI-first security tool for checking what an MCP server actually does—not only what its tool descriptions say it can do. It actively exercises a server's advertised capabilities, observes selected runtime activity, checks protocol metadata and responses, and compares behavior with saved baselines.
It also provides mcp-behave wrap, a stdio proxy for monitoring MCP traffic while an AI client uses a server. mcp-behave is CLI-first: it provides terminal, JSON, and SARIF output and does not ship a built-in graphical dashboard.
Why mcp-behave?
An MCP server can advertise a harmless tool while its implementation performs unexpected operations. For example, a tool described as a local document formatter might also read a credential file or attempt an outbound network connection.
mcp-behave compares two views of a server:
- Declared behavior: tools, input schemas, annotations, resources, prompts, and metadata exposed over MCP.
- Observed behavior: selected file, network, and process activity captured while the server is exercised or monitored.
The goal is to make unexpected behavior visible for review. A clean audit is not proof that a server is safe; it means no covered issue was observed in the tested scenarios.
What it checks
- Runtime activity: selected filesystem operations, network connection attempts, and subprocess launches.
- MCP metadata: tool definitions, schemas, descriptions, annotations, resources, prompts, and manifest changes.
- Content risks: prompt-injection patterns, invisible or bidirectional Unicode characters, terminal escape sequences, and external Markdown/HTML image references in tool output.
- Sensitive data: known secret patterns and configured canary tokens in inspected payloads.
- Client configuration: hard-coded credentials, broad filesystem mounts, shell wrappers, and unpinned package commands in supported MCP client configuration files.
Findings describe observed behavior and potential risks; they are not automatic accusations of malicious intent.
Install
The simplest option is to run with uvx:
uvx mcp-behave --version
Or install the Python package:
python -m pip install mcp-behave
mcp-behave --version
An npm package is also available:
npm install -g mcp-behave
mcp-behave --version
About the npm package: it is a Node.js launcher for the Python implementation, not a separate JavaScript auditing engine. It requires Node.js 16+ and a Python 3 environment; it uses uvx or pipx when available.
Quick start: audit an MCP server
Important: audits execute server code
An audit is active testing, not passive package inspection. The probe may call tools and read resources/prompts, and those operations can have side effects. Do not run an unfamiliar server against your normal host environment without isolation.
The audit sandbox defaults to none. Passing --sandbox auto asks mcp-behave to use Podman or Docker when available, but it does not guarantee isolation: if neither container runtime responds, the audit falls back to unsandboxed local execution. Container runs default to --network=none with the default python:3.12-slim or node:20-slim image and only the working directory mounted read-only at /workspace, so commands that download packages (npx -y, uvx) or reference host paths outside the working directory require pre-populated images or an already isolated disposable environment. When you require container isolation, run from a disposable directory with synthetic inputs and specify an explicit runtime (--sandbox docker or --sandbox podman) with a command and image that can run offline against /workspace.
Pass a stdio server command to run a one-shot audit. The audit prefix is optional. Running bare mcp-behave starts the tool's MCP service.
uvx mcp-behave python -m my_mcp_server
mcp-behave audit python -m my_mcp_server
Inside an already isolated disposable environment with synthetic fixture files, you can also audit a local server launched with npx or uvx:
uvx mcp-behave npx -y @modelcontextprotocol/server-filesystem /tmp/mcpb-fixture
uvx mcp-behave uvx mcp-server-git
The probe starts the server, initializes a session, discovers tools, resources, and prompts, and exercises advertised capabilities with synthesized inputs. It can call tools, read resources, and fetch prompts. Even an untraced audit executes server code and can cause side effects. The default audit environment redirects home and configuration paths to a temporary canary home and filters environment variables by name. An unsandboxed target still has the host access of the account that launched it.
With --transport sse or --transport streamable-http, supply one URL. The audit connects to the running remote server and exercises it for manifest and protocol analysis, without local OS tracing of the server.
Runtime monitoring with wrap
mcp-behave wrap runs between an AI client and a stdio MCP server. The client sends MCP messages to the proxy; the proxy forwards them to the target while monitoring protocol traffic and selected operating-system activity.
AI client <---- stdio / JSON-RPC ----> mcp-behave wrap <---- stdio / JSON-RPC ----> MCP server
|
+-- protocol monitoring
+-- runtime tracing (when available)
+-- policy checks, scanning, and telemetry
Start the inline proxy in monitoring mode with a controlled fixture:
uvx mcp-behave wrap \
--server my-server \
-- python -m my_mcp_server
By default, wrap monitors protocol traffic and can issue periodic synthetic tools/list requests to recheck the manifest. It publishes observed OS policy violations and emits alerts after the activity is observed. Protocol enforcement, response redaction, and OS sandboxing are independently configurable.
With --enforce, wrap requires a valid multi-server lockfile entry matching the selected server ID before launching the child, even with --fail-mode fail-open. With the default fail-closed mode, the inline filter rejects unapproved tools/call requests (including Unicode-escaped method names), JSON-RPC batch arrays, malformed JSON, and non-object payloads before forwarding, and replaces covered server responses containing a detected canary, critical secret, batch array, or malformed JSON with a JSON-RPC error. fail-open skips those inline blocks. wrap also bounds individual JSON-RPC messages and stdin queueing to 16 MiB (256 items max in queue; one oversized message up to 16 MiB is permitted when empty) and applies bounded process-group shutdown. Monitoring can still report findings.
--redact replaces detected secret and canary values in inspected server JSON payloads that reach the redaction step. Replacing or redacting a response leaves any OS side effects that already happened in place. Stderr, files, and network traffic are outside this protocol filter.
Create and use a behavioral lockfile
Generate or update the multi-server lockfile from an audit:
uvx mcp-behave --lock --server-id my-server python -m my_mcp_server
This writes mcp-behave.lock.json. Review the generated baseline before treating it as approved. Then run the server through wrap with enforcement enabled:
uvx mcp-behave wrap \
--server my-server \
--lockfile mcp-behave.lock.json \
--enforce \
-- python -m my_mcp_server
To review a manifest change observed by wrap and approve it into the lockfile:
uvx mcp-behave approve --server my-server
Useful wrap options:
| Option | Purpose |
|---|---|
--enforce |
Enforce lockfile-based tool policy checks. Requires a valid matching entry in mcp-behave.lock.json. |
--redact |
Replace detected sensitive values in inspected server responses. |
--canary TOKEN / --canary-file PATH |
Watch for configured canary values in inspected traffic. |
--sandbox auto |
Request the platform-appropriate sandbox backend. |
--no-trace |
Disable native runtime tracing and retain protocol-level monitoring. |
--no-reverify |
Disable periodic synthetic tools/list re-verification. |
wrap is an stdio proxy; it does not turn a remote HTTP MCP connection into a locally traced process.
Other commands
| Command | Use it for |
|---|---|
mcp-behave lint manifest.json |
Static checks of a manifest or tool-definition JSON without starting a server. |
mcp-behave scan-configs |
Find MCP servers in supported local client configuration files and inspect configuration risks. |
mcp-behave audit-configs |
Discover configured servers and run audits against them. This actively launches and exercises targets. |
mcp-behave inspect <command> |
View a correlated timeline of MCP messages and observed runtime events; can also inspect a prior output directory. |
mcp-behave serve |
Expose mcp-behave's audit and inspection tools through an MCP server interface. |
mcp-behave install / status / uninstall |
Add, inspect, or remove wrapper entries in supported local AI client configurations. |
CI and machine-readable output
Use JSON or SARIF output for automation and code-scanning workflows:
uvx mcp-behave --json --fail-on high python -m my_mcp_server
uvx mcp-behave --sarif python -m my_mcp_server > mcp-behave.sarif
The default output directory is /tmp/mcp_behave_out. Set --out-dir to choose another location. Exit codes for an audit are 0 for no findings at or above the selected threshold, 3 when the threshold is met, 2 for a tracing/setup failure, and 1 for other errors.
Legacy single-server baseline workflow
The init and check commands maintain the earlier single-server mcp-behave.lock format:
uvx mcp-behave init python -m my_mcp_server
uvx mcp-behave check python -m my_mcp_server
This is separate from the multi-server mcp-behave.lock.json used by wrap. Keep the two lockfile formats distinct.
Runtime tracing and platform notes
- Audit on macOS: uses a dynamic interposer via
DYLD_INSERT_LIBRARIESwhen available. Hardened or specially signed targets can reject injection, which can cause launch failure. - Audit on Linux: automatic selection tries an
LD_PRELOADinterposer first, thenstraceif installed.stracehas its own coverage and permission requirements. With no eligible tracer, the local target is still exercised untraced.--no-traceexplicitly selects that path when no container is active. Building a native interposer requires a C compiler. - Wrap on macOS and Linux: uses the platform's dynamic interposer and reports tracing status (
active,partial, ordisabled) in telemetry. It requires a handshake from the launched PID; if the launcher times out while descendants report ready, it emits ablind_spotalert and classifies tracing aspartial(descendant_only). With a sandbox command, wrap attempts interposition on the launcher. A handshake or an active container status provides no evidence of tracing coverage inside the container. - Native Windows: ordinary audit tracer selection has no native Windows backend. Wrap tracing reports
unsupported_oswhen enabled, and wrap--sandbox autoselects no backend. Explicit container use depends on a usable runtime and successful launch. Wrap also relies on asyncio stdio pipe integration, new sessions, and POSIX process-group signaling and cleanup, so the untraced path does not establish native Windows support.
Explicit tracer selection
--tracer auto (the default) selects the best available platform tracer. --tracer none or --no-trace explicitly requests untraced execution. Requesting an explicit unavailable backend (such as --tracer ebpf on macOS or unsupported Linux kernels, --tracer preload on macOS, or --tracer strace without strace installed) fails with exit code 2 before launching a local target. Remote audits (sse/streamable-http) and active container sandboxes (--sandbox) do not use host syscall tracers.
OS sandbox selection and defaults
Both audit and wrap default to --sandbox none.
- Audit:
--sandbox autochecks for responsive Podman first and then Docker. If neither responds, the audit can continue locally without a container. Explicit--sandbox dockeror--sandbox podmanuses that runtime name directly, so launch failures can surface. The initial banner labels the requested sandbox before availability is known. An active audit container bypasses host syscall tracing and recordssandbox-<runtime>as the tracer label. - Wrap:
--sandbox autoselects Seatbelt on macOS and a container on Linux. Explicit choices areseatbeltandcontainer. For a selected backend, unavailability or an error preparing the command aborts under the defaultfail-closedmode. Underfail-open, those cases can launch the original command with sandbox status disabled. On unsupported platforms,autoprepares the original command with disabled sandbox status even underfail-closed. These rules govern preparation. A launch error or a failure after the wrapped command starts does not trigger an unsandboxed retry. Active sandbox telemetry describes the prepared command. - Container defaults: no networking, a read-only bind mount of the current working directory at
/workspace, all capabilities dropped, and no new privileges. Audit can override the network mode. When supplied with an existing canary home directory, the command builder mounts it read-write at/canary_homeand redirects home and configuration variables there. Audit supplies its temporary canary home by default. Wrap's container preparation does not supply one.
Seatbelt lockfile hints
Seatbelt starts with an allow-default profile. Wrap passes the selected server's lockfile entry to the profile generator even when protocol enforcement is off. With no matching entry or no tools, the profile adds neither write nor outbound restrictions.
For a nonempty tool set, aggregation considers only tools with nonempty annotation records. It adds write restrictions when every considered tool has readOnlyHint=true, with exceptions for /tmp, /private/tmp, /dev/null, /dev/zero, and /dev/tty. Any considered tool with openWorldHint=true leaves outbound networking unrestricted by the profile. When all considered tools are closed-world, the profile restricts outbound networking to loopback.
Generated lockfiles fill in missing hints with readOnlyHint=false and openWorldHint=true. A tool with both defaults contributes to both permissive outcomes, so an active Seatbelt profile may leave writes and outbound networking unrestricted. Absent or empty legacy annotation records are skipped. If tools exist but all their annotation records are absent or empty, the empty all and any checks add both restrictions.
Security and coverage limitations
Native interposers observe selected dynamically linked libc calls. Direct syscalls, statically linked targets, and other uninstrumented operations may escape observation. Behavior tied to a particular input, environment, time, or external condition may be outside the scenarios tested. For a controlled disposable fixture, use multiple probe rounds and adversarial input testing where appropriate:
uvx mcp-behave --probe-rounds 3 --fuzz python -m my_mcp_server
Clean reports, trace and sandbox statuses, redaction, and baselines provide evidence bounded by the configuration and observations. Review baseline changes before approving them.
Evaluation
- Use a disposable environment and a controlled local fixture. Keep real credentials, production data, live client configurations, and sensitive host mounts out of the environment. Wrap starts from the parent environment, so launch the client and wrapper with a synthetic environment too.
- Audit from a scratch working directory containing only fixture files. For a container trial, confirm a responsive runtime and a fixture command that can run in the image. Use an explicit runtime if the trial requires a container. Keep the default disabled container network and leave
--unsafe-hostoff. - Use synthetic inputs and canaries. Compare audit findings across selected scenarios, then use a disposable stdio client to exercise wrap monitoring, enforcement with a reviewed fixture lockfile, and optional redaction. Inspect the reported trace and sandbox statuses along with the actual responses and expected fixture effects.
The repository includes benchmark corpora and reports covering paired benign/malicious server fixtures, multi-server authorization scenarios, deterministic runtime-policy tests, and audits of reference MCP servers. The README intentionally keeps detailed tables out of the getting-started path:
- Benchmark methodology and results
- CrossMCP-Bench report
- MCP-GuardBench report
- Pluto MCP Visibility report
- Official reference-server audit
These are project-maintained evaluations on specified corpora and fixtures. Results are corpus-specific; they are not independent certification or a guarantee that an arbitrary MCP server is safe.
Documentation
- Architecture and data flow
- Detection rules and observation matrix
- Technical whitepaper
- Research article: Auditing real-world MCP servers
- Roadmap
- Security policy
- Community feedback and issue tracker
Development
git clone https://github.com/navid72m/mcp-behave.git
cd mcp-behave
python -m pip install -e ".[test]"
pytest -v
The CI workflow runs tests on Linux and macOS. Contributions, bug reports, false-positive reports, and suggestions are welcome through GitHub Issues.
License
MIT. See LICENSE.
Metadata
Release files for mcp-behave 0.5.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mcp_behave-0.5.4.tar.gz | 162.7 kB | With provenance | Details for mcp_behave-0.5.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mcp_behave-0.5.4-py3-none-any.whl | Python 3 | none | any | Details for mcp_behave-0.5.4-py3-none-any.whl |
Total release size: 344.2 kB
Release files / mcp_behave-0.5.4.tar.gz
| Download URL | mcp_behave-0.5.4.tar.gz |
|---|---|
| Size | 162.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
29e0fd6bc657f7fb33bf0f88e86b00da327eee4759a4165bd2ebb6c8c8453f20
|
|
BLAKE2b-256 checksum How to use checksums |
5a85456571f3ad9aa2c2be9355f51cc2b061a818f388b61254db5e96c60b00a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logRelease files / mcp_behave-0.5.4-py3-none-any.whl
| Download URL | mcp_behave-0.5.4-py3-none-any.whl |
|---|---|
| Size | 181.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
11a829cf2e23dc144f2a2e67b5bc1578c75af2ca075ae5cc6f0510eff58fd14c
|
|
BLAKE2b-256 checksum How to use checksums |
b4747ae6de0573aa124b70cdb60d50121791e136238c85068f457c0059f19192
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logSecurity for mcp-behave 0.5.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for mcp_behave-0.5.4.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.