Skip to content

polykrate/human-context-protocol

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Human Context Protocol

CARGE / Modern Bureaucracy - Decentralized AI-Powered Compliance & Copyright Protection

Transform regulatory processes into executable AI workflows with blockchain proof.

License: GPL v3 Built with MCP

🎯 What is CARGE?

CARGE (Context-Aware Regulatory Governance Engine) is a decentralized platform that transforms bureaucratic processes into executable workflows:

  • AI-Powered: Natural language interaction instead of complex forms
  • Blockchain Proof: Every step generates cryptographic proof
  • GDPR Compliant: Local execution, encrypted storage, user-controlled keys
  • Cost Efficient: ~€0.05/workflow vs €5+ on Ethereum
  • EU Compatible: EBSI-ready W3C Verifiable Credentials

Use Cases

βœ… Copyright Protection (EU EBSI-compatible)
βœ… RGPD Compliance
βœ… KYC/AML Workflows
βœ… Legal Contracts & NDA
βœ… Supply Chain Certifications


πŸš€ Quick Start

Prerequisites

  • Node.js 18+
  • Claude Desktop (or any MCP-compatible AI client)
  • Network connectivity for P2P operations

Installation

# Clone the repository
git clone https://github.com/polykrate/human-context-protocol.git
cd human-context-protocol

# Install dependencies
npm install

# Build the project
npm run build

βš™οΈ MCP Configuration

Single Instance Setup

Add to your MCP configuration file (e.g., ~/.cursor/mcp.json or Claude Desktop config):

{
  "mcpServers": {
    "human-context-protocol": {
      "command": "node",
      "args": [
        "/path/to/human-context-protocol/build/index.js"
      ],
      "env": {
        "SEED": "your twelve word mnemonic seed phrase goes here for deterministic keys",
        "NAME": "my-agent",
        "HELIA_PORT": "4001",
        "SUBSTRATE_WS_URL": "wss://fraa-flashbox-4667-rpc.a.stagenet.tanssi.network",
        "SUBSTRATE_RPC_URL": "https://fraa-flashbox-4667-rpc.a.stagenet.tanssi.network",
        "MAIEUTIC_DEBUG": "false",
        "HELIA_DATA_PATH": "/path/to/data/IPFS/my-agent",
        "LEVELDB_DATA_PATH": "/path/to/data/levelDb/my-agent",
        "PROOF_PATH": "/path/to/data/proof/my-agent"
      }
    }
  }
}

Multi-Agent Setup (Recommended)

Run multiple agents simultaneously for testing workflows:

{
  "mcpServers": {
    "human-context-protocol-alice": {
      "command": "node",
      "args": ["/path/to/human-context-protocol/build/index.js"],
      "env": {
        "SEED": "earn upset sauce birth indicate spray bring glimpse paper soup release same",
        "NAME": "alice",
        "HELIA_PORT": "4001",
        "SUBSTRATE_WS_URL": "wss://fraa-flashbox-4667-rpc.a.stagenet.tanssi.network",
        "SUBSTRATE_RPC_URL": "https://fraa-flashbox-4667-rpc.a.stagenet.tanssi.network",
        "HELIA_DATA_PATH": "/home/user/data/IPFS/alice",
        "LEVELDB_DATA_PATH": "/home/user/data/levelDb/alice",
        "PROOF_PATH": "/home/user/data/proof/alice"
      }
    },
    "human-context-protocol-bob": {
      "command": "node",
      "args": ["/path/to/human-context-protocol/build/index.js"],
      "env": {
        "SEED": "purpose shrug zebra girl identify aerobic velvet civil lazy pull steel enter",
        "NAME": "bob",
        "HELIA_PORT": "4002",
        "SUBSTRATE_WS_URL": "wss://fraa-flashbox-4667-rpc.a.stagenet.tanssi.network",
        "SUBSTRATE_RPC_URL": "https://fraa-flashbox-4667-rpc.a.stagenet.tanssi.network",
        "HELIA_DATA_PATH": "/home/user/data/IPFS/bob",
        "LEVELDB_DATA_PATH": "/home/user/data/levelDb/bob",
        "PROOF_PATH": "/home/user/data/proof/bob"
      }
    }
  }
}

Environment Variables Explained

Variable Description Example
SEED 12-word BIP39 mnemonic for deterministic key generation "word1 word2 ... word12"
NAME Agent identifier (used for logging and data paths) "alice"
HELIA_PORT P2P networking port (must be unique per agent) 4001
SUBSTRATE_WS_URL WebSocket RPC endpoint for RAG Chain wss://...
SUBSTRATE_RPC_URL HTTP RPC endpoint for RAG Chain https://...
HELIA_DATA_PATH IPFS data storage directory /data/IPFS/alice
LEVELDB_DATA_PATH Local database path /data/levelDb/alice
PROOF_PATH Directory for cryptographic proofs /data/proof/alice
KUDO_GATEWAY_URL Kudo IPFS gateway URL for HTTP routing (optional) http://localhost:5001
MAIEUTIC_DEBUG Enable debug logging (optional) "true" or "false"

πŸ› οΈ Available MCP Tools

System & Infrastructure

get_system_info

Get comprehensive system status including keyring, Helia node, blockchain connection, and stored elicitations.

get_system_info({
  includeElicitations: true  // optional
})

update_pki_profile

Update or create your PKI profile on the blockchain with exchange keys and peer ID.

update_pki_profile({
  newCid: "bafybeigdyrzt5..."  // optional: update profile CID
})

get_pki_profile

Retrieve PKI profile information for any address.

get_pki_profile({
  address: "5DXBoe8maXbydrgqiKX1PCY9PS19Kfaq59vrroiXp4se7MgU"
})

IPFS Content Management

ipfs_depose

Store content on IPFS and get a CID.

ipfs_depose({
  content: "Your content here",
  contentType: "text/plain",
  encoding: "utf8"  // utf8, base64, or hex
})

ipfs_retrieve

Retrieve content from IPFS using a CID.

ipfs_retrieve({
  cid: "bafkreibhyxnitb2dg3dctp7mobotn4igbdqsz4w4g264smvlgia2ytav4m",
  outputEncoding: "utf8"  // utf8, base64, or hex
})

ipfs_check

Check if a CID is available and optionally retrieve it.

ipfs_check({
  cid: "bafkreib7nu2xbammtvg7wzdkn4fs3tpwibn2szzqjsx3mp63bnqojb3w7m",
  attemptRetrieval: true
})

RAG Metadata Management

store_rag_metadata

Store RAG (Retrieval-Augmented Generation) workflow metadata on blockchain.

store_rag_metadata({
  instructionCid: "bafkreiabc...",
  resourceCid: "bafkreidef...",
  schemaCid: "bafkreighi...",
  steps: ["0xhash1", "0xhash2"],  // array of step hashes
  name: "EU Copyright v3",
  description: "EU copyright protection workflow",
  tags: ["copyright", "eu", "master"],
  ttl: 432000  // optional: time-to-live in blocks
})

get_rag_metadata

Retrieve RAG metadata by hash.

get_rag_metadata({
  metadataHash: "0x0ec30e885128c18e0e35a403d901ef309f8574c47229d790c748b7cba6d10938"
})

search_rag_by_tags

Search for RAG workflows using tags (AND logic).

search_rag_by_tags({
  tags: ["copyright", "eu", "master"]
})

Workflow Execution

start_workflow

Start a workflow with initial data.

start_workflow({
  workflowHash: "0x0ec30e88...",
  targetAddress: "5DXBoe8maXbydrgqiKX1PCY9PS19Kfaq59vrroiXp4se7MgU",
  delivrable: {
    work: {
      title: "My Creative Work",
      type: "literature",
      description: "A poem about blockchain",
      creationDate: "2025-10-07",
      contentHash: "bafkreihwtfgwhjku627s3ybrf3r4grluxa5nbtxai6kbh2aik7vn4y3zny"
    }
  }
})

decrypt_previous_step

Decrypt and view the accumulated data from a workflow step.

decrypt_previous_step({
  contentHash: "0xe0c96f06853d17030fe9b01c48a4b389a2a3e64c0d90237dd12a3d76905df974"
})

extract_current_step

Extract the next step instructions from a workflow.

extract_current_step({
  contentHashPreviousStep: "0xe0c96f06853d17030fe9b01c48a4b389a2a3e64c0d90237dd12a3d76905df974"
})

complete_step

Complete a workflow step and move to the next.

complete_step({
  targetAddress: "5CLqgPWHnzKw7eF7pL8bV7kuV6FyJ3fFtJyGA7592jrrF1oM",
  contentHashPreviousStep: "0x7519e725790fbdec11a7d82a963197e8a4208d22e87d7faa357769502b730459",
  delivrable: {
    "customer-purchase": {
      "customerIdentity": "Wei Chen",
      "purchaseLocation": "Emperor's Cellar Shanghai",
      "purchaseDate": "2024-08-20",
      "bottleNumber": "#347/2500",
      "purchasePrice": "Β₯28,800",
      "qrCodeScanned": true,
      "verificationResult": "All 6 previous steps verified. Complete provenance chain confirmed."
    }
  }
})

Proof Management

check_proof

Verify a cryptographic proof file against the blockchain.

check_proof({
  proofPath: "/home/user/data/proof/brigite/proof_0x7519e725790fbdec11a7d82a963197e8a4208d22e87d7faa357769502b730459.json"
})

πŸ“– Example: EU Copyright Protection Workflow

Step 1: Search for the Copyright RAG

search_rag_by_tags({
  tags: ["copyright", "eu", "master"]
})

Result: RAG Hash 0x0ec30e885128c18e0e35a403d901ef309f8574c47229d790c748b7cba6d10938

Step 2: Store Your Work on IPFS

ipfs_depose({
  content: "Your creative work content here...",
  contentType: "text/plain",
  encoding: "utf8"
})

Result: CID bafkreihwtfgwhjku627s3ybrf3r4grluxa5nbtxai6kbh2aik7vn4y3zny

Step 3: Start the Copyright Workflow

start_workflow({
  workflowHash: "0x0ec30e885128c18e0e35a403d901ef309f8574c47229d790c748b7cba6d10938",
  targetAddress: "5DXBoe8maXbydrgqiKX1PCY9PS19Kfaq59vrroiXp4se7MgU",
  delivrable: {
    work: {
      title: "Justice Numérique - Poème sur CARGE",
      type: "literature",
      description: "A poem exploring decentralized justice and blockchain",
      creationDate: "2025-10-07",
      contentHash: "bafkreihwtfgwhjku627s3ybrf3r4grluxa5nbtxai6kbh2aik7vn4y3zny"
    }
  }
})

Result:

  • Crypto trail created on blockchain
  • IPFS CID for encrypted data
  • Proof file generated: proof_0xe0c96f06853d17030fe9b01c48a4b389a2a3e64c0d90237dd12a3d76905df974.json

Step 4: Extract Next Step (Creator Identity)

extract_current_step({
  contentHashPreviousStep: "0xe0c96f06853d17030fe9b01c48a4b389a2a3e64c0d90237dd12a3d76905df974"
})

Result: Instructions for Step 2 (creator identity) + accumulated data from Step 1

Step 5: Complete Creator Identity

complete_step({
  targetAddress: "5DXBoe8maXbydrgqiKX1PCY9PS19Kfaq59vrroiXp4se7MgU",
  contentHashPreviousStep: "0xe0c96f06853d17030fe9b01c48a4b389a2a3e64c0d90237dd12a3d76905df974",
  delivrable: {
    creator: {
      legalName: "Modern Bureaucracy SAS",
      email: "[email protected]",
      country: "FR",
      walletAddress: "5DXBoe8maXbydrgqiKX1PCY9PS19Kfaq59vrroiXp4se7MgU"
    }
  }
})

Result: Step 2 completed, proof generated

Step 6: Complete Rights Declaration (Final Step)

complete_step({
  targetAddress: "5DXBoe8maXbydrgqiKX1PCY9PS19Kfaq59vrroiXp4se7MgU",
  contentHashPreviousStep: "0xcee46f0d...",
  delivrable: {
    rights: {
      ownershipPercentage: 100,
      license: "cc-by-nc",
      commercialUse: false,
      derivativeWorks: true
    }
  }
})

Result:

  • βœ… Workflow completed
  • βœ… Final proof with complete copyright data
  • βœ… Blockchain verification available
  • βœ… EBSI-compatible W3C Verifiable Credential generated

Step 7: Verify the Proof

check_proof({
  proofPath: "/home/polycrate/projets/data/proof/brigite/proof_0x7519e725790fbdec11a7d82a963197e8a4208d22e87d7faa357769502b730459.json"
})

Result: Full crypto trail validation against blockchain


πŸ—οΈ Architecture

Components

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           MCP Client (Claude, Cursor)           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚ MCP Protocol
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚        Human Context Protocol Server            β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Keyring (Ed25519 + X25519)             β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Helia/IPFS (Content Storage)           β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Substrate Client (Blockchain)          β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  LevelDB (Local Storage)                β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
     β”‚               β”‚               β”‚
β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”
β”‚   IPFS   β”‚  β”‚  RAG Chain  β”‚  β”‚  Peers  β”‚
β”‚  Network β”‚  β”‚  Substrate  β”‚  β”‚  (P2P)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Security Model

  • End-to-End Encryption: ChaCha20-Poly1305 with X25519 ECDH
  • Perfect Forward Secrecy: Ephemeral keys per workflow step
  • Blockchain Coordination: Immutable audit trail
  • GDPR Compliance: Local execution, encrypted storage, user owns keys
  • No Vendor Lock-in: Open source, self-hosted

πŸ”§ Development

Building

npm run build      # Compile TypeScript
npm run dev        # Watch mode for development

Running Tests

npm run test-elicitation        # Core elicitation tests
npm run test-elicitation-tool   # MCP tool integration tests

Project Structure

human-context-protocol/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ index.ts              # Main MCP server entry point
β”‚   β”œβ”€β”€ keyring.ts            # Cryptographic key management
β”‚   β”œβ”€β”€ helia-node.ts         # IPFS/P2P networking
β”‚   β”œβ”€β”€ substrate.ts          # Blockchain client
β”‚   β”œβ”€β”€ storage.ts            # LevelDB persistence
β”‚   β”œβ”€β”€ crypto.ts             # Encryption utilities
β”‚   β”œβ”€β”€ elicitation.ts        # Maieutic elicitation logic
β”‚   β”œβ”€β”€ rag.ts                # RAG workflow engine
β”‚   β”œβ”€β”€ proof.ts              # Cryptographic proof generation
β”‚   └── tools/                # MCP tool implementations
β”‚       β”œβ”€β”€ workflow.ts
β”‚       β”œβ”€β”€ elicitation.ts
β”‚       β”œβ”€β”€ rag.ts
β”‚       β”œβ”€β”€ ipfs.ts
β”‚       β”œβ”€β”€ pki.ts
β”‚       β”œβ”€β”€ proof.ts
β”‚       └── system.ts
β”œβ”€β”€ build/                    # Compiled JavaScript (auto-generated)
β”œβ”€β”€ LICENSE                   # GPL-3.0
β”œβ”€β”€ package.json
β”œβ”€β”€ tsconfig.json
└── README.md

🀝 Contributing

We welcome contributions! This project follows:

  • Secure Development: Audited crypto libraries only
  • Input Validation: All external data validated
  • Error Handling: Comprehensive logging
  • Code Quality: TypeScript strict mode

πŸ“„ License

GNU General Public License v3.0

Copyright (C) 2025 Jean FranΓ§ois Meneust - Carge

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

See LICENSE for full details.


πŸ“ž Contact

Author: Jean FranΓ§ois Meneust
Company: Carge
Email: [email protected]
Website: https://carge.fr


🌟 Acknowledgments

Built with:

Inspired by:

  • Richard Stallman's Free Software philosophy (GPL-3.0)
  • The EBSI initiative for EU digital infrastructure
  • Modern Bureaucracy vision: "Code is law, bugs are the common enemy"

About

a MCP that structure human data for decentralized collaboration

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published