@ecadlabs/tezosx-mcp 1.0.0
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.
- package/LICENSE +201 -0
- package/README.md +335 -0
- package/dist/adapters/index.d.ts +37 -0
- package/dist/adapters/index.js +57 -0
- package/dist/adapters/node.d.ts +18 -0
- package/dist/adapters/node.js +35 -0
- package/dist/adapters/types.d.ts +52 -0
- package/dist/adapters/types.js +25 -0
- package/dist/adapters/worker.d.ts +35 -0
- package/dist/adapters/worker.js +50 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +144 -0
- package/dist/server.d.ts +36 -0
- package/dist/server.js +80 -0
- package/dist/tools/create_x402_payment.d.ts +27 -0
- package/dist/tools/create_x402_payment.js +55 -0
- package/dist/tools/fetch_with_x402.d.ts +28 -0
- package/dist/tools/fetch_with_x402.js +143 -0
- package/dist/tools/get_address.d.ts +20 -0
- package/dist/tools/get_address.js +24 -0
- package/dist/tools/get_addresses.d.ts +22 -0
- package/dist/tools/get_addresses.js +32 -0
- package/dist/tools/get_balance.d.ts +22 -0
- package/dist/tools/get_balance.js +27 -0
- package/dist/tools/get_dashboard.d.ts +21 -0
- package/dist/tools/get_dashboard.js +29 -0
- package/dist/tools/get_limits.d.ts +22 -0
- package/dist/tools/get_limits.js +61 -0
- package/dist/tools/get_operation_history.d.ts +21 -0
- package/dist/tools/get_operation_history.js +58 -0
- package/dist/tools/index.d.ts +113 -0
- package/dist/tools/index.js +59 -0
- package/dist/tools/parse_x402_requirements.d.ts +23 -0
- package/dist/tools/parse_x402_requirements.js +66 -0
- package/dist/tools/reveal_account.d.ts +34 -0
- package/dist/tools/reveal_account.js +51 -0
- package/dist/tools/send_xtz.d.ts +32 -0
- package/dist/tools/send_xtz.js +86 -0
- package/dist/tools/x402/sign.d.ts +12 -0
- package/dist/tools/x402/sign.js +76 -0
- package/dist/tools/x402/types.d.ts +40 -0
- package/dist/tools/x402/types.js +16 -0
- package/dist/webserver.d.ts +1 -0
- package/dist/webserver.js +10 -0
- package/dist/worker.bundle.js +134265 -0
- package/dist/worker.d.ts +13 -0
- package/dist/worker.js +132 -0
- package/frontend/dist/assets/index-RtTL1nIl.js +257 -0
- package/frontend/dist/assets/index-mSsI3AqQ.css +1 -0
- package/frontend/dist/index.html +16 -0
- package/package.json +70 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
# TezosX MCP
|
|
2
|
+
|
|
3
|
+
A Model Context Protocol server for Tezos with x402 payment support.
|
|
4
|
+
|
|
5
|
+
> **Warning:** This MCP is in alpha. Most things should work, but please be prepared for troubleshooting. Please report any problems on our [issues page](https://github.com/ecadlabs/TezosX-mcp/issues).
|
|
6
|
+
>
|
|
7
|
+
> As always, verify the output of your LLM before approving any transactions. Set reasonable limits. Trust but verify.
|
|
8
|
+
|
|
9
|
+
## Quick Deploy
|
|
10
|
+
|
|
11
|
+
[](https://railway.com/deploy/tezosx-mcp?referralCode=SVg46H&utm_medium=integration&utm_source=template&utm_campaign=generic)
|
|
12
|
+
<details>
|
|
13
|
+
<summary>Railway deployment steps</summary>
|
|
14
|
+
|
|
15
|
+
1. Deploy the template (set `TEZOS_NETWORK` to `shadownet` before clicking deploy if desired)
|
|
16
|
+
2. Click the deployed item and go to "Settings"
|
|
17
|
+
3. Scroll down to "Public Networking"
|
|
18
|
+
4. Your domain will be something like `tezosx-mcp-production-a12b.up.railway.app`
|
|
19
|
+
5. Navigate to your domain to open the frontend config, and set up your spending key and contract address
|
|
20
|
+
6. Back on Railway, navigate to the "Variables" tab and set `SPENDING_PRIVATE_KEY` and `SPENDING_CONTRACT` to the values you received
|
|
21
|
+
7. Optional: Enable the 'serverless' setting to reduce resource usage
|
|
22
|
+
8. Restart the deployment
|
|
23
|
+
9. Set up your AI Platform to use `[your domain]/mcp` as the URL
|
|
24
|
+
|
|
25
|
+
</details>
|
|
26
|
+
|
|
27
|
+
[](https://render.com/deploy?repo=https://github.com/ecadlabs/TezosX-mcp)
|
|
28
|
+
<details>
|
|
29
|
+
<summary>Render deployment steps</summary>
|
|
30
|
+
|
|
31
|
+
1. Click the button above to deploy the template
|
|
32
|
+
2. Once deployed, under "Sync" click "View details"
|
|
33
|
+
3. Click the hyperlink to "tezosx-mcp"
|
|
34
|
+
4. Navigate to your onrender.com custom URL and set up your spending key and contract address
|
|
35
|
+
5. Back on Render, navigate to the "Environment" tab and set `SPENDING_PRIVATE_KEY` and `SPENDING_CONTRACT` environment variables
|
|
36
|
+
6. Click "Manual deploy" at the top right and select "Restart service"
|
|
37
|
+
7. Set up your AI Platform to use `[your domain]/mcp` as the URL
|
|
38
|
+
|
|
39
|
+
Note: Render spins down free plan services during inactivity. The next request can take up to a minute while the instance spins back up. Upgrade to a paid plan to avoid this.
|
|
40
|
+
|
|
41
|
+
</details>
|
|
42
|
+
|
|
43
|
+
## Components
|
|
44
|
+
|
|
45
|
+
| Component | Description | Deployment |
|
|
46
|
+
|-----------|-------------|------------|
|
|
47
|
+
| **MCP Server** | Tezos wallet tools for AI agents | Claude Desktop / Railway / Render |
|
|
48
|
+
| **Facilitator** | Verifies & settles x402 payments | Cloudflare Worker |
|
|
49
|
+
| **Mint Worker** | Mints NFT receipts via x402 | Cloudflare Worker |
|
|
50
|
+
| **NFT Contract** | FA2 contract for collector cards | Tezos blockchain |
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## MCP Server
|
|
55
|
+
|
|
56
|
+
### Installation
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npm install @ecadlabs/tezosx-mcp
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Or run directly:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
npx tezosx-mcp
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Claude Desktop Configuration
|
|
69
|
+
|
|
70
|
+
Add to your Claude Desktop config (`~/Library/Application Support/Claude/claude_desktop_config.json` on macOS):
|
|
71
|
+
|
|
72
|
+
```json
|
|
73
|
+
{
|
|
74
|
+
"mcpServers": {
|
|
75
|
+
"tezos": {
|
|
76
|
+
"command": "npx",
|
|
77
|
+
"args": ["-y", "tezosx-mcp"],
|
|
78
|
+
"env": {
|
|
79
|
+
"TEZOS_NETWORK": "mainnet",
|
|
80
|
+
"SPENDING_CONTRACT": "KT1...",
|
|
81
|
+
"SPENDING_PRIVATE_KEY": "edsk..."
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Or run from source:
|
|
89
|
+
|
|
90
|
+
1. Clone the TezosX-mcp repository
|
|
91
|
+
2. In the `/TezosX-mcp/mcp` folder run `npm i && npm run build`
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
{
|
|
95
|
+
"mcpServers": {
|
|
96
|
+
"tezosx": {
|
|
97
|
+
"command": "node",
|
|
98
|
+
"args": ["/path/to/TezosX-mcp/mcp/dist/index.js"],
|
|
99
|
+
"env": {
|
|
100
|
+
"TEZOS_NETWORK": "mainnet",
|
|
101
|
+
"SPENDING_CONTRACT": "KT1...",
|
|
102
|
+
"SPENDING_PRIVATE_KEY": "edsk..."
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Environment Variables
|
|
110
|
+
|
|
111
|
+
| Variable | Required | Description |
|
|
112
|
+
|----------|----------|-------------|
|
|
113
|
+
| `SPENDING_PRIVATE_KEY` | Yes | Private key for the spending account (edsk/spsk/p2sk format) |
|
|
114
|
+
| `SPENDING_CONTRACT` | Yes | Address of the spending-limited wallet contract (KT1...) |
|
|
115
|
+
| `TEZOS_NETWORK` | No | `mainnet` (default) or `shadownet` |
|
|
116
|
+
| `MCP_TRANSPORT` | No | `stdio` (default) or `http` |
|
|
117
|
+
| `WEB_PORT` | No | Frontend port (default: 13205) |
|
|
118
|
+
|
|
119
|
+
### Available Tools
|
|
120
|
+
|
|
121
|
+
| Tool | Description |
|
|
122
|
+
|------|-------------|
|
|
123
|
+
| `get_balance` | Get the balance of the spending wallet |
|
|
124
|
+
| `get_addresses` | Get addresses associated with the spending contract |
|
|
125
|
+
| `get_limits` | Get current spending limits and allowances |
|
|
126
|
+
| `get_operation_history` | Get recent operations from the wallet |
|
|
127
|
+
| `get_dashboard` | Open the web dashboard for wallet management |
|
|
128
|
+
| `send_xtz` | Send XTZ from the spending wallet |
|
|
129
|
+
| `reveal_account` | Reveal an unrevealed account on-chain |
|
|
130
|
+
| `create_x402_payment` | Create an x402 payment header |
|
|
131
|
+
| `fetch_with_x402` | Fetch a URL with x402 payment |
|
|
132
|
+
| `parse_x402_requirements` | Parse x402 payment requirements from a response |
|
|
133
|
+
|
|
134
|
+
### Web Dashboard
|
|
135
|
+
|
|
136
|
+
The MCP server includes a web dashboard for managing the spending wallet. It starts automatically on `http://localhost:13205` (or your configured `WEB_PORT`).
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## Facilitator (Cloudflare Worker)
|
|
141
|
+
|
|
142
|
+
A Cloudflare Worker that verifies and settles x402 payments using the `exact-tezos` scheme.
|
|
143
|
+
|
|
144
|
+
### Deploy
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
cd facilitator
|
|
148
|
+
npm install
|
|
149
|
+
npm run deploy
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Configuration
|
|
153
|
+
|
|
154
|
+
Set `TEZOS_RPC_URL` in `wrangler.jsonc`:
|
|
155
|
+
|
|
156
|
+
```jsonc
|
|
157
|
+
{
|
|
158
|
+
"vars": {
|
|
159
|
+
"TEZOS_RPC_URL": "https://shadownet.tezos.ecadinfra.com"
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### API
|
|
165
|
+
|
|
166
|
+
| Endpoint | Description |
|
|
167
|
+
|----------|-------------|
|
|
168
|
+
| `GET /health` | Returns service status and connected block |
|
|
169
|
+
| `POST /verify` | Validates a payment payload. Returns `{ valid: true }` or `{ valid: false, reason: "..." }` |
|
|
170
|
+
| `POST /settle` | Injects a verified payment to the network. Returns `{ success: true, operationHash: "..." }` |
|
|
171
|
+
|
|
172
|
+
**Notes:**
|
|
173
|
+
- In-memory double-spend protection resets on deployment
|
|
174
|
+
- Only supports `exact-tezos` scheme with `XTZ`
|
|
175
|
+
- Operations must be verified before settlement
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## NFT Contract
|
|
180
|
+
|
|
181
|
+
Deploy the FA2 contract and authorize a minter:
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
cd mint
|
|
185
|
+
npm install
|
|
186
|
+
npm run deploy -- --minter tz1...
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## Mint Worker (Cloudflare Worker)
|
|
192
|
+
|
|
193
|
+
A Cloudflare Worker that mints Tezos NFTs when users pay via the x402 protocol. Returns `402 Payment Required` until a valid payment is received, then mints an NFT receipt to the payer.
|
|
194
|
+
|
|
195
|
+
### Features
|
|
196
|
+
|
|
197
|
+
- x402 payment protocol integration
|
|
198
|
+
- FA2-compliant NFT minting via Taquito
|
|
199
|
+
- Dynamic SVG receipt generation
|
|
200
|
+
- IPFS metadata storage via Pinata
|
|
201
|
+
|
|
202
|
+
### Prerequisites
|
|
203
|
+
|
|
204
|
+
1. **LIGO compiler** - For compiling the NFT contract
|
|
205
|
+
2. **Cloudflare account** - For deploying the worker
|
|
206
|
+
3. **Pinata account** - For IPFS uploads ([pinata.cloud](https://pinata.cloud))
|
|
207
|
+
4. **Tezos wallet** - Funded account for minting operations
|
|
208
|
+
|
|
209
|
+
### Deploy
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
cd mint/worker
|
|
213
|
+
npm install
|
|
214
|
+
npm run deploy
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Secrets
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
wrangler secret put TEZOS_RPC_URL # e.g., https://shadownet.tezos.ecadinfra.com
|
|
221
|
+
wrangler secret put MINTER_PRIVATE_KEY # edsk...
|
|
222
|
+
wrangler secret put NFT_CONTRACT # KT1...
|
|
223
|
+
wrangler secret put PAYMENT_RECIPIENT # tz1...
|
|
224
|
+
wrangler secret put PINATA_JWT # eyJ...
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Configuration
|
|
228
|
+
|
|
229
|
+
Edit `wrangler.jsonc`:
|
|
230
|
+
|
|
231
|
+
```jsonc
|
|
232
|
+
{
|
|
233
|
+
"vars": {
|
|
234
|
+
"NETWORK": "shadownet",
|
|
235
|
+
"PAYMENT_AMOUNT": "100000" // 0.1 XTZ in mutez
|
|
236
|
+
},
|
|
237
|
+
"services": [
|
|
238
|
+
{ "binding": "FACILITATOR", "service": "tezos-x402-facilitator" }
|
|
239
|
+
]
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
The mint worker uses a service binding to call the facilitator directly (no public URL needed).
|
|
244
|
+
|
|
245
|
+
### API
|
|
246
|
+
|
|
247
|
+
**`GET /mint` or `POST /mint`** - Mint an NFT after x402 payment
|
|
248
|
+
|
|
249
|
+
Query Parameters:
|
|
250
|
+
- `recipient` (optional) - Address to receive the NFT (defaults to payer)
|
|
251
|
+
|
|
252
|
+
Without payment (returns 402):
|
|
253
|
+
```json
|
|
254
|
+
{
|
|
255
|
+
"x402Version": 1,
|
|
256
|
+
"paymentRequirements": [{
|
|
257
|
+
"scheme": "exact-tezos",
|
|
258
|
+
"network": "shadownet",
|
|
259
|
+
"asset": "XTZ",
|
|
260
|
+
"amount": "100000",
|
|
261
|
+
"recipient": "tz1..."
|
|
262
|
+
}]
|
|
263
|
+
}
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
With valid payment (returns 200):
|
|
267
|
+
```json
|
|
268
|
+
{
|
|
269
|
+
"success": true,
|
|
270
|
+
"nft": {
|
|
271
|
+
"tokenId": 42,
|
|
272
|
+
"contract": "KT1...",
|
|
273
|
+
"recipient": "tz1...",
|
|
274
|
+
"metadataUri": "ipfs://Qm...",
|
|
275
|
+
"opHash": "oo..."
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
**`GET /` or `GET /health`** - Health check
|
|
281
|
+
|
|
282
|
+
### Error Codes
|
|
283
|
+
|
|
284
|
+
| Code | Description |
|
|
285
|
+
|------|-------------|
|
|
286
|
+
| `NO_PAYMENT` | No X-PAYMENT header provided |
|
|
287
|
+
| `INVALID_PAYMENT` | Payment verification failed |
|
|
288
|
+
| `WRONG_NETWORK` | Payment network doesn't match |
|
|
289
|
+
| `IPFS_UPLOAD_FAILED` | Failed to upload metadata to Pinata |
|
|
290
|
+
| `MINT_FAILED` | NFT contract call failed |
|
|
291
|
+
| `SETTLE_FAILED` | Payment settlement failed |
|
|
292
|
+
|
|
293
|
+
---
|
|
294
|
+
|
|
295
|
+
## Architecture
|
|
296
|
+
|
|
297
|
+
```
|
|
298
|
+
┌──────────────────┐
|
|
299
|
+
│ Client/Agent │
|
|
300
|
+
└────────┬─────────┘
|
|
301
|
+
│ 1. GET /mint
|
|
302
|
+
▼
|
|
303
|
+
┌──────────────────┐
|
|
304
|
+
│ Mint Worker │
|
|
305
|
+
└────────┬─────────┘
|
|
306
|
+
│ 2. Return 402 with payment requirements
|
|
307
|
+
▼
|
|
308
|
+
┌──────────────────┐
|
|
309
|
+
│ Client/Agent │
|
|
310
|
+
└────────┬─────────┘
|
|
311
|
+
│ 3. Sign payment, retry with X-PAYMENT header
|
|
312
|
+
▼
|
|
313
|
+
┌──────────────────┐ ┌──────────────────┐
|
|
314
|
+
│ Mint Worker │────▶│ Facilitator │
|
|
315
|
+
└────────┬─────────┘ │ (verify) │
|
|
316
|
+
│ └──────────────────┘
|
|
317
|
+
│ 4. Verified
|
|
318
|
+
┌────┴────┐
|
|
319
|
+
▼ ▼
|
|
320
|
+
┌────────┐ ┌────────┐
|
|
321
|
+
│ Pinata │ │ Tezos │
|
|
322
|
+
│ (IPFS) │ │ (mint) │
|
|
323
|
+
└────────┘ └────────┘
|
|
324
|
+
│
|
|
325
|
+
│ 5. Return NFT details
|
|
326
|
+
▼
|
|
327
|
+
┌──────────────────┐ ┌──────────────────┐
|
|
328
|
+
│ Client/Agent │ │ Facilitator │
|
|
329
|
+
└──────────────────┘ │ (settle) │
|
|
330
|
+
└──────────────────┘
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
## License
|
|
334
|
+
|
|
335
|
+
Apache-2.0
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment adapter factory and exports
|
|
3
|
+
* Automatically detects the runtime environment and creates the appropriate adapter
|
|
4
|
+
*/
|
|
5
|
+
export type { EnvironmentAdapter, EnvConfig, StaticFileConfig, RuntimeEnvironment } from './types.js';
|
|
6
|
+
export { detectEnvironment } from './types.js';
|
|
7
|
+
export { NodeAdapter, createNodeAdapter } from './node.js';
|
|
8
|
+
export { WorkerAdapter, createWorkerAdapter } from './worker.js';
|
|
9
|
+
export type { WorkerEnv } from './worker.js';
|
|
10
|
+
import { type EnvironmentAdapter } from './types.js';
|
|
11
|
+
import { type WorkerEnv } from './worker.js';
|
|
12
|
+
/**
|
|
13
|
+
* Create an environment adapter based on the detected runtime
|
|
14
|
+
* For Workers, pass the env bindings from the fetch handler
|
|
15
|
+
*/
|
|
16
|
+
export declare function createAdapter(workerEnv?: WorkerEnv): EnvironmentAdapter;
|
|
17
|
+
/**
|
|
18
|
+
* Get or create the singleton adapter instance
|
|
19
|
+
* Use this for convenience in modules that don't have access to the env bindings
|
|
20
|
+
*/
|
|
21
|
+
export declare function getAdapter(): EnvironmentAdapter;
|
|
22
|
+
/**
|
|
23
|
+
* Set the adapter instance (useful for Workers where env is per-request)
|
|
24
|
+
*/
|
|
25
|
+
export declare function setAdapter(adapter: EnvironmentAdapter): void;
|
|
26
|
+
/**
|
|
27
|
+
* Cross-platform base64 encode helper
|
|
28
|
+
*/
|
|
29
|
+
export declare function base64Encode(data: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Cross-platform base64 decode helper
|
|
32
|
+
*/
|
|
33
|
+
export declare function base64Decode(data: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Cross-platform logging helper
|
|
36
|
+
*/
|
|
37
|
+
export declare function log(message: string): void;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment adapter factory and exports
|
|
3
|
+
* Automatically detects the runtime environment and creates the appropriate adapter
|
|
4
|
+
*/
|
|
5
|
+
export { detectEnvironment } from './types.js';
|
|
6
|
+
export { NodeAdapter, createNodeAdapter } from './node.js';
|
|
7
|
+
export { WorkerAdapter, createWorkerAdapter } from './worker.js';
|
|
8
|
+
import { detectEnvironment } from './types.js';
|
|
9
|
+
import { createNodeAdapter } from './node.js';
|
|
10
|
+
import { createWorkerAdapter } from './worker.js';
|
|
11
|
+
// Singleton adapter instance for convenience
|
|
12
|
+
let _adapter = null;
|
|
13
|
+
/**
|
|
14
|
+
* Create an environment adapter based on the detected runtime
|
|
15
|
+
* For Workers, pass the env bindings from the fetch handler
|
|
16
|
+
*/
|
|
17
|
+
export function createAdapter(workerEnv) {
|
|
18
|
+
const env = detectEnvironment();
|
|
19
|
+
if (env === 'worker') {
|
|
20
|
+
return createWorkerAdapter(workerEnv);
|
|
21
|
+
}
|
|
22
|
+
return createNodeAdapter();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Get or create the singleton adapter instance
|
|
26
|
+
* Use this for convenience in modules that don't have access to the env bindings
|
|
27
|
+
*/
|
|
28
|
+
export function getAdapter() {
|
|
29
|
+
if (!_adapter) {
|
|
30
|
+
_adapter = createAdapter();
|
|
31
|
+
}
|
|
32
|
+
return _adapter;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Set the adapter instance (useful for Workers where env is per-request)
|
|
36
|
+
*/
|
|
37
|
+
export function setAdapter(adapter) {
|
|
38
|
+
_adapter = adapter;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Cross-platform base64 encode helper
|
|
42
|
+
*/
|
|
43
|
+
export function base64Encode(data) {
|
|
44
|
+
return getAdapter().base64Encode(data);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Cross-platform base64 decode helper
|
|
48
|
+
*/
|
|
49
|
+
export function base64Decode(data) {
|
|
50
|
+
return getAdapter().base64Decode(data);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Cross-platform logging helper
|
|
54
|
+
*/
|
|
55
|
+
export function log(message) {
|
|
56
|
+
getAdapter().log(message);
|
|
57
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js environment adapter
|
|
3
|
+
* Uses filesystem operations and process.env for local development
|
|
4
|
+
*/
|
|
5
|
+
import type { EnvironmentAdapter, EnvConfig } from './types.js';
|
|
6
|
+
export declare class NodeAdapter implements EnvironmentAdapter {
|
|
7
|
+
private envOverrides;
|
|
8
|
+
constructor(envOverrides?: Partial<EnvConfig>);
|
|
9
|
+
getEnv(key: keyof EnvConfig): string | undefined;
|
|
10
|
+
isWorker(): boolean;
|
|
11
|
+
base64Encode(data: string): string;
|
|
12
|
+
base64Decode(data: string): string;
|
|
13
|
+
log(message: string): void;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Create a Node.js adapter instance
|
|
17
|
+
*/
|
|
18
|
+
export declare function createNodeAdapter(envOverrides?: Partial<EnvConfig>): EnvironmentAdapter;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js environment adapter
|
|
3
|
+
* Uses filesystem operations and process.env for local development
|
|
4
|
+
*/
|
|
5
|
+
export class NodeAdapter {
|
|
6
|
+
envOverrides;
|
|
7
|
+
constructor(envOverrides = {}) {
|
|
8
|
+
this.envOverrides = envOverrides;
|
|
9
|
+
}
|
|
10
|
+
getEnv(key) {
|
|
11
|
+
// Check overrides first, then process.env
|
|
12
|
+
if (key in this.envOverrides) {
|
|
13
|
+
return this.envOverrides[key];
|
|
14
|
+
}
|
|
15
|
+
return process.env[key];
|
|
16
|
+
}
|
|
17
|
+
isWorker() {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
base64Encode(data) {
|
|
21
|
+
return Buffer.from(data).toString('base64');
|
|
22
|
+
}
|
|
23
|
+
base64Decode(data) {
|
|
24
|
+
return Buffer.from(data, 'base64').toString('utf-8');
|
|
25
|
+
}
|
|
26
|
+
log(message) {
|
|
27
|
+
console.error(`[tezosx-mcp] ${message}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Create a Node.js adapter instance
|
|
32
|
+
*/
|
|
33
|
+
export function createNodeAdapter(envOverrides) {
|
|
34
|
+
return new NodeAdapter(envOverrides);
|
|
35
|
+
}
|