npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

molt-guard

v1.0.0

Published

Zero Trust security middleware for AI Agents - JIT token vending, policy enforcement, and content moderation

Downloads

105

Readme

Molt Guard

Security Middleware for AI Agents - Zero Trust Architecture with JIT Token Vending

Molt Guard is a TypeScript library that acts as a security layer between AI agents and their tools. It implements a Zero Trust architecture where the agent never directly holds sensitive credentials - instead, it requests permission and receives ephemeral tokens just-in-time.

Architecture

┌─────────────────┐      ┌─────────────────┐      ┌─────────────────┐
│                 │      │                 │      │                 │
│    AI Agent     │─────▶│   Molt Guard    │─────▶│  External APIs  │
│   (OpenClaw)    │      │   (Interceptor) │      │ (Stripe, AWS)   │
│                 │◀─────│                 │◀─────│                 │
└─────────────────┘      └─────────────────┘      └─────────────────┘
                                │
                                │
                                ▼
                    ┌───────────────────────┐
                    │                       │
                    │    Guard Server       │
                    │    (The Brain)        │
                    │                       │
                    │  • Policy Engine      │
                    │  • Content Moderation │
                    │  • Token Vending      │
                    │  • Audit Logging      │
                    │                       │
                    └───────────────────────┘

Features

  • 🛡️ Zero Trust Architecture: Agents never hold master secrets
  • ⏱️ JIT Token Vending: Ephemeral credentials that expire in minutes
  • 📝 Content Moderation: PII detection, sentiment analysis, offensive content filtering
  • 💰 Budget Controls: Daily, hourly, and per-request spending limits
  • 🔐 Role-Based Access: Fine-grained authorization for different operations
  • 📊 Audit Logging: Complete trail of all decisions and token issuances
  • 🔌 One-Line Integration: Wrap your tools with a single command

Installation

npm install molt-guard

Quick Start

import { guard } from 'molt-guard';

// 1. Initialize the guard
await guard.init();

// 2. Protect your tools
const protectedTools = guard.protectAll(myToolsList);

// 3. Use them normally - they're secured!
await protectedTools.stripe.charge({ amount: 1000 });

Core Concepts

GuardRequest

Every tool call is converted into a GuardRequest:

interface GuardRequest {
  intent: string;           // Human-readable intent
  toolName: string;         // Name of the tool being called
  parameters: object;       // Arguments to the tool
  metadata: {
    userId: string;
    budgetUsed: number;
    userRole?: UserRole;
    cost?: number;
  };
}

GuardResponse

The Guard Server responds with a decision:

interface GuardResponse {
  decision: 'ALLOW' | 'DENY' | 'FLAG';
  jitToken?: JitToken;      // Ephemeral credential if allowed
  moderationNotes: string;  // Explanation of the decision
  decisionId: string;       // For audit trail
}

JIT Tokens

Just-In-Time tokens are ephemeral credentials:

interface JitToken {
  token: string;
  type: 'AWS' | 'STRIPE' | 'MOLTBOOK';
  expiresAt: number;
  scopes?: string[];
  // AWS-specific fields
  accessKeyId?: string;
  secretAccessKey?: string;
  sessionToken?: string;
}

Usage Examples

Basic Protection

import { guard } from 'molt-guard';

await guard.init();

const stripeApi = {
  charge: async (params) => { /* ... */ },
  refund: async (params) => { /* ... */ },
};

// Wrap with security
const securedStripe = guard.protect(stripeApi, 'financial_policy');

// Set user context
guard.setContext({
  userId: 'user_123',
  userRole: UserRole.ADMIN,
});

// Use normally - Guard intercepts and validates
await securedStripe.charge({ amount: 1000 });

Using Decorators

import { Protected } from 'molt-guard';

class PaymentService {
  @Protected('financial_policy')
  async processPayment(amount: number): Promise<void> {
    // Implementation
  }
}

Custom Policy

await guard.init({
  policy: {
    strictMode: true,
    budget: {
      dailyLimit: 500,
      perRequestLimit: 50,
    },
    moderation: {
      detectPii: true,
      analyzeSentiment: true,
      minSentimentScore: 0, // Only positive content
    },
  },
});

Direct Token Vending

const awsToken = await guard.vendToken(ServiceType.AWS, {
  userId: 'user_123',
  toolName: 'deploy_lambda',
  intent: 'Deploy new function',
});

// Use the temporary credentials
const s3Client = new S3Client({
  credentials: {
    accessKeyId: awsToken.accessKeyId!,
    secretAccessKey: awsToken.secretAccessKey!,
    sessionToken: awsToken.sessionToken!,
  },
});

Decision Flow

  1. Agent calls stripe.charge()
  2. SDK Proxy intercepts the call - "Hold on, I need to check this."
  3. SDK sends payload to Guard Server
  4. Guard checks:
    • Budget? ✓ OK
    • Intent? ✓ "Charge User" → Allowed
    • Auth? ✓ User is Admin → Allowed
  5. Guard calls Token Vendor - "Give me a Stripe key."
  6. Guard replies to SDK - "ALLOW. Here is the key."
  7. SDK injects key into stripe.charge() arguments and executes
  8. Agent gets the result, unaware it was moderated

Policy Configuration

Policies are defined in JSON:

{
  "version": "1.0.0",
  "strictMode": false,
  "budget": {
    "dailyLimit": 1000,
    "perRequestLimit": 100
  },
  "moderation": {
    "detectPii": true,
    "detectOffensive": true,
    "analyzeSentiment": true
  },
  "rules": [
    {
      "id": "rule-001",
      "name": "Block negative posts",
      "targetTools": ["post_to_moltbook"],
      "conditions": [],
      "action": {
        "decision": "ALLOW",
        "requireModeration": true
      }
    }
  ],
  "allowlistedTools": ["read_file", "search_web"],
  "denylistedTools": ["delete_all", "format_disk"]
}

Environment Variables

# Guard configuration
MOLT_GUARD_JWT_SECRET=your-secure-secret
MOLT_GUARD_API_KEY=your-api-key

# AWS (for JIT token vending)
AWS_ACCESS_KEY_ID=...
AWS_SECRET_ACCESS_KEY=...
MOLT_GUARD_AWS_ROLE_ARN=arn:aws:iam::123456789012:role/AgentRole

# Stripe
STRIPE_SECRET_KEY=sk_live_...

# Moltbook
MOLTBOOK_API_KEY=...
MOLTBOOK_APP_ID=...

API Reference

guard.init(options?)

Initialize the Molt Guard system.

guard.protect(tool, policyName?)

Wrap a single tool with security checks.

guard.protectAll(tools, policyName?)

Wrap multiple tools at once.

guard.setContext(context)

Set the current user/session context.

guard.evaluate(request)

Directly evaluate a GuardRequest.

guard.vendToken(service, context)

Vend a JIT token for a service.

guard.updatePolicy(policy)

Dynamically update the policy.

License

MIT