Metadata-Version: 2.4
Name: langchain-revsec
Version: 0.1.0
Summary: RevSec for LangChain agents: check each tool call before it runs (MCP tools against their MCP server), each prompt and tool result, and register the agent.
Author-email: "RevSec / RevUp AI, Inc." <hello@revupai.com>
License-Expression: LicenseRef-Proprietary
Project-URL: Homepage, https://revsec.app
Project-URL: Start a free trial, https://app.revsec.app/start?from=langchain
Keywords: langchain,langgraph,middleware,ai-agents,ai-security,guardrails,mcp,tool-calls
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Security
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: revsec-sdk<0.6,>=0.5.0
Requires-Dist: langchain<2,>=1.0
Requires-Dist: langchain-core<2,>=1.0
Provides-Extra: mcp
Requires-Dist: langchain-mcp-adapters>=0.1; extra == "mcp"
Provides-Extra: test
Requires-Dist: pytest>=7; extra == "test"
Requires-Dist: pytest-asyncio>=0.23; extra == "test"
Requires-Dist: langchain-mcp-adapters>=0.1; extra == "test"
Requires-Dist: mcp>=1.0; extra == "test"
Dynamic: license-file

# langchain-revsec

RevSec for LangChain agents. Add one middleware and RevSec checks each tool
call before it runs: a call to an MCP tool against that MCP server, a call to
one of the agent's own tools against the agent's own rules. A blocked call
never runs, and the model is told why. What the user asks is checked before it
reaches the model, and what each tool hands back before the model reads it.
What happened is recorded, and the agent is listed in your RevSec console with
its model and tools.

Your rules live in RevSec, not in your code. If you ship agents to customers,
each customer account gets its own rules, approvals and evidence.

## Get a key

- **Shipping agents to your customers?** [Start a free trial](https://app.revsec.app/start?from=langchain)
  and choose "AI we ship to our customers". Your Sandbox key is shown once, when you sign up.
- **Building agents for your own company?** [Book a demo](mailto:sales@revupai.com?subject=Book%20a%20RevSec%20demo).

```bash
pip install langchain-revsec
export REVSEC_API_KEY="<your key>"
export REVSEC_BASE_URL="https://app.revsec.app/fcc"
```

## Add it to your agent

Load your MCP tools with `get_mcp_tools` (in place of `client.get_tools()`)
and add the middleware:

```python
from langchain.agents import create_agent
from langchain_mcp_adapters.client import MultiServerMCPClient
from langchain_revsec import RevSecMiddleware, get_mcp_tools

client = MultiServerMCPClient({
    "github": {"transport": "streamable_http", "url": "https://api.githubcopilot.com/mcp/"},
})
tools = await get_mcp_tools(client)
agent = create_agent(
    "anthropic:claude-sonnet-5-5",
    tools=tools + [lookup_order],
    middleware=[RevSecMiddleware(agent_name="orders-agent")],
)
```

That's all. Block a tool in RevSec and run the agent: the call doesn't run,
and the model gets a tool message saying `Blocked by RevSec: <the reason>`,
so it can tell the user or try something else.

- **MCP tools** are checked against their MCP server: the server's approval,
  your MCP policies and its known vulnerabilities.
- **The agent's own tools** (functions in your code, like `lookup_order`) are
  checked as the agent's: its status (a quarantined agent is stopped) and its
  tool-call policies, such as "block `refund_order`". They are recorded with
  the agent's tool calls, never as an MCP server.
- **What a tool sends out** (secrets, personal data) is scanned by your data
  protection policies when you turn it on: `revsec.mcp.configure(..., dlp=True)`.
- **What a tool hands back** (a web page, a file, an MCP server's reply) is
  checked before the model reads it: instructions hidden in it, secrets,
  personal data. A result RevSec stops is replaced with a tool message saying
  `Withheld by RevSec: ...`; the call itself ran.
- **Calls RevSec stops, holds or flags** reach your SIEM, if one is connected
  in the RevSec console.

`pip install "langchain-revsec[mcp]"` installs LangChain's MCP adapter. RevSec
is told each server's address, or for a local server the package it runs;
never the rest of its launch command. Tools loaded with `client.get_tools()`
can't be told apart from the agent's own tools, so they are checked as the
agent's own; load them with `get_mcp_tools` to check them as MCP calls.

## Prompts

What the user asks is checked before each model call, with the same Model
Security check RevSec runs for coding tools on a laptop: your prompt rules and
the built-in checks (prompt injection, secrets, personal data). A prompt
RevSec stops never reaches the model; the agent answers
`Blocked by RevSec: <the reason>` instead. Each check is kept on the agent in
RevSec, in the same conversation as its tool calls, and the model it was about
to call is listed on the agent. No AI gateway is needed.

If your model calls go through the RevSec AI gateway (Settings → AI gateway in
the console), it checks prompts there; turn the check here off so each prompt
is checked once:

```python
from revsec import mcp
mcp.configure(api_key=os.environ["REVSEC_API_KEY"], check_prompts=False)
```

`check_tool_results=False` turns off the tool-result check.

## A graph you build yourself

In a LangGraph graph of your own, give its `ToolNode` the same checks:

```python
from langgraph.prebuilt import ToolNode

revsec = RevSecMiddleware(agent_name="orders-agent")
tools_node = ToolNode(tools, wrap_tool_call=revsec.wrap_tool_call, awrap_tool_call=revsec.awrap_tool_call)
revsec.register_agent(models=["claude-sonnet-5-5"], tools=[t.name for t in tools])  # optional
```

## Options

| Option | Default | What it does |
|---|---|---|
| `agent_name` | required | The agent's name in RevSec. Registering again updates the same agent. |
| `api_key` | `REVSEC_API_KEY` | Your RevSec key. |
| `base_url` | `REVSEC_BASE_URL` | Your RevSec address, ending in `/fcc`. |
| `register` | `True` | List the agent in RevSec on its first model call, with its model and tools. |
| `description`, `owner_email`, `environment` | none | Shown on the agent in RevSec. |
| `on_block` | `"message"` | `"raise"` raises `revsec.RevsecBlocked` instead of telling the model (a blocked call, a withheld tool result or a stopped prompt). |

A customer account key, such as the Sandbox key you get when you sign up,
checks the agent's tool calls and registers the agent in that customer account.

Calls and checks in one conversation (one LangGraph `thread_id`) are grouped
into one chain in RevSec's Activity Explorer.

## When RevSec can't be reached

By default a call is allowed when RevSec can't be reached, so an outage never
stops your agent. To block instead:

```python
from revsec import mcp
mcp.configure(api_key=os.environ["REVSEC_API_KEY"], failure_mode="fail_closed")
```

`mcp.configure(api_key=..., enabled=False)` turns the checks off. This package
is built on [revsec-sdk](https://pypi.org/project/revsec-sdk/); its README
covers these settings.

## License

Copyright (c) 2026 RevUp AI, Inc. Use is subject to the RevSec terms of service.
