Skip to main content

ServerConfig

Struct ServerConfig 

Source
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: Option<SharedPolicyStoreSection>

[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

Source

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");
Source

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");
Source

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:

  1. server.name is non-empty (trimmed).
  2. server.version is non-empty (trimmed).
  3. Every [[tools]] entry has a non-empty name.
  4. No [[tools]] entry mixes tool kinds (sql / path+method / script) — D-01 / T-90-02-04.
  5. Every [[database.tables]] entry has a non-empty name.
  6. When a [backend] block is present (http feature), its base_url is 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

Source§

fn clone(&self) -> ServerConfig

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 ServerConfig

Source§

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

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

impl Default for ServerConfig

Source§

fn default() -> ServerConfig

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

impl<'de> Deserialize<'de> for ServerConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<&ServerConfig> for StaticPromptHandler

Source§

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

Source§

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

Source§

fn eq(&self, other: &ServerConfig) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for ServerConfig

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ServerConfig

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> 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<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

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