signMessage
Sign messages securely using Ethereum wallets on the MCP Ethers Wallet server. Process messages with optional network or custom RPC provider for enhanced blockchain interaction.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| message | Yes | The message to sign | |
| provider | No | Optional. Either a network name or custom RPC URL. Use getAllNetworks to see available networks and their details, or getNetwork to get info about a specific network. You can use any network name returned by these tools as a provider value. |
Implementation Reference
- src/tools/core.ts:635-672 (handler)The handler function for the signMessage tool. It retrieves the wallet using ethersService.getWallet(provider), checks if wallet exists, signs the message using wallet.signMessage(message), and returns a JSON object containing the message, signature, and signer address.async ({ message, provider }) => { try { // First check if a wallet exists const wallet = await ethersService.getWallet(provider); if (!wallet) { return { isError: true, content: [{ type: "text", text: "No wallet available to sign message. Please create or load a wallet first." }] }; } // Sign the message const signature = await wallet.signMessage(message); return { content: [{ type: "text", text: JSON.stringify({ message, signature, signer: wallet.address }, null, 2) }] }; } catch (error) { return { isError: true, content: [{ type: "text", text: `Error signing message: ${error instanceof Error ? error.message : String(error)}` }] }; } } );
- src/tools/core.ts:629-634 (schema)Zod input schema for the signMessage tool: 'message' (required string), 'provider' (optional string describing network or RPC).{ message: z.string().describe( "The message to sign" ), provider: z.string().optional().describe(PROVIDER_DESCRIPTION) },
- src/tools/core.ts:627-673 (registration)Registers the 'signMessage' tool on the MCP server within the registerCoreTools function, specifying name, input schema, and handler.server.tool( "signMessage", { message: z.string().describe( "The message to sign" ), provider: z.string().optional().describe(PROVIDER_DESCRIPTION) }, async ({ message, provider }) => { try { // First check if a wallet exists const wallet = await ethersService.getWallet(provider); if (!wallet) { return { isError: true, content: [{ type: "text", text: "No wallet available to sign message. Please create or load a wallet first." }] }; } // Sign the message const signature = await wallet.signMessage(message); return { content: [{ type: "text", text: JSON.stringify({ message, signature, signer: wallet.address }, null, 2) }] }; } catch (error) { return { isError: true, content: [{ type: "text", text: `Error signing message: ${error instanceof Error ? error.message : String(error)}` }] }; } } );