pub struct McpServer {
tools: ToolRegistry,
resources: ResourceHandler,
transport: Transport,
port: u16,
rate_limit: RateLimitConfig,
jwt_authenticator: Option<JwtAuthenticator>,
cors_config: CorsConfig,
}Expand description
MCP server for subcog.
Fields§
§tools: ToolRegistryTool registry.
resources: ResourceHandlerResource handler.
transport: TransportTransport type.
port: u16HTTP port (if using HTTP transport).
rate_limit: RateLimitConfigRate limit configuration (ARCH-H1).
jwt_authenticator: Option<JwtAuthenticator>JWT authenticator for HTTP transport (SEC-H1).
cors_config: CorsConfigCORS configuration for HTTP transport (HIGH-SEC-006).
Implementations§
Source§impl McpServer
impl McpServer
Sourcepub fn with_cors_config(self, config: CorsConfig) -> Self
pub fn with_cors_config(self, config: CorsConfig) -> Self
Sets the CORS configuration for HTTP transport (HIGH-SEC-006).
By default, no origins are allowed (deny all CORS requests). Use this to explicitly allow specific origins.
Sourcepub fn with_jwt_authenticator(self, authenticator: JwtAuthenticator) -> Self
pub fn with_jwt_authenticator(self, authenticator: JwtAuthenticator) -> Self
Sets the JWT authenticator for HTTP transport (SEC-H1).
§Arguments
authenticator- The JWT authenticator to use for validating bearer tokens.
Sourcepub fn with_jwt_from_env(self) -> SubcogResult<Self>
pub fn with_jwt_from_env(self) -> SubcogResult<Self>
Initializes JWT authentication from environment variables.
Reads SUBCOG_MCP_JWT_SECRET, SUBCOG_MCP_JWT_ISSUER, and
SUBCOG_MCP_JWT_AUDIENCE from the environment.
§Errors
Returns an error if SUBCOG_MCP_JWT_SECRET is not set or too short.
Sourcepub const fn with_rate_limit(self, config: RateLimitConfig) -> Self
pub const fn with_rate_limit(self, config: RateLimitConfig) -> Self
Sourcefn try_init_resources() -> ResourceHandler
fn try_init_resources() -> ResourceHandler
Tries to initialize ResourceHandler with services.
Uses domain-scoped index (user-level index with project facets).
Sourcepub const fn with_transport(self, transport: Transport) -> Self
pub const fn with_transport(self, transport: Transport) -> Self
Sets the transport type.
Sourcepub async fn start(&mut self) -> SubcogResult<()>
pub async fn start(&mut self) -> SubcogResult<()>
Starts the MCP server with graceful shutdown handling (RES-M4).
Sets up signal handlers for SIGINT/SIGTERM before starting the server. The server will gracefully shut down when a signal is received.
§Errors
Returns an error if the server fails to start or signal handler cannot be installed.
fn build_handler(&mut self) -> McpHandler
Sourceasync fn run_stdio(&mut self) -> SubcogResult<()>
async fn run_stdio(&mut self) -> SubcogResult<()>
Runs the server over stdio with graceful shutdown (RES-M4).
Sourcefn graceful_shutdown(&self)
fn graceful_shutdown(&self)
Performs graceful shutdown cleanup (RES-M4).
Sourceasync fn run_http(&mut self) -> SubcogResult<()>
async fn run_http(&mut self) -> SubcogResult<()>
Runs the server over HTTP with JWT authentication (SEC-H1).
Requires the http feature and SUBCOG_MCP_JWT_SECRET environment variable.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for McpServer
impl !RefUnwindSafe for McpServer
impl Send for McpServer
impl Sync for McpServer
impl Unpin for McpServer
impl !UnwindSafe 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
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].