Skip to main content
Glama

account_sign_data

Cryptographically sign data using a local account's private key within the NEAR MCP server. Specify encoding to generate secure, encoded signatures with curve details.

Instructions

Cryptographically sign a piece of data with a local account's private key, then encode the result with the specified encoding. Outputs the curve, encoded signature, and encoding used.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
accountIdYesThe account id of the account that will sign the data. This account must be in the local keystore.
dataYesThe data to sign as a string.
networkIdNomainnet
signatureEncodingNoThe encoding to use for signature creation.base58

Implementation Reference

  • The handler function that retrieves the account's keypair from the keystore, signs the provided data string, encodes the signature in base58 or base64, and returns the signer account ID, curve type, encoded signature, and encoding used.
      async (args, _) => {
        const keyPairResult: Result<KeyPair, Error> = await getAccountKeyPair(
          args.accountId,
          args.networkId,
          keystore,
        );
        if (!keyPairResult.ok) {
          return {
            content: [{ type: 'text', text: `Error: ${keyPairResult.error}` }],
          };
        }
        const keyPair = keyPairResult.value;
        const signatureRaw = keyPair.sign(new TextEncoder().encode(args.data));
        const signatureEncodingResult: Result<string, Error> = (() => {
          try {
            switch (args.signatureEncoding) {
              case 'base64':
                return {
                  ok: true,
                  value: Buffer.from(signatureRaw.signature).toString('base64'),
                };
              case 'base58':
                return {
                  ok: true,
                  value: base58.encode(Buffer.from(signatureRaw.signature)),
                };
              default:
                throw new Error(
                  `Unsupported encoding: ${String(args.signatureEncoding)}`,
                );
            }
          } catch (e) {
            return { ok: false, error: new Error(e as string) };
          }
        })();
        if (!signatureEncodingResult.ok) {
          return {
            content: [
              { type: 'text', text: `Error: ${signatureEncodingResult.error}` },
            ],
          };
        }
    
        return {
          content: [
            {
              type: 'text',
              text: stringify_bigint({
                signerAccountId: args.accountId,
                curve: keyTypeToCurvePrefix(keyPair.getPublicKey().keyType),
                signature: signatureEncodingResult.value,
                encoding: args.signatureEncoding,
              }),
            },
          ],
        };
      },
    );
  • Zod schema defining the input parameters: accountId (string), networkId (enum testnet/mainnet, default mainnet), data (string), signatureEncoding (enum base58/base64, default base58).
      accountId: z
        .string()
        .describe(
          'The account id of the account that will sign the data. This account must be in the local keystore.',
        ),
      networkId: z.enum(['testnet', 'mainnet']).default('mainnet'),
      data: z.string().describe('The data to sign as a string.'),
      signatureEncoding: z
        .enum(['base58', 'base64'])
        .default('base58')
        .describe('The encoding to use for signature creation.'),
    },
  • MCP tool registration for 'account_sign_data' including name, description, input schema, and handler function.
      'account_sign_data',
      noLeadingWhitespace`
      Cryptographically sign a piece of data with a local account's private key, then encode the result with the specified encoding.
      Outputs the curve, encoded signature, and encoding used.`,
      {
        accountId: z
          .string()
          .describe(
            'The account id of the account that will sign the data. This account must be in the local keystore.',
          ),
        networkId: z.enum(['testnet', 'mainnet']).default('mainnet'),
        data: z.string().describe('The data to sign as a string.'),
        signatureEncoding: z
          .enum(['base58', 'base64'])
          .default('base58')
          .describe('The encoding to use for signature creation.'),
      },
      async (args, _) => {
        const keyPairResult: Result<KeyPair, Error> = await getAccountKeyPair(
          args.accountId,
          args.networkId,
          keystore,
        );
        if (!keyPairResult.ok) {
          return {
            content: [{ type: 'text', text: `Error: ${keyPairResult.error}` }],
          };
        }
        const keyPair = keyPairResult.value;
        const signatureRaw = keyPair.sign(new TextEncoder().encode(args.data));
        const signatureEncodingResult: Result<string, Error> = (() => {
          try {
            switch (args.signatureEncoding) {
              case 'base64':
                return {
                  ok: true,
                  value: Buffer.from(signatureRaw.signature).toString('base64'),
                };
              case 'base58':
                return {
                  ok: true,
                  value: base58.encode(Buffer.from(signatureRaw.signature)),
                };
              default:
                throw new Error(
                  `Unsupported encoding: ${String(args.signatureEncoding)}`,
                );
            }
          } catch (e) {
            return { ok: false, error: new Error(e as string) };
          }
        })();
        if (!signatureEncodingResult.ok) {
          return {
            content: [
              { type: 'text', text: `Error: ${signatureEncodingResult.error}` },
            ],
          };
        }
    
        return {
          content: [
            {
              type: 'text',
              text: stringify_bigint({
                signerAccountId: args.accountId,
                curve: keyTypeToCurvePrefix(keyPair.getPublicKey().keyType),
                signature: signatureEncodingResult.value,
                encoding: args.signatureEncoding,
              }),
            },
          ],
        };
      },
    );
  • Helper function to retrieve the KeyPair for a given account ID and network from the keystore, used by the account_sign_data handler.
    const getAccountKeyPair = async (
      accountId: string,
      networkId: string,
      keystore: UnencryptedFileSystemKeyStore,
    ): Promise<Result<KeyPair, Error>> => {
      try {
        const keyPair = await keystore.getKey(networkId, accountId);
        return { ok: true, value: keyPair };
      } catch (e) {
        return { ok: false, error: new Error(e as string) };
      }
    };
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses the core behavior (signing with a private key and encoding), but lacks details on permissions, rate limits, error conditions, or what happens if the account isn't local. It adds some context but misses critical behavioral traits for a cryptographic operation.

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 front-loaded with the core purpose in the first sentence, followed by output details. Every sentence earns its place with zero waste, making it appropriately sized and efficient for understanding the tool's function.

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

Completeness3/5

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

Given the complexity of cryptographic signing, no annotations, and no output schema, the description is incomplete. It covers the basic operation but lacks details on output format (beyond mentioning curve and encoding), error handling, or security implications. It's adequate but has clear gaps for a tool with no structured support.

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 75%, providing good parameter documentation. The description adds minimal value beyond the schema, mentioning encoding but not elaborating on parameters like accountId or data. It compensates slightly but doesn't fully address the 25% coverage gap or enhance understanding of required parameters.

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

Purpose5/5

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

The description clearly states the specific action ('Cryptographically sign a piece of data') with the resource ('a local account's private key'), and distinguishes it from siblings like account_verify_signature (verification) and account_view_account_summary (viewing). It precisely communicates the tool's function without being tautological.

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 no guidance on when to use this tool versus alternatives like account_verify_signature or other cryptographic operations. It mentions the account must be in the local keystore, but this is a prerequisite rather than usage context. No explicit when/when-not instructions are given.

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/nearai/near-mcp'

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