serial-mcp 0.7.2

MCP server for serial port communication. 22 tools (list/open/read/write/subscribe/get_status/reconfigure/list_profiles/open_profile/save_profile/delete_profile/get_log/clear_log/export_log/reconnect/...), resources, prompts, task cancellation, stdio + streamable-HTTP transports.
Documentation
//! JSON Schema helper functions to suppress non-standard `format` keywords
//! generated by schemars for unsigned integer types.
//!
//! # Why this module exists — READ BEFORE ADDING `uN`/`Option<uN>` FIELDS
//!
//! schemars 1.x emits a non-standard `"format": "uintN"` keyword for every
//! unsigned integer type (`uint8`, `uint16`, `uint32`, `uint64`, `uint`).
//! None of these are part of the JSON Schema spec. Validators (jsonschema,
//! AJV, …) log a warning like
//!
//! ```text
//! unknown format "uint16" ignored in schema at path "#/properties/vid"
//! ```
//!
//! and then silently drop the constraint. This is the source of the
//! `logs/unknown format "uintN" ignored` warnings this crate has shipped
//! multiple times.
//!
//! **Rule:** every `uN` / `Option<uN>` field on a struct that derives
//! [`schemars::JsonSchema`] MUST be annotated with
//! `#[schemars(schema_with = "crate::schema_helpers::uint_schema")]`
//! (or `option_uint_schema` for `Option<uN>`).
//!
//! Regression history:
//! - `b12b09fd` — initial fix for u32/u64/usize fields in tools/resources/prompts.
//! - `bc37a0b0` — follow-up for two new u64 fields.
//! - This commit — `PortInfo` (u16 vid/pid, u8 interface) added without
//!   overrides because the existing test only scanned `uint`/`uint32`/`uint64`
//!   and missed `uint8`/`uint16`.
//!
//! **Guards:** `serial::schema` (per-type schema scan, covers all known public
//! `JsonSchema` types) and `tools::tests::tool_schemas_have_no_nonstandard_uint_formats`
//! (tool `outputSchema` string scan, now covers uint8/uint16/uint32/uint64).
//! Do not delete these tests; extend the type list when adding new
//! `JsonSchema`-deriving structs with unsigned integer fields.

use schemars::{json_schema, Schema, SchemaGenerator};

use crate::limits::{
    MAX_READ_BYTES, MAX_STREAM_CHUNK_BYTES, MAX_TIMEOUT_MS, MIN_POLL_INTERVAL_MS, MIN_READ_BYTES,
    MIN_STREAM_CHUNK_BYTES,
};

/// Schema for unsigned integer fields without the non-standard `format` keyword.
/// Emits `{"type": "integer", "minimum": 0}`.
pub fn uint_schema(_gen: &mut SchemaGenerator) -> Schema {
    json_schema!({
        "type": "integer",
        "minimum": 0
    })
}

/// Schema for `Option<usize>`/`Option<u32>`/`Option<u64>` without the
/// non-standard `format` keyword.
/// Emits `{"anyOf": [{"type": "null"}, {"type": "integer", "minimum": 0}]}`.
pub fn option_uint_schema(_gen: &mut SchemaGenerator) -> Schema {
    json_schema!({
        "anyOf": [
            {"type": "null"},
            {"type": "integer", "minimum": 0}
        ]
    })
}

pub fn option_timeout_ms_schema(_gen: &mut SchemaGenerator) -> Schema {
    json_schema!({
        "anyOf": [
            {"type": "null"},
            {"type": "integer", "minimum": 0, "maximum": MAX_TIMEOUT_MS}
        ]
    })
}

/// Schema for `no_new_rx_timeout_ms`: rejects 0 (must be > 0) or null (disabled).
pub fn option_positive_timeout_ms_schema(_gen: &mut SchemaGenerator) -> Schema {
    json_schema!({
        "anyOf": [
            {"type": "null"},
            {"type": "integer", "minimum": 1, "maximum": MAX_TIMEOUT_MS}
        ]
    })
}

pub fn timeout_ms_schema(_gen: &mut SchemaGenerator) -> Schema {
    json_schema!({
        "type": "integer",
        "minimum": 0,
        "maximum": MAX_TIMEOUT_MS
    })
}

pub fn read_max_buffered_bytes_schema(_gen: &mut SchemaGenerator) -> Schema {
    json_schema!({
        "type": "integer",
        "minimum": MIN_READ_BYTES,
        "maximum": MAX_READ_BYTES
    })
}

pub fn stream_buffered_bytes_schema(_gen: &mut SchemaGenerator) -> Schema {
    json_schema!({
        "type": "integer",
        "minimum": MIN_STREAM_CHUNK_BYTES,
        "maximum": MAX_STREAM_CHUNK_BYTES
    })
}

pub fn poll_interval_ms_schema(_gen: &mut SchemaGenerator) -> Schema {
    json_schema!({
        "type": "integer",
        "minimum": MIN_POLL_INTERVAL_MS
    })
}

/// Schema for `Vec<u8>` byte array fields, suppressing the non-standard
/// `format: uint8` on the array items that schemars would otherwise emit.
pub fn byte_array_schema(_gen: &mut SchemaGenerator) -> Schema {
    json_schema!({
        "type": "array",
        "items": {
            "type": "integer",
            "minimum": 0,
            "maximum": 255
        }
    })
}