Module content_types

Module content_types 

Source
Expand description

Type-safe MCP content types for tool responses

This module provides compile-time safe wrappers for MCP tool responses to ensure they follow the MCP protocol format. This prevents issues where raw data is returned instead of properly formatted MCP responses.

§Problem Solved

Previously, tools could return raw JSON objects which would cause MCP clients like Claude Code to report “no results found” even when data was successfully retrieved. These types ensure all responses follow the MCP protocol’s expected format.

§Usage

use solidmcp::content_types::{McpResponse, McpContent};
use serde_json::json;

// Instead of returning raw data:
// Ok(json!({"results": [...], "total": 10}))

// Return type-safe MCP response:
Ok(McpResponse::with_text_and_data(
    "Found 10 results for your search query",
    json!({"results": [...], "total": 10})
))

Structs§

McpResponse
Complete MCP-compliant tool response

Enums§

McpContent
Type-safe representation of MCP content

Traits§

ToMcpResponse
Helper trait for converting types to MCP responses