Fix build: add response module, fix http_server, update Cargo.toml
Continuous Integration / Test Suite (macos-latest, nightly) (push) Has been cancelled
Continuous Integration / Test Suite (macos-latest, stable) (push) Has been cancelled
Continuous Integration / Test Suite (ubuntu-latest, 1.70.0) (push) Has been cancelled
Continuous Integration / Test Suite (ubuntu-latest, beta) (push) Has been cancelled
Continuous Integration / Test Suite (ubuntu-latest, nightly) (push) Has been cancelled
Continuous Integration / Test Suite (ubuntu-latest, stable) (push) Has been cancelled
Continuous Integration / Test Suite (windows-latest, stable) (push) Has been cancelled
Continuous Integration / Security Audit (push) Has been cancelled
Continuous Integration / Code Coverage (push) Has been cancelled
Continuous Integration / Performance Benchmarks (push) Has been cancelled
Continuous Integration / Memory Safety Check (push) Has been cancelled
Continuous Integration / Docker Build Test (push) Has been cancelled
Continuous Integration / Release Readiness (push) Has been cancelled
Continuous Integration / Integration Tests (push) Has been cancelled
Continuous Integration / Stress Testing (push) Has been cancelled
Continuous Integration / Notify Results (push) Has been cancelled

This commit is contained in:
2026-06-13 04:02:52 +00:00
parent bb547888bf
commit c5416bf745
4 changed files with 55 additions and 47 deletions
-8
View File
@@ -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;
+11 -5
View File
@@ -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<Arc<AppState>>
) -> Result<Response, axum::http::StatusCode> {
) -> axum::response::Response {
ws.on_upgrade(move |socket| async move {
let provider = state.provider.clone();
let mut ws = socket;
+43 -34
View File
@@ -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<String> },
Created { document_id: String, message: Option<String> },
Text { text: String },
Metadata { metadata: serde_json::Value },
Documents { documents: serde_json::Value },
Images { images: Vec<String>, message: Option<String> },
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<String> },
}
#[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<String>,
},
Created {
document_id: String,
message: Option<String>,
},
Text {
text: String,
},
Metadata {
metadata: Value,
},
Documents {
documents: Value,
},
Images {
images: Vec<String>,
message: Option<String>,
},
Security {
security: Value,
},
Storage {
storage: Value,
},
Statistics {
statistics: Value,
},
Structure {
structure: Value,
},
Error {
code: ErrorCode,
error: String,
hint: Option<String>,
},
}