|
| 1 | +# KeepKey MCP Server |
| 2 | + |
| 3 | +This module implements a Model Control Protocol (MCP) server for KeepKey Desktop. The MCP server provides a standardized interface for interacting with KeepKey devices through Server-Sent Events (SSE) and JSON-RPC. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The MCP server exposes endpoints that allow clients to: |
| 8 | + |
| 9 | +1. Connect via SSE for real-time communication |
| 10 | +2. Send JSON-RPC requests to perform actions on the KeepKey device |
| 11 | +3. Access information about the device and supported operations |
| 12 | + |
| 13 | +## Endpoints |
| 14 | + |
| 15 | +- `/mcp` - SSE endpoint for establishing a persistent connection |
| 16 | +- `/mcp/message?sessionId={sessionId}` - JSON-RPC endpoint for sending commands |
| 17 | + |
| 18 | +## Available Tools |
| 19 | + |
| 20 | +The MCP server provides the following tool categories: |
| 21 | + |
| 22 | +### System Tools |
| 23 | +- `keepkey-mcp_system-getFeatures` - Get device features information |
| 24 | +- `keepkey-mcp_system-getPublicKey` - Get public key for a specific path |
| 25 | +- `keepkey-mcp_system-ping` - Confirm device connectivity |
| 26 | + |
| 27 | +### Ethereum Tools |
| 28 | +- `keepkey-mcp_eth-signTransaction` - Sign an Ethereum transaction |
| 29 | +- `keepkey-mcp_eth-signTypedData` - Sign EIP-712 typed data |
| 30 | + |
| 31 | +### UTXO Tools |
| 32 | +- `keepkey-mcp_utxo-getAddress` - Get address from device |
| 33 | +- `keepkey-mcp_utxo-signTransaction` - Sign a UTXO-based transaction |
| 34 | + |
| 35 | +## Usage |
| 36 | + |
| 37 | +The MCP server is automatically started alongside the existing TSOA server in KeepKey Desktop. Clients can connect to the MCP server to perform operations on the connected KeepKey device. |
| 38 | + |
| 39 | +## Example Client |
| 40 | + |
| 41 | +```javascript |
| 42 | +// Connect to the MCP server via SSE |
| 43 | +const eventSource = new EventSource('http://localhost:1646/mcp'); |
| 44 | +let mcpEndpoint; |
| 45 | + |
| 46 | +// Listen for the endpoint event |
| 47 | +eventSource.addEventListener('endpoint', (event) => { |
| 48 | + mcpEndpoint = event.data; |
| 49 | + console.log('MCP Message endpoint:', mcpEndpoint); |
| 50 | + |
| 51 | + // Once we have the endpoint, initialize the connection |
| 52 | + initializeMcp(); |
| 53 | +}); |
| 54 | + |
| 55 | +async function initializeMcp() { |
| 56 | + // Initialize the MCP connection |
| 57 | + const response = await fetch(mcpEndpoint, { |
| 58 | + method: 'POST', |
| 59 | + headers: { 'Content-Type': 'application/json' }, |
| 60 | + body: JSON.stringify({ |
| 61 | + jsonrpc: '2.0', |
| 62 | + id: 1, |
| 63 | + method: 'initialize' |
| 64 | + }) |
| 65 | + }); |
| 66 | + |
| 67 | + // Handle the response |
| 68 | + const result = await response.json(); |
| 69 | + console.log('Initialize response:', result); |
| 70 | +} |
| 71 | + |
| 72 | +// Listen for SSE messages |
| 73 | +eventSource.addEventListener('message', (event) => { |
| 74 | + const data = JSON.parse(event.data); |
| 75 | + console.log('Received message:', data); |
| 76 | +}); |
| 77 | +``` |
0 commit comments