Skip to main content

ai-economy-sdk

CI PyPI version License: MIT

Payment-gated Model Context Protocol (MCP) server and client SDK for Algorand.

ai-economy-sdk turns Model Context Protocol (MCP) tools into monetized services on Algorand using the official x402 payment standard. On the server side, PaymentGate wraps FastMCP applications to enforce per-call micropayments, dynamic rates, and vendor passes with settle-on-success protection. On the client side, paid_mcp_session connects to payment-gated servers and automatically settles transactions only when tool execution succeeds.

Requirements

  • Python 3.10+
  • x402 >= 2.28, < 3.0
  • x402-algorand >= 0.2.0
  • fastmcp >= 3.4, < 4.0
  • py-algorand-sdk >= 2.6

Installation

pip install ai-economy-sdk

Installing ai-economy-sdk automatically installs x402-algorand and the official x402 package.

Quickstart

1. Server: Monetize FastMCP Tools

from fastmcp import FastMCP
from ai_economy_sdk import PaymentGate, DefaultAvmSigner

mcp = FastMCP("paid-service")


@mcp.tool()
def summarize(text: str) -> str:
    return f"Summary: {text[:50]}..."


gate = PaymentGate(
    signer=DefaultAvmSigner(server_private_key),
    network="localnet",
    pay_to=server_address,
    asset_id=0,  # Native ALGO (or ASA ID such as USDC)
    prices={"summarize": 5_000},  # 5,000 microALGO per call
)

app = gate.wrap(mcp)
# Run with: uvicorn server:app --port 8000

2. Client: Invoke Paid Tools

import asyncio
from ai_economy_sdk import paid_mcp_session


async def main():
    async with paid_mcp_session(
        "http://127.0.0.1:8000/sse",
        buyer_private_key,
        "localnet",
    ) as session:
        result = await session.call_tool("summarize", {"text": "Hello Algorand x402"})
        print(result.content[0].text)


asyncio.run(main())

Key Capabilities

  • Settle-on-Success: Payments are verified before tool execution, but committed on-chain only after the tool completes successfully. If a tool raises an error, the payment is never submitted and the buyer is not charged.
  • Identity Verification: Built-in X-Identity-Txn cryptographic proofs verify client account ownership without on-chain execution or transaction fees.
  • Spend Limits & Controls: Direct integration with official x402Client spend controls allows setting per-payment caps or whitelisting custom ASAs.
  • Vendor Passes & Subscriptions: Support for period-based access passes and subscription ASA tokens.
  • Replay Protection: Built-in replay prevention using memory or SQLite stores across single-process and multi-worker deployments.

Ecosystem

  • Documentation: Architecture guides, tutorials, and API references.
  • x402-avm/examples: Runnable examples for LocalNet, TestNet, and MainNet.
  • x402-algorand: Algorand exact payment scheme plugin for official x402.
  • x402-avm-js: TypeScript client for web browsers and Node.js.

Development

Clone the repository and install development dependencies:

git clone https://github.com/x402-avm/ai-economy-sdk.git
cd ai-economy-sdk
uv pip install -e ".[dev]"

Run tests across test tiers:

# Tier 1: Offline unit tests (default)
pytest

# Tier 2: AlgoKit LocalNet integration tests (requires `algokit localnet start`)
LOCALNET=1 pytest

# Tier 3: Public network simulations (TestNet/MainNet, simulate only)
PUBLIC_NETS=1 pytest

Check formatting and linting:

ruff check .
ruff format --check .

License

MIT License. Copyright (c) AI Economy Team.

Metadata

Release files for ai-economy-sdk 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ai-economy-sdk 0.4.1
File Size Uploaded Provenance Actions
ai_economy_sdk-0.4.1.tar.gz 52.5 kB Without provenance Details for ai_economy_sdk-0.4.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ai-economy-sdk 0.4.1
File Interpreter ABI Platform Actions
ai_economy_sdk-0.4.1-py3-none-any.whl Python 3 none any Details for ai_economy_sdk-0.4.1-py3-none-any.whl

Total release size: 86.3 kB

Release files / ai_economy_sdk-0.4.1.tar.gz

Download URL ai_economy_sdk-0.4.1.tar.gz
Size 52.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e18db0fb890735fdae5ae6c58424b9da0d15590d87bda50ca4831377bbfe006a
BLAKE2b-256 checksum
How to use checksums
aeeda188db257f3339c8769ab248827d1c783597aa9152328e9b1ea6da159bb3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / ai_economy_sdk-0.4.1-py3-none-any.whl

Download URL ai_economy_sdk-0.4.1-py3-none-any.whl
Size 33.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c81a5181acf2de29bd670bed2b43a961c3fd0ce2a3bb113937b9700ce2d60dcc
BLAKE2b-256 checksum
How to use checksums
11429175ebd0cb6bbdc400e051b74c2e3a7068aa7fb821a9d8ccbb93b3f68a69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Security for ai-economy-sdk 0.4.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page