pub struct ServerConfig {
pub server: ServerSection,
pub metadata: MetadataSection,
pub database: DatabaseSection,
pub backend: Option<BackendSection>,
pub code_mode: Option<CodeModeSection>,
pub tools: Vec<ToolDecl>,
pub prompts: Vec<PromptDecl>,
pub resources: Vec<ResourceDecl>,
pub shared_policy_store: Option<SharedPolicyStoreSection>,
}Expand description
Top-level pmcp-server-toolkit configuration parsed from a config.toml.
One struct parses the entire file in one shot (per D-13). All sub-sections
carry #[serde(deny_unknown_fields)] — a typo anywhere in the file is a
hard parse error.
§Entry points
Use ServerConfig::from_toml_strict_validated for production callers.
ServerConfig::from_toml is the no-validation variant for programmatic
merges; ServerConfig::validate runs the semantic checks separately.
§Examples
use pmcp_server_toolkit::config::ServerConfig;
let toml = r#"
[server]
name = "demo"
version = "0.1.0"
"#;
let cfg = ServerConfig::from_toml_strict_validated(toml)
.expect("valid minimum config");
assert_eq!(cfg.server.name, "demo");
assert_eq!(cfg.server.version, "0.1.0");Fields§
§server: ServerSection[server] — identity and version metadata.
metadata: MetadataSection[metadata] — admin-facing display defaults.
database: DatabaseSection[database] — backend connection + tables.
backend: Option<BackendSection>[backend] (optional, http feature) — OpenAPI/REST HTTP backend
declaration (base_url + [backend.auth] + [backend.http]).
Additive per the REF-01 superset invariant (D-06): a pure-SQL config
omits [backend] and this field parses to None. The whole section is
gated behind the http feature — a no-http build has no OpenAPI backend,
so exposing an unusable stub type would be misleading. See
BackendSection.
code_mode: Option<CodeModeSection>[code_mode] (optional) — code-mode policy and limits.
tools: Vec<ToolDecl>[[tools]] — declarative tool surface (TOML-defined handlers).
prompts: Vec<PromptDecl>[[prompts]] — declarative prompt surface.
resources: Vec<ResourceDecl>[[resources]] — declarative resource surface.
[shared_policy_store] (optional) — AVP/Cedar shared-policy-store
declaration emitted by the reference SQL server (is_reference = true),
which provisions the policy store all sibling SQL servers attach to.
Additive per the REF-01 superset invariant (Plan 85-01); parsed
verbatim — the toolkit does not provision SSM at parse time.
Implementations§
Source§impl ServerConfig
impl ServerConfig
Sourcepub fn from_toml(toml_str: &str) -> Result<Self>
pub fn from_toml(toml_str: &str) -> Result<Self>
Parse ServerConfig from a TOML config string.
Performs strict parsing (#[serde(deny_unknown_fields)] on every
section, per D-13). Does not run semantic validation — callers
wanting required-field guarantees should use
Self::from_toml_strict_validated instead.
§Errors
Returns ToolkitError::Parse on syntax error or unknown field. A
mis-spelled key (e.g. auto_aprove_levels for auto_approve_levels)
produces a parse error here, not a silent default.
§Example
use pmcp_server_toolkit::config::ServerConfig;
let toml = r#"
[server]
id = "demo"
name = "Demo"
version = "0.1.0"
"#;
let cfg = ServerConfig::from_toml(toml).expect("parse");
assert_eq!(cfg.server.name, "Demo");Sourcepub fn from_toml_strict_validated(toml_str: &str) -> Result<Self>
pub fn from_toml_strict_validated(toml_str: &str) -> Result<Self>
Parse + validate. Per Phase 83 review R8 — guards against the
missing-required-value trap that the Default impls on sub-sections
would otherwise hide behind silent empty strings (e.g. a typo’d
[serever] header makes server.name default to "").
§Errors
Returns ToolkitError::Parse on TOML syntax / unknown-field errors,
or ToolkitError::Validation (wrapping
ConfigValidationError) on missing required values
(empty server.name, empty server.version, empty tool name, empty
table name).
§Example
use pmcp_server_toolkit::config::ServerConfig;
let toml = r#"
[server]
name = "demo"
version = "0.1.0"
"#;
let cfg = ServerConfig::from_toml_strict_validated(toml).expect("valid");Sourcepub fn validate(&self) -> Result<(), ConfigValidationError>
pub fn validate(&self) -> Result<(), ConfigValidationError>
Validate required-field semantics that #[serde(default)] would
otherwise mask. Per Phase 83 review R8.
Rules checked, in order:
server.nameis non-empty (trimmed).server.versionis non-empty (trimmed).- Every
[[tools]]entry has a non-emptyname. - No
[[tools]]entry mixes tool kinds (sql/path+method/script) — D-01 / T-90-02-04. - Every
[[database.tables]]entry has a non-emptyname. - When a
[backend]block is present (httpfeature), itsbase_urlis non-empty (trimmed) — GAP 3 / WR-02. Absent on no-http builds.
§Errors
Returns a ConfigValidationError variant identifying the
first rule violated. Iteration order matches struct field order.
Trait Implementations§
Source§impl Clone for ServerConfig
impl Clone for ServerConfig
Source§fn clone(&self) -> ServerConfig
fn clone(&self) -> ServerConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ServerConfig
impl Debug for ServerConfig
Source§impl Default for ServerConfig
impl Default for ServerConfig
Source§fn default() -> ServerConfig
fn default() -> ServerConfig
Source§impl<'de> Deserialize<'de> for ServerConfig
impl<'de> Deserialize<'de> for ServerConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<&ServerConfig> for StaticPromptHandler
impl From<&ServerConfig> for StaticPromptHandler
Source§fn from(cfg: &ServerConfig) -> Self
fn from(cfg: &ServerConfig) -> Self
Build a single StaticPromptHandler from a crate::config::ServerConfig.
Returns a handler for the FIRST [[prompts]] entry, or — if none are
declared — a no-op handler named "<no-prompts>" with an empty body.
Multi-prompt servers should use prompt_handlers_from_config instead.
§Example
use pmcp_server_toolkit::{ServerConfig, StaticPromptHandler};
let cfg = ServerConfig::default();
let _handler = StaticPromptHandler::from(&cfg);Source§impl From<&ServerConfig> for StaticResourceHandler
impl From<&ServerConfig> for StaticResourceHandler
Source§fn from(cfg: &ServerConfig) -> Self
fn from(cfg: &ServerConfig) -> Self
Build a StaticResourceHandler from a parsed crate::config::ServerConfig.
Each [[resources]] entry in config becomes one LoadedResource.
Resources with no content field default to an empty body — the
strict-parse path’s crate::config::ServerConfig::validate does not
flag empty resource bodies (operators may use the placeholder form
"loaded from path.md" as a stable URI handle), so this construction
follows suit. Resources WITH content_file semantics are out of scope
for the lifted shape (Lambda runtime constraint, mirroring
LoadedResource::from_config).
Insertion order matches the order of [[resources]] declarations,
satisfying Pattern D (deterministic list() output).
§Example
use pmcp_server_toolkit::{ServerConfig, StaticResourceHandler};
let cfg = ServerConfig::default();
let handler = StaticResourceHandler::from(&cfg);
assert_eq!(handler.len(), 0); // default config has no [[resources]]Source§impl PartialEq for ServerConfig
impl PartialEq for ServerConfig
Source§fn eq(&self, other: &ServerConfig) -> bool
fn eq(&self, other: &ServerConfig) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for ServerConfig
impl Serialize for ServerConfig
impl StructuralPartialEq for ServerConfig
Auto Trait Implementations§
impl Freeze for ServerConfig
impl RefUnwindSafe for ServerConfig
impl Send for ServerConfig
impl Sync for ServerConfig
impl Unpin for ServerConfig
impl UnsafeUnpin for ServerConfig
impl UnwindSafe for ServerConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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