Skip to main content

Python SDK for Forge — the paid tool registry on Morpheus AI (MRC 60). Phase 1 listing rail + Phase 3 pre-paid escrow with relayer-attested per-call settlement on Arbitrum + Base.

Project description

hypnex-forge (Python)

Python SDK for Forge — the paid tool registry on Morpheus AI. Implements MRC 60 Phase 1 (paid listings) and Phase 3 (on-chain per-call settlement via pre-paid escrow).

pip install hypnex-forge

Affiliation & monetization

This SDK is published by Hypnex Labs. Hypnex is not affiliated with the Morpheus AI Foundation.

  • register() costs 1 MOR (configurable on-chain by claim-admin), forwarded directly to the Hypnex Labs treasury at 0x22B5C0075372E743042b2d62b3D254425Eb957D8 inside the same tx. The SDK auto-approves the MOR allowance on first use.
  • pricePerCallWei is what end users pay YOU per call. With Phase 3 escrow, on-chain settlement debits the agent's escrow at this rate, with 90% routed to the tool owner and 10% to the Hypnex treasury as a protocol fee. The fee is hard-capped at 20% in the contract; admin cannot rug.

Quickstart — Phase 1 (listings)

Read-only

from hypnex_forge import Forge

f = Forge(chain="arbitrum")
print(f.total_tools())
print(f.list_tools(0, 100))
print(f.get_listing_fee_wei())  # 10**18 = 1 MOR

Register a tool (with signer)

import os
from hypnex_forge import Forge

f = Forge(
    chain="arbitrum",
    rpc_url=os.environ["ETH_RPC_URL"],
    private_key=os.environ["PRIVATE_KEY"],
)

tx = f.register(
    namespace="myorg",
    name="websearch",
    mcp_uri="https://mcp.example.com/v1",
    categories=["search", "data"],
    price_per_call_wei=int(0.001 * 10**18),
)
print("tool registered:", tx)

Quickstart — Phase 3 (escrow + per-call settlement)

Three actors: the agent (who consumes the tool), the tool owner (who runs it), and the Hypnex relayer (which batches receipts and submits settle() on a 4-hourly cron).

1. Tool owner: register a signer key

from hypnex_forge import Escrow, tool_id

esc = Escrow(chain="arbitrum", private_key=os.environ["TOOL_OWNER_PK"])
tid = tool_id("myorg", "websearch")

esc.set_signer(tid, "0xYourSessionKeyOrEoa")

2. Agent: pre-fund per-tool escrow

from hypnex_forge import Escrow, tool_id

esc = Escrow(chain="arbitrum", private_key=os.environ["AGENT_PK"])
tid = tool_id("myorg", "websearch")

# Auto-approves MOR allowance on first call.
esc.deposit(tid, 10 * 10**18)  # 10 MOR runway
print("escrow balance:", esc.balance(tid))

3. Tool server: sign + post receipts

After every N calls, the tool's signer key signs a receipt and posts it to relayer.hypnex.xyz:

esc = Escrow(chain="arbitrum", private_key=os.environ["TOOL_OWNER_PK"])
esc.call_with_receipt(
    tool_id=tid,
    agent="0xAgentAddress",
    call_count=100,           # cumulative for this period
    period_id=42,             # strictly increasing per (toolId, agent)
)
# The relayer batches and submits settle() on the next cron tick.

4. Tool owner: withdraw accrued revenue

print("accrued:", esc.tool_revenue(tid) / 1e18, "MOR")
esc.withdraw_tool(tid, "0xYourColdWallet")

5. Agent: 24h-delayed self-custody exit

If a tool owner misbehaves, agents can pull remaining escrow back:

esc.agent_request_withdraw(tid)        # opens a 24h window
# ... 24 hours later ...
esc.agent_execute_withdraw(tid, "0xAgentAddress")

The relayer has the full 24h to flush pending settlements before the exit becomes executable.

Public API

Forge (Phase 1 — listings)

Forge(address=None, chain="arbitrum", w3=None, rpc_url=None,
      account=None, private_key=None)

# read
.total_tools() -> int
.list_tools(offset=0, limit=100) -> list[bytes32]
.tools_of(owner) -> list[bytes32]
.tools_in_category(label_or_bytes32) -> list[bytes32]
.get_tool(tool_id) -> Tool
.is_registered(tool_id) -> bool
.tool_id_of(namespace, name) -> bytes32
.get_listing_fee_wei() -> int
.get_claim_admin() -> str
.get_mor_balance(address=None) -> int
.get_mor_allowance(owner=None) -> int

# write (signer required)
.register(namespace, name, mcp_uri, categories, price_per_call_wei=0) -> tx
.update_tool(tool_id, mcp_uri, price_per_call_wei) -> tx
.set_categories(tool_id, categories) -> tx
.deactivate(tool_id) -> tx
.reactivate(tool_id) -> tx
.transfer_ownership(tool_id, new_owner) -> tx

Escrow (Phase 3 — per-call settlement)

Escrow(address=None, chain="arbitrum", w3=None, rpc_url=None,
       account=None, private_key=None, relayer_url=None)

# read
.balance(tool_id, agent=None) -> int
.tool_revenue(tool_id) -> int
.treasury_revenue() -> int
.signer_of(tool_id) -> str
.last_period_id(tool_id, agent) -> int
.withdraw_unlock_at(tool_id, agent) -> int
.protocol_fee_bps() -> int
.relayer_address() -> str
.claim_admin() -> str
.quote_settle(tool_id, call_count) -> (total, tool_payout, protocol_fee)

# agent-side write
.deposit(tool_id, amount, auto_approve=True) -> tx
.agent_request_withdraw(tool_id) -> tx
.agent_execute_withdraw(tool_id, to=None) -> tx

# tool-owner-side write
.set_signer(tool_id, new_signer) -> tx
.withdraw_tool(tool_id, to) -> tx
.sign_receipt(tool_id, agent, call_count, period_id) -> bytes
.post_receipt(tool_id, agent, call_count, period_id, signature, ...) -> dict
.call_with_receipt(tool_id, agent, call_count, period_id, ...) -> dict

# relayer / claim-admin write
.settle(tool_id, agent, call_count, period_id, signature) -> tx
.withdraw_treasury(to) -> tx
.set_relayer(new_relayer) -> tx
.set_protocol_fee_bps(new_bps) -> tx

Plus a pure helper:

receipt_struct_hash(*, chain_id, escrow_address, tool_id,
                    agent, call_count, period_id) -> bytes

The bytes returned match the on-chain Solidity recovery exactly:

keccak256(abi.encode(chainid, escrow, toolId, agent, callCount, periodId))

wrapped with the EIP-191 \x19Ethereum Signed Message:\n32 prefix when signed.

Environment variables

Variable Purpose
HYPNEX_FORGE_CHAIN Default chain (arbitrum or base)
HYPNEX_FORGE_RPC_URL Override RPC URL
HYPNEX_FORGE_ADDRESS Override ForgeToolRegistry address
HYPNEX_FORGE_ESCROW_ADDRESS Override ForgeEscrow address
HYPNEX_FORGE_RELAYER_URL Override relayer endpoint (default https://relayer.hypnex.xyz)
PRIVATE_KEY Required for write methods

Status

  • Phase 1 — paid listings on Arbitrum One + Base mainnet (live since 2026-05-09).

  • Phase 2 — discovery UI at forge.hypnex.xyz (live).

  • Phase 3 — pre-paid escrow + per-call settlement (ForgeEscrow). Live since 2026-05-09:

    SDK 0.2.1+ resolves these automatically when you pass chain="arbitrum" or chain="base". The Cloudflare Worker relayer at relayer.hypnex.xyz is the last operational piece; until it's live, receipts can be submitted directly to Escrow.settle() by the configured relayer EOA.

License

MIT (Copyright (c) 2026 Hypnex Labs). The MIT-licensed source includes hard-coded fee routers to the Hypnex Labs treasury for both the listing fee and the Phase-3 protocol fee — see "Affiliation & monetization" above.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hypnex_forge-0.2.2.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hypnex_forge-0.2.2-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file hypnex_forge-0.2.2.tar.gz.

File metadata

  • Download URL: hypnex_forge-0.2.2.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for hypnex_forge-0.2.2.tar.gz
Algorithm Hash digest
SHA256 b32286c4ad04d0ac4958f3d92ecb425c709b89d85252f4cb57f5ec5677f22e86
MD5 98c7f7751cc67c740c80be4d1c7428c0
BLAKE2b-256 5c86622a440da729d9abb4502c3c954893aea194426dba9410d4acb6b9ea676d

See more details on using hashes here.

File details

Details for the file hypnex_forge-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: hypnex_forge-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 16.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for hypnex_forge-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f1d388498b6322e02c8e039a6d18d1891d2651f1c860685c495cf4fc3d213452
MD5 acd77fdf51ca7ff5aebb055cd9e69622
BLAKE2b-256 6cb5df53cb84c32e9f22995a307710ede8d4fe28b95389c6aa573ce563db2b26

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page