Skip to main content

Config

Struct Config 

Source
pub struct Config {
Show 23 fields pub modes: ModeWords, pub capabilities: Capabilities, pub addr: String, pub bearer_tokens: Vec<String>, pub log_level: Level, pub timeout: Duration, pub cert_file: String, pub key_file: String, pub cors_origins: Vec<String>, pub lang: String, pub translations: HashMap<String, HashMap<String, String>>, pub channel_defaults: HashMap<String, String>, pub help_before: String, pub help_after: String, pub name: String, pub version: String, pub format: String, pub format_interactive: String, pub format_piped: String, pub format_from_flag: bool, pub response_headers: Vec<(String, String)>, pub no_server_headers: bool, pub allow_unknown_query: bool,
}
Expand description

Config 调整派发器。零值保持全部默认。

Fields§

§modes: ModeWords§capabilities: Capabilities§addr: String

serve 与 mcp(http) 模式的默认监听地址(各模式自己的 –addr flag 优先)。

§bearer_tokens: Vec<String>

开启 serve REST 与 MCP http 传输的 Bearer 凭据校验,每个元素是 一个可接受的 token;空表示不校验。命令行写法:–xyz.bearer=tok1,tok2 (stdio 传输为本地进程,不受影响)。

§log_level: Level

库自身诊断的日志级别(logx 输出到 stderr)。零值(LevelUnset) 保持默认 Info。命令行:–xyz.log-level=debug|info|warn|error。

§timeout: Duration

serve 模式的每请求超时(TimeoutLayer);0 = 不设超时。 (标准头超时在 Rust 实现里未单独配置,见 README 与 Go 版差异节。)

§cert_file: String

cert_file/key_file 同时给定则 serve 以 TLS 监听 (–xyz.tls-cert/–xyz.tls-key)。

§key_file: String§cors_origins: Vec<String>

CORSOrigins 非空则开启 CORS:逐个 Origin 放行(“*” 表示任意来源), OPTIONS 预检在鉴权之前应答。命令行:–xyz.cors=origin1,origin2。

§lang: String

界面语言覆盖:“”=自动(–xyz.lang flag > 本字段 > LANG/LC_ALL 环境 检测 > 英文默认)。取值 “en” | “zh-CN”。

§translations: HashMap<String, HashMap<String, String>>

用户的多语言内容覆盖表:语言 → (消息键 → 文本)。键名见 lang 目录 (xyz-spec §15.8 的规范键表)。

§channel_defaults: HashMap<String, String>

serve/mcp 启动时注入的通道级默认参数(字段线上名 → 字符串值): 请求/调用未显式提供时自动补上,优先级高于全局 default 属性、低于 显式入参与接口默认。命令行:–default k=v(可重复/逗号分隔对)。

§help_before: String

help 总览的自定义文本块:前者原样插在总览开头(程序名/描述/版本/ 仓库地址等自己拼),后者插在结尾(命令表之后,即使命令表被隐藏也 打印)。空 = 不插入。

§help_after: String§name: String

应用名(spec §11.6/§12.6):X-App-Name 响应头与 MCP serverInfo.name。 空 = 二进制 basename。

§version: String

应用版本(spec §11.6/§12.6):X-App-Version 响应头与 serverInfo.version。空 = version::version()(默认 “dev”)。 与 xyz 库自身的版本(version::SDK_VERSION → X-XYZ-Version)无关。

§format: String

代码级全局默认格式(spec §10.7 第四层):“”|auto = 按 TTY 解析为 format_interactive / format_piped。命令行 –xyz.format(第二层, format_from_flag 置位)与逐命令 CliHints.format(第三层)优先。

§format_interactive: String

format=auto 时交互式终端下的具体格式(默认 text)。

§format_piped: String

format=auto 时非交互(管道/重定向/其他程序调用)下的具体格式 (默认 jsonl)。

§format_from_flag: bool

标记 format 来自命令行 –xyz.format(命令行层,高于逐命令 hint)。

§response_headers: Vec<(String, String)>

附加到每个 HTTP 响应的自定义静态头(键值原样写入;与自动 X-App-/X-XYZ- 头并存)。命令行:–xyz.header k=v(可重复)。

§no_server_headers: bool

关闭自动服务器上下文头(HTTP 的 X-App-/X-XYZ- 与 MCP 结果的 _meta.xyz):spec §11.6/§12.8 的单一开关。自定义头不受影响。 命令行:–xyz.no-server-headers。

§allow_unknown_query: bool

接受未知 query 参数(默认 false = 严格:400 invalid_input,消息列出 该路由允许的参数集;spec §11.2)。静默忽略会让拼错/已移除的参数看起来 生效。命令行:–xyz.allow-unknown-query。

Implementations§

Source§

impl Config

Source

pub fn default_log_level(&self) -> Level

Source

pub fn resolved_name(&self) -> String

应用名:config 覆盖 > 二进制 basename(spec §11.6/§12.6)。

Source

pub fn resolved_version(&self) -> String

应用版本:config 覆盖 > 版本槽(默认 “dev”)。

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more