diff --git a/aimdb-client/CHANGELOG.md b/aimdb-client/CHANGELOG.md index d3f3e1e9..2efadbbe 100644 --- a/aimdb-client/CHANGELOG.md +++ b/aimdb-client/CHANGELOG.md @@ -20,6 +20,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- **`InboundRouteMetrics` and `InboundRouteStats` are re-exported** + (feature `observability`), the type of `RecordMetadata::inbound_routes`. + - **`AimxConnection::is_closed()` (#450):** whether the connection's engine has stopped. A caller keeping a connection open uses it to decide when to reconnect; an `internal` error reply does not mean the connection is gone. diff --git a/aimdb-client/src/lib.rs b/aimdb-client/src/lib.rs index 008bb80a..873d51c4 100644 --- a/aimdb-client/src/lib.rs +++ b/aimdb-client/src/lib.rs @@ -58,5 +58,8 @@ pub use engine::{AimxConnection, DrainResponse, RecordUpdate}; pub use aimdb_core::{Stamp, Stamped, WriteMetadata}; pub use error::{ClientError, ClientResult}; pub use protocol::{RecordMetadata, WelcomeMessage, CLIENT_NAME, PROTOCOL_VERSION}; +// The type of `RecordMetadata::inbound_routes`. +#[cfg(feature = "observability")] +pub use aimdb_core::{InboundRouteMetrics, InboundRouteStats}; // Arm a watch, then wait for updates written after it. pub use watch::{arm, await_updates, Armed, WatchOutcome, WatchStatus}; diff --git a/tools/aimdb-mcp/CHANGELOG.md b/tools/aimdb-mcp/CHANGELOG.md index 4fe0b264..9c566228 100644 --- a/tools/aimdb-mcp/CHANGELOG.md +++ b/tools/aimdb-mcp/CHANGELOG.md @@ -45,6 +45,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- **`list_records` returns `inbound_routes` (#494):** each inbound link's + admission counters (`accepted`, `upgraded`, `too_new`, `shape_mismatch`, + `malformed`, `decode_error`, ...), so an agent can see why values were + rejected. Omitted for records without inbound links. + - **`list_records` returns `schema_type` and `schema_version` (#420)** for records configured with a data-contract schema; both are omitted otherwise. diff --git a/tools/aimdb-mcp/README.md b/tools/aimdb-mcp/README.md index 4b356533..944b435c 100644 --- a/tools/aimdb-mcp/README.md +++ b/tools/aimdb-mcp/README.md @@ -229,8 +229,9 @@ List all records in an instance: ``` Query: "What records are in the demo instance?" -Result: Record names, types, buffer configs, producer/consumer counts, and the -declared schema (`schema_type`, `schema_version`) where the record has one +Result: Record names, types, buffer configs, producer/consumer counts, the +declared schema (`schema_type`, `schema_version`) where the record has one, and +per-link admission counters (`inbound_routes`) where it has inbound links ``` ### 4. get_record diff --git a/tools/aimdb-mcp/src/server.rs b/tools/aimdb-mcp/src/server.rs index 17e7e215..5ac2ba7f 100644 --- a/tools/aimdb-mcp/src/server.rs +++ b/tools/aimdb-mcp/src/server.rs @@ -191,8 +191,10 @@ impl McpServer { name: "list_records".to_string(), description: "List all records from a specific AimDB instance. Returns metadata including buffer type, capacity, producer/consumer counts, \ and the declared data contract as schema_type and schema_version. Those two fields \ - are absent when the record was configured without a schema. Use get_record to \ - see an observed value.".to_string(), + are absent when the record was configured without a schema. Records with inbound \ + links also carry inbound_routes: per-link counters of accepted, upgraded and \ + rejected values (too_new, shape_mismatch, malformed, decode_error, ...). Use \ + get_record to see an observed value.".to_string(), input_schema: json!({ "type": "object", "properties": { diff --git a/tools/aimdb-mcp/src/tools/record.rs b/tools/aimdb-mcp/src/tools/record.rs index 0875a4bd..e57983f0 100644 --- a/tools/aimdb-mcp/src/tools/record.rs +++ b/tools/aimdb-mcp/src/tools/record.rs @@ -74,6 +74,10 @@ struct RecordInfo { /// declares no schema. #[serde(skip_serializing_if = "Option::is_none")] schema_version: Option, + /// Per-link ingress counters (accepted, upgraded and each rejection + /// reason), one entry per inbound link. Absent when the record has none. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + inbound_routes: Vec, } /// List all records from a specific AimDB instance @@ -119,6 +123,7 @@ pub async fn list_records(args: Option) -> McpResult { outbound_connector_count: r.outbound_connector_count, schema_type: r.schema_type, schema_version: r.schema_version, + inbound_routes: r.inbound_routes, }) .collect(); @@ -301,6 +306,7 @@ mod tests { outbound_connector_count: 0, schema_type: schema_type.map(str::to_string), schema_version, + inbound_routes: Vec::new(), } } @@ -321,6 +327,33 @@ mod tests { assert!(!obj.contains_key("schema_version")); } + /// `list_records` passes each inbound link's admission counters through, + /// so an agent can see why values were rejected (#494). + #[test] + fn record_info_includes_inbound_routes() { + let mut info = record_info(None, None); + info.inbound_routes = vec![aimdb_client::InboundRouteMetrics { + link: "mqtt://sensors/temp".into(), + stats: aimdb_client::InboundRouteStats { + accepted: 3, + too_new: 1, + ..Default::default() + }, + }]; + let v = serde_json::to_value(info).unwrap(); + let route = &v["inbound_routes"][0]; + assert_eq!(route["link"], json!("mqtt://sensors/temp")); + assert_eq!(route["stats"]["accepted"], json!(3)); + assert_eq!(route["stats"]["too_new"], json!(1)); + } + + /// A record without inbound links omits the field, as the metadata does. + #[test] + fn record_info_omits_empty_inbound_routes() { + let v = serde_json::to_value(record_info(None, None)).unwrap(); + assert!(!v.as_object().unwrap().contains_key("inbound_routes")); + } + #[tokio::test] async fn test_list_records_missing_endpoint() { // Should fail without endpoint parameter