Skip to main content

Overview

The Secure MCP Gateway provides two Python modules for protecting LangChain and LangGraph applications:
  1. LangChain Module - BaseCallbackHandler for any LangChain component
  2. LangGraph Module - pre_model_hook and post_model_hook for LangGraph agents

LangChain Integration

Use the EnkryptGuardrailsHandler to protect any LangChain component including LLMs, chains, agents, tools, and retrievers.

Installation

Configure Guardrails

Basic Usage


Supported Hooks

The EnkryptGuardrailsHandler implements all LangChain BaseCallbackHandler methods:

Usage Examples

With Chains

With Agents

With Retrievers (RAG)

Audit-Only Mode

Disable Sensitive Tool Blocking


LangGraph Integration

For LangGraph’s create_react_agent, use pre_model_hook and post_model_hook.

Installation

Basic Usage

Convenience Functions

Tool Wrapping


Configuration

LangChain Configuration

guardrails_config.json

LangGraph Configuration

guardrails_config.json

Available Detectors


Logging

Logs are written to ~/langchain/guardrails_logs/ or ~/langgraph/guardrails_logs/:
  • on_llm_start.jsonl / pre_model_hook.jsonl - Input validation
  • on_llm_end.jsonl / post_model_hook.jsonl - Output validation
  • on_tool_start.jsonl / before_tool_call.jsonl - Tool input checks
  • combined_audit.jsonl - All events combined
  • security_alerts.jsonl - Security violations

View Logs


Metrics


Error Handling


Comparison

Use LangChain module for:
  • Standalone LangChain components
  • Chains and pipelines
  • RAG applications
  • Any non-LangGraph agent
Use LangGraph module for:
  • LangGraph’s create_react_agent
  • LangGraph workflows

Testing


Next Steps

CrewAI Integration

Protect multi-agent CrewAI systems

Configure Policies

Create custom guardrail policies

View Metrics

Monitor guardrails performance

Audit Logs

Review security events