Metadata-Version: 2.4
Name: langchain-relayshield
Version: 0.1.0
Summary: LangChain tools and a mandatory pre-execution gate for RelayShield's MCP registry risk and prompt-injection breach checks.
Project-URL: Homepage, https://relayshield.net
Project-URL: Documentation, https://api.relayshield.net/developers
Project-URL: Repository, https://github.com/nzdsf2-gif/langchain-relayshield
Author-email: RelayShield <relayshieldadmin@gmail.com>
License: MIT
Keywords: agents,ai,breach,langchain,mcp,security
Classifier: Development Status :: 4 - Beta
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 :: Internet
Classifier: Topic :: Security
Requires-Python: >=3.10
Requires-Dist: langchain-core>=0.3.0
Provides-Extra: middleware
Requires-Dist: langchain>=1.0.0; extra == 'middleware'
Requires-Dist: langgraph>=0.2.0; extra == 'middleware'
Provides-Extra: test
Requires-Dist: langchain>=1.0.0; extra == 'test'
Requires-Dist: langgraph>=0.2.0; extra == 'test'
Requires-Dist: pytest>=8.0.0; extra == 'test'
Description-Content-Type: text/markdown

# langchain-relayshield

LangChain tools and a mandatory pre-execution gate for [RelayShield](https://relayshield.net)'s agentic-security endpoints — MCP server registry risk and AI-agent-sourced credential breach detection.

## Install

```bash
pip install langchain-relayshield
```

The mandatory-gate middleware needs LangChain's agent runtime; install the extra if you want it:

```bash
pip install "langchain-relayshield[middleware]"
```

## Tools

```python
from langchain_relayshield import check_mcp_server_risk, check_prompt_injection_breach

result = check_mcp_server_risk.invoke({
    "api_key": "rs_live_...",
    "server_url": "https://mcp.example.com/sse",
})
```

- **`check_mcp_server_risk`** — flags known-malicious IOC matches, typosquat domains, and newly-registered domains hosting an MCP server, before an agent connects to or installs it.
- **`check_prompt_injection_breach`** — checks whether an email appears in RelayShield's stolen-session corpus with a suspected-agentic-source marker (a session/token exposure that shows signs of having been captured via a compromised AI agent).

Get a key at [api.relayshield.net/developers](https://api.relayshield.net/developers).

## Mandatory gate middleware

Most "AI agent security" checks are optional — the agent *can* call them, but nothing stops it skipping the call and taking the risky action anyway. `RelayShieldMCPGateMiddleware` is the other kind: a gate the agent's framework enforces *before* a protected action (connecting to or installing an MCP server) can happen at all.

```python
from langchain_relayshield.middleware import RelayShieldMCPGateMiddleware

agent = create_agent(
    model=...,
    tools=[...],
    middleware=[RelayShieldMCPGateMiddleware()],
)
```

Properties, all non-negotiable by design:

- A hook exception defaults to `defer`, never silently to `allow`.
- Bounded retry applies only to transient upstream failures (timeout/429/5xx) — auth failures, malformed responses, and payment-required states are terminal after one attempt.
- The audit log records decision, reason codes, check version, target, and timestamp — never keys, payment proofs, or session material.
- The raw connect/install tool should never be bound to the model directly — only a composite tool that routes through this gate.

Full design writeup and a 12-case protected-action acceptance suite: [relayshield-langchain-gate](https://github.com/nzdsf2-gif/relayshield-langchain-gate) (this middleware's original standalone reference implementation, now also packaged here).

## License

MIT
