opentool 0.7.1 → 0.7.3

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/README.md CHANGED
@@ -65,36 +65,63 @@ npx opentool validate
65
65
  npx opentool dev
66
66
  ```
67
67
 
68
- ### 4. x402
68
+ ### 4. Add x402 payments (optional)
69
69
 
70
- Include the definePayment function from the opentool package to define your payment config.
70
+ Protect your tools with crypto payments using x402:
71
71
 
72
72
  ```typescript
73
- import { generateText } from "opentool/ai";
74
- import { definePayment } from "opentool/payment";
73
+ // tools/premium-report.ts
74
+ import { z } from "zod";
75
+ import { defineX402Payment } from "opentool/x402";
76
+
77
+ export const schema = z.object({
78
+ symbol: z.string().describe("Crypto symbol (e.g., BTC)"),
79
+ });
75
80
 
76
- export const payment = definePayment({
77
- amount: "0.50",
81
+ export const payment = defineX402Payment({
82
+ amount: "0.001",
83
+ payTo: process.env.WALLET_ADDRESS!,
78
84
  currency: "USDC",
79
- payTo: "0x...",
80
- message: "Premium analytics require payment before access.",
81
- acceptedMethods: ["x402", "402"],
82
- acceptedCurrencies: ["USDC"],
83
- chains: ["base"],
84
- facilitator: "opentool",
85
+ network: "base-sepolia",
86
+ message: "Premium analytics require payment",
85
87
  });
86
88
 
87
89
  export async function POST(request: Request) {
88
90
  const payload = await request.json();
89
91
  const { symbol } = schema.parse(payload);
90
- const report = await generateText("Premium Content " + symbol);
92
+
91
93
  return Response.json({
92
- message: `Premium analytics for ${symbol}`,
94
+ report: `Premium analytics for ${symbol}`,
93
95
  });
94
96
  }
95
97
  ```
96
98
 
97
- ### 4. MCP
99
+ Test the payment flow:
100
+
101
+ ```bash
102
+ # Start dev server
103
+ WALLET_ADDRESS=0x... npx opentool dev --input tools
104
+
105
+ # Test with the x402 client
106
+ PRIVATE_KEY=0x... bun examples/full-metadata/test-x402.ts
107
+ ```
108
+
109
+ Or test manually:
110
+
111
+ ```bash
112
+ # Get 402 response with payment requirements
113
+ curl -X POST http://localhost:7000/premium-report \
114
+ -H "content-type: application/json" \
115
+ -d '{"symbol":"BTC"}'
116
+
117
+ # Pay and retry with X-PAYMENT header (generated by x402 client)
118
+ curl -X POST http://localhost:7000/premium-report \
119
+ -H "content-type: application/json" \
120
+ -H "X-PAYMENT: ${X402_HEADER}" \
121
+ -d '{"symbol":"BTC"}'
122
+ ```
123
+
124
+ ### MCP
98
125
 
99
126
  By default, tools are HTTP-only. Want them accessible via MCP clients like Claude Desktop? Just add this to your tool file:
100
127
 
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env node
2
- import { h as Metadata, I as InternalToolDefinition } from '../validate-CqB2Juma.js';
3
- export { G as GenerateMetadataOptions, i as GenerateMetadataResult, V as ValidateOptions, g as generateMetadata, a as generateMetadataCommand, l as loadAndValidateTools, v as validateCommand, j as validateFullCommand } from '../validate-CqB2Juma.js';
2
+ import { h as Metadata, I as InternalToolDefinition } from '../validate-BrOwtVYW.js';
3
+ export { G as GenerateMetadataOptions, j as GenerateMetadataResult, V as ValidateOptions, g as generateMetadata, a as generateMetadataCommand, l as loadAndValidateTools, v as validateCommand, k as validateFullCommand } from '../validate-BrOwtVYW.js';
4
4
  import 'zod';
5
- import '../index-D_bCF2Bf.js';
5
+ import '../x402/index.js';
6
+ import 'viem';
6
7
 
7
8
  interface BuildOptions {
8
9
  input: string;