Skip to main content

Billing SDK for MCP servers

Project description

metrify-sdk

Billing infrastructure for MCP servers. Add one decorator. Start charging. Get paid in USDT.


Installation

pip install metrify-sdk

Requires Python 3.8+


Quickstart (Provider)

Step 1 — Register at metrify.dev and get your pk_live_... provider key.

Step 2 — Install the SDK:

pip install metrify-sdk

Step 3 — Decorate your tools:

from metrify import Metrify
from mcp.server.fastmcp import FastMCP

mcp = FastMCP("my-mcp-server")
m = Metrify(provider_key="your_provider_key")

@mcp.tool()
@m.tool(price=0.01, description="Search the web for a query")
def search(query: str) -> str:
    # Your logic here
    return f"Results for: {query}"

if __name__ == "__main__":
    mcp.run(transport="streamable-http")

How billing works

When a consumer calls your tool, Metrify verifies their balance before execution. If sufficient, the tool runs. On success, the consumer wallet is debited atomically: 95% goes to you, 5% to Metrify. If your tool raises an exception, the consumer is not charged.

Consumer wallet → [Metrify] → Provider wallet
    $0.01000           ↓          $0.00950
                  fee: $0.00050

@m.tool() parameters

Parameter Type Required Description
price float Cost per call in USDT
description str Tool description shown to agents

Policy: no charge on upstream error

If your tool raises any exception, the consumer is not charged. Raise UpstreamError explicitly when an external API you depend on fails:

from metrify import Metrify, UpstreamError

m = Metrify(provider_key="your_provider_key")

@m.tool(price=0.05, description="Summarize text using an LLM")
async def summarize(text: str) -> str:
    try:
        result = await llm_client.complete(text)
    except Exception as e:
        raise UpstreamError(f"LLM unavailable: {e}")
    return result

The consumer receives your error message and is not charged. Idempotency keys are implemented from day one — duplicate charges are impossible.


Provider registration

metrify.dev — currently invite-only waitlist.


Links


License

MIT

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

metrify_sdk-0.2.3.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

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

metrify_sdk-0.2.3-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file metrify_sdk-0.2.3.tar.gz.

File metadata

  • Download URL: metrify_sdk-0.2.3.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.4

File hashes

Hashes for metrify_sdk-0.2.3.tar.gz
Algorithm Hash digest
SHA256 085870213d8ae08274ebd415445099b8848b07a1d31a74d5775caf061642132f
MD5 effba71bfb3c769759c0fd63b17918e1
BLAKE2b-256 fe0dd089f43bdb30f7473bb13a65140c1510a52b07434e585b6cbe8ad79e0215

See more details on using hashes here.

File details

Details for the file metrify_sdk-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: metrify_sdk-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.4

File hashes

Hashes for metrify_sdk-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0968f64a387d705def8064d0ebdcf6160f3fb99e38a803312c7e72ae61aa9fa6
MD5 c21c665dffe7624d7c1073910781cbf4
BLAKE2b-256 bb2d20a400885b65b692b126415ce712c01926a14ea833e4e883e30bb38de5a2

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