fullcourtdefense 1.0.1 → 1.0.3

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/cli/index.js CHANGED
@@ -7,7 +7,7 @@ const credits_1 = require("./commands/credits");
7
7
  const init_1 = require("./commands/init");
8
8
  const doctor_1 = require("./commands/doctor");
9
9
  const configure_1 = require("./commands/configure");
10
- const VERSION = '0.1.2';
10
+ const VERSION = '1.0.2';
11
11
  function parseArgs(argv) {
12
12
  const flags = {};
13
13
  let command = '';
package/dist/client.d.ts CHANGED
@@ -1,8 +1,8 @@
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;
5
- constructor(config: FullCourtDefenseConfig);
5
+ constructor(config?: FullCourtDefenseConfig);
6
6
  get shieldKey(): string;
7
7
  get baseURL(): string;
8
8
  get apiKey(): string;
@@ -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
@@ -2,6 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FullCourtDefense = void 0;
4
4
  const DEFAULT_API_URL = 'https://api.fullcourtdefense.ai';
5
+ const SHIELD_ID_ENV_VARS = ['FCD_SHIELD_ID', 'FULLCOURTDEFENSE_SHIELD_ID', 'AGENTGUARD_SHIELD_ID'];
6
+ const SHIELD_KEY_ENV_VARS = ['FCD_SHIELD_KEY', 'FULLCOURTDEFENSE_SHIELD_KEY', 'AGENTGUARD_SHIELD_KEY'];
7
+ const API_URL_ENV_VARS = ['FCD_API_URL', 'FULLCOURTDEFENSE_API_URL'];
8
+ const API_KEY_ENV_VARS = ['FCD_API_KEY', 'FULLCOURTDEFENSE_API_KEY', 'BOTGUARD_API_KEY'];
9
+ function readEnv(names) {
10
+ const env = globalThis.process?.env;
11
+ if (!env)
12
+ return undefined;
13
+ for (const name of names) {
14
+ const value = env[name];
15
+ if (value && value.trim())
16
+ return value.trim();
17
+ }
18
+ return undefined;
19
+ }
5
20
  function buildScanHeaders(shieldKey, metadata, inputSource) {
6
21
  const headers = { 'Content-Type': 'application/json' };
7
22
  if (shieldKey)
@@ -34,22 +49,43 @@ function extractShield(data) {
34
49
  function validateShieldId(shieldId) {
35
50
  if (!shieldId || typeof shieldId !== 'string' || !shieldId.trim()) {
36
51
  throw new Error('FullCourtDefense: shieldId is required.\n' +
37
- 'Get your free Shield ID at: https://fullcourtdefense.ai → Sign up → Shield → Create Shield\n' +
38
- 'Then pass it as: new FullCourtDefense({ shieldId: "sh_your_shield_id" })');
52
+ 'Pass it as: new FullCourtDefense({ shieldId: "sh_your_shield_id" })\n' +
53
+ 'Or set one of these env vars: FCD_SHIELD_ID, FULLCOURTDEFENSE_SHIELD_ID, AGENTGUARD_SHIELD_ID\n' +
54
+ 'Get a free Shield ID at: https://fullcourtdefense.ai → Sign up → Shield → Create Shield');
39
55
  }
40
56
  if (!shieldId.startsWith('sh_')) {
41
57
  throw new Error(`FullCourtDefense: Invalid shieldId "${shieldId}". Shield IDs start with "sh_" (e.g. "sh_2803733325433b6929281d5b").\n` +
42
58
  'Get your Shield ID at: https://fullcourtdefense.ai → Shield page');
43
59
  }
44
60
  }
61
+ function mcpToolResultToText(result) {
62
+ if (typeof result === 'string')
63
+ return result;
64
+ const content = result?.content;
65
+ if (Array.isArray(content)) {
66
+ const textBlocks = content
67
+ .filter((item) => item.type === 'text' && typeof item.text === 'string')
68
+ .map((item) => item.text);
69
+ if (textBlocks.length > 0)
70
+ return textBlocks.join('\n\n');
71
+ }
72
+ return JSON.stringify(result, null, 2) ?? String(result);
73
+ }
74
+ function mcpTextResult(text, isError) {
75
+ return {
76
+ ...(isError ? { isError: true } : {}),
77
+ content: [{ type: 'text', text }],
78
+ };
79
+ }
45
80
  class FullCourtDefense {
46
- constructor(config) {
47
- validateShieldId(config.shieldId);
81
+ constructor(config = {}) {
82
+ const shieldId = config.shieldId ?? readEnv(SHIELD_ID_ENV_VARS);
83
+ validateShieldId(shieldId);
48
84
  this.config = {
49
- shieldId: config.shieldId,
50
- apiKey: config.apiKey || '',
51
- shieldKey: config.shieldKey || '',
52
- apiUrl: (config.apiUrl || DEFAULT_API_URL).replace(/\/$/, ''),
85
+ shieldId: shieldId,
86
+ apiKey: config.apiKey ?? readEnv(API_KEY_ENV_VARS) ?? '',
87
+ shieldKey: config.shieldKey ?? readEnv(SHIELD_KEY_ENV_VARS) ?? '',
88
+ apiUrl: (config.apiUrl ?? readEnv(API_URL_ENV_VARS) ?? DEFAULT_API_URL).replace(/\/$/, ''),
53
89
  timeout: config.timeout || 120000,
54
90
  };
55
91
  this.chat = new ChatNamespace(this);
@@ -142,6 +178,65 @@ class FullCourtDefense {
142
178
  }
143
179
  return resp.json();
144
180
  }
181
+ // ── MCP one-call wrapper: run a tool, scan its output, return MCP-safe content ──
182
+ // Use this when integrating around an existing MCP callTool handler.
183
+ async protectMcpToolResponse(options) {
184
+ let rawResult;
185
+ try {
186
+ rawResult = await options.callTool();
187
+ }
188
+ catch (error) {
189
+ return mcpTextResult(JSON.stringify({
190
+ blocked: true,
191
+ reason: 'MCP tool call failed.',
192
+ error: error instanceof Error ? error.message : String(error),
193
+ toolName: options.toolName,
194
+ }, null, 2), true);
195
+ }
196
+ const toolResponse = options.resultToText
197
+ ? options.resultToText(rawResult)
198
+ : mcpToolResultToText(rawResult);
199
+ if (options.maxResponseChars && toolResponse.length > options.maxResponseChars) {
200
+ return mcpTextResult(JSON.stringify({
201
+ blocked: true,
202
+ reason: 'MCP tool response too large to scan safely. Paginate or narrow the query.',
203
+ toolName: options.toolName,
204
+ responseLength: toolResponse.length,
205
+ maxResponseChars: options.maxResponseChars,
206
+ }, null, 2), true);
207
+ }
208
+ try {
209
+ const scan = await this.scanToolResponse(toolResponse, {
210
+ toolName: options.toolName,
211
+ agentName: options.agentName,
212
+ operation: options.operation,
213
+ resourceType: options.resourceType,
214
+ toolArgs: options.toolArgs,
215
+ metadata: options.metadata,
216
+ });
217
+ if (scan.blocked) {
218
+ return mcpTextResult(JSON.stringify({
219
+ blocked: true,
220
+ reason: options.blockedMessage ?? scan.reason ?? 'MCP tool response blocked by FullCourtDefense.',
221
+ confidence: scan.confidence,
222
+ analysisPath: scan.analysisPath,
223
+ matchedPatterns: scan.matchedPatterns,
224
+ piiDetections: scan.piiDetections,
225
+ actionPolicy: scan._actionPolicy,
226
+ toolName: scan.toolName ?? options.toolName,
227
+ }, null, 2), true);
228
+ }
229
+ return mcpTextResult(scan.safeResponse ?? toolResponse);
230
+ }
231
+ catch (error) {
232
+ return mcpTextResult(JSON.stringify({
233
+ blocked: true,
234
+ reason: 'FullCourtDefense Shield scan unavailable. Tool output was not returned to the AI assistant.',
235
+ error: error instanceof Error ? error.message : String(error),
236
+ toolName: options.toolName,
237
+ }, null, 2), true);
238
+ }
239
+ }
145
240
  // ── RAG: scan retrieved document chunks for poisoning before building the LLM prompt ──
146
241
  // Uses the shield configured in the constructor (shieldId).
147
242
  // 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
@@ -20,14 +20,24 @@ export interface ShieldResult<T = any> {
20
20
  content: string | null;
21
21
  }
22
22
  export interface FullCourtDefenseConfig {
23
- shieldId: string;
23
+ /**
24
+ * Shield ID (`sh_…`). If omitted, the SDK reads it from the first env var
25
+ * found in: `FCD_SHIELD_ID`, `FULLCOURTDEFENSE_SHIELD_ID`, `AGENTGUARD_SHIELD_ID`.
26
+ */
27
+ shieldId?: string;
24
28
  /** LLM provider key — only required when using `fcd.chat.completions.create()` (the gateway). */
25
29
  apiKey?: string;
26
30
  /**
27
31
  * Per-shield key (sent as `x-shield-key`). Required when the shield owner has
28
32
  * locked the shield down with an API key. See your Shield page → "Access" tab.
33
+ * If omitted, the SDK reads it from the first env var found in:
34
+ * `FCD_SHIELD_KEY`, `FULLCOURTDEFENSE_SHIELD_KEY`, `AGENTGUARD_SHIELD_KEY`.
29
35
  */
30
36
  shieldKey?: string;
37
+ /**
38
+ * Backend URL. Defaults to `https://api.fullcourtdefense.ai`. Can also be set
39
+ * via `FCD_API_URL` / `FULLCOURTDEFENSE_API_URL` env var.
40
+ */
31
41
  apiUrl?: string;
32
42
  timeout?: number;
33
43
  }
@@ -68,6 +78,27 @@ export interface McpScanResult {
68
78
  toolName: string | null;
69
79
  _actionPolicy?: AgentSecurityActionPolicyResult;
70
80
  }
81
+ export interface McpTextContent {
82
+ type: 'text';
83
+ text: string;
84
+ }
85
+ export interface McpToolResult {
86
+ [key: string]: unknown;
87
+ isError?: boolean;
88
+ content: McpTextContent[];
89
+ }
90
+ export interface ProtectMcpToolResponseOptions {
91
+ toolName: string;
92
+ agentName?: string;
93
+ operation?: string;
94
+ resourceType?: string;
95
+ toolArgs?: Record<string, unknown>;
96
+ metadata?: ScanMetadata;
97
+ callTool: () => Promise<unknown>;
98
+ resultToText?: (result: unknown) => string;
99
+ blockedMessage?: string;
100
+ maxResponseChars?: number;
101
+ }
71
102
  export interface RagChunkResult {
72
103
  chunk: string;
73
104
  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.3",
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",