Skip to main content
The @centure/node-sdk provides a transport wrapper for the Model Context Protocol (MCP) that automatically scans messages for prompt injection attacks before they reach your MCP server.

What is MCP?

The Model Context Protocol is a standard for connecting AI models to external tools and data sources. The Centure SDK intercepts MCP messages to detect and block malicious prompts.

Installation

Install both the Centure SDK and the MCP SDK:

Basic Setup

Wrap any MCP transport with CentureMCPClientTransport to add automatic scanning:
The transport intercepts all messages sent through the MCP client and scans them before forwarding to the server.

Configuration Hooks

The transport provides hooks to customize scanning behavior:

shouldScanMessage

Determines whether a specific message should be scanned. Return false to skip scanning.
Parameters:
  • message (JSONRPCMessage) - The MCP message to potentially scan
  • extra (MessageExtraInfo) - Additional context about the message
Returns: boolean or { scan: boolean }

onAfterScan

Called after a message is scanned, regardless of the result. Use this for logging or metrics.
Parameters:
  • message (JSONRPCMessage) - The scanned message
  • extra (MessageExtraInfo) - Additional context
  • scanResult (ScanResponse) - The scan result from Centure API
Returns: void or { passthrough: boolean }

onUnsafeMessage

Called when an unsafe message is detected. Controls whether to block or allow the message.
Parameters:
  • message (JSONRPCMessage) - The unsafe message
  • extra (MessageExtraInfo) - Additional context
  • scanResult (ScanResponse) - The scan result from Centure API
Returns: { passthrough: boolean, replace?: JSONRPCMessage }
Always return an object from onUnsafeMessage. Set passthrough: false to block the message and optionally provide a replace message to send instead.

onBeforeSend

Called before any message is sent through the transport, before scanning occurs.
Parameters:
  • message (JSONRPCMessage) - The message about to be sent
  • extra (MessageExtraInfo) - Additional context
Returns: void

Complete Example

Here’s a production-ready configuration with all hooks:

Transport Types

CentureMCPClientTransportOptions

Configuration options for the transport wrapper:

Hook Context Types

Best Practices

Block high-confidence threats: Always block messages with high confidence detections in production environments.
Log all detections: Use onAfterScan to log scanning results for security monitoring and incident response.
Skip safe methods: Use shouldScanMessage to skip scanning for methods that cannot carry threats (e.g., tools/list, initialize).
Provide clear error messages: When blocking messages, include the request_id in error responses for debugging and support.
Do not allow high confidence detections to pass through without careful review. These indicate strong evidence of prompt injection attacks.

Supported Transports

The CentureMCPClientTransport works with any MCP transport implementation:
  • StdioClientTransport - Communicate with servers via stdin/stdout
  • SSEClientTransport - Communicate with servers via Server-Sent Events
  • Custom transports - Any transport implementing the MCP Transport interface

Error Handling

The transport handles scanning errors gracefully:
If the Centure API is unreachable or returns an error, the message is blocked by default. Use onAfterScan to implement custom fallback behavior.

Next Steps

Quickstart

Get started with basic SDK usage

API Reference

Explore response types and configuration options

MCP Documentation

Learn more about the Model Context Protocol

GitHub Repository

View source code and examples