|
1 | 1 | import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; |
2 | 2 | import { z } from 'zod'; |
3 | 3 | import { DEFAULT_NETWORK } from './chains.js'; |
| 4 | +import { isWalletEnabled } from './config.js'; |
4 | 5 |
|
5 | 6 | /** |
6 | 7 | * Register all EVM-related prompts with the MCP server |
7 | 8 | * @param server The MCP server instance |
8 | 9 | */ |
9 | 10 | export function registerEVMPrompts(server: McpServer) { |
| 11 | + // Register read-only prompts (always available) |
| 12 | + registerReadOnlyPrompts(server); |
| 13 | + |
| 14 | + // Register wallet-dependent prompts (only if wallet is enabled) |
| 15 | + if (isWalletEnabled()) { |
| 16 | + registerWalletPrompts(server); |
| 17 | + } else { |
| 18 | + console.error('Wallet functionality is disabled. Wallet-dependent prompts will not be available.'); |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +/** |
| 23 | + * Register read-only prompts that don't require wallet functionality |
| 24 | + * @param server The MCP server instance |
| 25 | + */ |
| 26 | +function registerReadOnlyPrompts(server: McpServer) { |
10 | 27 | // Basic block explorer prompt |
11 | 28 | server.prompt( |
12 | 29 | 'explore_block', |
@@ -57,18 +74,7 @@ export function registerEVMPrompts(server: McpServer) { |
57 | 74 | }) |
58 | 75 | ); |
59 | 76 |
|
60 | | - // Get wallet address from private key prompt |
61 | | - server.prompt('my_wallet_address', 'What is my wallet EVM address', {}, () => ({ |
62 | | - messages: [ |
63 | | - { |
64 | | - role: 'user', |
65 | | - content: { |
66 | | - type: 'text', |
67 | | - text: 'Please retrieve my wallet EVM address using tools get_address_from_private_key via MCP server.' |
68 | | - } |
69 | | - } |
70 | | - ] |
71 | | - })); |
| 77 | + |
72 | 78 |
|
73 | 79 | // Address analysis prompt |
74 | 80 | server.prompt( |
@@ -199,3 +205,67 @@ export function registerEVMPrompts(server: McpServer) { |
199 | 205 | } |
200 | 206 | ); |
201 | 207 | } |
| 208 | + |
| 209 | +/** |
| 210 | + * Register wallet-dependent prompts that require wallet functionality |
| 211 | + * @param server The MCP server instance |
| 212 | + */ |
| 213 | +function registerWalletPrompts(server: McpServer) { |
| 214 | + // Get wallet address from private key prompt |
| 215 | + server.prompt('my_wallet_address', 'What is my wallet EVM address', {}, () => ({ |
| 216 | + messages: [ |
| 217 | + { |
| 218 | + role: 'user', |
| 219 | + content: { |
| 220 | + type: 'text', |
| 221 | + text: 'Please retrieve my wallet EVM address using tools get_address_from_private_key via MCP server.' |
| 222 | + } |
| 223 | + } |
| 224 | + ] |
| 225 | + })); |
| 226 | + |
| 227 | + // Send transaction prompt |
| 228 | + server.prompt( |
| 229 | + 'send_transaction_guidance', |
| 230 | + 'Get guidance on sending a transaction', |
| 231 | + { |
| 232 | + toAddress: z.string().describe('The recipient address'), |
| 233 | + amount: z.string().describe('The amount to send (in SEI)'), |
| 234 | + network: z.string().optional().describe('Network name or chain ID. Defaults to Sei mainnet.') |
| 235 | + }, |
| 236 | + ({ toAddress, amount, network = DEFAULT_NETWORK }) => ({ |
| 237 | + messages: [ |
| 238 | + { |
| 239 | + role: 'user', |
| 240 | + content: { |
| 241 | + type: 'text', |
| 242 | + text: `I want to send ${amount} SEI to ${toAddress} on the ${network} network. Please guide me through this process, including checking my balance first, estimating gas, and executing the transaction safely.` |
| 243 | + } |
| 244 | + } |
| 245 | + ] |
| 246 | + }) |
| 247 | + ); |
| 248 | + |
| 249 | + // Token transfer guidance |
| 250 | + server.prompt( |
| 251 | + 'token_transfer_guidance', |
| 252 | + 'Get guidance on transferring tokens', |
| 253 | + { |
| 254 | + tokenAddress: z.string().describe('The token contract address'), |
| 255 | + toAddress: z.string().describe('The recipient address'), |
| 256 | + amount: z.string().describe('The amount to transfer'), |
| 257 | + network: z.string().optional().describe('Network name or chain ID. Defaults to Sei mainnet.') |
| 258 | + }, |
| 259 | + ({ tokenAddress, toAddress, amount, network = DEFAULT_NETWORK }) => ({ |
| 260 | + messages: [ |
| 261 | + { |
| 262 | + role: 'user', |
| 263 | + content: { |
| 264 | + type: 'text', |
| 265 | + text: `I want to transfer ${amount} tokens from contract ${tokenAddress} to ${toAddress} on the ${network} network. Please guide me through this process, including checking my balance first, approving the token if needed, and executing the transfer safely.` |
| 266 | + } |
| 267 | + } |
| 268 | + ] |
| 269 | + }) |
| 270 | + ); |
| 271 | +} |
0 commit comments