From c5416bf745e8ae60c5a686f8a015bf973af4dbd6 Mon Sep 17 00:00:00 2001 From: MCP Admin Date: Sat, 13 Jun 2026 04:02:52 +0000 Subject: [PATCH] Fix build: add response module, fix http_server, update Cargo.toml --- Cargo.toml | 1 + src/docx_tools.rs | 8 ----- src/http_server.rs | 16 +++++++--- src/response.rs | 77 ++++++++++++++++++++++++++-------------------- 4 files changed, 55 insertions(+), 47 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 42d524f..e718c46 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ mcp-spec = "0.1" # Async runtime tokio = { version = "1.40", features = ["full"] } async-trait = "0.1" +futures = "0.3" # DOCX manipulation (pure Rust) docx-rs = "0.4" diff --git a/src/docx_tools.rs b/src/docx_tools.rs index cef0b8c..ca49b53 100644 --- a/src/docx_tools.rs +++ b/src/docx_tools.rs @@ -1,12 +1,4 @@ use mcp_core::types::{Tool, CallToolResponse, ToolResponseContent, TextContent}; -// Adapt to latest MCP: we'll integrate via mcp-server Router separately -use serde_json::{json, Value}; -use std::path::PathBuf; -use std::sync::{Arc, RwLock}; -use tracing::{debug, info}; - -use crate::docx_handler::{DocxHandler, DocxStyle, TableData}; -use crate::converter::DocumentConverter; use crate::response::{ToolOutcome, ErrorCode}; #[cfg(feature = "advanced-docx")] use crate::advanced_docx::AdvancedDocxHandler; diff --git a/src/http_server.rs b/src/http_server.rs index 2c7cafa..06355d7 100644 --- a/src/http_server.rs +++ b/src/http_server.rs @@ -1,9 +1,9 @@ use axum::{ extract::{ - ws::{Message, WebSocket}, + ws::{Message}, State, WebSocketUpgrade, }, - response::{Html, Response}, + response::Html, routing::{get, post}, Router, Json, @@ -12,6 +12,7 @@ use futures::{SinkExt, StreamExt}; use serde::{Deserialize, Serialize}; use std::{ net::SocketAddr, + str::FromStr, sync::Arc, }; use tower_http::cors::{Any, CorsLayer}; @@ -51,14 +52,18 @@ pub async fn start_http_server(addr: &str, provider: DocxToolsProvider) -> anyho let state = Arc::new(AppState { provider }); let app = Router::new() - .state(state.clone()) + .with_state(state.clone()) // Serve HTML interface .route("/", get(index_handler)) .route("/api/tools", get(list_tools_handler)) .route("/api/call", post(call_tool_handler)) .route("/ws", get(ws_handler)) // CORS policy - allow all origins on LAN - .layer(CorsLayer::new().allow_origin(Any()).allow_methods(tower_http::cors::Method::any())); + .layer( + CorsLayer::new() + .allow_origin(Any) + .allow_methods([axum::http::Method::GET, axum::http::Method::POST]) + ); let addr = SocketAddr::from_str(addr).unwrap_or_else(|_| { info!("Invalid address format, using default 0.0.0.0:3000"); @@ -117,6 +122,7 @@ async fn call_tool_handler( "mimeType": image.mime_type }) }, + _ => serde_json::json!({}), } } else { serde_json::json!({}) @@ -133,7 +139,7 @@ async fn call_tool_handler( async fn ws_handler( ws: WebSocketUpgrade, State(state): State> -) -> Result { +) -> axum::response::Response { ws.on_upgrade(move |socket| async move { let provider = state.provider.clone(); let mut ws = socket; diff --git a/src/response.rs b/src/response.rs index 6124315..2b4314b 100644 --- a/src/response.rs +++ b/src/response.rs @@ -1,42 +1,51 @@ -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; +use serde_json::Value; #[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(tag = "type", rename_all = "snake_case")] -pub enum ToolOutcome { - Ok { message: Option }, - Created { document_id: String, message: Option }, - Text { text: String }, - Metadata { metadata: serde_json::Value }, - Documents { documents: serde_json::Value }, - Images { images: Vec, message: Option }, - Security { security: serde_json::Value }, - Storage { storage: serde_json::Value }, - Statistics { statistics: serde_json::Value }, - Structure { structure: serde_json::Value }, - Error { code: ErrorCode, error: String, hint: Option }, -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(rename_all = "SCREAMING_SNAKE_CASE")] pub enum ErrorCode { - DocNotFound, ValidationError, - SecurityDenied, - LimitExceeded, - UnknownTool, + DocNotFound, InternalError, + UnknownTool, } -impl ToolOutcome { - pub fn success(&self) -> bool { - !matches!(self, ToolOutcome::Error { .. }) - } - - pub fn into_json(self) -> serde_json::Value { - serde_json::to_value(self).unwrap_or_else(|e| serde_json::json!({ - "type": "error", - "code": ErrorCode::InternalError, - "error": format!("serialization failed: {}", e), - })) - } +#[derive(Debug, Clone)] +pub enum ToolOutcome { + Ok { + message: Option, + }, + Created { + document_id: String, + message: Option, + }, + Text { + text: String, + }, + Metadata { + metadata: Value, + }, + Documents { + documents: Value, + }, + Images { + images: Vec, + message: Option, + }, + Security { + security: Value, + }, + Storage { + storage: Value, + }, + Statistics { + statistics: Value, + }, + Structure { + structure: Value, + }, + Error { + code: ErrorCode, + error: String, + hint: Option, + }, }