Skip to main content
Glama
paladini

devutils-mcp-server

number_base_convert

Convert numbers between binary, octal, decimal, hexadecimal, or any base from 2 to 36. Specify the source and target bases to transform numerical values for programming, mathematics, or data analysis applications.

Instructions

Convert a number between different bases (binary, octal, decimal, hexadecimal, or any base 2-36).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
valueYesThe number string to convert
from_baseNoSource base (2-36, default: 10)
to_baseNoTarget base (2-36, default: 16)

Implementation Reference

  • The tool 'number_base_convert' is registered and implemented within the same `server.tool` call in `src/tools/converters.ts`.
    server.tool(
      "number_base_convert",
      "Convert a number between different bases (binary, octal, decimal, hexadecimal, or any base 2-36).",
      {
        value: z.string().describe("The number string to convert"),
        from_base: z
          .number()
          .int()
          .min(2)
          .max(36)
          .default(10)
          .describe("Source base (2-36, default: 10)"),
        to_base: z
          .number()
          .int()
          .min(2)
          .max(36)
          .default(16)
          .describe("Target base (2-36, default: 16)"),
      },
      async ({ value, from_base, to_base }) => {
        try {
          const decimal = parseInt(value, from_base);
          if (isNaN(decimal)) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: `Error: '${value}' is not a valid base-${from_base} number`,
                },
              ],
              isError: true,
            };
          }
    
          const result = {
            input: value,
            from_base,
            to_base,
            result: decimal.toString(to_base).toUpperCase(),
            decimal: decimal,
            binary: decimal.toString(2),
            octal: decimal.toString(8),
            hex: decimal.toString(16).toUpperCase(),
          };
    
          return {
            content: [
              { type: "text" as const, text: JSON.stringify(result, null, 2) },
            ],
          };
        } catch (e) {
          return {
            content: [
              {
                type: "text" as const,
                text: `Error: ${e instanceof Error ? e.message : String(e)}`,
              },
            ],
            isError: true,
          };
        }
      }
    );

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/paladini/devutils-mcp-server'

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