pub struct McpServer { /* private fields */ }Expand description
通用 MCP 服务框架。
典型用法(app 侧):
ⓘ
let biz = Router::new()
.route("/search", post(handle_search))
.route("/file", post(handle_file))
.with_state(state); // 先把 state 解析成 Router<()>
McpServer::new("sts-x", env!("CARGO_PKG_VERSION"), HINT)
.tool(Tool::new("search", "...", schema))
.tool(Tool::new("file", "...", schema))
.merge(biz) // 挂载业务路由
.serve("127.0.0.1", 9876)
.await?;Implementations§
Source§impl McpServer
impl McpServer
pub fn new( service: impl Into<String>, version: impl Into<String>, instructions: impl Into<String>, ) -> Self
Sourcepub fn tools(self, tools: impl IntoIterator<Item = Tool>) -> Self
pub fn tools(self, tools: impl IntoIterator<Item = Tool>) -> Self
批量声明工具。
Sourcepub fn merge(self, router: Router) -> Self
pub fn merge(self, router: Router) -> Self
合并 app 自有业务路由(如 /search /file)。
传入的 Router 需已 .with_state(...) 解析为 Router<()>。
Sourcepub fn into_router(self) -> Router
pub fn into_router(self) -> Router
组装成最终 axum Router(自动挂载 /health、/tools、/ 后再合并业务路由)。
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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>
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 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>
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