MCP server implementing cryptographic micropayment authorization via EIP-191 message signing
Project description
shack-payment-gateway
An MCP server that gates tool calls behind cryptographic micropayment authorization using Ethereum EIP-191 personal message signing.
Speaks JSON-RPC 2.0 over stdio. STDOUT carries only protocol messages; all diagnostic logs go to STDERR.
What it does
- A client that wants to call a paid tool first calls
request_authorization, which returns a unique challenge string (timestamp + random nonce). - The client signs that challenge with their Ethereum private key using the
EIP-191
personal_signscheme and obtains a 65-byte signature. - The client calls
verify_payment, passing the original challenge and the signature. The server recovers the signer's Ethereum address via ECDSA key recovery and compares it against the configured authorized wallet. - If the addresses match,
verified: trueis returned. Otherwiseverified: falseis returned.
In permissive mode (no --authorized-wallet flag), any valid signature
is accepted and the recovered address is returned as authorized. This mode
is useful for development and testing.
MCP tools
| Tool | Arguments | Description |
|---|---|---|
request_authorization |
tool_name (string), cost (string) |
Returns a unique EIP-191 challenge string the client must sign before calling a paid tool. cost must be a parseable decimal number (e.g. "1.5"). |
verify_payment |
challenge (string), signature (string) |
Verifies the EIP-191 signature against the challenge. Returns verified, recovered_address, and authorized_address. |
Configuration / CLI flags
| Flag | Env var | Default | Description |
|---|---|---|---|
--authorized-wallet <addr> |
SHACK_AUTHORIZED_WALLET |
(none) | Ethereum address that verify_payment accepts. Omit to run in permissive mode. |
Install
pip install .
Or in a virtual environment:
python -m venv .venv
source .venv/bin/activate
pip install .
Run
# Permissive mode (any valid signature is authorized):
shack-payment-gateway
# With a specific authorized wallet:
shack-payment-gateway --authorized-wallet 0xYourWalletAddress
# Via environment variable:
SHACK_AUTHORIZED_WALLET=0xYourWalletAddress shack-payment-gateway
Tests
# With the bundled virtual environment:
.venv/bin/python -m pytest -q
# Or with a system/global pytest:
pip install pytest
pytest
Usage example
The following shows a complete JSON-RPC 2.0 exchange. Each JSON object is sent as a single newline-terminated line on STDIN; responses arrive on STDOUT.
Step 1 — request a challenge:
{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"request_authorization","arguments":{"tool_name":"my_paid_tool","cost":"1.5"}}}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"content": [{
"type": "text",
"text": "{\"challenge\":\"Authorize execution of tool: my_paid_tool costing 1.5 Shack-Credits. Timestamp: 1716307200. Nonce: 4f3a2b1c...\",\"tool_name\":\"my_paid_tool\",\"cost\":\"1.5\"}"
}]
}
}
Step 2 — sign the challenge with your Ethereum private key (client-side,
not handled by this server) and call verify_payment:
{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"verify_payment","arguments":{"challenge":"Authorize execution of tool: my_paid_tool costing 1.5 Shack-Credits. Timestamp: 1716307200. Nonce: 4f3a2b1c...","signature":"0xe9d4cfdd...1b"}}}
Response (permissive mode):
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"content": [{
"type": "text",
"text": "{\"verified\":true,\"recovered_address\":\"0x1a642f0e3c3af545e7acbd38b07251b3990914f1\",\"authorized_address\":null}"
}]
}
}
License
Apache-2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file shack_payment_gateway-0.1.0.tar.gz.
File metadata
- Download URL: shack_payment_gateway-0.1.0.tar.gz
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d98e90792b13664b44ed35d9929a75c14e970b7b919ec3e4c968ec72663c027f
|
|
| MD5 |
aab32e0543818756ce0a7b145dae3180
|
|
| BLAKE2b-256 |
f3970a00e2d3c46643e99d6b339f378fa4cf9c59645fca1d851d28c47f6f5e9a
|
File details
Details for the file shack_payment_gateway-0.1.0-py3-none-any.whl.
File metadata
- Download URL: shack_payment_gateway-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ee78ac83e0af2915c0dad3797bb75adb87b1362b5798dcf74b5c42582624dbd
|
|
| MD5 |
a7f6a07745d9f9378aefcbc06da87ac4
|
|
| BLAKE2b-256 |
0c04e9396653835d58bbcf02694ec83f5e8425feca5f8b7d02ccaa08b3cbd870
|