@centure/node-sdk
Version:
A Typescript SDK for interacting with Centure's API
115 lines • 3.92 kB
TypeScript
import { Transport, TransportSendOptions } from "@modelcontextprotocol/sdk/shared/transport.js";
import { JSONRPCMessage, MessageExtraInfo } from "@modelcontextprotocol/sdk/types.js";
import { CentureClient } from "../client.js";
import { ScanResponse } from "../types.js";
/**
* JSONRPC error code for security violations detected by Centure scan.
* Falls within the implementation-specific server error range (-32000 to -32099).
*/
export declare const CENTURE_SECURITY_VIOLATION_ERROR = -32001;
/**
* Context passed to shouldScanMessage hook
*/
export type ShouldScanMessageContext = {
message: JSONRPCMessage;
extra?: MessageExtraInfo;
};
/**
* Context passed to onAfterScan hook
*/
export type OnAfterScanContext = {
message: JSONRPCMessage;
extra?: MessageExtraInfo;
scanResult: ScanResponse;
};
/**
* Context passed to onUnsafeMessage hook
*/
export type OnUnsafeMessageContext = {
message: JSONRPCMessage;
extra?: MessageExtraInfo;
scanResult: ScanResponse;
};
/**
* Result type for shouldScanMessage hook
*/
export type ShouldScanMessageResult = {
scan: boolean;
};
/**
* Result type for onAfterScan hook
*/
export type OnAfterScanResult = {
/**
* If true, the message will be passed through without further checks
*/
passthrough: boolean;
};
/**
* Result type for onUnsafeMessage hook
* - If passthrough is false, an error will be sent to the client
* - If replace is provided, that message will be sent instead of an error
*/
export type OnUnsafeMessageResult = {
passthrough: boolean;
replace?: JSONRPCMessage;
};
/**
* Configuration options for CentureMCPClientTransport.
*/
export type CentureMCPClientTransportOptions = {
/**
* The underlying transport to wrap.
*/
transport: Transport;
/**
* Centure API client for scanning messages.
*/
client: CentureClient;
/**
* Optional hook to determine if a message should be scanned.
* Called before scanning each incoming message from server to client.
* Can be sync or async.
*/
shouldScanMessage?: (context: ShouldScanMessageContext) => boolean | Promise<boolean>;
/**
* Optional hook called after scanning a message.
* Can be used for logging or custom logic based on scan results.
* Can be sync or async.
*/
onAfterScan?: (context: OnAfterScanContext) => OnAfterScanResult | Promise<OnAfterScanResult>;
/**
* Optional hook invoked when an unsafe message is detected.
* Allows the caller to decide whether to pass through or replace the message.
* Can be sync or async.
*/
onUnsafeMessage?: (context: OnUnsafeMessageContext) => OnUnsafeMessageResult | Promise<OnUnsafeMessageResult>;
};
export declare class CentureMCPClientTransport implements Transport {
private readonly wrappedTransport;
private readonly client;
private readonly shouldScanMessageHook?;
private readonly onAfterScanHook?;
private readonly onUnsafeMessageHook?;
onclose?: () => void;
onerror?: (error: Error) => void;
onmessage?: (message: JSONRPCMessage, extra?: MessageExtraInfo) => void;
sessionId?: string;
setProtocolVersion?: (version: string) => void;
constructor(options: CentureMCPClientTransportOptions);
/**
* Creates a JSONRPC error response for an unsafe message
* For tools/call, returns CallToolResult format with isError flag
* For all other methods, returns standard JSON-RPC error format
*/
private createErrorResponse;
/**
* Extracts content from a JSONRPC message for scanning
* Returns arrays of text and image content to scan separately
*/
private extractContentForScanning;
start(): Promise<void>;
send(message: JSONRPCMessage, options?: TransportSendOptions): Promise<void>;
close(): Promise<void>;
}
//# sourceMappingURL=centure-mcp-client-transport.d.ts.map