Skip to main content
Glama

wallet_get_private_key

Retrieve the private key for a wallet securely by providing the wallet data and optional password. Ensures access to wallet management on Ethereum and EVM-compatible chains.

Instructions

Get the wallet private key (with appropriate security warnings)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
passwordNoThe password to decrypt the wallet if it's encrypted
walletNoThe wallet (private key, mnemonic, or JSON). If not provided, uses PRIVATE_KEY environment variable if set.

Implementation Reference

  • The core handler function for the wallet_get_private_key tool. It retrieves the wallet instance using the getWallet helper and returns the private key in a formatted success response.
    export const getPrivateKeyHandler = async (input: any): Promise<ToolResultSchema> => {
      try {
        const wallet = await getWallet(input.wallet, input.password);
    
        return createSuccessResponse(
        `Wallet private key retrieved successfully:
          Private Key: ${wallet.privateKey}
        `);
      } catch (error) {
        return createErrorResponse(`Failed to get wallet private key: ${(error as Error).message}`);
      }
    };
  • Key helper utility that instantiates an ethers.Wallet from input wallet data (private key, mnemonic phrase, or encrypted JSON), supports password for decryption, falls back to PRIVATE_KEY env var, and connects to the provider.
    export const getWallet = async (
      walletData?: string, 
      password?: string,
    ): Promise<ethers.Wallet> => {
      const provider = getProvider()
      // If walletData is not provided, check for PRIVATE_KEY environment variable
      if (!walletData && process.env.PRIVATE_KEY) {
        const wallet = new ethers.Wallet(process.env.PRIVATE_KEY);
        return provider ? wallet.connect(provider) : wallet;
      }
      
      // If no walletData and no environment variable, throw an error
      if (!walletData) {
        throw new Error("Wallet data is required or set PRIVATE_KEY environment variable");
      }
      
      try {
        // Try to parse as JSON first
        if (walletData.startsWith("{")) {
          if (!password) {
            throw new Error("Password is required for encrypted JSON wallets");
          }
          
          const wallet = await ethers.Wallet.fromEncryptedJson(walletData, password);
          return provider ? wallet.connect(provider) : wallet;
        }
        
        // Check if it's a mnemonic (12, 15, 18, 21, or 24 words)
        const words = walletData.trim().split(/\s+/);
        if ([12, 15, 18, 21, 24].includes(words.length)) {
          const wallet = ethers.Wallet.fromMnemonic(walletData);
          return provider ? wallet.connect(provider) : wallet;
        }
        
        // Assume it's a private key
        const wallet = new ethers.Wallet(walletData);
        return provider ? wallet.connect(provider) : wallet;
      } catch (error) {
        throw new Error(`Invalid wallet data: ${(error as Error).message}`);
      }
    };
  • The input schema definition for the wallet_get_private_key tool, specifying optional wallet input and password parameters.
    {
      name: "wallet_get_private_key",
      description: "Get the wallet private key (with appropriate security warnings)",
      inputSchema: {
        type: "object",
        properties: {
          wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON). If not provided, uses PRIVATE_KEY environment variable if set." },
          password: { type: "string", description: "The password to decrypt the wallet if it's encrypted" }
        },
        required: []
      }
    },
  • src/tools.ts:569-569 (registration)
    Maps the tool name 'wallet_get_private_key' to its handler function getPrivateKeyHandler in the central handlers dictionary.
    "wallet_get_private_key": getPrivateKeyHandler,
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden but only adds a security warning about private key access. It fails to disclose critical behavioral traits such as whether this is a read-only operation, potential risks (e.g., exposure of sensitive data), or output format (e.g., returns a string). The warning is vague and insufficient for a high-stakes tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise—a single sentence that front-loads the core purpose and includes a relevant warning. Every word earns its place with no redundancy or fluff, making it efficient and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool handling sensitive private keys with no annotations or output schema, the description is inadequate. It lacks details on security implications, return values, error conditions, or usage context, leaving significant gaps for safe and effective agent operation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents both parameters. The description adds no parameter-specific semantics beyond implying security concerns, which does not enhance understanding of password or wallet usage. Baseline 3 is appropriate as the schema handles parameter documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Get') and resource ('wallet private key'), making the purpose evident. It distinguishes from siblings like wallet_get_public_key by specifying private key retrieval, but does not explicitly contrast with other wallet tools like wallet_from_private_key or wallet_encrypt.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides minimal guidance with a security warning, implying caution, but offers no explicit when-to-use context, prerequisites (e.g., when a wallet is encrypted), or alternatives (e.g., using wallet_from_private_key for different purposes). It lacks clear differentiation from sibling tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/dcSpark/mcp-cryptowallet-evm'

If you have feedback or need assistance with the MCP directory API, please join our Discord server