MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / format_rows_response

Function format_rows_response

src/environmentd/src/http/mcp.rs:973–996  ·  view source on GitHub ↗

Serialize rows to JSON and enforce the response size cap. If the serialized response exceeds `max_size` bytes, returns an error telling the agent to narrow its query. This mirrors how the HTTP SQL endpoint handles `max_result_size` in sql.rs — fail cleanly rather than silently truncating.

(
    rows: Vec<Vec<serde_json::Value>>,
    max_size: usize,
)

Source from the content-addressed store, hash-verified

971/// endpoint handles `max_result_size` in sql.rs — fail cleanly rather
972/// than silently truncating.
973fn format_rows_response(
974 rows: Vec<Vec<serde_json::Value>>,
975 max_size: usize,
976) -> Result<McpResult, McpRequestError> {
977 let text =
978 serde_json::to_string_pretty(&rows).map_err(|e| McpRequestError::Internal(anyhow!(e)))?;
979
980 if text.len() > max_size {
981 return Err(McpRequestError::QueryExecutionFailed(format!(
982 "Response size ({} bytes) exceeds the {} byte limit. \
983 Use LIMIT or WHERE to narrow your query.",
984 text.len(),
985 max_size,
986 )));
987 }
988
989 Ok(McpResult::ToolContent(ToolContentResult {
990 content: vec![ContentBlock {
991 content_type: "text".to_string(),
992 text,
993 }],
994 is_error: false,
995 }))
996}
997
998async fn get_data_products(
999 client: &mut AuthedClient,

Calls 1

lenMethod · 0.45