Skip to content

Commit 87ad9b4

Browse files
committed
Update README with new features and configuration options
Expanded documentation to cover resource and prompt conflict resolution, environment variable interpolation in configs, outbound x402 payments, per-server wallet overrides, and new payment modes. Added details on HTTP/SSE transport wrappers, header propagation, and request lifecycle. Updated configuration examples, environment variable references, and testing instructions. Improved clarity on conflict resolution, payment flows, and provided additional example configurations.
1 parent 4f8087f commit 87ad9b4

File tree

1 file changed

+106
-17
lines changed

1 file changed

+106
-17
lines changed

README.md

Lines changed: 106 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ A **production-ready MCP (Model Context Protocol) gateway** that aggregates mult
1010
- **🚀 Multi-Transport Support**: STDIO, HTTP, SSE, WebSocket - mix and match
1111
- **💪 Health Monitoring**: Automatic reconnection and health checks
1212
- **🛡️ Conflict Resolution**: Intelligent handling of duplicate tool names
13+
- **🧩 Resource & Prompt Resolution**: Optional conflict resolution for resources and prompts
1314
- **⚡ Dynamic Discovery**: Real-time capability updates and registry refresh
1415
- **📋 Configuration-Based**: YAML/JSON configuration for easy management
16+
- **🔐 Env Var Interpolation**: Use `${VAR}` and `${VAR:-default}` in config files
1517

1618
### Payment & Monetization
1719
- **💰 x402 Blockchain Payments**: Full EIP-712 signature validation with USDC
@@ -21,6 +23,8 @@ A **production-ready MCP (Model Context Protocol) gateway** that aggregates mult
2123
- **💸 Three Payment Modes**: Passthrough, Markup, Absorb
2224
- **📊 Flexible Pricing**: Per-tool, per-server, or global defaults
2325
- **🧪 Testnet Ready**: Base Sepolia support for safe testing
26+
- **↗️ Outbound x402 Payments**: Automatic downstream payments via x402-axios
27+
- **👛 Server Wallet Overrides**: Per-server `paymentWallet` setting for fine control
2428

2529
---
2630

@@ -34,23 +38,24 @@ The gateway enables **monetization of MCP tools** using blockchain payments and
3438
┌──────────────────┐
3539
│ AI Agent │ Anthropic Claude, OpenAI, etc.
3640
│ (with wallet) │ Uses x402-fetch or x402-axios
41+
│ or API key │ Sends Authorization/X-ELIZA-API-KEY headers
3742
└────────┬─────────┘
3843
│ MCP Protocol
39-
│ Auto-pays on HTTP 402
44+
│ Auto-pays on HTTP 402 or API key auth
4045
4146
┌──────────────────┐
42-
│ HTTP Wrapper │ Port 8000 (optional, for x402)
43-
│ 402 Gateway │ Returns HTTP 402 Payment Required
44-
└────────┬─────────┘ Verifies payments with facilitator
45-
│ OR Settles transactions on blockchain
46-
┌──────────────────┐
47-
│ STDIO Gateway │ Direct MCP (no payment support)
47+
│ HTTP Wrapper │ Port 8000 (optional, for payments)
48+
│ 402 Gateway │ Returns HTTP 402 (x402 payments)
49+
└────────┬─────────┘ • Validates API keys (tiered pricing)
50+
│ OR • Verifies payments with facilitator
51+
┌──────────────────┐ • Settles blockchain transactions
52+
│ STDIO Gateway │ Direct MCP (no payment/API key support)
4853
└────────┬─────────┘
4954
5055
│ MCP Protocol (authenticated)
5156
5257
┌──────────────────┐
53-
│ Gateway Core │ • Payment verification
58+
│ Gateway Core │ • Payment verification (x402 + API keys)
5459
│ │ • Tool routing
5560
│ │ • Namespace management
5661
└────────┬─────────┘
@@ -271,7 +276,11 @@ servers:
271276

272277
settings:
273278
enableToolConflictResolution: true
279+
enableResourceConflictResolution: true
280+
enablePromptConflictResolution: true
274281
logLevel: "info"
282+
healthCheckInterval: 60000
283+
maxConcurrentConnections: 10
275284
```
276285
277286
### With Payment Gating (Monetization)
@@ -348,6 +357,8 @@ servers:
348357
url: "https://premium-api.com"
349358
paymentMode: "markup"
350359
markup: "20%"
360+
# Optional: override wallet just for this server
361+
paymentWallet: "0xServerSpecificPrivateKey"
351362

352363
# Absorb mode - subscription model
353364
- name: "subscriber-api"
@@ -377,12 +388,33 @@ servers:
377388
- `markup`: Percentage (`20%`) or fixed amount (`$0.05`)
378389
- `defaultPricing`: Server-wide pricing defaults
379390
- `tools`: Per-tool configuration and pricing
391+
- `paymentWallet`: Private key override for outbound payments for this server
392+
- `timeout`, `retryAttempts`, `retryDelay`: Connection stability controls
380393

381394
**Pricing Fields:**
382395
- `x402`: Price for blockchain payments (e.g., `$0.01`)
383396
- `apiKeyTiers`: Tier-specific pricing (`{"premium": "free", "basic": "$0.05"}`)
384397
- `free`: Mark tool as free (true/false)
385398

399+
### Environment Variable Interpolation
400+
401+
You can reference environment variables directly inside YAML/JSON configs:
402+
403+
```yaml
404+
payment:
405+
enabled: true
406+
recipient: "${RECIPIENT_ADDRESS}"
407+
network: "${NETWORK:-base-sepolia}"
408+
servers:
409+
- name: "filesystem"
410+
transport:
411+
type: "stdio"
412+
command: "${MCP_COMMAND:-npx}"
413+
args: ["-y", "@modelcontextprotocol/server-filesystem", "${MCP_FS_ROOT:-/tmp}"]
414+
```
415+
416+
Supported formats: `${VAR}` and `${VAR:-default}`.
417+
386418
## 🎯 Usage
387419

388420
### 1. STDIO Mode (Claude Desktop, Cursor)
@@ -442,9 +474,15 @@ const mcpClient = await createMCPClient({
442474
### 3. Environment Variables
443475

444476
- `MCP_GATEWAY_NAME` - Gateway name (default: "Eliza MCP Gateway")
477+
- `MCP_GATEWAY_VERSION` - Gateway version (default: "1.0.0")
478+
- `MCP_GATEWAY_DESCRIPTION` - Description shown to clients
445479
- `MCP_LOG_LEVEL` - Log level: error, warn, info, debug (default: info)
446480
- `MCP_SERVERS` - Semicolon-separated server specs
447-
- `MCP_ENABLE_TOOL_CONFLICT_RESOLUTION` - Enable conflict resolution (default: true)
481+
- `MCP_ENABLE_TOOL_CONFLICT_RESOLUTION` - Enable tool conflict resolution (default: true)
482+
- `MCP_ENABLE_RESOURCE_CONFLICT_RESOLUTION` - Enable resource conflict resolution (default: true)
483+
- `MCP_ENABLE_PROMPT_CONFLICT_RESOLUTION` - Enable prompt conflict resolution (default: true)
484+
- `MCP_MAX_CONCURRENT_CONNECTIONS` - Max concurrent server connections (default: 10)
485+
- `MCP_HEALTH_CHECK_INTERVAL` - Health check interval in ms (default: 60000)
448486

449487
## 🚀 Transport Support
450488

@@ -496,6 +534,11 @@ See the `examples/` directory for complete, tested configurations:
496534
- [`examples/http-remote.yaml`](examples/http-remote.yaml) - Pure HTTP setup
497535
- [`examples/future-multi-transport.yaml`](examples/future-multi-transport.yaml) - All 4 transport types
498536
- [`examples/config.yaml`](examples/config.yaml) - Basic STDIO configuration
537+
- [`examples/paid-config.yaml`](examples/paid-config.yaml) - x402 + API key pricing
538+
- [`examples/passthrough-config.yaml`](examples/passthrough-config.yaml) - Pure passthrough routing
539+
- [`examples/hybrid-payment-config.yaml`](examples/hybrid-payment-config.yaml) - Mixed payment strategies
540+
- [`examples/absorb-config.yaml`](examples/absorb-config.yaml) - Subscription model (absorb)
541+
- [`examples/coingecko-wrapper-config.yaml`](examples/coingecko-wrapper-config.yaml) - HTTP wrapper for CoinGecko
499542

500543
## 🧪 Testing
501544

@@ -516,6 +559,7 @@ bun run test:all
516559
bun run test:quick # Quick smoke tests (~45s)
517560
bun run test # Full E2E tests (~180s)
518561
bun run test:payment # Payment E2E tests (~31s)
562+
bun run test:passthrough # Passthrough/Markup/Absorb E2E tests
519563
```
520564

521565
### Test Specific Configurations
@@ -569,7 +613,7 @@ bun run test:quick # Fast, essential tests only
569613
bun run test:all # Complete test suite
570614
```
571615

572-
See [TESTING.md](docs/TESTING.md) for detailed testing guide.
616+
See `tests/README.md` for the detailed testing guide.
573617

574618
## 📊 Example Output
575619

@@ -636,6 +680,21 @@ Available tools with namespacing:
636680
Local Remote Streaming
637681
```
638682
683+
### Transport Wrapper Options
684+
685+
- **HTTP Wrapper (`src/transports/http-wrapper.ts`)**: Spawns the stdio gateway per SSE session, handles HTTP/SSE endpoints, returns HTTP 402 for payments, and injects request headers into MCP messages for verification.
686+
- **SSE Server Transport (`src/transports/sse-server.ts`)**: Alternative built-in SSE/HTTP transport that can host the MCP server directly with CORS and header handling. Useful when you don’t want a subprocess per session.
687+
688+
Both wrappers inject inbound HTTP headers into MCP request params as metadata so the gateway core can verify payments.
689+
690+
### Header Propagation and Verification
691+
692+
1. Client sends HTTP request with headers (e.g., `X-PAYMENT`, `X-ELIZA-API-KEY`).
693+
2. Wrapper injects headers into MCP params as `_meta.headers`.
694+
3. Gateway core retrieves headers from `request.params._meta.headers`.
695+
4. `PaymentMiddleware.verifyPayment()` authorizes via API key or x402, or returns requirements for a 402 challenge.
696+
5. On success, request routes to the correct downstream MCP server.
697+
639698
### Complete Payment Flow
640699
641700
```mermaid
@@ -670,6 +729,12 @@ sequenceDiagram
670729
Wrapper-->>Agent: Tool result (SSE stream)
671730
```
672731

732+
### Payment Modes at a Glance
733+
734+
- **Passthrough**: Client pays upstream provider directly. Wrapper/gateway returns 402 and forwards/accepts x402 headers as needed; pricing is defined by the upstream. Use when aggregating already-paid MCP servers.
735+
- **Markup**: Client pays your gateway price; gateway calculates final price and pays the upstream via outbound wallet if needed. Use `payment.outboundWallet` (global) or `paymentWallet` (per server) to control the paying account.
736+
- **Absorb**: Client authenticates (e.g., API key tier free), and gateway pays all downstream costs using outbound wallet. Useful for subscriptions.
737+
673738
### Component Breakdown
674739

675740
#### 1. **HTTP Wrapper** (`src/transports/http-wrapper.ts`)
@@ -693,18 +758,44 @@ sequenceDiagram
693758
- Payment settlement
694759
- Pricing calculation (markup, passthrough, absorb)
695760

696-
#### 4. **Server Manager** (`src/core/server-manager.ts`)
761+
#### 4. **X402 Payment Client** (`src/core/x402-client.ts`)
762+
- Outbound payments to downstream HTTP/SSE services (markup/absorb)
763+
- Uses `x402-axios` for automatic 402 handling and signing
764+
- Supports per-server wallet override via `paymentWallet`
765+
766+
#### 5. **Server Manager** (`src/core/server-manager.ts`)
697767
- Multi-transport support (STDIO, HTTP, SSE, WebSocket)
698768
- Health monitoring
699769
- Automatic reconnection
700770
- Connection pooling
701771

702-
#### 5. **Gateway Registry** (`src/core/registry.ts`)
772+
#### 6. **Gateway Registry** (`src/core/registry.ts`)
703773
- Capability aggregation
704774
- Conflict resolution
705775
- Namespace application
706776
- Dynamic updates
707777

778+
#### 7. **SSE Server Transport** (`src/transports/sse-server.ts`)
779+
- Hosts SSE and message endpoints directly (no subprocess)
780+
- Injects headers and supports CORS/keep-alive
781+
- Can be paired with `PaymentMiddleware` for inline checks
782+
783+
### Conflict Resolution Rules
784+
785+
- **Tools**: If `enableToolConflictResolution` and a duplicate name is detected, the registry appends the server ID (e.g., `name``name_serverA`). Namespacing (`namespace: "docs"`) prefixes names (e.g., `docs:get-library-docs`).
786+
- **Resources**: If `enableResourceConflictResolution`, URIs are namespaced (query param when URL-like; otherwise `namespace:uri`). Duplicates are suffixed with server ID.
787+
- **Prompts**: If `enablePromptConflictResolution`, duplicate prompt names are suffixed with server ID; namespacing applies as with tools.
788+
789+
### Request Lifecycle (HTTP/SSE mode)
790+
791+
1. Client opens `GET /sse` to receive streaming events and obtains a per-session `POST /message` endpoint.
792+
2. Client posts MCP requests to `/message` with payment or API key headers.
793+
3. Wrapper injects headers into `_meta.headers` and forwards to the gateway stdio server (or inline MCP server for SSE transport).
794+
4. Gateway resolves the target tool/resource/prompt via the registry.
795+
5. Payment middleware authorizes or responds with 402 + `X-Accept-Payment`.
796+
6. On success, the request is routed to the downstream MCP server; response streams back via SSE and HTTP.
797+
7. Optional: for markup/absorb flows, outbound payments are executed with the configured wallet.
798+
708799
---
709800

710801
## 💼 Real-World Use Cases
@@ -815,11 +906,9 @@ payment:
815906
816907
## 📖 Documentation
817908
818-
- **[Payment Implementation](docs/PAYMENT_IMPLEMENTATION.md)** - Payment system details
819-
- **[Passthrough Guide](docs/PASSTHROUGH_PAYMENT.md)** - Passthrough mode setup
820-
- **[Anthropic + x402 Integration](docs/ANTHROPIC_X402_INTEGRATION.md)** - Complete guide
821-
- **[Testing Guide](docs/TESTING.md)** - Test suite documentation
822-
- **[Feature Map](docs/FEATURE_MAP.md)** - All features and capabilities
909+
- **Examples**: See the `examples/` directory for ready-to-run configs
910+
- **Testing Guide**: See `tests/README.md`
911+
- **Agents**: See `example-agents/` for SSE client examples
823912

824913
---
825914

0 commit comments

Comments
 (0)