Add HTTP interface, templates, generate_from_template, unified Dockerfile
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 00:22:02 +00:00
parent d3fbbcfd7c
commit f655336757
11 changed files with 1789 additions and 45 deletions
+37 -8
View File
@@ -15,6 +15,8 @@ mod converter;
mod pure_converter;
#[cfg(all(feature = "runtime-server", feature = "advanced-docx"))]
mod advanced_docx;
#[cfg(feature = "http-server")]
mod http_server;
mod security;
#[cfg(feature = "embedded-fonts")]
@@ -53,6 +55,39 @@ async fn main() -> Result<()> {
}
}
// Check if HTTP mode is enabled before consuming args
let http_mode = args.http_mode;
let http_address = args.http_address.clone();
let templates_dir = args.templates_dir.clone();
// Create the tools provider
let security_config = security::SecurityConfig::from_args(args);
info!("Starting DOCX MCP Server - Security: {}", security_config.get_summary());
info!("Templates directory: {}", templates_dir);
let provider = DocxToolsProvider::new_with_security_and_templates(
security_config,
std::path::PathBuf::from(&templates_dir),
);
// Check if HTTP mode is enabled
if http_mode {
#[cfg(feature = "http-server")]
{
let addr = http_address.unwrap_or_else(|| "0.0.0.0:3000".to_string());
info!("Starting in HTTP mode on {}", addr);
return http_server::start_http_server(&addr, provider).await;
}
#[cfg(not(feature = "http-server"))]
{
eprintln!("HTTP mode requires the 'http-server' feature to be enabled during build.");
eprintln!("Rebuild with: cargo build --release --features http-server");
return Err(anyhow::anyhow!("HTTP mode not available"));
}
}
// Default: stdio mode
#[cfg(feature = "runtime-server")]
{
use mcp_server::{Router, Server};
@@ -67,9 +102,6 @@ async fn main() -> Result<()> {
use std::future::Future;
use tokio::io::{stdin, stdout};
let security_config = security::SecurityConfig::from_args(args);
info!("Starting DOCX MCP Server - Security: {}", security_config.get_summary());
#[derive(Clone)]
struct DocxRouter(docx_tools::DocxToolsProvider);
@@ -80,7 +112,6 @@ async fn main() -> Result<()> {
CapabilitiesBuilder::new().with_tools(true).build()
}
fn list_tools(&self) -> Vec<SpecTool> {
// DocxToolsProvider::list_tools is async; block briefly with tokio runtime handle
let rt = tokio::runtime::Handle::current();
let tools = rt.block_on(self.0.list_tools());
tools.into_iter().map(|t| SpecTool{ name: t.name, description: t.description.unwrap_or_default(), input_schema: t.input_schema }).collect()
@@ -90,7 +121,6 @@ async fn main() -> Result<()> {
let name = tool_name.to_string();
Box::pin(async move {
let resp = provider.call_tool(&name, arguments).await;
// Convert our CallToolResponse (text JSON) to Content::text
let text = match resp.content.get(0) {
Some(mcp_core::types::ToolResponseContent::Text(t)) => t.text.clone(),
_ => serde_json::to_string(&resp).unwrap_or_else(|_| "{}".to_string()),
@@ -108,7 +138,7 @@ async fn main() -> Result<()> {
}
}
let router = DocxRouter(DocxToolsProvider::new_with_security(security_config));
let router = DocxRouter(provider);
let service = RouterService(router);
let server = Server::new(service);
let transport = mcp_server::ByteTransport::new(stdin(), stdout());
@@ -117,9 +147,8 @@ async fn main() -> Result<()> {
#[cfg(not(feature = "runtime-server"))]
{
// No runtime server compiled in; if no subcommand was used, exit with guidance
eprintln!("Runtime server disabled. Rebuild with --features runtime-server to run the MCP server.");
}
Ok(())
}
}