pub struct McpServer { /* private fields */ }Expand description
The main handle for the MCP integration.
McpServer can be attached to a RustApi instance (via its OpenAPI spec)
to automatically discover tools. Tool invocations (in later milestones)
will be driven through the normal RustAPI handler pipeline.
Implementations§
Source§impl McpServer
impl McpServer
Sourcepub fn from_rustapi(app: &RustApi, config: McpConfig) -> Self
pub fn from_rustapi(app: &RustApi, config: McpConfig) -> Self
Create an MCP server pre-attached to a RustApi instance.
This is the most ergonomic way when you already have a built RustApi.
If invocation_mode is InProcess or Auto, a direct in-process
dispatcher is captured for zero-overhead tool calls (see RequestInvoker).
Sourcepub fn from_spec(config: McpConfig, spec: &OpenApiSpec) -> Self
pub fn from_spec(config: McpConfig, spec: &OpenApiSpec) -> Self
Create from an explicit OpenAPI spec.
Sourcepub fn with_openapi(self, spec: OpenApiSpec) -> Self
pub fn with_openapi(self, spec: OpenApiSpec) -> Self
Attach (or replace) the OpenAPI spec used for discovery.
Call this after RustApi::auto() / builder if you built the app first.
Sourcepub fn with_http_base(self, base: impl Into<String>) -> Self
pub fn with_http_base(self, base: impl Into<String>) -> Self
Configure the base URL of the main RustAPI HTTP server.
When set, tools/call will proxy the call over HTTP to this base
(typically “http://127.0.0.1:8080” when using the concurrent runner).
This guarantees that tool invocations go through the exact same
middleware, auth, validation, and handler code as normal traffic.
Sourcepub fn capabilities(&self) -> Vec<McpCapability>
pub fn capabilities(&self) -> Vec<McpCapability>
Return the capabilities this server currently advertises.
Sourcepub fn initialize(&self) -> InitializeResult
pub fn initialize(&self) -> InitializeResult
Perform the initialize handshake.
MCP clients call this first. Returns server info + supported capabilities.
Sourcepub async fn list_tools(&self) -> Result<Vec<McpTool>>
pub async fn list_tools(&self) -> Result<Vec<McpTool>>
Discover and return the list of tools that should be exposed to MCP clients.
Tools are derived from the attached OpenAPI spec (from RustApi), filtered
according to McpConfig::allowed_tags and allowed_path_prefixes.
Sourcepub async fn call_tool(&self, req: ToolCallRequest) -> Result<ToolCallResponse>
pub async fn call_tool(&self, req: ToolCallRequest) -> Result<ToolCallResponse>
Execute a tool call by proxying it as a real HTTP request to the main
RustAPI server (using the configured http_base).
This is the heart of Native MCP: the call goes through your normal layers, interceptors, extractors, validation, error handling, etc.
Source§impl McpServer
impl McpServer
Sourcepub async fn serve(self, addr: &str) -> Result<()>
pub async fn serve(self, addr: &str) -> Result<()>
Start serving the MCP protocol over HTTP on the given address.
This starts a sidecar HTTP server (separate from your main RustAPI HTTP server) that MCP clients (Claude, etc.) can connect to for tool discovery and invocation.
Supports a minimal JSON-RPC over POST transport for:
initializetools/listtools/call(proxies to the main RustAPI server so full middleware / validation / error handling applies)
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for McpServer
impl !UnwindSafe for McpServer
impl Freeze for McpServer
impl Send for McpServer
impl Sync for McpServer
impl Unpin for McpServer
impl UnsafeUnpin for McpServer
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