This document outlines the plan to implement NIP-89 and NIP-90 support for the Groq MCP server, turning it into a Nostr Data Vending Machine (DVM).
The Groq MCP server will be extended to:
- Advertise itself as a NIP-89 application handler
- Handle NIP-90 job requests for LLM completions
- Process payments and deliver results according to the NIP-90 protocol
Create and publish a kind:31990 event to advertise LLM completion capabilities:
{
"kind": 31990,
"content": {
"name": "Groq DVM",
"about": "LLM completion service powered by Groq's API",
"picture": "", // Optional: Add service icon
"nip90Params": {
"models": [
"gemma-7b-it",
"llama3-70b-8192",
"llama3-8b-8192",
"mixtral-8x7b-32768"
]
}
},
"tags": [
["k", "5100"], // Register as LLM completion handler
["web", "https://api-endpoint/chat/<bech32>"]
]
}
Implement handler for kind:5100 (LLM Completion) requests:
{
"kind": 5100,
"content": "",
"tags": [
["i", "What is the capital of France?", "text"],
["param", "model", "mixtral-8x7b-32768"],
["param", "temperature", "0.7"],
["param", "max_tokens", "1024"],
["param", "top_p", "1"],
["bid", "1000"] // 1000 msats
]
}
Return results in kind:6100 events:
{
"kind": 6100,
"content": "The capital of France is Paris.",
"tags": [
["request", "<job-request-event-json>"],
["e", "<job-request-id>", "<relay-hint>"],
["amount", "1000", "<optional-bolt11>"]
]
}
Implement status updates:
{
"kind": 7000,
"tags": [
["status", "processing"],
["e", "<job-request-id>"],
["p", "<customer-pubkey>"]
]
}
- Add Nostr Dependencies:
npm install nostr-tools websocket-polyfill
- New Source Files:
src/nostr/types.ts
- Nostr event type definitionssrc/nostr/handler.ts
- NIP-90 request handling logicsrc/nostr/events.ts
- Event creation/publishing utilitiessrc/nostr/payment.ts
- Payment processing logic
- Code Changes:
- Extend server.ts to handle Nostr events
- Add payment processing capabilities
- Implement job queue management
- Add relay connection management
- Set up Nostr event handling infrastructure
- Implement NIP-89 handler advertisement
- Basic NIP-90 job request processing
- Simple job result delivery
- Implement payment verification
- Add support for Lightning payments
- Handle payment-required status updates
- Add job queuing system
- Implement rate limiting
- Add support for encrypted requests
- Implement job cancellation
- Create test suite for Nostr integration
- Document API endpoints and event formats
- Create usage examples
- Security review
New environment variables needed:
NOSTR_PRIVATE_KEY=<hex-private-key>
NOSTR_RELAYS=wss://relay1,wss://relay2
LIGHTNING_NODE_URL=<ln-node-url>
LIGHTNING_MACAROON=<macaroon>
- Validate all incoming Nostr events
- Verify payments before processing
- Rate limit requests per pubkey
- Implement timeout handling
- Sanitize all input data
- Handle encrypted requests securely
- Unit tests for event handling
- Integration tests with Nostr relays
- Payment processing tests
- Load testing for concurrent jobs
- Security testing for encrypted requests
- Support for more LLM models
- Advanced payment options
- Job priority system
- Result caching
- Automated pricing based on load
- Integration with other DVMs for job chaining