Hmbown/CodeWhale · error
.size must be an integer
Error message
{context}.size must be an integer What it means
parse_resource_entry validates fields returned by an MCP server when building a resource descriptor for the catalog. MCP requires resource 'size' to be an integer byte count; if the server returned a non-integer JSON value (string, float, bool, null) this error is thrown to reject the malformed entry rather than propagate bad metadata.
Solutions
- Fix the MCP server (or fixture) to emit 'size' as a JSON integer number of bytes
- Coerce/normalize the value in an intermediary proxy before it reaches this client
- Remove the 'size' field if the real byte count is unknown — the field is optional
Example fix
// before (server response)
{"name":"doc.txt","size":"1024"}
// after
{"name":"doc.txt","size":1024} Defensive patterns
Strategy: validation
Validate before calling
fn has_valid_size(v: &Value) -> bool {
v.get("size").map_or(true, |s| s.is_i64() || s.is_u64())
} Type guard
fn size_is_integer(v: &serde_json::Value) -> bool {
v.as_i64().is_some() || v.as_u64().is_some()
} Try / catch
match client.list_resources_with_metadata().await {
Ok(entries) => use(entries),
Err(e) if e.to_string().contains(".size must be an integer") => {
log::warn("server sent non-integer resource size; skipping");
}
Err(e) => return Err(e),
} Prevention
- Emit size as a JSON integer byte count from servers
- Validate server fixtures against the MCP resource schema in CI
- Fuzz-test server serialization with non-integer sizes
When it happens
Trigger: list_resources_with_metadata parses a resources/list response whose resource entry contains a 'size' field that is neither a JSON integer (i64/u64) — e.g. "size": "1024" or "size": 10.5.
Common situations: Third-party MCP servers serializing size as a string or float; hand-written mock servers or fixtures with stringified numbers; schema drift after an MCP server upgrade.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- .annotations is not a valid MCP annotations object
- invalid JSON payload at key
- bad_target
- Burn rate is optional. When set, it must be a positive $/hr.
- Cargo metadata dependencies for
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/1583ccfbfd5ddf20.
Report an issue: GitHub.
Appendix: source
Thrown at crates/mcp/src/stdio_client.rs:199
.get("uri")
.and_then(Value::as_str)
.with_context(|| format!("{context}.uri must be a string"))?
.to_string();
let name = fields
.get("name")
.and_then(Value::as_str)
.with_context(|| format!("{context}.name must be a string"))?
.to_string();
let description = optional_string_field(fields, "description", &context)?;
let mime_type = optional_string_field(fields, "mimeType", &context)?;
let mut metadata = json!({"name": name});
if let Some(mime_type) = mime_type {
metadata["mimeType"] = Value::String(mime_type);
}
if let Some(size) = fields.get("size") {
if size.as_i64().is_none() && size.as_u64().is_none() {
bail!("{context}.size must be an integer");
}
metadata["size"] = size.clone();
}
if let Some(annotations) = fields.get("annotations") {
if !valid_annotations(annotations) {
bail!("{context}.annotations is not a valid MCP annotations object");
}
metadata["annotations"] = annotations.clone();
}
Ok((
McpResourceDescriptor {
server_name: server_name.to_string(),
uri,
description,
},
metadata,
))View on GitHub (pinned to 73e0f67d83)