Metadata-Version: 2.3
Name: mcp-behave
Version: 0.6.0
Summary: Runtime behavioral auditor for MCP servers — scope-violation detection via native libc interposition & runtime tracing
Project-URL: Homepage, https://www.navidmirnouri.com/mcp-behave/
Project-URL: Documentation, https://www.navidmirnouri.com/mcp-behave/
Project-URL: Repository, https://github.com/navid72m/mcp-behave
Project-URL: Issues, https://github.com/navid72m/mcp-behave/issues
Author-email: Navid Mirnoori Langeroudi <navid72m@gmail.com>
License: MIT
Keywords: agents,auditing,mcp,sandbox,security,tracer
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Security
Classifier: Topic :: Software Development :: Quality Assurance
Requires-Python: >=3.10
Requires-Dist: mcp<2.0,>=1.0
Provides-Extra: test
Requires-Dist: pytest>=8.0; extra == 'test'
Description-Content-Type: text/markdown

<p align="center">
  <img src="assets/logo.png" alt="mcp-behave logo" width="96" />
</p>

# mcp-behave

**See what your MCP servers actually do at runtime.** Audit them before connecting them to an AI agent, monitor live tool calls, and enforce reviewed behavioral policies.

[![CI](https://github.com/navid72m/mcp-behave/actions/workflows/ci.yml/badge.svg)](https://github.com/navid72m/mcp-behave/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/mcp-behave.svg)](https://pypi.org/project/mcp-behave/)
[![npm](https://img.shields.io/npm/v/mcp-behave.svg)](https://www.npmjs.com/package/mcp-behave)
[![MCP Registry](https://img.shields.io/badge/MCP%20Registry-listed-blue)](https://registry.modelcontextprotocol.io/v0.1/servers?search=io.github.navid72m/mcp-behave)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
[![PyPI Downloads](https://static.pepy.tech/personalized-badge/mcp-behave?period=total&units=ABBREVIATION&left_color=BLACK&right_color=GREEN&left_text=downloads)](https://pepy.tech/projects/mcp-behave)
[![npm downloads](https://img.shields.io/npm/dw/mcp-behave)](https://www.npmjs.com/package/mcp-behave)

[Quick start](#quick-start) · [Runtime monitoring](#2-monitor-your-ai-client) · [Validation](#validation) · [Documentation](#documentation) · [Discussions](https://github.com/navid72m/mcp-behave/discussions)

<p align="center">
  <a href="demo.gif"><img src="demo.gif" alt="mcp-behave terminal demonstration" width="800" /></a>
</p>

## Quick start

Run without permanent installation using [uvx](https://docs.astral.sh/uv/), or install with pip or npm:

```bash
uvx mcp-behave --version
# or
pip install mcp-behave
# or
npm install -g mcp-behave
```

The npm package launches the Python implementation. Native tracing supports compatible macOS and Linux runtimes; building the interposer requires a C compiler.

### 1. Audit a server

Discover MCP capabilities, exercise them with schema-aware inputs, and compare declared metadata with observed file, network and process activity.

```bash
uvx mcp-behave audit python -m my_mcp_server
```

> **Safety:** Audits execute server code and may invoke mutating tools. Use synthetic data in a disposable environment. Canary HOME redirection is not OS isolation; sandboxing is off by default. For untrusted targets, use a suitable isolated container or VM. Audit `--sandbox auto` may fall back to unsandboxed execution.

### 2. Monitor your AI client

Already using Claude Desktop, Claude Code or Cursor? Preview configuration changes, then wrap one existing server (replace `filesystem` with its configured name):

```bash
uvx mcp-behave status --client claude
uvx mcp-behave install filesystem --client claude --dry-run
uvx mcp-behave install filesystem --client claude
```

Restart the client and use its MCP tools normally. To undo the integration:

```bash
uvx mcp-behave uninstall filesystem --client claude
```

Or configure the stdio proxy manually. Example for a controlled filesystem fixture:

```bash
mkdir -p /tmp/mcpb-fixture
uvx mcp-behave wrap --server filesystem --state-dir /tmp/mcpb-logs \
  -- npx -y @modelcontextprotocol/server-filesystem@2.4.1 /tmp/mcpb-fixture
```

`wrap` is launched by an MCP client, not used as an interactive shell. It forwards JSON-RPC and records session telemetry (JSONL and SQLite). With the explicit state directory above, session logs are in `/tmp/mcpb-logs/sessions/`.

```text
AI client <--> mcp-behave wrap <--> MCP server
                    |
                    +-- Protocol monitoring & policy checks
                    +-- Native runtime events & tool attribution
                    +-- Session telemetry
```

Example from a post-release macOS filesystem test (selected event fields):

```json
{
  "event": "file_write",
  "target": "/private/tmp/mcp-behave-test/hello.txt",
  "current_tool": "write_file",
  "request_id": 3,
  "source": "interposition",
  "evidence_tier": "observed"
}
```

### 3. Enforce reviewed behavior

Generate a multi-server lockfile in an isolated test environment, review it, then enable inline policy enforcement:

```bash
uvx mcp-behave --lock --server-id my-server python -m my_mcp_server
uvx mcp-behave wrap --server my-server --lockfile mcp-behave.lock.json \
  --enforce -- python -m my_mcp_server
```

`--enforce` requires a valid matching lockfile entry. The default fail-closed policy blocks covered protocol violations and stops forwarding when required tracing coverage is detected to be unavailable or degraded. `--fail-mode fail-open` skips inline blocking; `--redact` separately enables response redaction. Native OS activity is observed, not universally blocked or undone.

## Features

| Capability | What it does |
| --- | --- |
| Active auditing | Schema-aware probes, optional declarative probe profiles, static lint and behavioral findings. |
| Live monitoring | Stdio proxy with native file, network and process observation and tool-call attribution. |
| Policy enforcement | Reviewed multi-server lockfiles, inline filtering, manifest re-verification and optional redaction. |
| Behavioral regression | `init` / `check` detect drift against a separate single-server baseline. |
| Configuration security | Scan MCP client configs for risky settings; install or remove wrappers. |
| CI integration | JSON, SARIF and severity-based audit exit codes. |

## What's new in v0.5.8

- Improved macOS support for npm-based MCP servers with a Darwin npx launch adapter.
- Hardened fail-closed request forwarding, final telemetry draining and PID tracking degradation handling.
- Conservative attribution when telemetry is lost, with explicit shutdown uncertainty.
- Improved nested-schema argument synthesis, fixture-assisted probe profiles and detection precision.
- Frozen release artifacts with checksum-verified CI promotion and trusted publishing.

[Read the v0.5.8 release notes](https://github.com/navid72m/mcp-behave/releases/tag/v0.5.8).

## CI and other commands

```bash
uvx mcp-behave --json --fail-on high python -m my_mcp_server
uvx mcp-behave --sarif python -m my_mcp_server > mcp-behave.sarif
```

| Command | Purpose |
| --- | --- |
| `lint manifest.json` | Static checks without launching a server. |
| `scan-configs` / `audit-configs` | Inspect client configuration / actively audit configured targets. |
| `inspect` | Correlated audit timeline. |
| `init` / `check` | Single-server behavioral baseline and regression check. |
| `approve` | Review and approve a manifest change into the multi-server lockfile. |
| `serve` | Expose auditing capabilities over MCP. |

Run `uvx mcp-behave --help` or `uvx mcp-behave wrap --help` for options. The legacy `mcp-behave.lock` format is distinct from `mcp-behave.lock.json`.

## Validation

| v0.5.8 release validation | Result |
| --- | --- |
| macOS regression suite | 538 passed |
| Linux regression suite (non-root ARM64 container, installed wheel) | 530 passed, 8 skipped |
| Real-world wrap/enforce scenarios | Seven servers evaluated |
| Filesystem acceptance | 30 successful runs (including initial cache population) |
| Public installations | PyPI/uvx and npm smoke tests passed |

Evaluated servers include MotherDuck, DBHub, Qdrant, Excel, MCP Memory Service, Desktop Commander and Filesystem. These are selected, project-maintained scenarios, not comprehensive coverage or security certification. Cold-cache launches may time out or degrade tracing; the v0.5.8 soak was short-duration lifecycle validation, not an endurance test.

[Release notes](https://github.com/navid72m/mcp-behave/releases/tag/v0.5.8) · [Historical validation (v0.5.7)](VALIDATION.md) · [Benchmarks and historical endurance results](BENCHMARK.md) · [Integration examples](examples/integrations/README.md)

## Security boundaries

- Native interposition observes selected dynamic-library calls, not every syscall. Static binaries, direct syscalls, macOS SIP and hardened runtimes can limit coverage.
- `wrap` supports local stdio; remote SSE/Streamable HTTP audits do not trace the remote host. npm package installation can occur outside runtime monitoring.
- Tracing, protocol enforcement and OS sandboxing are different controls. `wrap --no-trace --enforce` is rejected in fail-closed mode; active tracing does not prove complete telemetry. Shutdown may report `telemetry_complete: false` even with zero reported drops.
- A clean audit is not proof of safety. Review coverage, findings, lockfile changes and platform limitations before trusting a server.

## Documentation

| Resource | Details |
| --- | --- |
| [Architecture](ARCHITECTURE.md) | Internal design and data flow |
| [Detailed usage reference (v0.5.8)](https://github.com/navid72m/mcp-behave/blob/v0.5.8/README.md) | Full CLI examples, sandbox semantics, probe profiles and platform caveats |
| [Detection matrix](docs/detection_matrix.md) | Rules and observation coverage |
| [Security policy](SECURITY.md) | Threat boundaries and private vulnerability reporting |
| [Technical whitepaper](docs/mcp_behave_technical_whitepaper.pdf) · [Research article](https://www.navidmirnouri.com/blog/auditing-mcp-servers-with-mcp-behave.html) | Background and experiments |
| [Changelog](CHANGELOG.md) · [Roadmap](ROADMAP.md) | Changes and planned work |

## Community

Questions, ideas and integration experiences are welcome in [GitHub Discussions](https://github.com/navid72m/mcp-behave/discussions). Report reproducible bugs in [Issues](https://github.com/navid72m/mcp-behave/issues); report sensitive vulnerabilities privately as described in [SECURITY.md](SECURITY.md).

To contribute, clone the repository, install with `python -m pip install -e ".[test]"`, and run `pytest -v`.

MIT — [License](LICENSE).

<!-- mcp-name: io.github.navid72m/mcp-behave -->
