Metadata-Version: 2.3
Name: mcp-behave
Version: 0.7.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
Requires-Dist: tomlkit<1,>=0.13
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

**Know what your MCP servers actually do — not just what they say they do.**

An open-source runtime security auditor for the Model Context Protocol (MCP). Observe file access, network connections and process activity; detect behavioral drift; and investigate retained activity directly from your AI assistant.

[![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)

[Try the demo](#try-it-yourself) · [Monitor your client](#monitor-your-ai-client) · [Ask your AI assistant](#ask-your-ai-assistant) · [Docs](#documentation) · [Give feedback](#help-shape-the-project)

## Why mcp-behave?

An MCP tool can declare itself read-only, yet the code behind it may write files, launch processes or access the network. Tool descriptions and annotations are useful hints, not an enforcement boundary. A server update can also change runtime behavior without changing its tool descriptions.

mcp-behave helps reveal that gap:

| What a tool declares | What runtime observation may reveal |
| --- | --- |
| “Read a document” | Expected file reads |
| `readOnlyHint: true` | An unexpected file write |
| “Works locally” | A connection to an external host |

*Illustrative examples, not findings against a particular server.*

## Quick setup

Configure monitoring and the security assistant in one step:

​```bash
uvx mcp-behave@0.7.0 setup
​```

Supports Claude Desktop, Claude Code, Cursor, Codex,
Antigravity, Gemini CLI, VS Code, Cline, Roo Code,
Windsurf and Zed.

Preview changes without modifying your configuration:

​```bash
uvx mcp-behave@0.7.0 setup --dry-run
​```

[Setup guide](docs/setup.md)

## Try it yourself

**No AI client, API key or existing MCP server required.** Use a controlled synthetic fixture that simulates a server update: the tool metadata and response stay the same, but its runtime behavior changes.

You need [uv](https://docs.astral.sh/uv/getting-started/installation/), a compatible macOS/Linux runtime and a C compiler (Xcode Command Line Tools on macOS; a build toolchain such as `build-essential` on Debian/Ubuntu).

```bash
git clone https://github.com/navid72m/mcp-behave.git
cd mcp-behave
uv run --managed-python --script examples/demo/demo.py
```

![mcp-behave behavioral drift demo](assets/quickstart.gif)

The demo pins v0.6.0 and the tested MCP SDK. The first run downloads dependencies and may install Python 3.12; subsequent runs can reuse the cache. It does not modify your MCP client configuration.

**What you'll see:**

1. A clean behavioral baseline is recorded.
2. The unchanged server passes verification.
3. The simulated update writes a synthetic file. The real `check` command must identify that exact write, return exit code `3`, and report the same manifest hash.

This is detection, not prevention. If tracing is unavailable or the expected evidence is missing, the demo reports an inconclusive result rather than a pass. [Demo details and troubleshooting](examples/demo/README.md)

## Use it with your own MCP server

| Workflow | When to use it |
| --- | --- |
| **[Audit](#audit-before-connecting)** | Before connecting: probe declared versus observed behavior. |
| **[Wrap](#monitor-your-ai-client)** | During execution: observe live tool calls and runtime activity. |
| **[Serve](#ask-your-ai-assistant)** | Investigate retained activity from your AI client. |

Install or run a published version:

```bash
uvx mcp-behave@0.6.0 --version
# or
python -m pip install mcp-behave==0.6.0
```

An [npm launcher](https://www.npmjs.com/package/mcp-behave) is also available. It delegates to Python and does not currently guarantee a matching Python package version. Prefer a pinned `uvx` or pip installation when reproducibility matters.

### Audit before connecting

Replace the example target with the command that normally launches your MCP server:

```bash
uvx mcp-behave@0.6.0 audit -- python -m your_mcp_server
```

The audit discovers tools, exercises their schemas and reports observed runtime activity, findings and confidence limitations. Use `--json` or `--sarif` for machine-readable output.

> **Safety:** An audit executes target code and may invoke mutating tools. Use synthetic data in a disposable environment. For an untrusted target, use an isolated container or VM with appropriate filesystem and network restrictions. Canary HOME redirection is not a sandbox, and `--sandbox auto` can fall back to unsandboxed execution.

### Monitor your AI client

**Guided setup (development preview):** configure monitoring and the optional local security assistant together, with a preview and private rollback backup. From a repository checkout, run:

```bash
uv run mcp-behave setup --dry-run
uv run mcp-behave setup
```

The wizard is not yet part of the published v0.6.0 package. See the [setup guide](docs/setup.md) for supported clients, prerequisites and rollback. It does not verify native tracing or start target servers.

**`wrap` is the runtime monitoring proxy.** Unlike a one-time audit, it observes supported native file, network and process activity while your AI client calls MCP tools.

#### Option A — Wrap a local stdio server manually

Prefix your existing launch command with `mcp-behave wrap`:

```bash
uvx mcp-behave@0.6.0 wrap --server my-server -- python -m your_mcp_server
```

Use this as your MCP client's launch command, not as an interactive terminal application. For a controlled filesystem example (requires Node.js/npm):

```bash
mkdir -p /tmp/mcpb-demo-files
uvx mcp-behave@0.6.0 wrap --server filesystem-demo \
  -- npx -y @modelcontextprotocol/server-filesystem@2.4.1 /tmp/mcpb-demo-files
```

Example MCP client configuration for the same command:

```json
{
  "mcpServers": {
    "filesystem-demo": {
      "command": "uvx",
      "args": [
        "mcp-behave@0.6.0", "wrap",
        "--server", "filesystem-demo",
        "--", "npx", "-y",
        "@modelcontextprotocol/server-filesystem@2.4.1",
        "/tmp/mcpb-demo-files"
      ]
    }
  }
}
```

Create the fixture directory first. Merge this entry into your existing client configuration. If the client cannot find `uvx` or `npx`, use their absolute paths (`command -v uvx`, `command -v npx`) and ensure Node.js is on the client's PATH. Restart the client and ask it to create a synthetic `hello.txt` in the fixture directory. The example enables monitoring, not enforcement or OS isolation.

#### Option B — Automatically configure an existing server

Already using Claude Desktop? Check the configuration and preview changes. Replace `filesystem` with the actual configured server name:

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

If the preview is correct, enable monitoring, then restart the client:

```bash
uvx mcp-behave@0.6.0 install filesystem --client claude
```

Undo the integration:

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

#### Where does the telemetry go?

```text
~/.local/state/mcp-behave/
├── sessions/
│   └── <session-id>.jsonl
└── telemetry.db
```

The default follows `$XDG_STATE_HOME` when set. Use `--state-dir /absolute/path/to/state` to choose a different location. Telemetry may contain private information; keep it local and review coverage before drawing conclusions. For other clients, see [integration examples](examples/integrations/README.md).

### Ask your AI assistant

**New in v0.6.0:** query the retained runtime telemetry through MCP. After wrapping a server, add a separate local stdio entry for the security assistant. Example for clients using an `mcpServers` configuration (replace the executable path with the output of `command -v uvx`):

```json
{
  "mcpServers": {
    "mcp-behave-security": {
      "command": "/absolute/path/to/uvx",
      "args": ["mcp-behave@0.6.0", "serve"]
    }
  }
}
```

Merge the entry into your existing configuration rather than replacing your servers. If your proxy uses an explicit `--state-dir`, give `serve` the same directory. Restart your client and generate some monitored activity, then ask:

> What MCP server activity was recorded in the last 24 hours? Investigate the latest session and explain any coverage gaps.

The assistant can list recorded servers, summarize retained sessions, query event categories and surface reported telemetry gaps. It does not infer complete coverage, live server status or tool success from incomplete records. Detailed runtime fields are opt-in and may contain sensitive or adversarial content; keep the assistant local and trusted. Active audit execution is denied by default unless the operator explicitly authorizes it.

**Try both together:** [Wrap + Serve walkthrough](examples/demo/WRAP_SERVE.md) or run `uv run --managed-python --script examples/demo/wrap_serve.py` from a clone to exercise the real MCP protocol without an AI client.

![Wrap and Serve demonstration](assets/wrap-serve.gif)

## How it works

```text
AI client <──> mcp-behave wrap <──> MCP server
                       │                │
                       │       native runtime events
                       ▼                │
                  JSONL + SQLite <──────┘
                       │
                       ▼
              MCP security assistant
```

| Capability | Use it for |
| --- | --- |
| `audit` | Probe a server and review observed behavior |
| `wrap` | Monitor live local tool calls and runtime events |
| `init` / `check` | Detect changes against a reviewed behavioral baseline |
| `serve` | Investigate retained activity from an MCP client |
| `--json` / `--sarif` | Integrate auditing into CI |
| `--enforce` | Apply a reviewed multi-server lockfile to covered protocol actions |

## Validation and limitations

The project-maintained v0.6.0 candidate evaluation reported:

- 557 macOS source tests passed; 549 Linux source tests passed (8 skipped).
- 40/40 selected real-server monitoring scenarios and 40/40 fail-open compatibility scenarios matched expected success/error status across MotherDuck, Excel, Qdrant, DBHub, MCP Memory Service and Desktop Commander.
- JSON and SARIF output parsed for all six targets; retained telemetry storage checks matched across 22 recorded sessions (including two previous-version sessions).

These are selected compatibility and regression tests, not independent certification or exhaustive security verification. Strict fail-closed initialization halted on native telemetry backpressure for all six targets in the tested container setup, in both v0.5.8 and v0.6.0. Automated audit coverage for Memory Service was degraded by an unavailable embedding backend. Randomized temporary paths can trigger behavioral baseline differences.

Native tracing observes selected library calls on compatible macOS and Linux runtimes. Direct syscalls, static binaries, macOS SIP and hardened runtimes can limit coverage. Remote audits do not trace the remote host. A clean audit is not proof of safety. Native activity is observed, not universally blocked or undone; protocol enforcement and OS sandboxing are separate controls. Fail-open compatibility is not proof of inline blocking. Review coverage and policies before enabling enforcement.

[Historical validation](VALIDATION.md) · [Benchmarks](BENCHMARK.md) · [Security policy](SECURITY.md)

## Documentation

| Resource | Details |
| --- | --- |
| [Architecture](ARCHITECTURE.md) | Runtime engine and data flow |
| [CLI reference (v0.5.8)](https://github.com/navid72m/mcp-behave/blob/v0.5.8/README.md) | Advanced setup, sandbox semantics and probe profiles |
| [Detection matrix](docs/detection_matrix.md) | Detection rules and coverage |
| [Integration examples](examples/integrations/README.md) | Real-server fixtures and configurations |
| [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) | Project changes and planned work |

## Help shape the project

**Tried the demo? We'd like to hear from you.** Even if it didn't work, your feedback helps improve onboarding.

- What operating system and MCP client are you using?
- Did the demo work? Where did you get stuck?
- Which server or security question would you like to investigate next?

[Share your experience in GitHub Discussions](https://github.com/navid72m/mcp-behave/discussions) · [Report a reproducible bug](https://github.com/navid72m/mcp-behave/issues)

Do not share private telemetry or credentials. Report vulnerabilities privately as described in [SECURITY.md](SECURITY.md).

Contributions are welcome. For development, install with `python -m pip install -e ".[test]"` and run `pytest -v`.

MIT — [License](LICENSE).

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