Skip to main content

Bitcoin Stratigraphy MCP Client

Verified, digest-only notarization in five lines

This is the existing independent bitcoin-stratigraphy-mcp-client distribution, not a new runtime. In an async entrypoint, with your existing NIP-98 private_key, pay_invoice, durable async persist_preimage, and independent issuer PEM pin:

from bitcoin_stratigraphy_mcp_client import L402Nip98Transport
async with L402Nip98Transport(private_key, pay_invoice=pay_invoice, persist_preimage=persist_preimage, expected_issuer_public_key=issuer_pin) as client:
    await client.verify_handshake()
    receipt = await client.notarize({"event": "agent-checkpoint"}, label="local-only")
    print(receipt["payloadSha256"])

Only the RFC 8785 canonical UTF-8 SHA-256 {hash} reaches the existing notarize tool. Raw payload and label stay local; hashes are not guaranteed anonymous. Calendar receipts are not confirmed Bitcoin inclusion. The official MCP session, fresh NIP-98 authorization and existing one-retry payment contract are preserved. Existing wallet_handler(L402Challenge) callbacks and exports remain supported.

enforce_handshake=True is the default before paid execution. Explicit False opts out for legacy/custom hosts; unreachable discovery never silently bypasses verification. The package exports async verify_covenant, verify_tool_integrity, verify_handshake, and typed CovenantViolationError / IntegrityViolationError. The full signed covenant must meet the 2100 bps minimum and split.

Honest coverage: server signatures authenticate description hash bytes and the full signed covenant, not tool names, timestamps, schemas or the entire manifest. Optional expected_manifest_sha256 pins the raw manifest bytes; optional expected_tool_schema_hashes pins live unpaid tools/list JCS(inputSchema) SHA-256 hashes. A mismatch fails closed; no schema or whole manifest guarantee is claimed without the respective pin. Results expose signatureCoverage, wholeManifestPinned, inputSchemasPinned, and independentlyPinnedIssuer. A JWKS fetched from the same host is discovery, not an independent pin; boot checks cannot prevent later redeployment.

pay_invoice(bolt11, next_action) and l402_token are optional convenience interfaces. Async persist_preimage(payment_hash, preimage) / on_preimage runs after proof validation and before the single L402 retry; failure blocks retry. Conflicting deterministic next-action instructions fail before wallet access. Unknown payment outcomes and rejected retries never authorize a second automatic wallet payment for that invoice within this transport lifetime. Without a durable hook, cached proofs are in-memory only. Keep proofs out of logs.

Framework adapters and examples

Identity-bound Streamable HTTP for enterprise AI orchestration.

bitcoin-stratigraphy-mcp-client adds NIP-98 Schnorr authentication and an explicit L402 wallet handoff to the official MCP Python SDK. LangChain, CrewAI integrations that consume MCP sessions, and framework-independent orchestrators retain the standard MCP protocol. The adapter does not implement or modify server tools, fleet routing, treasury limits, or settlement policy.

Install

Python 3.10 or newer is required. This distribution is supplied as source; it has not been published to PyPI.

python -m pip install './sdk/python/mcp-client[langchain]'

The existing bitcoin-stratigraphy-enterprise distribution in sdk/python remains independently installable. Both packages can coexist.

LangChain integration: four lines

Provide private_key as a 64-character hexadecimal Schnorr secret from your secret manager, an async wallet_handler following the contract below, and a configured LangChain model. Install LangChain and your chosen model provider separately.

from bitcoin_stratigraphy_mcp_client import L402Nip98Transport
from langchain.agents import create_agent
async with L402Nip98Transport(private_key, wallet_handler).langchain_tools() as tools:
    agent = create_agent(model, tools=tools)

Run await agent.ainvoke(...) inside the same context so the MCP session stays open while tools execute. The helper loads tools from a real mcp.ClientSession, not a replacement agent or a mock tool catalog.

CrewAI Multi-Agent Integration

Install the optional integration in your orchestration application:

python -m pip install './sdk/python/mcp-client[crewai]'

With private_key, wallet_handler and a configured CrewAI llm, this is the complete four-line tool-to-agent integration:

from crewai import Agent
from bitcoin_stratigraphy_mcp_client.crewai import CrewAISwarmTools
with CrewAISwarmTools(private_key, wallet_handler) as tools:
    agent = Agent(role="Treasury auditor", goal="Audit swarm data", backstory="Enterprise risk team", tools=tools, llm=llm)

Keep the context open while running Crew(...).kickoff() or await Crew(...).kickoff_async(). The same tools can be assigned to several agents within that context. Construct a new context for each independent swarm run.

Native tools, unchanged transport. CrewAIMCPTool subclasses crewai.tools.BaseTool. Discovery uses the official MCP tools/list protocol, including pagination; each call forwards the original MCP name and exact validated arguments. CrewAI-safe display names replace punctuation with _; collisions are rejected rather than routed to the wrong tool.

Full schema and result fidelity. Input JSON Schemas, including local $defs, required fields, nested objects and numeric constraints, are retained and validated before a network call or payment. External schema references are rejected to avoid fetching untrusted URLs. MCP text, structured content and other result fields are serialized as JSON for the agent; isError results raise CrewAIToolError. The wrapper disables CrewAI result caching, so repeated paid or stateful calls are not silently replaced with old outputs.

One session owner. A dedicated AnyIO portal owns the HTTP client and MCP session. Sync CrewAI workers and async callers submit work to that loop rather than moving the transport between event loops. Exiting closes the session and transport; retained tool objects cannot execute after exit. Wallet callbacks run on the portal loop, so initialize loop-affine wallet clients inside the callback. Local payment failures are returned to the pending MCP caller through a client-only error envelope and re-raised; no error envelope is sent to the server, no additional payment is attempted, and callers do not hang on a failed background HTTP task.

Optional dependency boundary. Ordinary package imports do not load CrewAI. Import bitcoin_stratigraphy_mcp_client.crewai explicitly when using it. This integration is verified against CrewAI 1.6.1. Install optional framework dependencies in your orchestration application's project, not in the server project: newer CrewAI releases may impose dependency constraints that conflict with the server's unrelated FastAPI tooling. Neither the backend requirements nor the original L402/NIP-98 transport implementation are changed.

Wallet contract and payment safety

from bitcoin_stratigraphy_mcp_client import L402Challenge, L402Nip98Transport

async def wallet_handler(challenge: L402Challenge) -> str:
    # Your orchestrator owns invoice decoding, spend approval and wallet credentials.
    # Validate the invoice's payment hash, amount, destination/network and expiry.
    # Enforce your own per-payment and cumulative budget before authorizing payment.
    return await approved_wallet.pay_invoice(challenge.invoice)

approved_wallet is your application's wallet implementation, not a bundled wallet service. The handler receives the macaroon, Lightning invoice, payment hash, and optional quoted amount_sats. It returns the payment's 32-byte preimage as hexadecimal; raising an exception declines payment. The quoted amount is untrusted metadata, not a wallet spending authorization.

The transport:

  • Signs every HTTP attempt with a NIP-98 kind-27235 event using BIP-340 Schnorr signatures from libsecp256k1 via coincurve.
  • Binds the exact HTTPS URL, method, and non-empty request bytes. A fresh nonce avoids same-second event-ID collisions on replay-protected routes.
  • Uses X-Nostr-Authorization for identity and reserves Authorization for L402 <macaroon>:<preimage>, so the two mechanisms coexist.
  • Requires matching header/body challenge fields and verifies the returned preimage against the challenge payment hash before sending it.
  • Makes at most one paid retry, preserving the original request bytes and signing a fresh event. It never retries ordinary network failures or other HTTP errors.
  • Serializes wallet calls, deduplicates an identical invoice challenge within the transport's bounded in-memory proof cache, and times out the wallet after 120 seconds by default. Wallets must independently deduplicate payments across processes and resolve uncertain/cancelled payments before paying again.
  • Refuses other endpoints, redirects, externally supplied auth headers, and malformed or oversized L402 challenges. Keys, invoices, macaroons and preimages are not logged by this package; configure your own HTTP logging accordingly.

The production endpoint defaults to https://bitcoinstratigraphy.com/mcp. Construct a new transport for each client/session lifetime. Closing it clears cached payment proofs and closes its underlying HTTP transport.

Official MCP client and framework factory hook

L402Nip98Transport subclasses httpx.AsyncBaseTransport, the official MCP SDK's HTTP extension surface. Its session() context manager owns the HTTP client, invokes mcp.client.streamable_http.streamable_http_client, initializes mcp.ClientSession, and closes all resources on exit. SSE and JSON response handling remain with the official SDK.

Alternatively, use transport.http_client_factory as the httpx_client_factory hook in a LangChain Streamable HTTP connection. Supply a new transport per framework connection; do not reuse a closed factory across get_tools() and subsequent independent sessions. Direct session integration above avoids that lifecycle ambiguity.

The adapter handles invoice-bearing L402 challenges only. Hashcash admission challenges without an L402 invoice fail explicitly; they do not trigger wallet payments. Fleet registration, NWC pairing, wallet funding and server-side credit qualification remain separate application responsibilities. A returned L402 credential is never assumed to override the Treasury Firewall.

Verification

The tests use public fixture keys and mocked HTTP only; no network, database, funded wallet, production credentials or backend test changes are required.

PYTHONPATH=sdk/python/mcp-client/src python -m unittest discover -s sdk/python/mcp-client/tests -v
cd sdk/python/mcp-client && python -m mypy src

NIP-98-only tests can run independently without LangChain:

PYTHONPATH=sdk/python/mcp-client/src python -m unittest discover -s sdk/python/mcp-client/tests -p test_nip98.py -v

The optional LangChain test requires the langchain extra. Native CrewAI tests require the crewai extra; without it, that isolated test module is skipped. For full SDK verification, install both extras and the dev extra first.

python -m pip install './sdk/python/mcp-client[langchain,crewai,dev]'
PYTHONPATH=sdk/python/mcp-client/src python -m unittest discover -s sdk/python/mcp-client/tests -v

Licensing

Created & Architected by Charles R. Strogish. Copyright (c) 2026 Charles R. Strogish.

Dual-licensed under AGPL-3.0-only or a separately executed commercial license. See the parent SDK's enterprise terms and the repository license. API payments do not grant commercial software rights.

Metadata

Release files for bitcoin-stratigraphy-mcp-client 0.1.0

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

Source distribution (sdist)

Source distribution for bitcoin-stratigraphy-mcp-client 0.1.0
File Size Uploaded Provenance Actions
bitcoin_stratigraphy_mcp_client-0.1.0.tar.gz 25.1 kB With provenance Details for bitcoin_stratigraphy_mcp_client-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bitcoin-stratigraphy-mcp-client 0.1.0
File Interpreter ABI Platform Actions
bitcoin_stratigraphy_mcp_client-0.1.0-py3-none-any.whl Python 3 none any Details for bitcoin_stratigraphy_mcp_client-0.1.0-py3-none-any.whl

Total release size: 49.3 kB

Release files / bitcoin_stratigraphy_mcp_client-0.1.0.tar.gz

Download URL bitcoin_stratigraphy_mcp_client-0.1.0.tar.gz
Size 25.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7215e0ef36b89d04a1297529dd48bf4b89edfe091390cb304031fa81e05cb309
BLAKE2b-256 checksum
How to use checksums
1a8a7e1110ba4a0b8f04efcc6ee4ce6bf55a8553e4bb630ca2b3c5354a6e8a8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / bitcoin_stratigraphy_mcp_client-0.1.0-py3-none-any.whl

Download URL bitcoin_stratigraphy_mcp_client-0.1.0-py3-none-any.whl
Size 24.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
79c7132fd4566fb2a75952adf20991f0ae3f466dbf50fb02dcdbe2aeb5e10cca
BLAKE2b-256 checksum
How to use checksums
0ddb3cfee892dbe00731f61d156bbc667f78d96e47d419bcf1412d02218505fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Security for bitcoin-stratigraphy-mcp-client 0.1.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for bitcoin_stratigraphy_mcp_client-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

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