@webdecoy/ai-protection 0.1.0-alpha.7 → 0.1.0-alpha.8

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/MCP.md CHANGED
@@ -11,7 +11,7 @@ resource authorization.
11
11
  Available in `0.1.0-alpha.5` and later compatible alpha releases:
12
12
 
13
13
  ```sh
14
- npm install @webdecoy/ai-protection@0.1.0-alpha.7 @modelcontextprotocol/sdk@1.31.0
14
+ npm install @webdecoy/ai-protection@0.1.0-alpha.8 @modelcontextprotocol/sdk@1.31.0
15
15
  ```
16
16
 
17
17
  Requires Node 22.22.3+ and MCP SDK **1.31.0**. The MCP SDK is an optional peer, so
@@ -143,7 +143,7 @@ include tenant IDs, hostnames containing secrets, or customer information.
143
143
 
144
144
  An authenticated MCP client calls `tools/list`. Each nonempty response queues a
145
145
  best-effort advertisement of the visible tool names and SHA-256 input-schema
146
- hashes. The AI Protection dashboard shows **Advertised MCP tools**, including
146
+ hashes. The AI Protection dashboard shows **MCP tool inventory**, including
147
147
  tools that have never executed. This does not scan unwrapped servers, hidden tools,
148
148
  resources, prompts or alternate routes. No network request is made at handler
149
149
  construction. Discovery is off unless configured and requires sharedRuntime.
@@ -164,3 +164,29 @@ never blocks authorization, and does not retry. Call `await handler.flush()` at
164
164
  host shutdown/lifecycle boundary to drain pending discovery reports; it does not
165
165
  wait for active tool calls or action reports. Abruptly terminated hosts can lose
166
166
  reports. Discovery advertisements never increment tool action or request counts.
167
+
168
+
169
+ ### Calls before discovery (alpha.8+)
170
+
171
+ With `discovery` enabled, the adapter also attaches the registered server label
172
+ and schema fingerprint to each `tools/call` action report. This includes local
173
+ permission/scope denials for registered tools. It works before a client calls
174
+ `tools/list`; no listing round trip is required to execute an authorized tool.
175
+ Unknown tool names and requests rejected before authentication do not gain
176
+ registry metadata. Turning discovery off omits the new call metadata too.
177
+
178
+ The inventory combines advertisements and action evidence by property, server
179
+ label and tool name. Attempt/start/completion reports sharing an action ID count
180
+ once. Counts include denied attempts, so they are not successful-execution totals.
181
+ “Call evidence only” means no advertisement was captured in the bounded seven-day
182
+ sample. Clients can call directly; hidden scopes, sampling and missing telemetry
183
+ also limit coverage. This is not an attack or permission-gap verdict. Older action
184
+ reports without metadata still appear in the general activity table, aggregated
185
+ by tool name across servers; their server/schema association remains unknown.
186
+
187
+ Deploy a runtime accepting optional `tool_action.tool_schema` before upgrading an
188
+ integration with discovery enabled. Older runtimes reject affected action reports
189
+ without changing admission. The action API also supports optional `toolSchema:
190
+ {serverId, hash}` on trusted registered definitions; it is snapshotted and validated,
191
+ never read from tool arguments. This is SDK-reported metadata, not authorization
192
+ or independent verification of a schema.
@@ -39,7 +39,7 @@ export function prepareActionRuntime(options, definitions) {
39
39
  const payload={schema:2,request_id:event.eventId,timestamp:event.timestamp,decision:event.decision,reason:event.reason,
40
40
  degraded:event.checks.some(c=>c.decision==='unavailable'),checks,handler_attempted:event.attempted,
41
41
  action:event.decision==='deny'?'denied':event.outcome==='unknown'?'handler_error':'forwarded',
42
- tool_action:{action_id:event.actionId,name:event.action,policy_version:event.policyVersion,outcome:event.outcome,...(event.caller?{caller:event.caller}:{}),...(event.work?{work:event.work}:{})}};
42
+ tool_action:{action_id:event.actionId,name:event.action,policy_version:event.policyVersion,outcome:event.outcome,...(event.toolSchema?{tool_schema:{server_id:event.toolSchema.serverId,hash:event.toolSchema.hash}}:{}),...(event.caller?{caller:event.caller}:{}),...(event.work?{work:event.work}:{})}};
43
43
  const response=await fetch(new URL('/api/v1/sdk/ai-abuse/reports',url),{method:'POST',redirect:'error',signal,
44
44
  headers:{Authorization:`Bearer ${c.webdecoyKey}`,'X-WebDecoy-Property-ID':c.propertyId,'Content-Type':'application/json'},body:JSON.stringify(payload)});
45
45
  await response.body?.cancel();if(!response.ok)throw Error('Action reporting unavailable');
package/actions.d.mts CHANGED
@@ -32,7 +32,10 @@ export interface ActionWork {
32
32
  /** Confirmed work after completed execution. No async/detached measurement; excess/unknown retains maximum. */
33
33
  measure?(result:unknown,context:ActionContext):number;
34
34
  }
35
+ /** Server-supplied metadata, not proof of a verified schema or authorization. */
36
+ export interface ToolSchemaEvidence { readonly serverId: string; readonly hash: string; }
35
37
  export interface ActionEvent {
38
+ readonly toolSchema?: ToolSchemaEvidence;
36
39
  /** Pseudonymous application-authenticated subject, not WebDecoy-verified agent identity. */
37
40
  readonly caller?: {readonly schema:1;readonly source:'application_auth';readonly id:string};
38
41
  readonly work?:ActionWorkEvidence;
@@ -64,6 +67,10 @@ export interface ActionRuntime {
64
67
  reportingTimeoutMs?:number;maxPendingReports?:number;
65
68
  }
66
69
  export interface ActionDefinition {
70
+ /** Optional non-secret server label and canonical SHA-256 schema hash. MCP discovery fills this automatically.
71
+ * Requires a runtime supporting tool_schema evidence; does not change admission.
72
+ */
73
+ toolSchema?: ToolSchemaEvidence;
67
74
  limits?: ActionLimits;
68
75
  requiredScopes: readonly string[];
69
76
  validate(args: ActionInput): boolean | Promise<boolean>;
package/actions.mjs CHANGED
@@ -72,7 +72,11 @@ export function createActionProtection(options) {
72
72
  definition.requiredScopes.some(s => !bounded(s)) ||
73
73
  ['validate','authorize','execute'].some(k => typeof definition[k] !== 'function') ||
74
74
  (definition.policy !== undefined && typeof definition.policy !== 'function')) throw Error('Invalid action definition');
75
- actions.set(name, Object.freeze({...definition,requiredScopes:Object.freeze([...definition.requiredScopes])}));
75
+ const t = definition.toolSchema;
76
+ if (t !== undefined && (!t || typeof t.serverId !== 'string' || !token.test(t.serverId) ||
77
+ typeof t.hash !== 'string' || !/^[a-f0-9]{64}$/.test(t.hash))) throw Error('Invalid tool schema evidence');
78
+ const toolSchema = t === undefined ? undefined : Object.freeze({serverId:t.serverId,hash:t.hash});
79
+ actions.set(name, Object.freeze({...definition,toolSchema,requiredScopes:Object.freeze([...definition.requiredScopes])}));
76
80
  }
77
81
  if (!actions.size || actions.size > 128) throw Error('Expected 1–128 actions');
78
82
  const runtime=prepareActionRuntime(options,actions);
@@ -91,7 +95,7 @@ export function createActionProtection(options) {
91
95
  function emit(decision, reason, outcome) {
92
96
 
93
97
  const event = Object.freeze({schema:1, eventId:randomUUID(), timestamp:new Date().toISOString(), actionId, action:eventAction, policyVersion,
94
- ...(callerEvidence?{caller:callerEvidence}:{}),evaluation:'local', decision, reason, attempted, outcome,...(work?{work:Object.freeze({...work.evidence})}:{}),checks:Object.freeze(checks.map(c=>Object.freeze({...c})))});
98
+ ...(callerEvidence?{caller:callerEvidence}:{}),...(action?.toolSchema?{toolSchema:action.toolSchema}:{}),evaluation:'local', decision, reason, attempted, outcome,...(work?{work:Object.freeze({...work.evidence})}:{}),checks:Object.freeze(checks.map(c=>Object.freeze({...c})))});
95
99
  if(runtime)void runtime.report(event);
96
100
  if(!sink||pendingEvents>=100)return;
97
101
  pendingEvents++;
package/mcp.d.mts CHANGED
@@ -4,7 +4,7 @@ import type {CallToolResult, Tool} from '@modelcontextprotocol/sdk/types.js';
4
4
  import type {ActionContext, ActionDefinition, ActionEvent, ActionRuntime, TrustedCaller} from './actions.mjs';
5
5
 
6
6
  /** Explicitly registered tool; inputSchema describes discovery, validate enforces input. */
7
- export interface ProtectedTool extends ActionDefinition {
7
+ export interface ProtectedTool extends Omit<ActionDefinition, 'toolSchema'> {
8
8
  description: string;
9
9
  inputSchema: Tool['inputSchema'];
10
10
  /** Await all protected work and return a complete MCP result, never a detached stream. */
@@ -21,7 +21,7 @@ export interface ProtectedMCPOptions {
21
21
  policyVersion: string;
22
22
  sharedRuntime?: ActionRuntime;
23
23
  tools: Record<string, ProtectedTool>;
24
- /** Opt-in tools/list metadata: stable non-secret server label and SHA-256 input-schema hashes.
24
+ /** Opt-in tools/list and tools/call metadata: stable non-secret server label and SHA-256 input-schema hashes.
25
25
  * Requires sharedRuntime. Reuse serverId across replicas; separate different servers.
26
26
  */
27
27
  discovery?: { serverId: string };
package/mcp.mjs CHANGED
@@ -11,7 +11,7 @@ export function createProtectedMCPHandler(options) {
11
11
  if ((resource.protocol !== 'https:' && !(loopback && resource.protocol === 'http:')) || resource.pathname !== '/mcp' || resource.search || resource.hash || resource.username || resource.password || issuer.protocol !== 'https:' || issuer.search || issuer.hash || issuer.username || issuer.password)
12
12
  throw Error('Invalid MCP resource configuration');
13
13
  const metadataURL = new URL(metadataPath, resource).href;
14
- const tools = Object.fromEntries(Object.entries(options.tools).map(([name, t]) => [name, { ...t, requiredScopes: [...t.requiredScopes], inputSchema: structuredClone(t.inputSchema) }]));
14
+ const tools = Object.fromEntries(Object.entries(options.tools).map(([name, t]) => [name, { ...t, toolSchema: undefined, requiredScopes: [...t.requiredScopes], inputSchema: structuredClone(t.inputSchema) }]));
15
15
  // Validate the closed registry at startup, not only after a client arrives.
16
16
  createActionProtection({ policyVersion: options.policyVersion, authenticate: options.authenticate, actions: tools, sharedRuntime: options.sharedRuntime });
17
17
  for (const tool of Object.values(tools))
@@ -30,6 +30,8 @@ export function createProtectedMCPHandler(options) {
30
30
  };
31
31
  const hashes = options.discovery ? Object.fromEntries(Object.entries(tools).map(([name, tool]) =>
32
32
  [name, createHash('sha256').update(canonical(JSON.parse(JSON.stringify(tool.inputSchema)))).digest('hex')])) : {};
33
+ if (options.discovery) for (const [name, tool] of Object.entries(tools))
34
+ tool.toolSchema = Object.freeze({serverId:options.discovery.serverId,hash:hashes[name]});
33
35
  const runtime = options.sharedRuntime && { ...options.sharedRuntime };
34
36
  const serverId = options.discovery?.serverId;
35
37
  const catalogReporter = options.discovery ? createReporter({
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "check:package": "node scripts/check-package.mjs",
11
11
  "test:types": "tsc --strict --noEmit --module nodenext --target es2022 test/types.mts test/mcp-types.mts"
12
12
  },
13
- "version": "0.1.0-alpha.7",
13
+ "version": "0.1.0-alpha.8",
14
14
  "exports": {
15
15
  "./fetch": {
16
16
  "types": "./fetch.d.mts",