@authentify2026/agents 0.1.0 → 0.2.0
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 +8 -0
- package/dist/index.d.ts +1 -1
- package/dist/mcp.js +13 -1
- package/dist/policy.d.ts +12 -1
- package/dist/policy.js +4 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -100,6 +100,14 @@ Each adapter accepts `{ onBlocked: 'throw' }`, which throws
|
|
|
100
100
|
`authorizeToolCall(client, policy, name, args)` is the framework-free core
|
|
101
101
|
if you run your own tool loop.
|
|
102
102
|
|
|
103
|
+
**Sessions.** Set `sessionId` on the policy (build one policy per run or
|
|
104
|
+
conversation) and every tool call in that run is sent with it, so
|
|
105
|
+
Authentify lists them together. A mapping can set its own `sessionId` or
|
|
106
|
+
`parentRequestId` (`@authentify2026/sdk` 0.7+). With no `sessionId` on the
|
|
107
|
+
policy, the MCP guard uses a hash of the transport's session (Streamable
|
|
108
|
+
HTTP), so each client connection is grouped without the raw id leaving
|
|
109
|
+
your server; stdio connections have none.
|
|
110
|
+
|
|
103
111
|
LangChain: see [`@authentify2026/langchain`](https://www.npmjs.com/package/@authentify2026/langchain).
|
|
104
112
|
|
|
105
113
|
MIT licensed. © 4Sure Technologies LLC.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { authorizeToolCall, ToolCallBlockedError } from './policy';
|
|
2
|
-
export type { AuthentifyGuard, ToolAuthorization, ToolPolicy, ToolCallCheck } from './policy';
|
|
2
|
+
export type { AuthentifyGuard, ToolAuthorization, ToolPolicy, ToolCallCheck, ToolCallDefaults } from './policy';
|
|
3
3
|
export { createAnthropicToolRunner } from './anthropic';
|
|
4
4
|
export type { AnthropicToolUseBlock, AnthropicToolResultBlock, AnthropicToolHandler, AnthropicToolRunnerOptions } from './anthropic';
|
|
5
5
|
export { guardOpenAITool, guardOpenAITools } from './openai';
|
package/dist/mcp.js
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createMcpGuard = createMcpGuard;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
4
5
|
const policy_1 = require("./policy");
|
|
6
|
+
// The MCP SDK passes the transport's session id as `extra.sessionId`
|
|
7
|
+
// (Streamable HTTP; stdio has none). It routes that client's requests on
|
|
8
|
+
// this server, so only a hash of it goes to Authentify: the calls are
|
|
9
|
+
// still grouped per connection, and the audit record never holds a value
|
|
10
|
+
// someone could present to this server.
|
|
11
|
+
function mcpSessionId(extra) {
|
|
12
|
+
const id = extra?.sessionId;
|
|
13
|
+
if (typeof id !== 'string' || !id)
|
|
14
|
+
return undefined;
|
|
15
|
+
return 'mcp-' + (0, node_crypto_1.createHash)('sha256').update(id).digest('hex').slice(0, 32);
|
|
16
|
+
}
|
|
5
17
|
/**
|
|
6
18
|
* Wraps tool handlers so each call is checked with Authentify first:
|
|
7
19
|
*
|
|
@@ -14,7 +26,7 @@ const policy_1 = require("./policy");
|
|
|
14
26
|
function createMcpGuard(client, policy, options = {}) {
|
|
15
27
|
return function guard(toolName, handler) {
|
|
16
28
|
return async (args, extra) => {
|
|
17
|
-
const check = await (0, policy_1.authorizeToolCall)(client, policy, toolName, args);
|
|
29
|
+
const check = await (0, policy_1.authorizeToolCall)(client, policy, toolName, args, { sessionId: mcpSessionId(extra) });
|
|
18
30
|
if (!check.allowed) {
|
|
19
31
|
if (options.onBlocked === 'throw')
|
|
20
32
|
throw new policy_1.ToolCallBlockedError(toolName, check);
|
package/dist/policy.d.ts
CHANGED
|
@@ -20,6 +20,17 @@ export interface ToolPolicy {
|
|
|
20
20
|
unlisted?: 'deny' | 'skip';
|
|
21
21
|
/** Applied to every request that doesn't set its own endUserId. */
|
|
22
22
|
endUserId?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Applied to every request that doesn't set its own sessionId, so one
|
|
25
|
+
* run's tool calls are listed together in Authentify. Build the policy
|
|
26
|
+
* per run (or per conversation) to give each its own id. The MCP guard
|
|
27
|
+
* falls back to the transport's session when this is unset.
|
|
28
|
+
*/
|
|
29
|
+
sessionId?: string;
|
|
30
|
+
}
|
|
31
|
+
/** Per-call values an adapter knows that the policy doesn't, such as the MCP transport session. */
|
|
32
|
+
export interface ToolCallDefaults {
|
|
33
|
+
sessionId?: string;
|
|
23
34
|
}
|
|
24
35
|
export type ToolCallCheck = {
|
|
25
36
|
allowed: true;
|
|
@@ -39,7 +50,7 @@ export type ToolCallCheck = {
|
|
|
39
50
|
* (including one thrown by the policy's own mapping) all come back as
|
|
40
51
|
* `allowed: false`.
|
|
41
52
|
*/
|
|
42
|
-
export declare function authorizeToolCall(client: AuthentifyGuard, policy: ToolPolicy, toolName: string, args: unknown): Promise<ToolCallCheck>;
|
|
53
|
+
export declare function authorizeToolCall(client: AuthentifyGuard, policy: ToolPolicy, toolName: string, args: unknown, defaults?: ToolCallDefaults): Promise<ToolCallCheck>;
|
|
43
54
|
/** Thrown by the adapters when configured with `onBlocked: 'throw'`. */
|
|
44
55
|
export declare class ToolCallBlockedError extends Error {
|
|
45
56
|
readonly toolName: string;
|
package/dist/policy.js
CHANGED
|
@@ -13,7 +13,7 @@ function isDecisionError(err) {
|
|
|
13
13
|
* (including one thrown by the policy's own mapping) all come back as
|
|
14
14
|
* `allowed: false`.
|
|
15
15
|
*/
|
|
16
|
-
async function authorizeToolCall(client, policy, toolName, args) {
|
|
16
|
+
async function authorizeToolCall(client, policy, toolName, args, defaults = {}) {
|
|
17
17
|
const map = Object.prototype.hasOwnProperty.call(policy.tools, toolName) ? policy.tools[toolName] : undefined;
|
|
18
18
|
if (!map) {
|
|
19
19
|
if (policy.unlisted === 'skip')
|
|
@@ -42,6 +42,9 @@ async function authorizeToolCall(client, policy, toolName, args) {
|
|
|
42
42
|
return { allowed: true };
|
|
43
43
|
if (policy.endUserId && !params.endUserId)
|
|
44
44
|
params = { ...params, endUserId: policy.endUserId };
|
|
45
|
+
const sessionId = policy.sessionId ?? defaults.sessionId;
|
|
46
|
+
if (sessionId && !params.sessionId)
|
|
47
|
+
params = { ...params, sessionId };
|
|
45
48
|
try {
|
|
46
49
|
return { allowed: true, response: await client.guard(params) };
|
|
47
50
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@authentify2026/agents",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Authentify guards for agent frameworks: every tool call is authorized before it runs (OpenAI Agents SDK, Anthropic tool use, MCP servers)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|