Skip to main content

chant/mcp/
response.rs

1//! MCP response helpers for constructing consistent JSON responses.
2
3use serde_json::{json, Value};
4
5/// Create an MCP text response.
6///
7/// This is the standard format for successful tool responses in MCP.
8pub fn mcp_text_response(text: impl Into<String>) -> Value {
9    json!({
10        "content": [
11            {
12                "type": "text",
13                "text": text.into()
14            }
15        ]
16    })
17}
18
19/// Create an MCP error response.
20///
21/// This format is used for tool-level errors (not JSON-RPC protocol errors).
22pub fn mcp_error_response(text: impl Into<String>) -> Value {
23    json!({
24        "content": [
25            {
26                "type": "text",
27                "text": text.into()
28            }
29        ],
30        "isError": true
31    })
32}