Adapters & Frameworks
One import change, same API, now with policy enforcement
19 questions
MACAW provides drop-in secure adapters for popular AI frameworks:
Framework Adapter Status OpenAI SecureOpenAIProduction-ready Anthropic/Claude SecureAnthropicProduction-ready LangChain Drop-in LangChain wrappers ( macaw_adapters.langchain)Production-ready LiteLLM (100+ providers) SecureLiteLLMProduction-ready Pydantic AI SecurePydanticAIProduction-ready MCP (servers you build) SecureMCPProduction-ready MCP proxy (servers you don't control) SecureMCPProxyProduction-ready Install with:
pip install "macaw-adapters[all]"Open source: All adapters are Apache 2.0 licensed at github.com/macawsecurity/secureAI. Contributors welcome - we're actively looking for help with new framework integrations.
A MACAW adapter is a thin wrapper that extends the
MACAWClientSDK to provide drop-in replacements for popular AI libraries. The architecture:┌─────────────────────────────────────────────────────────┐ │ Your Application │ │ from macaw_adapters.openai import SecureOpenAI │ └─────────────────────────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────┐ │ macaw-adapters (pip) │ │ SecureOpenAI, SecureAnthropic, SecureLiteLLM, │ │ SecurePydanticAI, SecureMCP, SecureMCPProxy, │ │ LangChain wrappers │ │ Thin wrappers that route through MACAWClient │ └─────────────────────────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────┐ │ macaw_client SDK (binary) │ │ MACAWClient - handles registration, policy, signing │ │ Installed by macaw-ai install, or console download │ └─────────────────────────────────────────────────────────┘Adapters give you the same API you already know (OpenAI, Anthropic, etc.) with MACAW's policy enforcement, cryptographic signing, and audit logging built in.
SecureOpenAIis a drop-in replacement for the OpenAI Python client. Same API, same methods - but with MACAW protection.# Before from openai import OpenAI client = OpenAI() # After (one import change) from macaw_adapters.openai import SecureOpenAI client = SecureOpenAI(app_name="customer-support-bot") # Same API works exactly the same response = client.chat.completions.create( model="gpt-4o", messages=[{"role": "user", "content": "Hello"}] )Both provide the same SecureOpenAI API. The difference is trace visibility for registered tools:
Version Tool Trace Flow Architecture openaialice → app ↔ app(loopback)Single MACAWClient openai_ext_toolsalice → app → app-tools/fnTwo MACAWClients Standard (
macaw_adapters.openai): A single client owns LLM ops and your registered tools. When the LLM calls a tool, traces show the app calling itself.Explicit Tools (
macaw_adapters.openai_ext_tools): Two-client architecture separates LLM operations from user tools. Traces explicitly show: user → LLM service → tools service.# Standard - simpler, good for most use cases from macaw_adapters.openai import SecureOpenAI # Explicit Tools - when you need explicit tool observability from macaw_adapters.openai_ext_tools import SecureOpenAIUse
openai_ext_toolswhen you need distinct observability spans for LLM → Tool invocations.SecureAnthropicis a drop-in replacement for the Anthropic Python client:# Before from anthropic import Anthropic client = Anthropic() # After from macaw_adapters.anthropic import SecureAnthropic client = SecureAnthropic(app_name="research-assistant") # Same API response = client.messages.create( model="claude-sonnet-4-20250514", max_tokens=100, messages=[{"role": "user", "content": "Hello"}] )Both provide the same SecureAnthropic API. The difference is trace visibility for registered tools:
Version Tool Trace Flow Architecture anthropicalice → app ↔ app(loopback)Single MACAWClient anthropic_ext_toolsalice → app → app-tools/fnTwo MACAWClients Standard (
macaw_adapters.anthropic): A single client owns LLM ops and your registered tools. When Claude calls a tool, traces show the app calling itself.Explicit Tools (
macaw_adapters.anthropic_ext_tools): Two-client architecture separates LLM operations from user tools. Traces explicitly show: user → LLM service → tools service.# Standard - simpler, good for most use cases from macaw_adapters.anthropic import SecureAnthropic # Explicit Tools - when you need explicit tool observability from macaw_adapters.anthropic_ext_tools import SecureAnthropicUse
anthropic_ext_toolswhen you need distinct observability spans for LLM → Tool invocations.Yes - comprehensive support. MACAW provides drop-in replacements for LangChain's core components:
Category MACAW Components LLM Classes ChatOpenAI,ChatAnthropic(or explicitSecureChatOpenAI,SecureChatAnthropic)Memory ConversationBufferMemory,ConversationBufferWindowMemory,ConversationSummaryMemoryAgents create_react_agent,create_openai_functions_agent,AgentExecutorTools SecureToolWrapper,wrap_tools,@secure_tooldecoratorCallbacks MACAWCallbackHandler# LLMs - same names as LangChain, drop-in replacement from macaw_adapters.langchain import ChatOpenAI, ChatAnthropic # Memory - drop-in replacement from macaw_adapters.langchain.memory import ConversationBufferMemory # Agents - drop-in replacement from macaw_adapters.langchain.agents import create_react_agent, AgentExecutor # Tools - wrap existing tools for policy enforcement from macaw_adapters.langchain.tools import wrap_tools, secure_toolAll LangChain patterns work: chains, agents, RAG pipelines, memory - with policy enforcement at every step.
SecureMCPis a FastMCP-compatible API for building MCP servers you write with MACAW policy enforcement. Every tool invocation is authenticated, authorized, and logged.from macaw_adapters.mcp import SecureMCP, Context mcp = SecureMCP("calculator") @mcp.tool(description="Add two numbers") def add(a: float, b: float) -> float: return a + b if __name__ == "__main__": mcp.run()SecureMCPProxyis an inline gateway for external MCP servers you don't control (Snowflake, Databricks, Salesforce, etc.). It wraps 3rd-party MCP servers with MACAW security without modifying them.from macaw_adapters.mcp import SecureMCPProxy # HTTP transport (remote MCP servers) proxy = SecureMCPProxy( app_name="snowflake-mcp", upstream_url="http://localhost:9000/mcp" ) # stdio transport (local MCP servers via subprocess) proxy = SecureMCPProxy( app_name="salesforce-dx", command=["npx", "@salesforce/mcp", "--orgs", "DEFAULT"] ) # Use tools - same API as any MCP client tools = proxy.list_tools() result = proxy.call_tool("run_snowflake_query", {"statement": "SELECT 1"})Every call through the proxy gets cryptographic signing, policy enforcement, and audit logging.
Use Case Adapter Building your own MCP server SecureMCPConnecting to Snowflake MCP SecureMCPProxyConnecting to Databricks MCP SecureMCPProxyConnecting to Salesforce MCP SecureMCPProxyWrapping any 3rd-party MCP server SecureMCPProxySecureMCP: FastMCP-compatible decorator API. Use
@mcp.tool(),@mcp.resource(),@mcp.prompt()decorators to build secure MCP servers.SecureMCPProxy: Inline gateway pattern. Wraps external MCP servers with MACAW security without touching the upstream server code.
Use
bind_to_user()to create per-user proxies with proper identity propagation:from macaw_adapters.mcp import SecureMCPProxy from macaw_client import MACAWClient, RemoteIdentityProvider # Service creates shared proxy proxy = SecureMCPProxy( app_name="data-platform", upstream_url="http://localhost:9000/mcp" ) # Authenticate users via your IdP (Keycloak, Okta, etc.) alice_jwt, _ = RemoteIdentityProvider().login("alice", "Alice123!") alice = MACAWClient(user_name="alice", iam_token=alice_jwt, app_name="data-platform") alice.register() # Bind proxy to Alice's identity alice_proxy = proxy.bind_to_user(alice) # All calls now carry Alice's identity and apply her policies result = alice_proxy.call_tool("run_query", {"statement": "SELECT * FROM data"})This solves the "shared context" problem in standard MCP. Even with persistent connections (stdio), each call gets a fresh AuthenticatedContext with the correct user identity.
SecureLiteLLMwraps LiteLLM to access 100+ LLM providers with MACAW security. True drop-in replacement - just change your import.# Before import litellm response = litellm.completion(model="groq/llama3-70b-8192", messages=[...]) # After from macaw_adapters import litellm response = litellm.completion(model="groq/llama3-70b-8192", messages=[...])Supported providers include: Groq, Together AI, Mistral, OpenAI, Anthropic, AWS Bedrock, Azure OpenAI, Google Vertex, Cohere, local vLLM, Ollama, and 90+ more.
Yes. Use the
api_baseparameter to connect to local models:from macaw_adapters import litellm # vLLM response = litellm.completion( model="openai/llama3", messages=[...], api_base="http://localhost:8000/v1" ) # Ollama response = litellm.completion( model="ollama/llama3", messages=[...], api_base="http://localhost:11434" )Local models get the same MACAW security: policy enforcement, cryptographic signing, and audit logging.
app_nameidentifies your application in MACAW. It's used for:- Registration: Your app registers as
app:<app_name> - Tool namespacing: Tools become
tool:<app_name>/generate,tool:<app_name>/complete, etc. - Policy targeting: Policies can allow/deny specific apps (e.g.,
tool:customer-support-bot/*) - Audit logs: All operations are tagged with your app name
Choose something descriptive and consistent - it appears throughout the Console.
- Registration: Your app registers as
Pass the user's JWT token to carry their identity:
client = SecureOpenAI( app_name="my-app", jwt_token=user_jwt, # From your IdP user_name="alice" ) # All calls now carry Alice's identity # Policies apply based on her claimsFor multi-user SaaS apps, use
bind_to_user()to efficiently share one service across many users. See Identity Integration for details.Yes. All adapters extend
MACAWClientfrom the SDK. To build your own:- Import
MACAWClientfrommacaw_client - Create tools that wrap your target API
- Register tools with MACAW-compliant names (
tool:<app>/<operation>) - Route calls through
invoke_tool()for policy enforcement
from macaw_client import MACAWClient class SecureMyAPI: def __init__(self, app_name: str): self.client = MACAWClient( app_name=app_name, tools={ f"tool:{app_name}/query": {"handler": self._handle_query} } ) self.client.register() def query(self, params): return self.client.invoke_tool( f"tool:{self.client.app_name}/query", parameters=params )See Building Custom Adapters for complete guidance.
- Import
Yes. All adapters support both sync and async:
# Sync response = client.chat.completions.create(...) # Async response = await client.chat.completions.acreate(...)The async versions work exactly like the underlying OpenAI/Anthropic async APIs.
Yes. Streaming works exactly like the underlying APIs:
stream = client.chat.completions.create( model="gpt-4o", messages=[{"role": "user", "content": "Hello"}], stream=True ) for chunk in stream: print(chunk.choices[0].delta.content, end="")Policy enforcement happens at the start of the stream. Audit logging captures the complete interaction.
Minimal changes. For standard-compliant OpenAI, Anthropic, LangChain, LiteLLM, or MCP:
- Change the import
- Add
app_nameparameter
That's it. Your existing API calls, parameters, and logic stay exactly the same.