@pyrimid/sdk 0.1.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/README.md +205 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-server.d.ts +18 -0
- package/dist/mcp-server.d.ts.map +1 -0
- package/dist/mcp-server.js +200 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/middleware.d.ts +68 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +204 -0
- package/dist/middleware.js.map +1 -0
- package/dist/resolver.d.ts +49 -0
- package/dist/resolver.d.ts.map +1 -0
- package/dist/resolver.js +169 -0
- package/dist/resolver.js.map +1 -0
- package/dist/types.d.ts +127 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +50 -0
- package/dist/types.js.map +1 -0
- package/package.json +79 -0
package/README.md
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# @pyrimid/sdk
|
|
2
|
+
|
|
3
|
+
Onchain monetization infrastructure for agent-to-agent commerce on Base.
|
|
4
|
+
|
|
5
|
+
**Pyrimid** is a one-layer affiliate distribution protocol. Vendors list products. Agents earn commissions by distributing them. Payments settle instantly in USDC via smart contracts. Protocol takes 1%.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @pyrimid/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Peer Dependencies
|
|
14
|
+
|
|
15
|
+
The SDK uses peer dependencies to keep the bundle small — install only what you need:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# Path 1: Resolver (no extra deps needed — just fetch)
|
|
19
|
+
npm install @pyrimid/sdk
|
|
20
|
+
|
|
21
|
+
# Path 2: MCP Server
|
|
22
|
+
npm install @pyrimid/sdk @modelcontextprotocol/sdk zod
|
|
23
|
+
|
|
24
|
+
# Path 3: Vendor Middleware (no extra deps for basic usage)
|
|
25
|
+
# For x402 payment verification in the resolver:
|
|
26
|
+
npm install @pyrimid/sdk @x402/fetch
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Three Integration Paths
|
|
30
|
+
|
|
31
|
+
### Path 1: Embedded Resolver (Framework Developers)
|
|
32
|
+
|
|
33
|
+
Highest leverage. Embed `PyrimidResolver` in your agent framework — every agent on your stack routes purchases through Pyrimid with your affiliate ID. One integration, thousands of passive sales.
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { PyrimidResolver } from '@pyrimid/sdk';
|
|
37
|
+
|
|
38
|
+
const resolver = new PyrimidResolver({
|
|
39
|
+
affiliateId: 'af_your_id',
|
|
40
|
+
// Optional:
|
|
41
|
+
// catalogUrl: 'https://pyrimid.ai/api/v1/catalog',
|
|
42
|
+
// cacheTtlMs: 5 * 60 * 1000,
|
|
43
|
+
// preferVerifiedVendors: true,
|
|
44
|
+
// maxPriceUsdc: 10_000_000, // $10
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Search the catalog by natural language
|
|
48
|
+
const product = await resolver.findProduct("btc trading signal");
|
|
49
|
+
|
|
50
|
+
if (product) {
|
|
51
|
+
console.log(`Found: ${product.vendor_name} — ${product.price_display}`);
|
|
52
|
+
|
|
53
|
+
// Purchase with automatic x402 payment
|
|
54
|
+
const receipt = await resolver.purchase(product, agentWallet);
|
|
55
|
+
console.log(`Paid $${receipt.paid_usdc / 1e6}, earned $${receipt.affiliate_earned / 1e6}`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Multi-result search
|
|
59
|
+
const products = await resolver.findProducts("image generation", 10);
|
|
60
|
+
|
|
61
|
+
// Browse by category
|
|
62
|
+
const tradingTools = await resolver.findByCategory("trading");
|
|
63
|
+
|
|
64
|
+
// Get affiliate stats
|
|
65
|
+
const stats = await resolver.getStats();
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Path 2: MCP Recommender (Server Operators)
|
|
69
|
+
|
|
70
|
+
Deploy an MCP server wrapping the Pyrimid catalog. Other agents connect as a tool and browse/buy — your affiliate ID on every transaction.
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { createPyrimidMcpServer } from '@pyrimid/sdk';
|
|
74
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
75
|
+
|
|
76
|
+
const server = createPyrimidMcpServer({
|
|
77
|
+
affiliateId: 'af_your_id',
|
|
78
|
+
serverName: 'my-trading-recommender',
|
|
79
|
+
// catalogUrl: 'https://pyrimid.ai/api/v1/catalog',
|
|
80
|
+
// refreshIntervalMs: 5 * 60 * 1000,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Connect via stdio (for Claude Desktop, etc.)
|
|
84
|
+
const transport = new StdioServerTransport();
|
|
85
|
+
await server.connect(transport);
|
|
86
|
+
|
|
87
|
+
// Tools exposed:
|
|
88
|
+
// pyrimid_browse — keyword search with filters
|
|
89
|
+
// pyrimid_categories — list categories with counts
|
|
90
|
+
// pyrimid_buy — purchase a product via x402
|
|
91
|
+
// pyrimid_preview — show payment split breakdown
|
|
92
|
+
// pyrimid_register_affiliate — registration instructions
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Or use the hosted HTTP endpoint at `https://pyrimid.ai/api/mcp` (JSON-RPC 2.0):
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
# List available tools
|
|
99
|
+
curl -X POST https://pyrimid.ai/api/mcp \
|
|
100
|
+
-H "Content-Type: application/json" \
|
|
101
|
+
-d '{"jsonrpc":"2.0","method":"tools/list","id":1}'
|
|
102
|
+
|
|
103
|
+
# Search the catalog
|
|
104
|
+
curl -X POST https://pyrimid.ai/api/mcp \
|
|
105
|
+
-H "Content-Type: application/json" \
|
|
106
|
+
-d '{"jsonrpc":"2.0","method":"tools/call","params":{"name":"pyrimid_browse","arguments":{"query":"trading signals"}},"id":2}'
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Path 3: Vendor Middleware (Product Vendors)
|
|
110
|
+
|
|
111
|
+
10 lines to activate affiliate distribution on your existing API. Works with Express, Hono, Fastify, or any Connect-compatible framework:
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
import { pyrimidMiddleware } from '@pyrimid/sdk';
|
|
115
|
+
|
|
116
|
+
app.use(pyrimidMiddleware({
|
|
117
|
+
vendorId: 'vn_your_id',
|
|
118
|
+
products: {
|
|
119
|
+
'/api/signals/latest': {
|
|
120
|
+
productId: 'signals_latest',
|
|
121
|
+
price: 250_000, // $0.25 in USDC atomic units (6 decimals)
|
|
122
|
+
affiliateBps: 2000, // 20% affiliate commission
|
|
123
|
+
},
|
|
124
|
+
'/api/analysis/deep': {
|
|
125
|
+
productId: 'deep_analysis',
|
|
126
|
+
price: 1_000_000, // $1.00
|
|
127
|
+
affiliateBps: 1500, // 15%
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
}));
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
For Next.js App Router, use the `withPyrimid` wrapper:
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
import { withPyrimid } from '@pyrimid/sdk';
|
|
137
|
+
|
|
138
|
+
export const GET = withPyrimid({
|
|
139
|
+
vendorId: 'vn_your_id',
|
|
140
|
+
productId: 'signals_latest',
|
|
141
|
+
price: 250_000,
|
|
142
|
+
affiliateBps: 2000,
|
|
143
|
+
}, async (req, receipt) => {
|
|
144
|
+
// receipt.verified === true — payment confirmed onchain
|
|
145
|
+
// receipt.tx_hash, receipt.affiliate_id, receipt.paid_usdc, receipt.split
|
|
146
|
+
return Response.json({ signal: 'BTC LONG', confidence: 0.82 });
|
|
147
|
+
});
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Utility: Payment Split Calculator
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
import { calculateSplit } from '@pyrimid/sdk';
|
|
154
|
+
|
|
155
|
+
const split = calculateSplit(250_000, 2000); // price, affiliateBps
|
|
156
|
+
// split.total_usdc = 250000
|
|
157
|
+
// split.protocol_fee = 2500 (1%)
|
|
158
|
+
// split.affiliate_commission = 49500 (20% of remainder)
|
|
159
|
+
// split.vendor_share = 198000
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Contracts (Base Mainnet)
|
|
163
|
+
|
|
164
|
+
| Contract | Address | Deploy Block |
|
|
165
|
+
|----------|---------|-------------|
|
|
166
|
+
| PyrimidRegistry | `0x2263852363Bce16791A059c6F6fBb590f0b98c89` | 43437586 |
|
|
167
|
+
| PyrimidCatalog | `0x1ae8EbbFf7c5A15a155c9bcF9fF7984e7C8e0E74` | 43437593 |
|
|
168
|
+
| PyrimidRouter | `0x6594A6B2785b1f8505b291bDc50E017b5599aFC8` | 43437600 |
|
|
169
|
+
| PyrimidTreasury | `0xdF29F94EA8053cC0cb1567D0A8Ac8dd3d1E00908` | 43437579 |
|
|
170
|
+
|
|
171
|
+
USDC: `0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913`
|
|
172
|
+
|
|
173
|
+
ABI fragments are exported from the SDK:
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
import { ROUTER_ABI, REGISTRY_ABI, CATALOG_ABI, TREASURY_ABI, PYRIMID_ADDRESSES } from '@pyrimid/sdk';
|
|
177
|
+
|
|
178
|
+
const addresses = PYRIMID_ADDRESSES.base;
|
|
179
|
+
// addresses.REGISTRY, addresses.CATALOG, addresses.ROUTER, addresses.TREASURY, addresses.USDC
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Commission Split
|
|
183
|
+
|
|
184
|
+
Every transaction splits automatically onchain:
|
|
185
|
+
|
|
186
|
+
```
|
|
187
|
+
1% → Protocol treasury
|
|
188
|
+
5–50% → Affiliate (set per product by vendor)
|
|
189
|
+
Remainder → Vendor
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
No affiliate on the sale? Vendor gets 99%, protocol gets 1%.
|
|
193
|
+
|
|
194
|
+
## API Endpoints
|
|
195
|
+
|
|
196
|
+
| Endpoint | Description |
|
|
197
|
+
|----------|-------------|
|
|
198
|
+
| `GET /api/v1/catalog` | Aggregated product catalog (query, category, price filters) |
|
|
199
|
+
| `GET /api/v1/stats` | Protocol, affiliate, or vendor statistics |
|
|
200
|
+
| `POST /api/mcp` | MCP JSON-RPC 2.0 endpoint (tools/list, tools/call) |
|
|
201
|
+
| `GET /api/mcp` | MCP server info + tool definitions |
|
|
202
|
+
|
|
203
|
+
## License
|
|
204
|
+
|
|
205
|
+
Proprietary. Source-available, non-commercial. See LICENSE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @pyrimid/sdk — Onchain monetization infrastructure for agent-to-agent commerce
|
|
3
|
+
*
|
|
4
|
+
* Three integration paths:
|
|
5
|
+
* 1. PyrimidResolver — Embed in agent frameworks for passive affiliate earnings
|
|
6
|
+
* 2. MCP Server — Deploy a catalog recommender agents can connect to
|
|
7
|
+
* 3. Vendor Middleware — Add to your API to activate affiliate distribution
|
|
8
|
+
*
|
|
9
|
+
* @example Resolver (framework developers)
|
|
10
|
+
* import { PyrimidResolver } from '@pyrimid/sdk';
|
|
11
|
+
* const resolver = new PyrimidResolver({ affiliateId: 'af_your_id' });
|
|
12
|
+
* const product = await resolver.findProduct("trading signals");
|
|
13
|
+
*
|
|
14
|
+
* @example MCP Server (recommender operators)
|
|
15
|
+
* import { createPyrimidMcpServer } from '@pyrimid/sdk';
|
|
16
|
+
* const server = createPyrimidMcpServer({ affiliateId: 'af_your_id' });
|
|
17
|
+
*
|
|
18
|
+
* @example Vendor Middleware (product vendors)
|
|
19
|
+
* import { pyrimidMiddleware } from '@pyrimid/sdk';
|
|
20
|
+
* app.use(pyrimidMiddleware({ vendorId: 'vn_your_id', products: { ... } }));
|
|
21
|
+
*
|
|
22
|
+
* PROPRIETARY — All rights reserved.
|
|
23
|
+
*/
|
|
24
|
+
export { PYRIMID_ADDRESSES, ROUTER_ABI, REGISTRY_ABI, CATALOG_ABI, TREASURY_ABI, } from './types.js';
|
|
25
|
+
export type { Network, PyrimidProduct, CatalogResponse, CatalogQueryParams, PurchaseResult, PaymentSplit, AffiliateStats, VendorStats, ProtocolStats, ResolverConfig, McpServerConfig, VendorMiddlewareConfig, } from './types.js';
|
|
26
|
+
export { PyrimidResolver } from './resolver.js';
|
|
27
|
+
export { createPyrimidMcpServer } from './mcp-server.js';
|
|
28
|
+
export { pyrimidMiddleware, withPyrimid, calculateSplit, } from './middleware.js';
|
|
29
|
+
export type { PaymentReceipt } from './middleware.js';
|
|
30
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,EACL,iBAAiB,EACjB,UAAU,EACV,YAAY,EACZ,WAAW,EACX,YAAY,GACb,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,OAAO,EACP,cAAc,EACd,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,YAAY,EACZ,cAAc,EACd,WAAW,EACX,aAAa,EACb,cAAc,EACd,eAAe,EACf,sBAAsB,GACvB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGhD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAGzD,OAAO,EACL,iBAAiB,EACjB,WAAW,EACX,cAAc,GACf,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @pyrimid/sdk — Onchain monetization infrastructure for agent-to-agent commerce
|
|
3
|
+
*
|
|
4
|
+
* Three integration paths:
|
|
5
|
+
* 1. PyrimidResolver — Embed in agent frameworks for passive affiliate earnings
|
|
6
|
+
* 2. MCP Server — Deploy a catalog recommender agents can connect to
|
|
7
|
+
* 3. Vendor Middleware — Add to your API to activate affiliate distribution
|
|
8
|
+
*
|
|
9
|
+
* @example Resolver (framework developers)
|
|
10
|
+
* import { PyrimidResolver } from '@pyrimid/sdk';
|
|
11
|
+
* const resolver = new PyrimidResolver({ affiliateId: 'af_your_id' });
|
|
12
|
+
* const product = await resolver.findProduct("trading signals");
|
|
13
|
+
*
|
|
14
|
+
* @example MCP Server (recommender operators)
|
|
15
|
+
* import { createPyrimidMcpServer } from '@pyrimid/sdk';
|
|
16
|
+
* const server = createPyrimidMcpServer({ affiliateId: 'af_your_id' });
|
|
17
|
+
*
|
|
18
|
+
* @example Vendor Middleware (product vendors)
|
|
19
|
+
* import { pyrimidMiddleware } from '@pyrimid/sdk';
|
|
20
|
+
* app.use(pyrimidMiddleware({ vendorId: 'vn_your_id', products: { ... } }));
|
|
21
|
+
*
|
|
22
|
+
* PROPRIETARY — All rights reserved.
|
|
23
|
+
*/
|
|
24
|
+
// Core types & constants
|
|
25
|
+
export { PYRIMID_ADDRESSES, ROUTER_ABI, REGISTRY_ABI, CATALOG_ABI, TREASURY_ABI, } from './types.js';
|
|
26
|
+
// Resolver — Path 1: Embedded distribution
|
|
27
|
+
export { PyrimidResolver } from './resolver.js';
|
|
28
|
+
// MCP Server — Path 2: Catalog recommender
|
|
29
|
+
export { createPyrimidMcpServer } from './mcp-server.js';
|
|
30
|
+
// Vendor Middleware — Path 3: Payment integration
|
|
31
|
+
export { pyrimidMiddleware, withPyrimid, calculateSplit, } from './middleware.js';
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,yBAAyB;AACzB,OAAO,EACL,iBAAiB,EACjB,UAAU,EACV,YAAY,EACZ,WAAW,EACX,YAAY,GACb,MAAM,YAAY,CAAC;AAiBpB,2CAA2C;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,2CAA2C;AAC3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,kDAAkD;AAClD,OAAO,EACL,iBAAiB,EACjB,WAAW,EACX,cAAc,GACf,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pyrimid MCP Server — All products as callable paid tools
|
|
3
|
+
*
|
|
4
|
+
* The canonical storefront for the Pyrimid network. Every product from
|
|
5
|
+
* every vendor is exposed as an MCP tool that agents can discover and call.
|
|
6
|
+
* Payment happens inline via x402.
|
|
7
|
+
*
|
|
8
|
+
* Three modes:
|
|
9
|
+
* 1. Official server (default affiliate → treasury)
|
|
10
|
+
* 2. Custom affiliate (your affiliate ID → your wallet)
|
|
11
|
+
* 3. Specialized recommender (curated vertical subset)
|
|
12
|
+
*
|
|
13
|
+
* PROPRIETARY — @pyrimid/sdk
|
|
14
|
+
*/
|
|
15
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
16
|
+
import type { McpServerConfig } from './types.js';
|
|
17
|
+
export declare function createPyrimidMcpServer(config?: McpServerConfig): McpServer;
|
|
18
|
+
//# sourceMappingURL=mcp-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,KAAK,EAAkB,eAAe,EAAE,MAAM,YAAY,CAAC;AAGlE,wBAAgB,sBAAsB,CAAC,MAAM,GAAE,eAAoB,aAuOlE"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pyrimid MCP Server — All products as callable paid tools
|
|
3
|
+
*
|
|
4
|
+
* The canonical storefront for the Pyrimid network. Every product from
|
|
5
|
+
* every vendor is exposed as an MCP tool that agents can discover and call.
|
|
6
|
+
* Payment happens inline via x402.
|
|
7
|
+
*
|
|
8
|
+
* Three modes:
|
|
9
|
+
* 1. Official server (default affiliate → treasury)
|
|
10
|
+
* 2. Custom affiliate (your affiliate ID → your wallet)
|
|
11
|
+
* 3. Specialized recommender (curated vertical subset)
|
|
12
|
+
*
|
|
13
|
+
* PROPRIETARY — @pyrimid/sdk
|
|
14
|
+
*/
|
|
15
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
16
|
+
import { z } from 'zod';
|
|
17
|
+
import { calculateSplit } from './middleware.js';
|
|
18
|
+
export function createPyrimidMcpServer(config = {}) {
|
|
19
|
+
const { affiliateId = 'af_treasury', catalogUrl = 'https://api.pyrimid.ai/v1/catalog', serverName = 'pyrimid-catalog', refreshIntervalMs = 5 * 60 * 1000, } = config;
|
|
20
|
+
const server = new McpServer({
|
|
21
|
+
name: serverName,
|
|
22
|
+
version: '0.1.0',
|
|
23
|
+
});
|
|
24
|
+
let cachedProducts = [];
|
|
25
|
+
let lastFetch = 0;
|
|
26
|
+
async function refreshCatalog() {
|
|
27
|
+
if (Date.now() - lastFetch < refreshIntervalMs && cachedProducts.length > 0) {
|
|
28
|
+
return cachedProducts;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const res = await fetch(catalogUrl);
|
|
32
|
+
const data = await res.json();
|
|
33
|
+
cachedProducts = data.products;
|
|
34
|
+
lastFetch = Date.now();
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
console.error('[pyrimid] Catalog refresh failed:', e);
|
|
38
|
+
}
|
|
39
|
+
return cachedProducts;
|
|
40
|
+
}
|
|
41
|
+
// ═══════════════════════════════════════════════════════════
|
|
42
|
+
// DISCOVERY TOOLS
|
|
43
|
+
// ═══════════════════════════════════════════════════════════
|
|
44
|
+
server.tool('pyrimid_browse', 'Search the Pyrimid product catalog. Returns products matching your query, sorted by relevance and trust (ERC-8004 verified vendors first). Use this to find APIs, data feeds, trading signals, AI tools, and any digital service available on the network.', {
|
|
45
|
+
query: z.string().describe('What you need, e.g. "btc trading signals" or "image generation"'),
|
|
46
|
+
max_results: z.number().optional().default(5).describe('Maximum results to return'),
|
|
47
|
+
max_price_usd: z.number().optional().default(10).describe('Max price per call in USD'),
|
|
48
|
+
verified_only: z.boolean().optional().default(false).describe('Only ERC-8004 verified vendors'),
|
|
49
|
+
}, async ({ query, max_results, max_price_usd, verified_only }) => {
|
|
50
|
+
const products = await refreshCatalog();
|
|
51
|
+
const keywords = query.toLowerCase().split(/\s+/);
|
|
52
|
+
const maxPriceAtomic = max_price_usd * 1_000_000;
|
|
53
|
+
const results = products
|
|
54
|
+
.filter(p => p.price_usdc <= maxPriceAtomic)
|
|
55
|
+
.filter(p => !verified_only || p.vendor_erc8004)
|
|
56
|
+
.map(p => {
|
|
57
|
+
const searchable = `${p.description} ${p.tags.join(' ')} ${p.category} ${p.vendor_name}`.toLowerCase();
|
|
58
|
+
let score = 0;
|
|
59
|
+
for (const kw of keywords) {
|
|
60
|
+
if (searchable.includes(kw))
|
|
61
|
+
score += 10;
|
|
62
|
+
}
|
|
63
|
+
if (p.vendor_erc8004)
|
|
64
|
+
score += 5;
|
|
65
|
+
score += Math.min(p.monthly_volume / 1000, 5);
|
|
66
|
+
return { product: p, score };
|
|
67
|
+
})
|
|
68
|
+
.filter(s => s.score > 0)
|
|
69
|
+
.sort((a, b) => b.score - a.score)
|
|
70
|
+
.slice(0, max_results);
|
|
71
|
+
if (results.length === 0) {
|
|
72
|
+
return {
|
|
73
|
+
content: [{ type: 'text', text: `No products found matching "${query}". Try broader terms or increase max_price_usd.` }],
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const formatted = results.map((r, i) => {
|
|
77
|
+
const p = r.product;
|
|
78
|
+
const verified = p.vendor_erc8004 ? ' [ERC-8004 VERIFIED]' : '';
|
|
79
|
+
return [
|
|
80
|
+
`${i + 1}. ${p.vendor_name} — ${p.product_id}${verified}`,
|
|
81
|
+
` ${p.description}`,
|
|
82
|
+
` Price: ${p.price_display} | Commission: ${p.affiliate_bps / 100}% | Volume: ${p.monthly_volume}/mo`,
|
|
83
|
+
` → Use pyrimid_buy with vendor_id="${p.vendor_id}" product_id="${p.product_id}"`,
|
|
84
|
+
].join('\n');
|
|
85
|
+
}).join('\n\n');
|
|
86
|
+
return { content: [{ type: 'text', text: `Found ${results.length} products:\n\n${formatted}` }] };
|
|
87
|
+
});
|
|
88
|
+
server.tool('pyrimid_categories', 'List all product categories available on the Pyrimid network with product counts.', {}, async () => {
|
|
89
|
+
const products = await refreshCatalog();
|
|
90
|
+
const cats = {};
|
|
91
|
+
for (const p of products) {
|
|
92
|
+
if (!cats[p.category])
|
|
93
|
+
cats[p.category] = { count: 0, verified: 0 };
|
|
94
|
+
cats[p.category].count++;
|
|
95
|
+
if (p.vendor_erc8004)
|
|
96
|
+
cats[p.category].verified++;
|
|
97
|
+
}
|
|
98
|
+
const formatted = Object.entries(cats)
|
|
99
|
+
.sort((a, b) => b[1].count - a[1].count)
|
|
100
|
+
.map(([cat, info]) => `• ${cat}: ${info.count} products (${info.verified} verified)`)
|
|
101
|
+
.join('\n');
|
|
102
|
+
return {
|
|
103
|
+
content: [{
|
|
104
|
+
type: 'text',
|
|
105
|
+
text: `Pyrimid Catalog — ${products.length} products across ${Object.keys(cats).length} categories:\n\n${formatted}\n\nUse pyrimid_browse to search.`,
|
|
106
|
+
}],
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
// ═══════════════════════════════════════════════════════════
|
|
110
|
+
// PURCHASE TOOLS
|
|
111
|
+
// ═══════════════════════════════════════════════════════════
|
|
112
|
+
server.tool('pyrimid_buy', 'Purchase a product from the Pyrimid network. Pays via x402 (USDC on Base) and returns the product data.', {
|
|
113
|
+
vendor_id: z.string().describe('Vendor ID from browse results'),
|
|
114
|
+
product_id: z.string().describe('Product ID from browse results'),
|
|
115
|
+
}, async ({ vendor_id, product_id }) => {
|
|
116
|
+
const products = await refreshCatalog();
|
|
117
|
+
const product = products.find(p => p.vendor_id === vendor_id && p.product_id === product_id);
|
|
118
|
+
if (!product) {
|
|
119
|
+
return { content: [{ type: 'text', text: `Product not found: ${vendor_id}/${product_id}. Use pyrimid_browse first.` }] };
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
const response = await fetch(product.endpoint, {
|
|
123
|
+
method: product.method,
|
|
124
|
+
headers: { 'X-Affiliate-ID': affiliateId },
|
|
125
|
+
});
|
|
126
|
+
if (response.status === 402) {
|
|
127
|
+
const paymentRequired = response.headers.get('X-PAYMENT-REQUIRED');
|
|
128
|
+
return {
|
|
129
|
+
content: [{
|
|
130
|
+
type: 'text',
|
|
131
|
+
text: `Payment required: ${product.price_display} USDC on Base.\nPayment details: ${paymentRequired}\nThe x402 client will handle payment automatically on retry.`,
|
|
132
|
+
}],
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
if (!response.ok) {
|
|
136
|
+
return { content: [{ type: 'text', text: `Purchase failed: HTTP ${response.status}` }] };
|
|
137
|
+
}
|
|
138
|
+
const data = await response.json();
|
|
139
|
+
return {
|
|
140
|
+
content: [{
|
|
141
|
+
type: 'text',
|
|
142
|
+
text: `Purchase successful — ${product.vendor_name} / ${product.product_id}\nPaid: ${product.price_display}\n\nData:\n${JSON.stringify(data, null, 2)}`,
|
|
143
|
+
}],
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
return {
|
|
148
|
+
content: [{ type: 'text', text: `Purchase error: ${error instanceof Error ? error.message : 'Unknown'}` }],
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
server.tool('pyrimid_preview', 'Preview the payment split for a product without buying. Shows protocol, affiliate, and vendor shares.', {
|
|
153
|
+
vendor_id: z.string().describe('Vendor ID'),
|
|
154
|
+
product_id: z.string().describe('Product ID'),
|
|
155
|
+
}, async ({ vendor_id, product_id }) => {
|
|
156
|
+
const products = await refreshCatalog();
|
|
157
|
+
const product = products.find(p => p.vendor_id === vendor_id && p.product_id === product_id);
|
|
158
|
+
if (!product) {
|
|
159
|
+
return { content: [{ type: 'text', text: `Product not found: ${vendor_id}/${product_id}` }] };
|
|
160
|
+
}
|
|
161
|
+
const split = calculateSplit(product.price_usdc, product.affiliate_bps);
|
|
162
|
+
return {
|
|
163
|
+
content: [{
|
|
164
|
+
type: 'text',
|
|
165
|
+
text: [
|
|
166
|
+
`Payment split for ${product.vendor_name} / ${product.product_id}:`,
|
|
167
|
+
` Total: $${(split.total_usdc / 1_000_000).toFixed(4)}`,
|
|
168
|
+
` Protocol: $${(split.protocol_fee / 1_000_000).toFixed(4)} (1%)`,
|
|
169
|
+
` Affiliate: $${(split.affiliate_commission / 1_000_000).toFixed(4)} (${split.affiliate_bps / 100}%)`,
|
|
170
|
+
` Vendor: $${(split.vendor_share / 1_000_000).toFixed(4)} (${((split.vendor_share / split.total_usdc) * 100).toFixed(1)}%)`,
|
|
171
|
+
].join('\n'),
|
|
172
|
+
}],
|
|
173
|
+
};
|
|
174
|
+
});
|
|
175
|
+
// ═══════════════════════════════════════════════════════════
|
|
176
|
+
// AFFILIATE TOOLS
|
|
177
|
+
// ═══════════════════════════════════════════════════════════
|
|
178
|
+
server.tool('pyrimid_register_affiliate', 'Register as a Pyrimid affiliate agent. Free, permissionless. Returns your affiliate ID.', {
|
|
179
|
+
wallet_address: z.string().describe('Your Base wallet address for USDC commissions'),
|
|
180
|
+
referrer_id: z.string().optional().describe('Affiliate who referred you (earns $5 bonus on your first sale)'),
|
|
181
|
+
}, async ({ wallet_address, referrer_id }) => {
|
|
182
|
+
return {
|
|
183
|
+
content: [{
|
|
184
|
+
type: 'text',
|
|
185
|
+
text: [
|
|
186
|
+
`Register as a Pyrimid affiliate on Base:`,
|
|
187
|
+
``,
|
|
188
|
+
` Contract: 0x2263852363Bce16791A059c6F6fBb590f0b98c89`,
|
|
189
|
+
` Function: ${referrer_id ? `registerAffiliateWithReferral("${referrer_id}")` : 'registerAffiliate()'}`,
|
|
190
|
+
` From: ${wallet_address}`,
|
|
191
|
+
` Cost: Free (gas only, ~$0.01 on Base)`,
|
|
192
|
+
``,
|
|
193
|
+
`After registration, use your affiliate ID with @pyrimid/sdk to start earning.`,
|
|
194
|
+
].join('\n'),
|
|
195
|
+
}],
|
|
196
|
+
};
|
|
197
|
+
});
|
|
198
|
+
return server;
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=mcp-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-server.js","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,MAAM,UAAU,sBAAsB,CAAC,SAA0B,EAAE;IACjE,MAAM,EACJ,WAAW,GAAG,aAAa,EAC3B,UAAU,GAAG,mCAAmC,EAChD,UAAU,GAAG,iBAAiB,EAC9B,iBAAiB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,GAClC,GAAG,MAAM,CAAC;IAEX,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;QAC3B,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,OAAO;KACjB,CAAC,CAAC;IAEH,IAAI,cAAc,GAAqB,EAAE,CAAC;IAC1C,IAAI,SAAS,GAAG,CAAC,CAAC;IAElB,KAAK,UAAU,cAAc;QAC3B,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,GAAG,iBAAiB,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;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AC,IAAI,CAAC;iBACb,CAAC;SACH,CAAC;IACJ,CAAC,CACF,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pyrimid Vendor Middleware — 10-line x402 integration
|
|
3
|
+
*
|
|
4
|
+
* Drop this into any Express/Hono/Next.js server to activate
|
|
5
|
+
* affiliate-attributed commission splitting on your products.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* import { pyrimidMiddleware } from '@pyrimid/sdk';
|
|
9
|
+
* app.use(pyrimidMiddleware({
|
|
10
|
+
* vendorId: 'vn_your_id',
|
|
11
|
+
* products: {
|
|
12
|
+
* '/api/signals/latest': { productId: 'signals_latest', price: 250000, affiliateBps: 2000 }
|
|
13
|
+
* }
|
|
14
|
+
* }));
|
|
15
|
+
*
|
|
16
|
+
* PROPRIETARY — @pyrimid/sdk
|
|
17
|
+
*/
|
|
18
|
+
import { type VendorMiddlewareConfig, type PaymentSplit } from './types.js';
|
|
19
|
+
export declare function calculateSplit(priceUsdc: number, affiliateBps: number): PaymentSplit;
|
|
20
|
+
interface MiddlewareRequest {
|
|
21
|
+
url?: string;
|
|
22
|
+
path?: string;
|
|
23
|
+
method?: string;
|
|
24
|
+
headers: Record<string, string | string[] | undefined> | Headers;
|
|
25
|
+
}
|
|
26
|
+
interface MiddlewareResponse {
|
|
27
|
+
status: (code: number) => MiddlewareResponse;
|
|
28
|
+
setHeader: (key: string, value: string) => MiddlewareResponse;
|
|
29
|
+
json: (body: unknown) => void;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Express/Connect-compatible middleware.
|
|
33
|
+
*
|
|
34
|
+
* Intercepts requests to configured product endpoints, checks for x402
|
|
35
|
+
* payment, verifies via the CommissionRouter, and either returns a 402
|
|
36
|
+
* with payment requirements or passes through to the next handler.
|
|
37
|
+
*/
|
|
38
|
+
export declare function pyrimidMiddleware(config: VendorMiddlewareConfig): (req: MiddlewareRequest, res: MiddlewareResponse, next: () => void) => Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Wraps a Next.js API route handler with Pyrimid payment verification.
|
|
41
|
+
*
|
|
42
|
+
* Usage (app router):
|
|
43
|
+
* import { withPyrimid } from '@pyrimid/sdk';
|
|
44
|
+
* export const GET = withPyrimid({
|
|
45
|
+
* vendorId: 'vn_your_id',
|
|
46
|
+
* productId: 'signals_latest',
|
|
47
|
+
* price: 250000,
|
|
48
|
+
* affiliateBps: 2000,
|
|
49
|
+
* }, async (req, paymentReceipt) => {
|
|
50
|
+
* return Response.json({ signal: '...' });
|
|
51
|
+
* });
|
|
52
|
+
*/
|
|
53
|
+
export declare function withPyrimid(product: {
|
|
54
|
+
vendorId: string;
|
|
55
|
+
productId: string;
|
|
56
|
+
price: number;
|
|
57
|
+
affiliateBps: number;
|
|
58
|
+
network?: 'base';
|
|
59
|
+
}, handler: (req: Request, receipt: PaymentReceipt) => Promise<Response>): (req: Request) => Promise<Response>;
|
|
60
|
+
interface PaymentReceipt {
|
|
61
|
+
verified: boolean;
|
|
62
|
+
tx_hash: string;
|
|
63
|
+
affiliate_id: string;
|
|
64
|
+
paid_usdc: number;
|
|
65
|
+
split: PaymentSplit;
|
|
66
|
+
}
|
|
67
|
+
export type { PaymentReceipt };
|
|
68
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAGL,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EAClB,MAAM,YAAY,CAAC;AAMpB,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,YAAY,CAapF;AAMD,UAAU,iBAAiB;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MA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