lightning-enable-mcp 1.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lightning_enable_mcp-1.1.0/.gitignore +95 -0
- lightning_enable_mcp-1.1.0/LICENSE +21 -0
- lightning_enable_mcp-1.1.0/PKG-INFO +314 -0
- lightning_enable_mcp-1.1.0/README.md +273 -0
- lightning_enable_mcp-1.1.0/pyproject.toml +110 -0
- lightning_enable_mcp-1.1.0/src/lightning_enable_mcp/__init__.py +48 -0
- lightning_enable_mcp-1.1.0/src/lightning_enable_mcp/budget.py +207 -0
- lightning_enable_mcp-1.1.0/src/lightning_enable_mcp/l402_client.py +257 -0
- lightning_enable_mcp-1.1.0/src/lightning_enable_mcp/license.py +301 -0
- lightning_enable_mcp-1.1.0/src/lightning_enable_mcp/nwc_wallet.py +492 -0
- lightning_enable_mcp-1.1.0/src/lightning_enable_mcp/opennode_wallet.py +269 -0
- lightning_enable_mcp-1.1.0/src/lightning_enable_mcp/py.typed +0 -0
- lightning_enable_mcp-1.1.0/src/lightning_enable_mcp/server.py +656 -0
- lightning_enable_mcp-1.1.0/src/lightning_enable_mcp/strike_wallet.py +608 -0
- lightning_enable_mcp-1.1.0/src/lightning_enable_mcp/tools/__init__.py +24 -0
- lightning_enable_mcp-1.1.0/src/lightning_enable_mcp/tools/access_resource.py +111 -0
- lightning_enable_mcp-1.1.0/src/lightning_enable_mcp/tools/budget.py +159 -0
- lightning_enable_mcp-1.1.0/src/lightning_enable_mcp/tools/license.py +335 -0
- lightning_enable_mcp-1.1.0/src/lightning_enable_mcp/tools/pay_challenge.py +118 -0
- lightning_enable_mcp-1.1.0/src/lightning_enable_mcp/tools/pay_invoice.py +134 -0
- lightning_enable_mcp-1.1.0/src/lightning_enable_mcp/tools/wallet.py +59 -0
- lightning_enable_mcp-1.1.0/tests/__init__.py +1 -0
- lightning_enable_mcp-1.1.0/tests/test_budget.py +226 -0
- lightning_enable_mcp-1.1.0/tests/test_l402_client.py +122 -0
- lightning_enable_mcp-1.1.0/tests/test_nwc_wallet.py +83 -0
- lightning_enable_mcp-1.1.0/tests/test_pay_invoice.py +354 -0
- lightning_enable_mcp-1.1.0/tests/test_server.py +107 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
*.egg-info/
|
|
24
|
+
.installed.cfg
|
|
25
|
+
*.egg
|
|
26
|
+
|
|
27
|
+
# PyInstaller
|
|
28
|
+
*.manifest
|
|
29
|
+
*.spec
|
|
30
|
+
|
|
31
|
+
# Installer logs
|
|
32
|
+
pip-log.txt
|
|
33
|
+
pip-delete-this-directory.txt
|
|
34
|
+
|
|
35
|
+
# Unit test / coverage reports
|
|
36
|
+
htmlcov/
|
|
37
|
+
.tox/
|
|
38
|
+
.nox/
|
|
39
|
+
.coverage
|
|
40
|
+
.coverage.*
|
|
41
|
+
.cache
|
|
42
|
+
nosetests.xml
|
|
43
|
+
coverage.xml
|
|
44
|
+
*.cover
|
|
45
|
+
*.py,cover
|
|
46
|
+
.hypothesis/
|
|
47
|
+
.pytest_cache/
|
|
48
|
+
|
|
49
|
+
# Translations
|
|
50
|
+
*.mo
|
|
51
|
+
*.pot
|
|
52
|
+
|
|
53
|
+
# Sphinx documentation
|
|
54
|
+
docs/_build/
|
|
55
|
+
|
|
56
|
+
# PyBuilder
|
|
57
|
+
target/
|
|
58
|
+
|
|
59
|
+
# Jupyter Notebook
|
|
60
|
+
.ipynb_checkpoints
|
|
61
|
+
|
|
62
|
+
# IPython
|
|
63
|
+
profile_default/
|
|
64
|
+
ipython_config.py
|
|
65
|
+
|
|
66
|
+
# pyenv
|
|
67
|
+
.python-version
|
|
68
|
+
|
|
69
|
+
# Environments
|
|
70
|
+
.env
|
|
71
|
+
.venv
|
|
72
|
+
env/
|
|
73
|
+
venv/
|
|
74
|
+
ENV/
|
|
75
|
+
env.bak/
|
|
76
|
+
venv.bak/
|
|
77
|
+
|
|
78
|
+
# mypy
|
|
79
|
+
.mypy_cache/
|
|
80
|
+
.dmypy.json
|
|
81
|
+
dmypy.json
|
|
82
|
+
|
|
83
|
+
# Ruff
|
|
84
|
+
.ruff_cache/
|
|
85
|
+
|
|
86
|
+
# IDE
|
|
87
|
+
.idea/
|
|
88
|
+
.vscode/
|
|
89
|
+
*.swp
|
|
90
|
+
*.swo
|
|
91
|
+
*~
|
|
92
|
+
|
|
93
|
+
# OS
|
|
94
|
+
.DS_Store
|
|
95
|
+
Thumbs.db
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Lightning Enable
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lightning-enable-mcp
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: MCP server for L402 Lightning payments - access paid APIs with AI agents
|
|
5
|
+
Project-URL: Homepage, https://lightningenable.com
|
|
6
|
+
Project-URL: Documentation, https://github.com/refinedelement/lightning-enable-mcp
|
|
7
|
+
Project-URL: Repository, https://github.com/refinedelement/lightning-enable-mcp
|
|
8
|
+
Project-URL: Issues, https://github.com/refinedelement/lightning-enable-mcp/issues
|
|
9
|
+
Author-email: Lightning Enable <support@lightningenable.com>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: agents,ai,bitcoin,l402,lightning,lsat,mcp,model-context-protocol,nostr,nwc,payments
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
22
|
+
Classifier: Topic :: Office/Business :: Financial :: Point-Of-Sale
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Requires-Dist: aiohttp>=3.9.0
|
|
26
|
+
Requires-Dist: bech32>=1.2.0
|
|
27
|
+
Requires-Dist: bolt11>=2.0.0
|
|
28
|
+
Requires-Dist: cryptography>=41.0.0
|
|
29
|
+
Requires-Dist: httpx>=0.25.0
|
|
30
|
+
Requires-Dist: mcp>=1.0.0
|
|
31
|
+
Requires-Dist: pydantic>=2.0.0
|
|
32
|
+
Requires-Dist: secp256k1>=0.14.0
|
|
33
|
+
Requires-Dist: websockets>=12.0
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: mypy>=1.0.0; extra == 'dev'
|
|
36
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
|
|
37
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
|
|
38
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
39
|
+
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
40
|
+
Description-Content-Type: text/markdown
|
|
41
|
+
|
|
42
|
+
# Lightning Enable MCP Server
|
|
43
|
+
|
|
44
|
+
An MCP (Model Context Protocol) server that enables AI agents to access L402-protected APIs with automatic Lightning Network payments.
|
|
45
|
+
|
|
46
|
+
## Overview
|
|
47
|
+
|
|
48
|
+
Lightning Enable MCP provides tools for AI agents (like Claude) to:
|
|
49
|
+
|
|
50
|
+
- **Access paid APIs** - Automatically handle L402 payment challenges
|
|
51
|
+
- **Manage Lightning payments** - Pay invoices via Nostr Wallet Connect (NWC)
|
|
52
|
+
- **Control spending** - Set per-request and session budgets
|
|
53
|
+
- **Track payments** - View payment history and wallet balance
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
### Using pip
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install lightning-enable-mcp
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Using uvx (recommended for Claude Desktop)
|
|
64
|
+
|
|
65
|
+
No installation needed - uvx handles it automatically.
|
|
66
|
+
|
|
67
|
+
## Configuration
|
|
68
|
+
|
|
69
|
+
### Environment Variables
|
|
70
|
+
|
|
71
|
+
| Variable | Required | Default | Description |
|
|
72
|
+
|----------|----------|---------|-------------|
|
|
73
|
+
| `NWC_CONNECTION_STRING` | Yes* | - | Nostr Wallet Connect URI |
|
|
74
|
+
| `OPENNODE_API_KEY` | Yes* | - | OpenNode API key (alternative to NWC) |
|
|
75
|
+
| `OPENNODE_ENVIRONMENT` | No | production | "production" or "dev" for testnet |
|
|
76
|
+
| `L402_MAX_SATS_PER_REQUEST` | No | 1000 | Maximum sats per single request |
|
|
77
|
+
| `L402_MAX_SATS_PER_SESSION` | No | 10000 | Maximum sats for entire session |
|
|
78
|
+
|
|
79
|
+
*Either `NWC_CONNECTION_STRING` or `OPENNODE_API_KEY` is required. NWC takes precedence if both are set.
|
|
80
|
+
|
|
81
|
+
### Wallet Options
|
|
82
|
+
|
|
83
|
+
#### Option 1: OpenNode (Recommended for Testing)
|
|
84
|
+
|
|
85
|
+
Use your OpenNode account to pay invoices. Great for testing since you likely already have an OpenNode account if you're using Lightning Enable.
|
|
86
|
+
|
|
87
|
+
1. Get your API key from https://app.opennode.com (or https://app.dev.opennode.com for testnet)
|
|
88
|
+
2. Ensure the API key has withdrawal permissions
|
|
89
|
+
3. Fund your OpenNode account
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
export OPENNODE_API_KEY="your-api-key"
|
|
93
|
+
export OPENNODE_ENVIRONMENT="dev" # Use testnet for testing
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
#### Option 2: Nostr Wallet Connect (NWC)
|
|
97
|
+
|
|
98
|
+
NWC allows this server to pay invoices using your Lightning wallet. You can get a connection string from:
|
|
99
|
+
|
|
100
|
+
1. **Alby** - https://getalby.com (Browser extension or Alby Hub)
|
|
101
|
+
2. **Mutiny Wallet** - https://mutinywallet.com
|
|
102
|
+
3. **Coinos** - https://coinos.io
|
|
103
|
+
4. **Any NWC-compatible wallet**
|
|
104
|
+
|
|
105
|
+
The connection string looks like:
|
|
106
|
+
```
|
|
107
|
+
nostr+walletconnect://pubkey?relay=wss://relay.example.com&secret=hexsecret
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Claude Desktop Configuration
|
|
111
|
+
|
|
112
|
+
Add to your Claude Desktop config (`claude_desktop_config.json`):
|
|
113
|
+
|
|
114
|
+
**Using OpenNode:**
|
|
115
|
+
```json
|
|
116
|
+
{
|
|
117
|
+
"mcpServers": {
|
|
118
|
+
"lightning-enable": {
|
|
119
|
+
"command": "uvx",
|
|
120
|
+
"args": ["lightning-enable-mcp"],
|
|
121
|
+
"env": {
|
|
122
|
+
"OPENNODE_API_KEY": "your-opennode-api-key",
|
|
123
|
+
"OPENNODE_ENVIRONMENT": "dev"
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
**Using NWC:**
|
|
131
|
+
```json
|
|
132
|
+
{
|
|
133
|
+
"mcpServers": {
|
|
134
|
+
"lightning-enable": {
|
|
135
|
+
"command": "uvx",
|
|
136
|
+
"args": ["lightning-enable-mcp"],
|
|
137
|
+
"env": {
|
|
138
|
+
"NWC_CONNECTION_STRING": "nostr+walletconnect://your-pubkey?relay=wss://relay.getalby.com/v1&secret=your-secret"
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Or if installed via pip, replace `"command": "uvx", "args": ["lightning-enable-mcp"]` with just `"command": "lightning-enable-mcp"`.
|
|
146
|
+
|
|
147
|
+
## Available Tools
|
|
148
|
+
|
|
149
|
+
### access_l402_resource
|
|
150
|
+
|
|
151
|
+
Fetch a URL with automatic L402 payment handling.
|
|
152
|
+
|
|
153
|
+
**Parameters:**
|
|
154
|
+
| Name | Type | Required | Default | Description |
|
|
155
|
+
|------|------|----------|---------|-------------|
|
|
156
|
+
| `url` | string | Yes | - | The URL to fetch |
|
|
157
|
+
| `method` | string | No | GET | HTTP method (GET, POST, PUT, DELETE) |
|
|
158
|
+
| `headers` | object | No | {} | Additional request headers |
|
|
159
|
+
| `body` | string | No | - | Request body for POST/PUT |
|
|
160
|
+
| `max_sats` | integer | No | 1000 | Maximum sats to pay for this request |
|
|
161
|
+
|
|
162
|
+
**Example:**
|
|
163
|
+
```
|
|
164
|
+
Use access_l402_resource to fetch https://api.example.com/premium-data
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
**Returns:** Response body text or error message
|
|
168
|
+
|
|
169
|
+
### pay_l402_challenge
|
|
170
|
+
|
|
171
|
+
Manually pay an L402 invoice and get the authorization token.
|
|
172
|
+
|
|
173
|
+
**Parameters:**
|
|
174
|
+
| Name | Type | Required | Default | Description |
|
|
175
|
+
|------|------|----------|---------|-------------|
|
|
176
|
+
| `invoice` | string | Yes | - | BOLT11 invoice string |
|
|
177
|
+
| `macaroon` | string | Yes | - | Base64-encoded macaroon from L402 challenge |
|
|
178
|
+
| `max_sats` | integer | No | 1000 | Maximum sats allowed for this payment |
|
|
179
|
+
|
|
180
|
+
**Returns:** L402 token in format `macaroon:preimage` for use in Authorization header
|
|
181
|
+
|
|
182
|
+
### check_wallet_balance
|
|
183
|
+
|
|
184
|
+
Check the connected wallet balance via NWC.
|
|
185
|
+
|
|
186
|
+
**Parameters:** None
|
|
187
|
+
|
|
188
|
+
**Returns:** Current balance in satoshis
|
|
189
|
+
|
|
190
|
+
### get_payment_history
|
|
191
|
+
|
|
192
|
+
List recent L402 payments made during this session.
|
|
193
|
+
|
|
194
|
+
**Parameters:**
|
|
195
|
+
| Name | Type | Required | Default | Description |
|
|
196
|
+
|------|------|----------|---------|-------------|
|
|
197
|
+
| `limit` | integer | No | 10 | Maximum number of payments to return |
|
|
198
|
+
| `since` | string | No | - | ISO timestamp to filter payments from |
|
|
199
|
+
|
|
200
|
+
**Returns:** List of payments with url, amount, timestamp, and status
|
|
201
|
+
|
|
202
|
+
### configure_budget
|
|
203
|
+
|
|
204
|
+
Set spending limits for the session.
|
|
205
|
+
|
|
206
|
+
**Parameters:**
|
|
207
|
+
| Name | Type | Required | Default | Description |
|
|
208
|
+
|------|------|----------|---------|-------------|
|
|
209
|
+
| `per_request` | integer | No | 1000 | Maximum sats per individual request |
|
|
210
|
+
| `per_session` | integer | No | 10000 | Maximum total sats for the session |
|
|
211
|
+
|
|
212
|
+
**Returns:** Confirmation of new limits
|
|
213
|
+
|
|
214
|
+
### pay_invoice
|
|
215
|
+
|
|
216
|
+
Pay a Lightning invoice directly and get the preimage as proof of payment. Use this to pay any BOLT11 Lightning invoice without L402 protocol overhead.
|
|
217
|
+
|
|
218
|
+
**Parameters:**
|
|
219
|
+
| Name | Type | Required | Default | Description |
|
|
220
|
+
|------|------|----------|---------|-------------|
|
|
221
|
+
| `invoice` | string | Yes | - | BOLT11 Lightning invoice string to pay |
|
|
222
|
+
| `max_sats` | integer | No | 1000 | Maximum sats allowed to pay |
|
|
223
|
+
|
|
224
|
+
**Example:**
|
|
225
|
+
```
|
|
226
|
+
Use pay_invoice to pay lnbc100n1pj9npjpp5... with max_sats 500
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
**Returns:** JSON with payment result including:
|
|
230
|
+
- `success`: boolean - Whether payment succeeded
|
|
231
|
+
- `preimage`: string - Payment preimage (proof of payment)
|
|
232
|
+
- `message`: string - Status message
|
|
233
|
+
- `invoice.paid`: string - Truncated invoice that was paid
|
|
234
|
+
|
|
235
|
+
## How L402 Works
|
|
236
|
+
|
|
237
|
+
L402 (formerly LSAT) is a protocol for API monetization using Lightning Network:
|
|
238
|
+
|
|
239
|
+
1. Client requests a resource
|
|
240
|
+
2. Server returns `402 Payment Required` with a `WWW-Authenticate` header containing:
|
|
241
|
+
- A macaroon (authorization token)
|
|
242
|
+
- A BOLT11 Lightning invoice
|
|
243
|
+
3. Client pays the invoice, receiving a preimage
|
|
244
|
+
4. Client retries the request with `Authorization: L402 <macaroon>:<preimage>`
|
|
245
|
+
5. Server validates and returns the resource
|
|
246
|
+
|
|
247
|
+
This MCP server handles steps 2-5 automatically when you use `access_l402_resource`.
|
|
248
|
+
|
|
249
|
+
## Security Considerations
|
|
250
|
+
|
|
251
|
+
- **Budget Limits**: Always set appropriate spending limits for your use case
|
|
252
|
+
- **NWC Secret**: Keep your NWC connection string secure - it allows payments from your wallet
|
|
253
|
+
- **Session Isolation**: Each server instance maintains its own budget and payment history
|
|
254
|
+
- **Invoice Verification**: The server verifies invoice amounts before paying
|
|
255
|
+
|
|
256
|
+
## Development
|
|
257
|
+
|
|
258
|
+
### Setup
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
git clone https://github.com/refinedelement/lightning-enable-mcp
|
|
262
|
+
cd lightning-enable-mcp
|
|
263
|
+
pip install -e ".[dev]"
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### Running Tests
|
|
267
|
+
|
|
268
|
+
```bash
|
|
269
|
+
pytest
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Type Checking
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
mypy src/lightning_enable_mcp
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### Linting
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
ruff check src/
|
|
282
|
+
ruff format src/
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## Architecture
|
|
286
|
+
|
|
287
|
+
```
|
|
288
|
+
lightning_enable_mcp/
|
|
289
|
+
├── server.py # Main MCP server and tool registration
|
|
290
|
+
├── l402_client.py # L402 protocol implementation
|
|
291
|
+
├── nwc_wallet.py # Nostr Wallet Connect client
|
|
292
|
+
├── budget.py # Spending limit management
|
|
293
|
+
└── tools/
|
|
294
|
+
├── access_resource.py # access_l402_resource tool
|
|
295
|
+
├── pay_challenge.py # pay_l402_challenge tool
|
|
296
|
+
├── wallet.py # check_wallet_balance tool
|
|
297
|
+
└── budget.py # configure_budget, get_payment_history tools
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
## License
|
|
301
|
+
|
|
302
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
303
|
+
|
|
304
|
+
## Support
|
|
305
|
+
|
|
306
|
+
- **Issues**: https://github.com/refinedelement/lightning-enable-mcp/issues
|
|
307
|
+
- **Documentation**: https://lightningenable.com/docs
|
|
308
|
+
- **Discord**: https://discord.gg/lightningenable
|
|
309
|
+
|
|
310
|
+
## Related Projects
|
|
311
|
+
|
|
312
|
+
- [Lightning Enable](https://lightningenable.com) - Bitcoin Lightning payment API middleware
|
|
313
|
+
- [MCP Specification](https://modelcontextprotocol.io) - Model Context Protocol
|
|
314
|
+
- [NIP-47](https://github.com/nostr-protocol/nips/blob/master/47.md) - Nostr Wallet Connect
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
# Lightning Enable MCP Server
|
|
2
|
+
|
|
3
|
+
An MCP (Model Context Protocol) server that enables AI agents to access L402-protected APIs with automatic Lightning Network payments.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Lightning Enable MCP provides tools for AI agents (like Claude) to:
|
|
8
|
+
|
|
9
|
+
- **Access paid APIs** - Automatically handle L402 payment challenges
|
|
10
|
+
- **Manage Lightning payments** - Pay invoices via Nostr Wallet Connect (NWC)
|
|
11
|
+
- **Control spending** - Set per-request and session budgets
|
|
12
|
+
- **Track payments** - View payment history and wallet balance
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
### Using pip
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install lightning-enable-mcp
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Using uvx (recommended for Claude Desktop)
|
|
23
|
+
|
|
24
|
+
No installation needed - uvx handles it automatically.
|
|
25
|
+
|
|
26
|
+
## Configuration
|
|
27
|
+
|
|
28
|
+
### Environment Variables
|
|
29
|
+
|
|
30
|
+
| Variable | Required | Default | Description |
|
|
31
|
+
|----------|----------|---------|-------------|
|
|
32
|
+
| `NWC_CONNECTION_STRING` | Yes* | - | Nostr Wallet Connect URI |
|
|
33
|
+
| `OPENNODE_API_KEY` | Yes* | - | OpenNode API key (alternative to NWC) |
|
|
34
|
+
| `OPENNODE_ENVIRONMENT` | No | production | "production" or "dev" for testnet |
|
|
35
|
+
| `L402_MAX_SATS_PER_REQUEST` | No | 1000 | Maximum sats per single request |
|
|
36
|
+
| `L402_MAX_SATS_PER_SESSION` | No | 10000 | Maximum sats for entire session |
|
|
37
|
+
|
|
38
|
+
*Either `NWC_CONNECTION_STRING` or `OPENNODE_API_KEY` is required. NWC takes precedence if both are set.
|
|
39
|
+
|
|
40
|
+
### Wallet Options
|
|
41
|
+
|
|
42
|
+
#### Option 1: OpenNode (Recommended for Testing)
|
|
43
|
+
|
|
44
|
+
Use your OpenNode account to pay invoices. Great for testing since you likely already have an OpenNode account if you're using Lightning Enable.
|
|
45
|
+
|
|
46
|
+
1. Get your API key from https://app.opennode.com (or https://app.dev.opennode.com for testnet)
|
|
47
|
+
2. Ensure the API key has withdrawal permissions
|
|
48
|
+
3. Fund your OpenNode account
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
export OPENNODE_API_KEY="your-api-key"
|
|
52
|
+
export OPENNODE_ENVIRONMENT="dev" # Use testnet for testing
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
#### Option 2: Nostr Wallet Connect (NWC)
|
|
56
|
+
|
|
57
|
+
NWC allows this server to pay invoices using your Lightning wallet. You can get a connection string from:
|
|
58
|
+
|
|
59
|
+
1. **Alby** - https://getalby.com (Browser extension or Alby Hub)
|
|
60
|
+
2. **Mutiny Wallet** - https://mutinywallet.com
|
|
61
|
+
3. **Coinos** - https://coinos.io
|
|
62
|
+
4. **Any NWC-compatible wallet**
|
|
63
|
+
|
|
64
|
+
The connection string looks like:
|
|
65
|
+
```
|
|
66
|
+
nostr+walletconnect://pubkey?relay=wss://relay.example.com&secret=hexsecret
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Claude Desktop Configuration
|
|
70
|
+
|
|
71
|
+
Add to your Claude Desktop config (`claude_desktop_config.json`):
|
|
72
|
+
|
|
73
|
+
**Using OpenNode:**
|
|
74
|
+
```json
|
|
75
|
+
{
|
|
76
|
+
"mcpServers": {
|
|
77
|
+
"lightning-enable": {
|
|
78
|
+
"command": "uvx",
|
|
79
|
+
"args": ["lightning-enable-mcp"],
|
|
80
|
+
"env": {
|
|
81
|
+
"OPENNODE_API_KEY": "your-opennode-api-key",
|
|
82
|
+
"OPENNODE_ENVIRONMENT": "dev"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**Using NWC:**
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"mcpServers": {
|
|
93
|
+
"lightning-enable": {
|
|
94
|
+
"command": "uvx",
|
|
95
|
+
"args": ["lightning-enable-mcp"],
|
|
96
|
+
"env": {
|
|
97
|
+
"NWC_CONNECTION_STRING": "nostr+walletconnect://your-pubkey?relay=wss://relay.getalby.com/v1&secret=your-secret"
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Or if installed via pip, replace `"command": "uvx", "args": ["lightning-enable-mcp"]` with just `"command": "lightning-enable-mcp"`.
|
|
105
|
+
|
|
106
|
+
## Available Tools
|
|
107
|
+
|
|
108
|
+
### access_l402_resource
|
|
109
|
+
|
|
110
|
+
Fetch a URL with automatic L402 payment handling.
|
|
111
|
+
|
|
112
|
+
**Parameters:**
|
|
113
|
+
| Name | Type | Required | Default | Description |
|
|
114
|
+
|------|------|----------|---------|-------------|
|
|
115
|
+
| `url` | string | Yes | - | The URL to fetch |
|
|
116
|
+
| `method` | string | No | GET | HTTP method (GET, POST, PUT, DELETE) |
|
|
117
|
+
| `headers` | object | No | {} | Additional request headers |
|
|
118
|
+
| `body` | string | No | - | Request body for POST/PUT |
|
|
119
|
+
| `max_sats` | integer | No | 1000 | Maximum sats to pay for this request |
|
|
120
|
+
|
|
121
|
+
**Example:**
|
|
122
|
+
```
|
|
123
|
+
Use access_l402_resource to fetch https://api.example.com/premium-data
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**Returns:** Response body text or error message
|
|
127
|
+
|
|
128
|
+
### pay_l402_challenge
|
|
129
|
+
|
|
130
|
+
Manually pay an L402 invoice and get the authorization token.
|
|
131
|
+
|
|
132
|
+
**Parameters:**
|
|
133
|
+
| Name | Type | Required | Default | Description |
|
|
134
|
+
|------|------|----------|---------|-------------|
|
|
135
|
+
| `invoice` | string | Yes | - | BOLT11 invoice string |
|
|
136
|
+
| `macaroon` | string | Yes | - | Base64-encoded macaroon from L402 challenge |
|
|
137
|
+
| `max_sats` | integer | No | 1000 | Maximum sats allowed for this payment |
|
|
138
|
+
|
|
139
|
+
**Returns:** L402 token in format `macaroon:preimage` for use in Authorization header
|
|
140
|
+
|
|
141
|
+
### check_wallet_balance
|
|
142
|
+
|
|
143
|
+
Check the connected wallet balance via NWC.
|
|
144
|
+
|
|
145
|
+
**Parameters:** None
|
|
146
|
+
|
|
147
|
+
**Returns:** Current balance in satoshis
|
|
148
|
+
|
|
149
|
+
### get_payment_history
|
|
150
|
+
|
|
151
|
+
List recent L402 payments made during this session.
|
|
152
|
+
|
|
153
|
+
**Parameters:**
|
|
154
|
+
| Name | Type | Required | Default | Description |
|
|
155
|
+
|------|------|----------|---------|-------------|
|
|
156
|
+
| `limit` | integer | No | 10 | Maximum number of payments to return |
|
|
157
|
+
| `since` | string | No | - | ISO timestamp to filter payments from |
|
|
158
|
+
|
|
159
|
+
**Returns:** List of payments with url, amount, timestamp, and status
|
|
160
|
+
|
|
161
|
+
### configure_budget
|
|
162
|
+
|
|
163
|
+
Set spending limits for the session.
|
|
164
|
+
|
|
165
|
+
**Parameters:**
|
|
166
|
+
| Name | Type | Required | Default | Description |
|
|
167
|
+
|------|------|----------|---------|-------------|
|
|
168
|
+
| `per_request` | integer | No | 1000 | Maximum sats per individual request |
|
|
169
|
+
| `per_session` | integer | No | 10000 | Maximum total sats for the session |
|
|
170
|
+
|
|
171
|
+
**Returns:** Confirmation of new limits
|
|
172
|
+
|
|
173
|
+
### pay_invoice
|
|
174
|
+
|
|
175
|
+
Pay a Lightning invoice directly and get the preimage as proof of payment. Use this to pay any BOLT11 Lightning invoice without L402 protocol overhead.
|
|
176
|
+
|
|
177
|
+
**Parameters:**
|
|
178
|
+
| Name | Type | Required | Default | Description |
|
|
179
|
+
|------|------|----------|---------|-------------|
|
|
180
|
+
| `invoice` | string | Yes | - | BOLT11 Lightning invoice string to pay |
|
|
181
|
+
| `max_sats` | integer | No | 1000 | Maximum sats allowed to pay |
|
|
182
|
+
|
|
183
|
+
**Example:**
|
|
184
|
+
```
|
|
185
|
+
Use pay_invoice to pay lnbc100n1pj9npjpp5... with max_sats 500
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
**Returns:** JSON with payment result including:
|
|
189
|
+
- `success`: boolean - Whether payment succeeded
|
|
190
|
+
- `preimage`: string - Payment preimage (proof of payment)
|
|
191
|
+
- `message`: string - Status message
|
|
192
|
+
- `invoice.paid`: string - Truncated invoice that was paid
|
|
193
|
+
|
|
194
|
+
## How L402 Works
|
|
195
|
+
|
|
196
|
+
L402 (formerly LSAT) is a protocol for API monetization using Lightning Network:
|
|
197
|
+
|
|
198
|
+
1. Client requests a resource
|
|
199
|
+
2. Server returns `402 Payment Required` with a `WWW-Authenticate` header containing:
|
|
200
|
+
- A macaroon (authorization token)
|
|
201
|
+
- A BOLT11 Lightning invoice
|
|
202
|
+
3. Client pays the invoice, receiving a preimage
|
|
203
|
+
4. Client retries the request with `Authorization: L402 <macaroon>:<preimage>`
|
|
204
|
+
5. Server validates and returns the resource
|
|
205
|
+
|
|
206
|
+
This MCP server handles steps 2-5 automatically when you use `access_l402_resource`.
|
|
207
|
+
|
|
208
|
+
## Security Considerations
|
|
209
|
+
|
|
210
|
+
- **Budget Limits**: Always set appropriate spending limits for your use case
|
|
211
|
+
- **NWC Secret**: Keep your NWC connection string secure - it allows payments from your wallet
|
|
212
|
+
- **Session Isolation**: Each server instance maintains its own budget and payment history
|
|
213
|
+
- **Invoice Verification**: The server verifies invoice amounts before paying
|
|
214
|
+
|
|
215
|
+
## Development
|
|
216
|
+
|
|
217
|
+
### Setup
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
git clone https://github.com/refinedelement/lightning-enable-mcp
|
|
221
|
+
cd lightning-enable-mcp
|
|
222
|
+
pip install -e ".[dev]"
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Running Tests
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
pytest
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Type Checking
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
mypy src/lightning_enable_mcp
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Linting
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
ruff check src/
|
|
241
|
+
ruff format src/
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Architecture
|
|
245
|
+
|
|
246
|
+
```
|
|
247
|
+
lightning_enable_mcp/
|
|
248
|
+
├── server.py # Main MCP server and tool registration
|
|
249
|
+
├── l402_client.py # L402 protocol implementation
|
|
250
|
+
├── nwc_wallet.py # Nostr Wallet Connect client
|
|
251
|
+
├── budget.py # Spending limit management
|
|
252
|
+
└── tools/
|
|
253
|
+
├── access_resource.py # access_l402_resource tool
|
|
254
|
+
├── pay_challenge.py # pay_l402_challenge tool
|
|
255
|
+
├── wallet.py # check_wallet_balance tool
|
|
256
|
+
└── budget.py # configure_budget, get_payment_history tools
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## License
|
|
260
|
+
|
|
261
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
262
|
+
|
|
263
|
+
## Support
|
|
264
|
+
|
|
265
|
+
- **Issues**: https://github.com/refinedelement/lightning-enable-mcp/issues
|
|
266
|
+
- **Documentation**: https://lightningenable.com/docs
|
|
267
|
+
- **Discord**: https://discord.gg/lightningenable
|
|
268
|
+
|
|
269
|
+
## Related Projects
|
|
270
|
+
|
|
271
|
+
- [Lightning Enable](https://lightningenable.com) - Bitcoin Lightning payment API middleware
|
|
272
|
+
- [MCP Specification](https://modelcontextprotocol.io) - Model Context Protocol
|
|
273
|
+
- [NIP-47](https://github.com/nostr-protocol/nips/blob/master/47.md) - Nostr Wallet Connect
|