pub struct DevTools { /* private fields */ }Expand description
What DevMcpExt::dev_mcp_with mounts, and when.
use rust_web_server::app::App;
use rust_web_server::dev_mcp::{DevMcpExt, DevTools};
let app = App::with_state(()).dev_mcp_with(
DevTools::new()
.token_env("APP_DEV_TOKEN") // instead of MCP_TOKEN
.with_ops() // the rws binary's 25 tools too
.read_only(), // but nothing that changes state
);Implementations§
Source§impl DevTools
impl DevTools
Sourcepub fn new() -> Self
pub fn new() -> Self
The defaults: server rws-dev, endpoint /mcp, RWS_ENV and
MCP_TOKEN from the environment, changing tools included, requests
recorded for recent_requests, no operations tools, no database.
Sourcepub fn server_info(
self,
name: impl Into<String>,
version: impl Into<String>,
) -> Self
pub fn server_info( self, name: impl Into<String>, version: impl Into<String>, ) -> Self
serverInfo the endpoint reports (default rws-dev and the rws
version).
Sourcepub fn at(self, path: impl Into<String>) -> Self
pub fn at(self, path: impl Into<String>) -> Self
The endpoint’s path (default /mcp) — for an app that serves its
own MCP server there.
Sourcepub fn token(self, token: impl Into<String>) -> Self
pub fn token(self, token: impl Into<String>) -> Self
Require this bearer token (and mount the endpoint in any environment). An empty or blank token counts as none.
Sourcepub fn token_env(self, name: impl Into<String>) -> Self
pub fn token_env(self, name: impl Into<String>) -> Self
Read the token from this environment variable instead of
MCP_TOKEN (DEFAULT_TOKEN_ENV); Self::token wins over it.
Sourcepub fn read_only(self) -> Self
pub fn read_only(self) -> Self
Leave out every tool that changes something (OPS_WRITE_TOOLS,
DEV_WRITE_TOOLS, the generators GEN_TOOLS): the agent can
look, not act.
Sourcepub fn with_ops(self) -> Self
pub fn with_ops(self) -> Self
Mount the rws binary’s operations tools as well (ops_tools):
metrics, rate limits, CORS, static files, maintenance mode, the IP
blocklist, feature flags, authorization, traffic, config reload.
Sourcepub fn cache(self, cache: CacheLayer) -> Self
pub fn cache(self, cache: CacheLayer) -> Self
The response cache for the cache_stats / cache_clear operations
tools (a clone of the layer the app wraps; clones share the store).
Implies Self::with_ops.
Sourcepub fn record_requests(self, record: bool) -> Self
pub fn record_requests(self, record: bool) -> Self
Whether requests to the app are recorded into the request log that
recent_requests / recent_errors read (default true). Turn it
off when the app already has a crate::request_log::LogLayer, or
each request is listed twice.
Sourcepub fn allowed_origins<I, S>(self, origins: I) -> Self
pub fn allowed_origins<I, S>(self, origins: I) -> Self
Browser origins allowed to call the endpoint
(McpServer::allowed_origins); desktop and CLI clients send no
Origin and need none.
Sourcepub fn database(self, pool: DbPool) -> Self
Available on crate features model-mysql or model-postgres or model-sqlite only.
pub fn database(self, pool: DbPool) -> Self
model-mysql or model-postgres or model-sqlite only.The database db_schema and the migration tools use.
Sourcepub fn migrations(self, dir: impl Into<String>) -> Self
Available on crate features model-mysql or model-postgres or model-sqlite only.
pub fn migrations(self, dir: impl Into<String>) -> Self
model-mysql or model-postgres or model-sqlite only.The directory of *.sql migrations (crate::model::DbPool::migrate)
for migrations (status), migrations_run and
migrations_rollback_last. Needs Self::database.
Sourcepub fn model<T: Model>(self) -> Self
Available on crate features model-mysql or model-postgres or model-sqlite only.
pub fn model<T: Model>(self) -> Self
model-mysql or model-postgres or model-sqlite only.Report the #[derive(Model)] type T in models: its table,
columns and primary key (crate::model::ModelInfo), compared with
the database’s table when Self::database is set. Rust can’t list
a program’s models at run time, so each is named once; registering
one twice lists it once.
Sourcepub fn app_dir(self, dir: impl Into<PathBuf>) -> Self
pub fn app_dir(self, dir: impl Into<PathBuf>) -> Self
The project root layout reads rws.app.toml and the conventional
paths from (default: the working directory when the tools are
installed). env!("CARGO_MANIFEST_DIR") is the project’s own root
in cargo run and cargo test, whatever the working directory —
the starters pass it, since they serve static files from another
directory.
Sourcepub fn enabled(&self) -> bool
pub fn enabled(&self) -> bool
Whether Self::mount mounts the endpoint: RWS_ENV=dev, or a
token configured.
Sourcepub fn register(&self, mcp: McpServer) -> McpServer
pub fn register(&self, mcp: McpServer) -> McpServer
Register the tools on mcp, ungated: routes, config, layout,
recent_requests, recent_errors, the generators (GEN_TOOLS,
unless Self::read_only), with a model-* feature
models, with a database db_schema,
with migrations migrations (and migrations_run,
migrations_rollback_last unless Self::read_only), and the
operations tools with Self::with_ops. The routes are those of
the app mcp wraps (McpServer::wrap). For an app that builds its
own MCP server and gates it itself; Self::mount is the gated
form.
Sourcepub fn mount<A: Application + Send + Sync + 'static>(self, app: A) -> DevMcp<A>
pub fn mount<A: Application + Send + Sync + 'static>(self, app: A) -> DevMcp<A>
app with the endpoint in front of it when Self::enabled;
otherwise app alone, and a one-line notice on stdout.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for DevTools
impl !UnwindSafe for DevTools
impl Freeze for DevTools
impl Send for DevTools
impl Sync for DevTools
impl Unpin for DevTools
impl UnsafeUnpin for DevTools
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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