Skip to main content

Overview

The enkrypt_secure_call_tools tool provides secure batch execution of MCP server tools with comprehensive guardrail checks, PII handling, and detailed response tracking.
This is the only recommended way to execute tools from MCP servers through the gateway. Direct server access bypasses security protections.

Tool Signature

Parameters

Context
required
MCP context (automatically provided by the client)
str
required
Name of the server containing the tools to execute
list
default:"[]"
List of tool calls to execute. Each item should be an object with:Special behavior:
  • Empty list []: Triggers tool discovery only (no execution)
  • Single item: Executes one tool
  • Multiple items: Executes all tools in sequence within the same session
Important: If you need to execute multiple tools, pass them all in a single list. Multiple separate calls will create new sessions each time, which may fail or be inefficient.

Return Value

string
required
Overall status: "success", "error", "blocked_input", or "blocked_output"
string
Human-readable description of the execution result
array
Array of individual tool execution results
object
Summary statistics about the batch execution

Usage Examples

Execute a Single Tool

Execute Multiple Tools in Sequence

Discovery Mode (No Execution)

To discover tools without executing them:

Response Structure

Successful Execution

Blocked by Input Guardrails

Blocked by Output Guardrails

Security Features

Input Guardrails

Before executing tools, the gateway validates input arguments:
Automatically detects and redacts personally identifiable information:
The original PII is stored securely and restored in the response.
Checks for:
  • NSFW content
  • Toxic language
  • Hate speech
  • Profanity
Detects and blocks:
  • SQL injection attempts
  • Command injection
  • Prompt injection
  • XSS attacks
Validates against custom organizational policies:
  • Topic restrictions
  • Keyword blocking
  • Business rules

Output Guardrails

After execution, responses are validated:
All input guardrail checks are also applied to outputs.
Ensures the response is relevant to the input:
Verifies the response follows instructions:
Identifies potentially fabricated information in responses.
Automatically restores redacted PII in the response if the output is safe.

Async Guardrails

For improved performance, guardrails can run asynchronously:
Configuration
When enabled:
  • Input guardrails and tool execution run in parallel
  • Response is blocked if guardrails detect violations
  • Reduces total execution time by ~50%

Implementation Details

Service Location

Implemented in: src/secure_mcp_gateway/services/execution/secure_tool_execution_service.py:64

Execution Flow

  1. Authentication - Validate gateway credentials
  2. Server Lookup - Find server configuration
  3. Tool Discovery - Ensure tools are available (cached or discovered)
  4. Session Creation - Open persistent session to server
  5. For each tool call:
    • Input Guardrails - Validate input (if enabled)
    • PII Redaction - Redact sensitive data (if enabled)
    • Tool Execution - Call the actual tool
    • Output Guardrails - Validate output (if enabled)
    • PII Restoration - Restore redacted data (if safe)
  6. Session Cleanup - Close server connection
  7. Summary - Return execution results

Session Management

All tool calls in a single request share the same server session. This is critical for stateful operations.

Error Handling

Execution stops on first error or block:

Tool Annotations

Performance Optimization

Batch Calls

Execute multiple tools in one request to reuse the session.

Async Guardrails

Enable async guardrails to run checks in parallel with execution.

Cache Tools

Ensure tools are discovered and cached before execution.

Timeout Tuning

Adjust timeout settings for slow tools via gateway config.

Common Use Cases

Execute external API calls with automatic PII protection:
The gateway redacts the email before sending to the server.
Execute complex workflows in a single session:
Automatically filter inappropriate content:
Toxic or NSFW content is blocked before posting.
Enforce organizational policies on tool usage:
Policy violations are blocked automatically.

Error Codes

Error: Tool not found for this serverSolution: Use enkrypt_discover_all_tools to see available tools
Error: Tool execution failedCauses: Server error, invalid arguments, connectivity issuesSolution: Check tool arguments and server logs
Error: Input/output blocked by guardrailsSolution: Review violation details in the response
Error: Authentication failedSolution: Verify gateway key configuration

Configuration Reference

Configure guardrails per-server in enkrypt_mcp_config.json:

List Servers

See available servers to execute tools from

Discover Tools

Find available tools before execution

Timeout Metrics

Monitor execution performance

Guardrails Config

Configure security policies