llamaindex-relayshield
LlamaIndex tools and a mandatory pre-execution gate for RelayShield's agentic-security endpoints — MCP server registry risk and AI-agent-sourced credential breach detection.
Install
pip install llamaindex-relayshield
Tools
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.core.llms.openai import OpenAI
from llamaindex_relayshield import check_mcp_server_risk_tool, check_prompt_injection_breach_tool
agent = FunctionAgent(
tools=[check_mcp_server_risk_tool, check_prompt_injection_breach_tool],
llm=OpenAI(model="gpt-4o-mini"),
)
result = await agent.run(
"Is it safe to connect to the MCP server at https://mcp.example.com/sse? My RelayShield key is rs_live_..."
)
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).
Both tools take api_key as a call argument rather than reading it from the environment implicitly — a shared agent process can act safely on behalf of multiple callers with different RelayShield keys.
Get a key at api.relayshield.net/developers.
Mandatory gate
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. The RelayShield gate is the other kind: enforced before a protected action (connecting to or installing an MCP server) can happen at all.
LlamaIndex has no dedicated pre-execution hook API like LangChain's wrap_tool_call or the OpenAI Agents SDK's @tool_input_guardrail. What it does have is call_tool() — a workflow step every built-in agent (FunctionAgent, ReActAgent, CodeActAgent) inherits unmodified from BaseWorkflowAgent. This package subclasses it:
from llamaindex_relayshield import RelayShieldGatedFunctionAgent
from llamaindex_relayshield import check_mcp_server_risk_tool
agent = RelayShieldGatedFunctionAgent(
tools=[connect_mcp_server_tool, check_mcp_server_risk_tool],
llm=OpenAI(model="gpt-4o-mini"),
# Names of tools this gate applies to -- everything else runs unmodified.
protected_tools={"connect_mcp_server"},
)
RelayShieldGatedReActAgent and RelayShieldGatedCodeActAgent are the same pattern for the other two built-in agent types.
Properties, all non-negotiable by design:
- A hook exception defaults to
defer(blocked, with an explanatory message), never silently toallow— a gate failure must not become a pass. - 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 gate logs the decision, reason codes, check version, target, and timestamp — never keys, payment proofs, or session material.
- Only tool names listed in
protected_toolsare gated; everything else passes straight through to normal execution.
A note on how this is implemented, since it's less standard than the other two integrations: overriding call_tool() on a subclass only works because the override re-applies LlamaIndex's @step decorator. Verified directly against the installed package — LlamaIndex's step registry only recognizes methods carrying the _step_config attribute that @step sets at definition time; an override without it would silently fail to register as a step at all, breaking every tool call in the agent, not just skipping the gate.
Same normalized policy as langchain-relayshield's RelayShieldMCPGateMiddleware, openai-agents-relayshield's relayshield_mcp_gate, and the original standalone reference implementation, relayshield-langchain-gate — ported rather than imported, so this package has no dependency on LangChain/LangGraph or the OpenAI Agents SDK.
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llamaindex_relayshield-0.1.0.tar.gz.
File metadata
- Download URL: llamaindex_relayshield-0.1.0.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01c0542ffde4662b6ae0d9100974370f7844206e145ba82a3a70bffd55dff077
|
|
| MD5 |
54a8e8056ae722df58c2dfa96c6e50b9
|
|
| BLAKE2b-256 |
06dde2bfa684853f5586ead35fd74d8a6eac5c0e8aa2fcf2f0e2ecccd5fea260
|
Provenance
The following attestation bundles were made for llamaindex_relayshield-0.1.0.tar.gz:
Publisher:
publish.yml on nzdsf2-gif/llamaindex-relayshield
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
llamaindex_relayshield-0.1.0.tar.gz -
Subject digest:
01c0542ffde4662b6ae0d9100974370f7844206e145ba82a3a70bffd55dff077 - Sigstore transparency entry: 2236192908
- Sigstore integration time:
-
Permalink:
nzdsf2-gif/llamaindex-relayshield@72261fe1f011036f7dbd3056b75b718200c2421d -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/nzdsf2-gif
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@72261fe1f011036f7dbd3056b75b718200c2421d -
Trigger Event:
release
-
Statement type:
File details
Details for the file llamaindex_relayshield-0.1.0-py3-none-any.whl.
File metadata
- Download URL: llamaindex_relayshield-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac30e5dde6959119c8cdb4da21060ae8f71caa966526ac248801e30d24a3546e
|
|
| MD5 |
b9beb3a14f0c2d475b9264c3d0caec67
|
|
| BLAKE2b-256 |
fe840eaca9d36cf89a0749fdf635e38ca6d4ee7f662a5e69006168e5087d5c11
|
Provenance
The following attestation bundles were made for llamaindex_relayshield-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on nzdsf2-gif/llamaindex-relayshield
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
llamaindex_relayshield-0.1.0-py3-none-any.whl -
Subject digest:
ac30e5dde6959119c8cdb4da21060ae8f71caa966526ac248801e30d24a3546e - Sigstore transparency entry: 2236193065
- Sigstore integration time:
-
Permalink:
nzdsf2-gif/llamaindex-relayshield@72261fe1f011036f7dbd3056b75b718200c2421d -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/nzdsf2-gif
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@72261fe1f011036f7dbd3056b75b718200c2421d -
Trigger Event:
release
-
Statement type: