fp-conv

io.github.sw23由 GitHub 账号 sw23 发布v1.5.1更新于 Nov 7, 2026

Encode, decode, and convert numbers across FP32, FP16, BF16, TF32, FP8/6/4, and integer formats.

已验证STDIO仅桌面开发者工具数据与分析

概览

AI 生成的概览

本地 MCP 服务器,让助手在 FP32、FP16、BF16、FP8 及整数等格式之间编码、解码和转换数值。

可以做什么
  • 列出与查看格式:列出预设格式,并获取某格式的偏置、取值范围和特殊值支持
  • 编码数值:把十进制数值或 Infinity/NaN 编码为二进制、十六进制及分量拆解
  • 解码位模式:把二进制或十六进制位模式还原为十进制数值及分量
  • 格式间转换:在两种格式间转换数值或位模式,支持舍入与溢出模式并给出精度损失分析
适用场景
适合处理底层数值表示的场景:查看某个值在 bf16 或 fp8 中的样子、排查位模式,或评估在 ML 与 IEEE 格式之间转换时的精度损失。
运行要求
通过 npx 以 stdio 在本地运行(需要 Node.js);无需账号、API 密钥或环境变量。可选在 127.0.0.1 上启动本地 Streamable HTTP 端点。
安装前请注意
可选的 HTTP 传输没有身份验证,默认只绑定 127.0.0.1;除非自行添加身份验证,否则不要绑定到非回环接口。各工具为只读计算,不需要任何凭据。

安装

在 SourceWeft 中

  1. 打开 控制台中的 fp-conv,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

fp-conv-mcp

[npm]

A Model Context Protocol (MCP) server that gives AI agents direct, local tools for floating-point conversions. It is the server-side companion to the fp-conv web app and reuses the same conversion library.

Encode, decode, and convert numbers across FP32, FP64, FP16, BF16, TF32, FP8, FP6, FP4, MX scale/element types, signed/unsigned ints, and custom formats. Supports rounding modes, overflow (saturation) behavior, and calculates precision loss.

Tools

ToolDescription
list_formatsList all available format presets (keys, names, categories, parameters).
get_format_infoGet detailed information about a format (bias, range, special-value support).
encode_numberEncode a decimal value (or Infinity/NaN) into a format. Returns binary, hex, and components.
decode_bitsDecode a binary or hex bit-pattern into a format. Returns the decimal value and components.
convert_formatConvert a value from one format to another.

For convert_format, the source is either a value, constructed using the input format's standard defaults, or bits, a binary or hex bit pattern in the input format used exactly as given; exactly one of the two is required. Its roundingMode and overflowMode parameters apply only when encoding the output format. encode_number applies those parameters to its sole format.

convert_format also takes nanMode, which decides what a NaN source becomes: canonical (default) gives the output format's canonical quiet NaN, and preserve keeps the sign and as many high-order payload bits as fit, quieted (IEEE 754-2019 §6.2.3). A NaN's sign and payload exist only in its bit pattern, so give it as bits: { "bits": "0xFFC00000", "inputFormat": "fp32", "outputFormat": "fp16", "nanMode": "preserve" } returns 0xFE00, where canonical returns 0x7E00. See NaN behavior.

Formats

All tools accept either a preset key (string) or a custom format object.

Preset keys

CategoryKeys
IEEE 754"fp64", "fp32", "fp16"
ML"bf16", "tf32"
OCP"fp8_e5m2", "fp8_e4m3", "fp6_e3m2", "fp6_e2m3", "fp4_e2m1", "e8m0", "mxint8"
Integer"int32", "uint32", "int16", "uint16", "int8", "uint8", "int4", "uint4"

Custom formats

For floating-point:

json
{ "signBits": 1, "exponentBits": 5, "mantissaBits": 10, "bias": 15, "hasInfinity": true, "hasNaN": true }
FieldRequiredDescription
signBitsnoNumber of sign bits, 0 or 1 (default 1)
exponentBitsyesNumber of exponent bits
mantissaBitsyesNumber of mantissa (fraction) bits
biasnoExponent bias; defaults to 2^(exponentBits-1) - 1
hasInfinitynoWhether the format can represent ±Infinity (default true)
hasNaNnoWhether the format can represent NaN (default true). Decided by the layout when hasInfinity is set: true with a mantissa field (passing false there is an error), false without one
hasSubnormalsnoWhether exponent field 0 is a subnormal/zero region (default true). Set false for a scale type such as E8M0.

For integers:

json
{ "bits": 16, "signed": true }
FieldRequiredDescription
bitsyesTotal bit width (1–64)
signednotrue for signed two's-complement, false for unsigned (default true)
fractionBitsnoImplicit 2^-fractionBits scale (default 0; MXINT8 uses 6)
symmetricnoLeave the most-negative encoding unused so the range is symmetric (default false)

Precision note: encoding, decoding and conversion are exact at every width. A value a JSON number could not name exactly (a 64-bit integer's maximum, a mantissa wider than 53 bits, a magnitude outside fp64's range) is returned as a decimal digit string rather than a rounded number. Every flag in a custom format, when given, must be a JSON boolean.

Client configuration

Refer to the following examples with details on how to configure the MCP server:

VS Code (.vscode/mcp.json)

json
{  "servers": {    "fp-conv": {      "type": "stdio",      "command": "npx",      "args": ["-y", "fp-conv-mcp"]    }  }}

Claude Code

bash
claude mcp add fp-conv -- npx -y fp-conv-mcp

GitHub Copilot CLI

bash
copilot mcp add fp-conv -- npx -y fp-conv-mcp

Cursor (.cursor/mcp.json) / Windsurf / Claude Desktop

json
{  "mcpServers": {    "fp-conv": {      "command": "npx",      "args": ["-y", "fp-conv-mcp"]    }  }}

Antigravity (~/.gemini/config/mcp_config.json)

json
{  "mcpServers": {    "fp-conv": {      "command": "npx",      "args": ["-y", "fp-conv-mcp"]    }  }}

Streamable HTTP (local only)

Alternatively, the server can run a local Streamable HTTP endpoint:

bash
npm install -g fp-conv-mcpfp-conv-mcp --http --host 127.0.0.1 --port 3001# endpoint: http://127.0.0.1:3001/mcp

Security: The HTTP transport has no authentication and binds to 127.0.0.1 by default. Do not bind it to a non-loopback interface unless you add your own authentication and understand the implications.

To block DNS-rebinding and cross-site requests from web pages, the server refuses (403) a request whose Host is not a loopback name or the --host address, and one whose Origin names any other host. A wildcard bind (--host 0.0.0.0) cannot know its own names, so it skips the Host check and only accepts an Origin that is loopback or matches the Host. Request bodies are capped at 1 MiB, and a session idle for 30 minutes is closed.

Usage

Once connected, you can ask an agent things like:

  • "Encode 3.14159 as bf16 and show the binary."
  • "What does the fp16 bit-pattern 0x3E00 decode to?"
  • "Convert 0.1 from fp32 to fp8 e4m3 and tell me the precision loss."
  • "List all supported formats."

Debugging

Use the MCP Inspector:

bash
npx @modelcontextprotocol/inspector npx fp-conv-mcp

Then open the Tools tab, click List Tools, and try any tool.

Development

This package lives in the fp-conv repository as an npm workspace. The published bundle (dist/index.js) inlines the shared conversion engine (lib/floating-point.js) and tool definitions (src/webmcp.js) from the repo root via esbuild, keeping a single source of truth.

bash
npm install                         # from the repo rootnpm run build --workspace fp-conv-mcpnpm test  --workspace fp-conv-mcp

License

MIT © Spencer Williams

来源:packages/fp-conv-mcp/README.md,提交 1fd706a

工具

5

list_formats

List formats

List all available floating-point and integer format presets supported by this converter. Returns format keys, names, categories, and parameters (bits, exponent, mantissa, etc.).

无需输入参数。

encode_number

Encode number

Encode a decimal number (or special value like Infinity / NaN) into a specified floating-point or integer format. Returns binary, hex, and component breakdown.

输入参数value必填format必填overflowModeroundingMode

decode_bits

Decode bits

Decode a binary or hexadecimal bit-pattern into a specified format. Returns the decimal value and full component breakdown.

输入参数bits必填format必填

convert_format

Convert format

Convert a value or bit pattern from one floating-point or integer format to another. Returns full encoding details for both formats and precision loss analysis.

输入参数bitsvaluenanModeinputFormat必填outputFormat必填overflowModeroundingMode

get_format_info

Get format info

Get detailed information about a floating-point or integer format, including value range (max/min normal, subnormal), bias, and special value support.

输入参数format必填

版本历史

1
  1. v1.5.1最新Oct 31, 2026

评分

已满足适用检查项的 90%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分
  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具必需15 分
  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分