fullcourtdefense 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -265,17 +265,17 @@ Scan MCP tool responses for hidden injection attacks **before** the LLM sees the
265
265
  ```typescript
266
266
  import { FullCourtDefense } from 'fullcourtdefense';
267
267
 
268
- const fcd = new FullCourtDefense({ shieldId: 'sh_your_shield_id' });
269
-
270
- const toolResult = await mcpClient.callTool('web_search', { query: userQuery });
271
-
272
- const scan = await fcd.scanToolResponse(toolResult.text, { toolName: 'web_search' });
273
-
274
- if (scan.blocked) {
275
- throw new Error(`Injection detected: ${scan.reason}`);
276
- }
268
+ const fcd = new FullCourtDefense({
269
+ shieldId: 'sh_your_shield_id',
270
+ shieldKey: 'shsk_your_shield_key',
271
+ });
277
272
 
278
- return scan.safeResponse;
273
+ return fcd.protectMcpToolResponse({
274
+ toolName: 'web_search',
275
+ agentName: 'my-mcp-server',
276
+ toolArgs: { query: userQuery },
277
+ callTool: () => mcpClient.callTool('web_search', { query: userQuery }),
278
+ });
279
279
  ```
280
280
 
281
281
  ### What it catches
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AgentRegistrationInput, AgentSecurityApiResult, AgentToolCallCheckResult, AgentToolCallInput, FullCourtDefenseConfig, McpScanResult, RagScanResult, ScanMetadata, ScanResult, ShieldResult } from './types';
1
+ import { AgentRegistrationInput, AgentSecurityApiResult, AgentToolCallCheckResult, AgentToolCallInput, FullCourtDefenseConfig, McpScanResult, McpToolResult, ProtectMcpToolResponseOptions, RagScanResult, ScanMetadata, ScanResult, ShieldResult } from './types';
2
2
  export declare class FullCourtDefense {
3
3
  private config;
4
4
  chat: ChatNamespace;
@@ -22,6 +22,7 @@ export declare class FullCourtDefense {
22
22
  toolArgs?: Record<string, unknown>;
23
23
  metadata?: ScanMetadata;
24
24
  }): Promise<McpScanResult>;
25
+ protectMcpToolResponse(options: ProtectMcpToolResponseOptions): Promise<McpToolResult>;
25
26
  scanChunks(chunks: string[], options?: {
26
27
  metadata?: ScanMetadata;
27
28
  }): Promise<RagScanResult>;
package/dist/client.js CHANGED
@@ -42,6 +42,25 @@ function validateShieldId(shieldId) {
42
42
  'Get your Shield ID at: https://fullcourtdefense.ai → Shield page');
43
43
  }
44
44
  }
45
+ function mcpToolResultToText(result) {
46
+ if (typeof result === 'string')
47
+ return result;
48
+ const content = result?.content;
49
+ if (Array.isArray(content)) {
50
+ const textBlocks = content
51
+ .filter((item) => item.type === 'text' && typeof item.text === 'string')
52
+ .map((item) => item.text);
53
+ if (textBlocks.length > 0)
54
+ return textBlocks.join('\n\n');
55
+ }
56
+ return JSON.stringify(result, null, 2) ?? String(result);
57
+ }
58
+ function mcpTextResult(text, isError) {
59
+ return {
60
+ ...(isError ? { isError: true } : {}),
61
+ content: [{ type: 'text', text }],
62
+ };
63
+ }
45
64
  class FullCourtDefense {
46
65
  constructor(config) {
47
66
  validateShieldId(config.shieldId);
@@ -142,6 +161,65 @@ class FullCourtDefense {
142
161
  }
143
162
  return resp.json();
144
163
  }
164
+ // ── MCP one-call wrapper: run a tool, scan its output, return MCP-safe content ──
165
+ // Use this when integrating around an existing MCP callTool handler.
166
+ async protectMcpToolResponse(options) {
167
+ let rawResult;
168
+ try {
169
+ rawResult = await options.callTool();
170
+ }
171
+ catch (error) {
172
+ return mcpTextResult(JSON.stringify({
173
+ blocked: true,
174
+ reason: 'MCP tool call failed.',
175
+ error: error instanceof Error ? error.message : String(error),
176
+ toolName: options.toolName,
177
+ }, null, 2), true);
178
+ }
179
+ const toolResponse = options.resultToText
180
+ ? options.resultToText(rawResult)
181
+ : mcpToolResultToText(rawResult);
182
+ if (options.maxResponseChars && toolResponse.length > options.maxResponseChars) {
183
+ return mcpTextResult(JSON.stringify({
184
+ blocked: true,
185
+ reason: 'MCP tool response too large to scan safely. Paginate or narrow the query.',
186
+ toolName: options.toolName,
187
+ responseLength: toolResponse.length,
188
+ maxResponseChars: options.maxResponseChars,
189
+ }, null, 2), true);
190
+ }
191
+ try {
192
+ const scan = await this.scanToolResponse(toolResponse, {
193
+ toolName: options.toolName,
194
+ agentName: options.agentName,
195
+ operation: options.operation,
196
+ resourceType: options.resourceType,
197
+ toolArgs: options.toolArgs,
198
+ metadata: options.metadata,
199
+ });
200
+ if (scan.blocked) {
201
+ return mcpTextResult(JSON.stringify({
202
+ blocked: true,
203
+ reason: options.blockedMessage ?? scan.reason ?? 'MCP tool response blocked by FullCourtDefense.',
204
+ confidence: scan.confidence,
205
+ analysisPath: scan.analysisPath,
206
+ matchedPatterns: scan.matchedPatterns,
207
+ piiDetections: scan.piiDetections,
208
+ actionPolicy: scan._actionPolicy,
209
+ toolName: scan.toolName ?? options.toolName,
210
+ }, null, 2), true);
211
+ }
212
+ return mcpTextResult(scan.safeResponse ?? toolResponse);
213
+ }
214
+ catch (error) {
215
+ return mcpTextResult(JSON.stringify({
216
+ blocked: true,
217
+ reason: 'FullCourtDefense Shield scan unavailable. Tool output was not returned to the AI assistant.',
218
+ error: error instanceof Error ? error.message : String(error),
219
+ toolName: options.toolName,
220
+ }, null, 2), true);
221
+ }
222
+ }
145
223
  // ── RAG: scan retrieved document chunks for poisoning before building the LLM prompt ──
146
224
  // Uses the shield configured in the constructor (shieldId).
147
225
  // Usage: const result = await fcd.scanChunks(retrievedChunks)
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { FullCourtDefense, FullCourtDefense as FCD } from './client';
2
- export { ShieldResult, ShieldVerdict, FullCourtDefenseConfig, McpScanResult, RagScanResult, RagChunkResult, ScanMetadata, ScanResult, AgentRegistrationInput, AgentToolCallInput, AgentToolCallCheckResult, AgentSecurityActionPolicyResult, AgentSecurityDecision, AgentSecurityApiResult, } from './types';
2
+ export { ShieldResult, ShieldVerdict, FullCourtDefenseConfig, McpScanResult, McpTextContent, McpToolResult, ProtectMcpToolResponseOptions, RagScanResult, RagChunkResult, ScanMetadata, ScanResult, AgentRegistrationInput, AgentToolCallInput, AgentToolCallCheckResult, AgentSecurityActionPolicyResult, AgentSecurityDecision, AgentSecurityApiResult, } from './types';
package/dist/types.d.ts CHANGED
@@ -68,6 +68,27 @@ export interface McpScanResult {
68
68
  toolName: string | null;
69
69
  _actionPolicy?: AgentSecurityActionPolicyResult;
70
70
  }
71
+ export interface McpTextContent {
72
+ type: 'text';
73
+ text: string;
74
+ }
75
+ export interface McpToolResult {
76
+ [key: string]: unknown;
77
+ isError?: boolean;
78
+ content: McpTextContent[];
79
+ }
80
+ export interface ProtectMcpToolResponseOptions {
81
+ toolName: string;
82
+ agentName?: string;
83
+ operation?: string;
84
+ resourceType?: string;
85
+ toolArgs?: Record<string, unknown>;
86
+ metadata?: ScanMetadata;
87
+ callTool: () => Promise<unknown>;
88
+ resultToText?: (result: unknown) => string;
89
+ blockedMessage?: string;
90
+ maxResponseChars?: number;
91
+ }
71
92
  export interface RagChunkResult {
72
93
  chunk: string;
73
94
  blocked: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fullcourtdefense",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Full Court Defense — real-time AI firewall and CLI scanner for chatbots, agents, MCP servers and RAG pipelines.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",