langchain-revsec 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ Copyright (c) 2026 RevUp AI, Inc. All rights reserved.
2
+
3
+ Use of this software is subject to the RevSec terms of service.
@@ -0,0 +1,2 @@
1
+ recursive-include tests *.py
2
+ global-exclude __pycache__ *.py[cod]
@@ -0,0 +1,170 @@
1
+ Metadata-Version: 2.4
2
+ Name: langchain-revsec
3
+ Version: 0.1.0
4
+ 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.
5
+ Author-email: "RevSec / RevUp AI, Inc." <hello@revupai.com>
6
+ License-Expression: LicenseRef-Proprietary
7
+ Project-URL: Homepage, https://revsec.app
8
+ Project-URL: Start a free trial, https://app.revsec.app/start?from=langchain
9
+ Keywords: langchain,langgraph,middleware,ai-agents,ai-security,guardrails,mcp,tool-calls
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Security
18
+ Requires-Python: >=3.10
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: revsec-sdk<0.6,>=0.5.0
22
+ Requires-Dist: langchain<2,>=1.0
23
+ Requires-Dist: langchain-core<2,>=1.0
24
+ Provides-Extra: mcp
25
+ Requires-Dist: langchain-mcp-adapters>=0.1; extra == "mcp"
26
+ Provides-Extra: test
27
+ Requires-Dist: pytest>=7; extra == "test"
28
+ Requires-Dist: pytest-asyncio>=0.23; extra == "test"
29
+ Requires-Dist: langchain-mcp-adapters>=0.1; extra == "test"
30
+ Requires-Dist: mcp>=1.0; extra == "test"
31
+ Dynamic: license-file
32
+
33
+ # langchain-revsec
34
+
35
+ RevSec for LangChain agents. Add one middleware and RevSec checks each tool
36
+ call before it runs: a call to an MCP tool against that MCP server, a call to
37
+ one of the agent's own tools against the agent's own rules. A blocked call
38
+ never runs, and the model is told why. What the user asks is checked before it
39
+ reaches the model, and what each tool hands back before the model reads it.
40
+ What happened is recorded, and the agent is listed in your RevSec console with
41
+ its model and tools.
42
+
43
+ Your rules live in RevSec, not in your code. If you ship agents to customers,
44
+ each customer account gets its own rules, approvals and evidence.
45
+
46
+ ## Get a key
47
+
48
+ - **Shipping agents to your customers?** [Start a free trial](https://app.revsec.app/start?from=langchain)
49
+ and choose "AI we ship to our customers". Your Sandbox key is shown once, when you sign up.
50
+ - **Building agents for your own company?** [Book a demo](mailto:sales@revupai.com?subject=Book%20a%20RevSec%20demo).
51
+
52
+ ```bash
53
+ pip install langchain-revsec
54
+ export REVSEC_API_KEY="<your key>"
55
+ export REVSEC_BASE_URL="https://app.revsec.app/fcc"
56
+ ```
57
+
58
+ ## Add it to your agent
59
+
60
+ Load your MCP tools with `get_mcp_tools` (in place of `client.get_tools()`)
61
+ and add the middleware:
62
+
63
+ ```python
64
+ from langchain.agents import create_agent
65
+ from langchain_mcp_adapters.client import MultiServerMCPClient
66
+ from langchain_revsec import RevSecMiddleware, get_mcp_tools
67
+
68
+ client = MultiServerMCPClient({
69
+ "github": {"transport": "streamable_http", "url": "https://api.githubcopilot.com/mcp/"},
70
+ })
71
+ tools = await get_mcp_tools(client)
72
+ agent = create_agent(
73
+ "anthropic:claude-sonnet-5-5",
74
+ tools=tools + [lookup_order],
75
+ middleware=[RevSecMiddleware(agent_name="orders-agent")],
76
+ )
77
+ ```
78
+
79
+ That's all. Block a tool in RevSec and run the agent: the call doesn't run,
80
+ and the model gets a tool message saying `Blocked by RevSec: <the reason>`,
81
+ so it can tell the user or try something else.
82
+
83
+ - **MCP tools** are checked against their MCP server: the server's approval,
84
+ your MCP policies and its known vulnerabilities.
85
+ - **The agent's own tools** (functions in your code, like `lookup_order`) are
86
+ checked as the agent's: its status (a quarantined agent is stopped) and its
87
+ tool-call policies, such as "block `refund_order`". They are recorded with
88
+ the agent's tool calls, never as an MCP server.
89
+ - **What a tool sends out** (secrets, personal data) is scanned by your data
90
+ protection policies when you turn it on: `revsec.mcp.configure(..., dlp=True)`.
91
+ - **What a tool hands back** (a web page, a file, an MCP server's reply) is
92
+ checked before the model reads it: instructions hidden in it, secrets,
93
+ personal data. A result RevSec stops is replaced with a tool message saying
94
+ `Withheld by RevSec: ...`; the call itself ran.
95
+ - **Calls RevSec stops, holds or flags** reach your SIEM, if one is connected
96
+ in the RevSec console.
97
+
98
+ `pip install "langchain-revsec[mcp]"` installs LangChain's MCP adapter. RevSec
99
+ is told each server's address, or for a local server the package it runs;
100
+ never the rest of its launch command. Tools loaded with `client.get_tools()`
101
+ can't be told apart from the agent's own tools, so they are checked as the
102
+ agent's own; load them with `get_mcp_tools` to check them as MCP calls.
103
+
104
+ ## Prompts
105
+
106
+ What the user asks is checked before each model call, with the same Model
107
+ Security check RevSec runs for coding tools on a laptop: your prompt rules and
108
+ the built-in checks (prompt injection, secrets, personal data). A prompt
109
+ RevSec stops never reaches the model; the agent answers
110
+ `Blocked by RevSec: <the reason>` instead. Each check is kept on the agent in
111
+ RevSec, in the same conversation as its tool calls, and the model it was about
112
+ to call is listed on the agent. No AI gateway is needed.
113
+
114
+ If your model calls go through the RevSec AI gateway (Settings → AI gateway in
115
+ the console), it checks prompts there; turn the check here off so each prompt
116
+ is checked once:
117
+
118
+ ```python
119
+ from revsec import mcp
120
+ mcp.configure(api_key=os.environ["REVSEC_API_KEY"], check_prompts=False)
121
+ ```
122
+
123
+ `check_tool_results=False` turns off the tool-result check.
124
+
125
+ ## A graph you build yourself
126
+
127
+ In a LangGraph graph of your own, give its `ToolNode` the same checks:
128
+
129
+ ```python
130
+ from langgraph.prebuilt import ToolNode
131
+
132
+ revsec = RevSecMiddleware(agent_name="orders-agent")
133
+ tools_node = ToolNode(tools, wrap_tool_call=revsec.wrap_tool_call, awrap_tool_call=revsec.awrap_tool_call)
134
+ revsec.register_agent(models=["claude-sonnet-5-5"], tools=[t.name for t in tools]) # optional
135
+ ```
136
+
137
+ ## Options
138
+
139
+ | Option | Default | What it does |
140
+ |---|---|---|
141
+ | `agent_name` | required | The agent's name in RevSec. Registering again updates the same agent. |
142
+ | `api_key` | `REVSEC_API_KEY` | Your RevSec key. |
143
+ | `base_url` | `REVSEC_BASE_URL` | Your RevSec address, ending in `/fcc`. |
144
+ | `register` | `True` | List the agent in RevSec on its first model call, with its model and tools. |
145
+ | `description`, `owner_email`, `environment` | none | Shown on the agent in RevSec. |
146
+ | `on_block` | `"message"` | `"raise"` raises `revsec.RevsecBlocked` instead of telling the model (a blocked call, a withheld tool result or a stopped prompt). |
147
+
148
+ A customer account key, such as the Sandbox key you get when you sign up,
149
+ checks the agent's tool calls and registers the agent in that customer account.
150
+
151
+ Calls and checks in one conversation (one LangGraph `thread_id`) are grouped
152
+ into one chain in RevSec's Activity Explorer.
153
+
154
+ ## When RevSec can't be reached
155
+
156
+ By default a call is allowed when RevSec can't be reached, so an outage never
157
+ stops your agent. To block instead:
158
+
159
+ ```python
160
+ from revsec import mcp
161
+ mcp.configure(api_key=os.environ["REVSEC_API_KEY"], failure_mode="fail_closed")
162
+ ```
163
+
164
+ `mcp.configure(api_key=..., enabled=False)` turns the checks off. This package
165
+ is built on [revsec-sdk](https://pypi.org/project/revsec-sdk/); its README
166
+ covers these settings.
167
+
168
+ ## License
169
+
170
+ Copyright (c) 2026 RevUp AI, Inc. Use is subject to the RevSec terms of service.
@@ -0,0 +1,138 @@
1
+ # langchain-revsec
2
+
3
+ RevSec for LangChain agents. Add one middleware and RevSec checks each tool
4
+ call before it runs: a call to an MCP tool against that MCP server, a call to
5
+ one of the agent's own tools against the agent's own rules. A blocked call
6
+ never runs, and the model is told why. What the user asks is checked before it
7
+ reaches the model, and what each tool hands back before the model reads it.
8
+ What happened is recorded, and the agent is listed in your RevSec console with
9
+ its model and tools.
10
+
11
+ Your rules live in RevSec, not in your code. If you ship agents to customers,
12
+ each customer account gets its own rules, approvals and evidence.
13
+
14
+ ## Get a key
15
+
16
+ - **Shipping agents to your customers?** [Start a free trial](https://app.revsec.app/start?from=langchain)
17
+ and choose "AI we ship to our customers". Your Sandbox key is shown once, when you sign up.
18
+ - **Building agents for your own company?** [Book a demo](mailto:sales@revupai.com?subject=Book%20a%20RevSec%20demo).
19
+
20
+ ```bash
21
+ pip install langchain-revsec
22
+ export REVSEC_API_KEY="<your key>"
23
+ export REVSEC_BASE_URL="https://app.revsec.app/fcc"
24
+ ```
25
+
26
+ ## Add it to your agent
27
+
28
+ Load your MCP tools with `get_mcp_tools` (in place of `client.get_tools()`)
29
+ and add the middleware:
30
+
31
+ ```python
32
+ from langchain.agents import create_agent
33
+ from langchain_mcp_adapters.client import MultiServerMCPClient
34
+ from langchain_revsec import RevSecMiddleware, get_mcp_tools
35
+
36
+ client = MultiServerMCPClient({
37
+ "github": {"transport": "streamable_http", "url": "https://api.githubcopilot.com/mcp/"},
38
+ })
39
+ tools = await get_mcp_tools(client)
40
+ agent = create_agent(
41
+ "anthropic:claude-sonnet-5-5",
42
+ tools=tools + [lookup_order],
43
+ middleware=[RevSecMiddleware(agent_name="orders-agent")],
44
+ )
45
+ ```
46
+
47
+ That's all. Block a tool in RevSec and run the agent: the call doesn't run,
48
+ and the model gets a tool message saying `Blocked by RevSec: <the reason>`,
49
+ so it can tell the user or try something else.
50
+
51
+ - **MCP tools** are checked against their MCP server: the server's approval,
52
+ your MCP policies and its known vulnerabilities.
53
+ - **The agent's own tools** (functions in your code, like `lookup_order`) are
54
+ checked as the agent's: its status (a quarantined agent is stopped) and its
55
+ tool-call policies, such as "block `refund_order`". They are recorded with
56
+ the agent's tool calls, never as an MCP server.
57
+ - **What a tool sends out** (secrets, personal data) is scanned by your data
58
+ protection policies when you turn it on: `revsec.mcp.configure(..., dlp=True)`.
59
+ - **What a tool hands back** (a web page, a file, an MCP server's reply) is
60
+ checked before the model reads it: instructions hidden in it, secrets,
61
+ personal data. A result RevSec stops is replaced with a tool message saying
62
+ `Withheld by RevSec: ...`; the call itself ran.
63
+ - **Calls RevSec stops, holds or flags** reach your SIEM, if one is connected
64
+ in the RevSec console.
65
+
66
+ `pip install "langchain-revsec[mcp]"` installs LangChain's MCP adapter. RevSec
67
+ is told each server's address, or for a local server the package it runs;
68
+ never the rest of its launch command. Tools loaded with `client.get_tools()`
69
+ can't be told apart from the agent's own tools, so they are checked as the
70
+ agent's own; load them with `get_mcp_tools` to check them as MCP calls.
71
+
72
+ ## Prompts
73
+
74
+ What the user asks is checked before each model call, with the same Model
75
+ Security check RevSec runs for coding tools on a laptop: your prompt rules and
76
+ the built-in checks (prompt injection, secrets, personal data). A prompt
77
+ RevSec stops never reaches the model; the agent answers
78
+ `Blocked by RevSec: <the reason>` instead. Each check is kept on the agent in
79
+ RevSec, in the same conversation as its tool calls, and the model it was about
80
+ to call is listed on the agent. No AI gateway is needed.
81
+
82
+ If your model calls go through the RevSec AI gateway (Settings → AI gateway in
83
+ the console), it checks prompts there; turn the check here off so each prompt
84
+ is checked once:
85
+
86
+ ```python
87
+ from revsec import mcp
88
+ mcp.configure(api_key=os.environ["REVSEC_API_KEY"], check_prompts=False)
89
+ ```
90
+
91
+ `check_tool_results=False` turns off the tool-result check.
92
+
93
+ ## A graph you build yourself
94
+
95
+ In a LangGraph graph of your own, give its `ToolNode` the same checks:
96
+
97
+ ```python
98
+ from langgraph.prebuilt import ToolNode
99
+
100
+ revsec = RevSecMiddleware(agent_name="orders-agent")
101
+ tools_node = ToolNode(tools, wrap_tool_call=revsec.wrap_tool_call, awrap_tool_call=revsec.awrap_tool_call)
102
+ revsec.register_agent(models=["claude-sonnet-5-5"], tools=[t.name for t in tools]) # optional
103
+ ```
104
+
105
+ ## Options
106
+
107
+ | Option | Default | What it does |
108
+ |---|---|---|
109
+ | `agent_name` | required | The agent's name in RevSec. Registering again updates the same agent. |
110
+ | `api_key` | `REVSEC_API_KEY` | Your RevSec key. |
111
+ | `base_url` | `REVSEC_BASE_URL` | Your RevSec address, ending in `/fcc`. |
112
+ | `register` | `True` | List the agent in RevSec on its first model call, with its model and tools. |
113
+ | `description`, `owner_email`, `environment` | none | Shown on the agent in RevSec. |
114
+ | `on_block` | `"message"` | `"raise"` raises `revsec.RevsecBlocked` instead of telling the model (a blocked call, a withheld tool result or a stopped prompt). |
115
+
116
+ A customer account key, such as the Sandbox key you get when you sign up,
117
+ checks the agent's tool calls and registers the agent in that customer account.
118
+
119
+ Calls and checks in one conversation (one LangGraph `thread_id`) are grouped
120
+ into one chain in RevSec's Activity Explorer.
121
+
122
+ ## When RevSec can't be reached
123
+
124
+ By default a call is allowed when RevSec can't be reached, so an outage never
125
+ stops your agent. To block instead:
126
+
127
+ ```python
128
+ from revsec import mcp
129
+ mcp.configure(api_key=os.environ["REVSEC_API_KEY"], failure_mode="fail_closed")
130
+ ```
131
+
132
+ `mcp.configure(api_key=..., enabled=False)` turns the checks off. This package
133
+ is built on [revsec-sdk](https://pypi.org/project/revsec-sdk/); its README
134
+ covers these settings.
135
+
136
+ ## License
137
+
138
+ Copyright (c) 2026 RevUp AI, Inc. Use is subject to the RevSec terms of service.
@@ -0,0 +1,25 @@
1
+ """langchain-revsec: RevSec for LangChain agents.
2
+
3
+ Add one middleware to ``create_agent``: RevSec checks each tool call before it
4
+ runs (an MCP tool against its MCP server, the agent's own tools as the
5
+ agent's), what the user asks before it reaches the model, and what each tool
6
+ hands back before the model reads it; records what happened, and lists the
7
+ agent in your RevSec console with its model and tools.
8
+
9
+ from langchain.agents import create_agent
10
+ from langchain_revsec import RevSecMiddleware, get_mcp_tools
11
+
12
+ tools = await get_mcp_tools(mcp_client)
13
+ agent = create_agent(model, tools=tools + my_tools,
14
+ middleware=[RevSecMiddleware(agent_name="orders-agent")])
15
+
16
+ No AI gateway is needed. A team whose model calls go through the RevSec AI
17
+ gateway turns the prompt check here off: ``revsec.mcp.configure(check_prompts=False)``.
18
+
19
+ Set REVSEC_API_KEY and REVSEC_BASE_URL first (Settings → SDK in the console).
20
+ """
21
+ from langchain_revsec._version import __version__
22
+ from langchain_revsec.mcp import get_mcp_tools
23
+ from langchain_revsec.middleware import RevSecMiddleware
24
+
25
+ __all__ = ["RevSecMiddleware", "get_mcp_tools", "__version__"]
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"
@@ -0,0 +1,74 @@
1
+ """MCP tools that RevSec files under the right MCP server.
2
+
3
+ LangChain's MCP adapter turns each MCP server's tools into ordinary tools, and
4
+ the server they came from is not kept on them. ``get_mcp_tools`` loads them
5
+ server by server and notes on each tool which server it belongs to and how
6
+ that server is reached, so RevSecMiddleware checks the call against that MCP
7
+ server (its approval, its policies, its known vulnerabilities) and the server
8
+ attaches to the record RevSec already has for it.
9
+
10
+ from langchain_mcp_adapters.client import MultiServerMCPClient
11
+ from langchain_revsec import RevSecMiddleware, get_mcp_tools
12
+
13
+ client = MultiServerMCPClient({"github": {"transport": "streamable_http",
14
+ "url": "https://api.githubcopilot.com/mcp/"}})
15
+ tools = await get_mcp_tools(client) # in place of client.get_tools()
16
+ agent = create_agent(model, tools=tools, middleware=[RevSecMiddleware(agent_name="orders-agent")])
17
+
18
+ Tools loaded with ``client.get_tools()`` carry no note, so RevSecMiddleware
19
+ can't tell them from the agent's own tools and checks them as the agent's own:
20
+ load MCP tools with ``get_mcp_tools`` so they are checked as MCP calls.
21
+ """
22
+ from __future__ import annotations
23
+
24
+ from typing import Any, Dict, List, Optional
25
+
26
+ from revsec._launch import package_from_launch
27
+
28
+ # Where a tool's MCP server is noted, in the tool's LangChain metadata.
29
+ METADATA_KEY = "revsec_mcp_server"
30
+
31
+ _REMOTE = ("streamable_http", "sse", "websocket", "http")
32
+
33
+
34
+ def server_identity(name: str, connection: Dict[str, Any]) -> Dict[str, Any]:
35
+ """How RevSec recognises the server behind a MultiServerMCPClient
36
+ connection: its address for a remote server, the package a runner starts
37
+ for a local one (never the launch's other arguments)."""
38
+ ident: Dict[str, Any] = {"server": name}
39
+ transport = str(connection.get("transport") or "").lower()
40
+ url = connection.get("url")
41
+ command = connection.get("command")
42
+ if url and (transport in _REMOTE or not command):
43
+ ident.update(server_url=str(url), transport="remote")
44
+ elif command:
45
+ ident["transport"] = "stdio"
46
+ package = package_from_launch(str(command), [str(a) for a in (connection.get("args") or [])])
47
+ if package:
48
+ ident["package"] = package
49
+ return ident
50
+
51
+
52
+ async def get_mcp_tools(client: Any, *, server_name: Optional[str] = None) -> List[Any]:
53
+ """``client.get_tools()``, with each tool's MCP server noted for RevSec.
54
+ ``client`` is a langchain_mcp_adapters MultiServerMCPClient; give
55
+ ``server_name`` for one server's tools only."""
56
+ names = [server_name] if server_name else list(getattr(client, "connections", {}) or {})
57
+ prefixed = bool(getattr(client, "tool_name_prefix", False))
58
+ tools: List[Any] = []
59
+ for name in names:
60
+ ident = server_identity(name, client.connections[name])
61
+ for tool in await client.get_tools(server_name=name):
62
+ mcp_name = tool.name
63
+ if prefixed and mcp_name.startswith(f"{name}_"):
64
+ mcp_name = mcp_name[len(name) + 1:]
65
+ tool.metadata = {**(tool.metadata or {}), METADATA_KEY: {**ident, "tool": mcp_name}}
66
+ tools.append(tool)
67
+ return tools
68
+
69
+
70
+ def noted_server(tool: Any) -> Optional[Dict[str, Any]]:
71
+ """The MCP server get_mcp_tools noted on a tool, or None for any other tool."""
72
+ meta = getattr(tool, "metadata", None) or {}
73
+ noted = meta.get(METADATA_KEY) if isinstance(meta, dict) else None
74
+ return noted if isinstance(noted, dict) and noted.get("server") else None