mcp_common/lib.rs
1//! MCP Common - Shared types and utilities for MCP proxy modules
2//!
3//! This crate provides common functionality shared across mcp-sse-proxy
4//! and mcp-streamable-proxy to avoid code duplication.
5//!
6//! # Feature Flags
7//!
8//! - `telemetry`: 基础 OpenTelemetry 支持
9//! - `otlp`: OTLP exporter 支持(用于 Jaeger 等)
10//!
11//! # 国际化 (i18n)
12//!
13//! 本 crate 提供多语言支持,使用 rust-i18n 实现。
14//!
15//! ## 使用方法
16//!
17//! ```rust,ignore
18//! // 注:doctest 无法通过(t! 展开依赖 #[macro_use] 注入的内部宏 _rust_i18n_t,
19//! //! 在 doctest 的独立 crate 中不可见),故标记 ignore;实际用法如下。
20//! use mcp_common::{t, set_locale, init_locale_from_env};
21//!
22//! // 初始化语言设置(程序启动时调用)
23//! init_locale_from_env();
24//!
25//! // 获取翻译
26//! let msg = t!("errors.mcp_proxy.service_not_found", service = "my-service");
27//! ```
28
29// 初始化 i18n,必须在 crate root 调用
30#[macro_use]
31extern crate rust_i18n;
32
33// 初始化翻译文件,使用 crate 内置 locales(支持独立发布)
34i18n!("locales", fallback = "en");
35
36pub mod backend_bridge;
37pub mod client_config;
38pub mod config;
39pub mod diagnostic;
40pub mod i18n;
41pub mod mirror;
42pub mod process_compat;
43pub mod retry;
44pub mod tool_filter;
45
46#[cfg(feature = "telemetry")]
47pub mod telemetry;
48
49// Re-export main types
50pub use backend_bridge::BackendBridge;
51pub use client_config::McpClientConfig;
52pub use config::McpServiceConfig;
53pub use process_compat::check_windows_command;
54pub use process_compat::ensure_runtime_path;
55pub use process_compat::resolve_windows_command;
56pub use process_compat::spawn_stderr_reader;
57pub use retry::capped_exponential_delay;
58pub use tool_filter::ToolFilter;
59
60// Re-export i18n types
61pub use i18n::{
62 AVAILABLE_LOCALES, DEFAULT_LOCALE, current_locale, init_locale_from_env, set_locale, t,
63};
64
65// Re-export telemetry types when feature is enabled
66#[cfg(feature = "telemetry")]
67pub use telemetry::{TracingConfig, TracingGuard, create_otel_layer, init_tracing};