cleanpy 0.1.2

Python 3.12+ 最佳实践知识库 - MCP 服务器
Documentation
// Type definitions for cleanpy MCP server
// All data structures used across the application

use serde::{Deserialize, Serialize};

/// Topic information structure with embedded content
/// All documentation content is embedded at compile time via build.rs
#[derive(Debug, Clone, Serialize)]
pub struct TopicInfo {
    pub topic: &'static str,
    pub title: &'static str,
    pub when_to_use: &'static str,
    pub keywords: &'static [&'static str],
    pub file: &'static str,
    #[serde(skip_serializing)] // Don't include content in JSON serialization
    pub content: &'static str, // Embedded content from markdown files
}

/// Topic summary for list_topics (without file path)
#[derive(Debug, Serialize)]
pub struct TopicSummary {
    pub topic: &'static str,
    pub title: &'static str,
    pub when_to_use: &'static str,
    pub keywords: &'static [&'static str],
}

// JSON-RPC Message Types
#[derive(Debug, Deserialize)]
pub struct JsonRpcRequest {
    #[allow(dead_code)]
    pub jsonrpc: String,
    pub id: Option<serde_json::Value>,
    pub method: String,
    #[serde(default)]
    pub params: Option<serde_json::Value>,
}

#[derive(Debug, Serialize)]
pub struct JsonRpcResponse {
    pub jsonrpc: &'static str,
    pub id: Option<serde_json::Value>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub result: Option<serde_json::Value>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub error: Option<JsonRpcError>,
}

#[derive(Debug, Serialize)]
pub struct JsonRpcError {
    pub code: i32,
    pub message: String,
}

// MCP Protocol Types
#[derive(Debug, Serialize)]
pub struct InitializeResult {
    #[serde(rename = "protocolVersion")]
    pub protocol_version: &'static str,
    pub capabilities: Capabilities,
    #[serde(rename = "serverInfo")]
    pub server_info: ServerInfo,
}

#[derive(Debug, Serialize)]
pub struct Capabilities {
    pub tools: std::collections::HashMap<String, serde_json::Value>,
}

#[derive(Debug, Serialize)]
pub struct ServerInfo {
    pub name: &'static str,
    pub version: &'static str,
}

#[derive(Debug, Serialize)]
pub struct ToolSchema {
    pub name: &'static str,
    pub description: &'static str,
    #[serde(rename = "inputSchema")]
    pub input_schema: serde_json::Value,
}

#[derive(Debug, Serialize)]
pub struct ToolsListResult {
    pub tools: Vec<ToolSchema>,
}

#[derive(Debug, Serialize)]
pub struct ToolResult {
    pub content: Vec<ToolContent>,
}

#[derive(Debug, Serialize)]
pub struct ToolContent {
    pub r#type: &'static str,
    pub text: String,
}

/// Document metadata and content for search results
#[derive(Debug, Clone)]
pub(crate) struct DocumentMatch {
    pub topic: String,
    pub title: String,
    pub when_to_use: String,
    pub keywords: Vec<String>,
    pub file_path: String,
    pub matched_keywords: Vec<String>,
    pub relevance_score: f32,
}