Skip to main content

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
18//! use mcp_common::{t, set_locale, init_locale_from_env};
19//!
20//! // 初始化语言设置(程序启动时调用)
21//! init_locale_from_env();
22//!
23//! // 获取翻译
24//! let msg = t!("errors.mcp_proxy.service_not_found", service = "my-service");
25//! ```
26
27// 初始化 i18n,必须在 crate root 调用
28#[macro_use]
29extern crate rust_i18n;
30
31// 初始化翻译文件,使用 crate 内置 locales(支持独立发布)
32i18n!("locales", fallback = "en");
33
34pub mod backend_bridge;
35pub mod client_config;
36pub mod config;
37pub mod diagnostic;
38pub mod i18n;
39pub mod mirror;
40pub mod process_compat;
41pub mod tool_filter;
42
43#[cfg(feature = "telemetry")]
44pub mod telemetry;
45
46// Re-export main types
47pub use backend_bridge::BackendBridge;
48pub use client_config::McpClientConfig;
49pub use config::McpServiceConfig;
50pub use process_compat::check_windows_command;
51pub use process_compat::ensure_runtime_path;
52pub use process_compat::resolve_windows_command;
53pub use process_compat::spawn_stderr_reader;
54pub use tool_filter::ToolFilter;
55
56// Re-export i18n types
57pub use i18n::{
58    AVAILABLE_LOCALES, DEFAULT_LOCALE, current_locale, init_locale_from_env, set_locale, t,
59};
60
61// Re-export telemetry types when feature is enabled
62#[cfg(feature = "telemetry")]
63pub use telemetry::{TracingConfig, TracingGuard, create_otel_layer, init_tracing};