pub struct MicrokernelServer<P: OAuthProviderTrait<S, DefaultClientManager<S>> + 'static, S: OAuthStorage + Clone + 'static, M: McpServerHandler = McpServer> { /* private fields */ }Expand description
Microkernel server builder that composes independent handlers
This builder demonstrates the microkernel principle where services are composed from independent, single-responsibility components. Now supports any OAuth provider, storage backend, and MCP server through trait abstraction.
Implementations§
Source§impl<P: OAuthProviderTrait<S, DefaultClientManager<S>> + 'static, S: OAuthStorage + Clone + 'static, M: McpServerHandler> MicrokernelServer<P, S, M>
impl<P: OAuthProviderTrait<S, DefaultClientManager<S>> + 'static, S: OAuthStorage + Clone + 'static, M: McpServerHandler> MicrokernelServer<P, S, M>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new microkernel server builder
Examples found in repository?
examples/custom_mcp_server_example.rs (line 478)
413async fn main() -> AppResult<()> {
414 // Load environment variables
415 dotenv::dotenv().ok();
416
417 // Load configuration
418 let config = Config::from_env()?;
419
420 // Initialize tracing
421 init_tracing(&config)?;
422
423 tracing::info!("Starting Custom MCP Server example with Cognito and DynamoDB storage...");
424
425 // Create Cognito OAuth configuration
426 let cognito_config = CognitoOAuthConfig {
427 client_id: config.cognito.client_id.clone(),
428 client_secret: config.cognito.client_secret.clone().unwrap_or_default(),
429 redirect_uri: format!(
430 "http://{}:{}/oauth/callback",
431 config.server.host, config.server.port
432 ),
433 scope: config.cognito.scope.clone(),
434 provider_name: "cognito".to_string(),
435 };
436
437 // Get DynamoDB configuration
438 let table_name =
439 env::var("DYNAMODB_TABLE_NAME").unwrap_or_else(|_| "oauth-storage".to_string());
440 let create_table = env::var("DYNAMODB_CREATE_TABLE")
441 .unwrap_or_else(|_| "true".to_string())
442 .parse::<bool>()
443 .unwrap_or(true);
444
445 // Log configuration
446 log_startup_info(&config, &table_name, create_table);
447
448 // Create DynamoDB storage
449 let (storage, client_manager) = create_dynamodb_storage(
450 table_name.clone(),
451 create_table,
452 Some("expires_at".to_string()),
453 )
454 .await
455 .map_err(|e| {
456 remote_mcp_kernel::error::AppError::Internal(format!(
457 "Failed to create DynamoDB storage: {}",
458 e
459 ))
460 })?;
461
462 // Create Cognito OAuth provider with DynamoDB storage
463 let oauth_handler = oauth_provider_rs::CognitoOAuthHandler::new_simple(
464 storage,
465 client_manager,
466 cognito_config,
467 config.cognito.cognito_domain.clone(),
468 config.cognito.region.clone(),
469 config.cognito.user_pool_id.clone(),
470 );
471
472 let oauth_provider = OAuthProvider::new(oauth_handler);
473
474 // Create custom MCP server
475 let custom_mcp_server = CustomMcpServer::new("Custom File & System MCP Server".to_string());
476
477 // Build microkernel with custom MCP server using convenience methods
478 let microkernel = MicrokernelServer::new()
479 .with_oauth_provider(oauth_provider)
480 .with_mcp_streamable_handler(custom_mcp_server.clone())
481 .with_mcp_sse_handler(custom_mcp_server, SseHandlerConfig::default());
482
483 // Start the microkernel server
484 let bind_address = config.bind_socket_addr()?;
485 tracing::info!("🚀 Starting microkernel server on {}", bind_address);
486 microkernel.serve(bind_address).await?;
487
488 Ok(())
489}Sourcepub fn with_oauth_provider(self, oauth_provider: OAuthProvider<P, S>) -> Self
pub fn with_oauth_provider(self, oauth_provider: OAuthProvider<P, S>) -> Self
Add OAuth provider handler
Examples found in repository?
examples/custom_mcp_server_example.rs (line 479)
413async fn main() -> AppResult<()> {
414 // Load environment variables
415 dotenv::dotenv().ok();
416
417 // Load configuration
418 let config = Config::from_env()?;
419
420 // Initialize tracing
421 init_tracing(&config)?;
422
423 tracing::info!("Starting Custom MCP Server example with Cognito and DynamoDB storage...");
424
425 // Create Cognito OAuth configuration
426 let cognito_config = CognitoOAuthConfig {
427 client_id: config.cognito.client_id.clone(),
428 client_secret: config.cognito.client_secret.clone().unwrap_or_default(),
429 redirect_uri: format!(
430 "http://{}:{}/oauth/callback",
431 config.server.host, config.server.port
432 ),
433 scope: config.cognito.scope.clone(),
434 provider_name: "cognito".to_string(),
435 };
436
437 // Get DynamoDB configuration
438 let table_name =
439 env::var("DYNAMODB_TABLE_NAME").unwrap_or_else(|_| "oauth-storage".to_string());
440 let create_table = env::var("DYNAMODB_CREATE_TABLE")
441 .unwrap_or_else(|_| "true".to_string())
442 .parse::<bool>()
443 .unwrap_or(true);
444
445 // Log configuration
446 log_startup_info(&config, &table_name, create_table);
447
448 // Create DynamoDB storage
449 let (storage, client_manager) = create_dynamodb_storage(
450 table_name.clone(),
451 create_table,
452 Some("expires_at".to_string()),
453 )
454 .await
455 .map_err(|e| {
456 remote_mcp_kernel::error::AppError::Internal(format!(
457 "Failed to create DynamoDB storage: {}",
458 e
459 ))
460 })?;
461
462 // Create Cognito OAuth provider with DynamoDB storage
463 let oauth_handler = oauth_provider_rs::CognitoOAuthHandler::new_simple(
464 storage,
465 client_manager,
466 cognito_config,
467 config.cognito.cognito_domain.clone(),
468 config.cognito.region.clone(),
469 config.cognito.user_pool_id.clone(),
470 );
471
472 let oauth_provider = OAuthProvider::new(oauth_handler);
473
474 // Create custom MCP server
475 let custom_mcp_server = CustomMcpServer::new("Custom File & System MCP Server".to_string());
476
477 // Build microkernel with custom MCP server using convenience methods
478 let microkernel = MicrokernelServer::new()
479 .with_oauth_provider(oauth_provider)
480 .with_mcp_streamable_handler(custom_mcp_server.clone())
481 .with_mcp_sse_handler(custom_mcp_server, SseHandlerConfig::default());
482
483 // Start the microkernel server
484 let bind_address = config.bind_socket_addr()?;
485 tracing::info!("🚀 Starting microkernel server on {}", bind_address);
486 microkernel.serve(bind_address).await?;
487
488 Ok(())
489}Sourcepub fn with_streamable_handler(
self,
streamable_handler: StreamableHttpHandler<M>,
) -> Self
pub fn with_streamable_handler( self, streamable_handler: StreamableHttpHandler<M>, ) -> Self
Add streamable HTTP handler
Sourcepub fn with_sse_handler(
self,
sse_handler: SseHandler<M>,
config: SseHandlerConfig,
) -> Self
pub fn with_sse_handler( self, sse_handler: SseHandler<M>, config: SseHandlerConfig, ) -> Self
Add SSE handler with configuration
Sourcepub fn with_mcp_sse_handler(
self,
mcp_server: M,
config: SseHandlerConfig,
) -> Self
pub fn with_mcp_sse_handler( self, mcp_server: M, config: SseHandlerConfig, ) -> Self
Create SSE handler with MCP server and configuration
Examples found in repository?
examples/custom_mcp_server_example.rs (line 481)
413async fn main() -> AppResult<()> {
414 // Load environment variables
415 dotenv::dotenv().ok();
416
417 // Load configuration
418 let config = Config::from_env()?;
419
420 // Initialize tracing
421 init_tracing(&config)?;
422
423 tracing::info!("Starting Custom MCP Server example with Cognito and DynamoDB storage...");
424
425 // Create Cognito OAuth configuration
426 let cognito_config = CognitoOAuthConfig {
427 client_id: config.cognito.client_id.clone(),
428 client_secret: config.cognito.client_secret.clone().unwrap_or_default(),
429 redirect_uri: format!(
430 "http://{}:{}/oauth/callback",
431 config.server.host, config.server.port
432 ),
433 scope: config.cognito.scope.clone(),
434 provider_name: "cognito".to_string(),
435 };
436
437 // Get DynamoDB configuration
438 let table_name =
439 env::var("DYNAMODB_TABLE_NAME").unwrap_or_else(|_| "oauth-storage".to_string());
440 let create_table = env::var("DYNAMODB_CREATE_TABLE")
441 .unwrap_or_else(|_| "true".to_string())
442 .parse::<bool>()
443 .unwrap_or(true);
444
445 // Log configuration
446 log_startup_info(&config, &table_name, create_table);
447
448 // Create DynamoDB storage
449 let (storage, client_manager) = create_dynamodb_storage(
450 table_name.clone(),
451 create_table,
452 Some("expires_at".to_string()),
453 )
454 .await
455 .map_err(|e| {
456 remote_mcp_kernel::error::AppError::Internal(format!(
457 "Failed to create DynamoDB storage: {}",
458 e
459 ))
460 })?;
461
462 // Create Cognito OAuth provider with DynamoDB storage
463 let oauth_handler = oauth_provider_rs::CognitoOAuthHandler::new_simple(
464 storage,
465 client_manager,
466 cognito_config,
467 config.cognito.cognito_domain.clone(),
468 config.cognito.region.clone(),
469 config.cognito.user_pool_id.clone(),
470 );
471
472 let oauth_provider = OAuthProvider::new(oauth_handler);
473
474 // Create custom MCP server
475 let custom_mcp_server = CustomMcpServer::new("Custom File & System MCP Server".to_string());
476
477 // Build microkernel with custom MCP server using convenience methods
478 let microkernel = MicrokernelServer::new()
479 .with_oauth_provider(oauth_provider)
480 .with_mcp_streamable_handler(custom_mcp_server.clone())
481 .with_mcp_sse_handler(custom_mcp_server, SseHandlerConfig::default());
482
483 // Start the microkernel server
484 let bind_address = config.bind_socket_addr()?;
485 tracing::info!("🚀 Starting microkernel server on {}", bind_address);
486 microkernel.serve(bind_address).await?;
487
488 Ok(())
489}Sourcepub fn with_mcp_streamable_handler(self, mcp_server: M) -> Self
pub fn with_mcp_streamable_handler(self, mcp_server: M) -> Self
Create streamable HTTP handler with MCP server
Examples found in repository?
examples/custom_mcp_server_example.rs (line 480)
413async fn main() -> AppResult<()> {
414 // Load environment variables
415 dotenv::dotenv().ok();
416
417 // Load configuration
418 let config = Config::from_env()?;
419
420 // Initialize tracing
421 init_tracing(&config)?;
422
423 tracing::info!("Starting Custom MCP Server example with Cognito and DynamoDB storage...");
424
425 // Create Cognito OAuth configuration
426 let cognito_config = CognitoOAuthConfig {
427 client_id: config.cognito.client_id.clone(),
428 client_secret: config.cognito.client_secret.clone().unwrap_or_default(),
429 redirect_uri: format!(
430 "http://{}:{}/oauth/callback",
431 config.server.host, config.server.port
432 ),
433 scope: config.cognito.scope.clone(),
434 provider_name: "cognito".to_string(),
435 };
436
437 // Get DynamoDB configuration
438 let table_name =
439 env::var("DYNAMODB_TABLE_NAME").unwrap_or_else(|_| "oauth-storage".to_string());
440 let create_table = env::var("DYNAMODB_CREATE_TABLE")
441 .unwrap_or_else(|_| "true".to_string())
442 .parse::<bool>()
443 .unwrap_or(true);
444
445 // Log configuration
446 log_startup_info(&config, &table_name, create_table);
447
448 // Create DynamoDB storage
449 let (storage, client_manager) = create_dynamodb_storage(
450 table_name.clone(),
451 create_table,
452 Some("expires_at".to_string()),
453 )
454 .await
455 .map_err(|e| {
456 remote_mcp_kernel::error::AppError::Internal(format!(
457 "Failed to create DynamoDB storage: {}",
458 e
459 ))
460 })?;
461
462 // Create Cognito OAuth provider with DynamoDB storage
463 let oauth_handler = oauth_provider_rs::CognitoOAuthHandler::new_simple(
464 storage,
465 client_manager,
466 cognito_config,
467 config.cognito.cognito_domain.clone(),
468 config.cognito.region.clone(),
469 config.cognito.user_pool_id.clone(),
470 );
471
472 let oauth_provider = OAuthProvider::new(oauth_handler);
473
474 // Create custom MCP server
475 let custom_mcp_server = CustomMcpServer::new("Custom File & System MCP Server".to_string());
476
477 // Build microkernel with custom MCP server using convenience methods
478 let microkernel = MicrokernelServer::new()
479 .with_oauth_provider(oauth_provider)
480 .with_mcp_streamable_handler(custom_mcp_server.clone())
481 .with_mcp_sse_handler(custom_mcp_server, SseHandlerConfig::default());
482
483 // Start the microkernel server
484 let bind_address = config.bind_socket_addr()?;
485 tracing::info!("🚀 Starting microkernel server on {}", bind_address);
486 microkernel.serve(bind_address).await?;
487
488 Ok(())
489}Sourcepub fn build_router(self) -> AppResult<Router>
pub fn build_router(self) -> AppResult<Router>
Build the composed router from all registered handlers
This method demonstrates the microkernel composition principle where independent components are combined into a unified service.
Sourcepub async fn serve(self, bind_address: SocketAddr) -> AppResult<()>
pub async fn serve(self, bind_address: SocketAddr) -> AppResult<()>
Start the microkernel server
Examples found in repository?
examples/oauth_standard_mcp_server.rs (line 38)
8async fn main() -> AppResult<()> {
9 // Load environment variables
10 dotenv::dotenv().ok();
11
12 // Load configuration
13 let config = Config::from_env()?;
14
15 // Initialize tracing
16 init_tracing(&config)?;
17
18 tracing::info!("Starting MCP OAuth server with microkernel architecture...");
19
20 // Create OAuth provider
21 let github_config = GitHubOAuthConfig {
22 client_id: config.github.client_id.clone(),
23 client_secret: config.github.client_secret.clone(),
24 redirect_uri: config.github.redirect_uri.clone(),
25 scope: config.github.scope.clone(),
26 provider_name: "github".to_string(),
27 };
28 let oauth_provider = GitHubOAuthProvider::new_github(github_config);
29
30 // Log configuration
31 log_startup_info(&config);
32
33 // Create microkernel server with all handlers composed
34 let microkernel = create_full_github_microkernel(oauth_provider);
35
36 // Start the microkernel server
37 let bind_address = config.bind_socket_addr()?;
38 microkernel.serve(bind_address).await?;
39
40 Ok(())
41}More examples
examples/oauth_cognito_mcp_server.rs (line 43)
8async fn main() -> AppResult<()> {
9 // Load environment variables
10 dotenv::dotenv().ok();
11
12 // Load configuration
13 let config = Config::from_env()?;
14
15 // Initialize tracing
16 init_tracing(&config)?;
17
18 tracing::info!("Starting MCP OAuth server with Cognito and microkernel architecture...");
19
20 // Create Cognito OAuth provider
21 let cognito_config = CognitoOAuthConfig {
22 client_id: config.cognito.client_id.clone(),
23 client_secret: config.cognito.client_secret.clone().unwrap_or_default(),
24 redirect_uri: config.cognito.redirect_uri.clone(),
25 scope: config.cognito.scope.clone(),
26 provider_name: "cognito".to_string(),
27 };
28 let oauth_provider = CognitoOAuthProvider::new_cognito(
29 cognito_config,
30 config.cognito.cognito_domain.clone(),
31 config.cognito.region.clone(),
32 config.cognito.user_pool_id.clone(),
33 );
34
35 // Log configuration
36 log_startup_info(&config);
37
38 // Create microkernel server with all handlers composed
39 let microkernel = create_full_cognito_microkernel(oauth_provider);
40
41 // Start the microkernel server
42 let bind_address = config.bind_socket_addr()?;
43 microkernel.serve(bind_address).await?;
44
45 Ok(())
46}examples/oauth_cognito_dynamodb_mcp_server.rs (line 110)
59async fn main() -> AppResult<()> {
60 // Load environment variables
61 dotenv::dotenv().ok();
62
63 // Load configuration
64 let config = Config::from_env()?;
65
66 // Initialize tracing
67 init_tracing(&config)?;
68
69 tracing::info!("Starting MCP OAuth server with Cognito and DynamoDB storage...");
70
71 // Create Cognito OAuth configuration
72 let cognito_config = CognitoOAuthConfig {
73 client_id: config.cognito.client_id.clone(),
74 client_secret: config.cognito.client_secret.clone().unwrap_or_default(),
75 redirect_uri: format!(
76 "http://{}:{}/oauth/callback",
77 config.server.host, config.server.port
78 ),
79 scope: config.cognito.scope.clone(),
80 provider_name: "cognito".to_string(),
81 };
82
83 // Get DynamoDB configuration
84 let table_name =
85 env::var("DYNAMODB_TABLE_NAME").unwrap_or_else(|_| "oauth-storage".to_string());
86 let create_table = env::var("DYNAMODB_CREATE_TABLE")
87 .unwrap_or_else(|_| "true".to_string())
88 .parse::<bool>()
89 .unwrap_or(true);
90
91 // Log configuration
92 log_startup_info(&config, &table_name, create_table);
93
94 // Create microkernel server with Cognito OAuth and DynamoDB storage
95 let microkernel = create_full_cognito_microkernel_dynamodb(
96 cognito_config,
97 config.cognito.cognito_domain.clone(),
98 config.cognito.region.clone(),
99 config.cognito.user_pool_id.clone(),
100 table_name,
101 create_table,
102 )
103 .await
104 .map_err(|e| {
105 remote_mcp_kernel::error::AppError::Internal(format!("Failed to create microkernel: {}", e))
106 })?;
107
108 // Start the microkernel server
109 let bind_address = config.bind_socket_addr()?;
110 microkernel.serve(bind_address).await?;
111
112 Ok(())
113}examples/custom_mcp_server_example.rs (line 486)
413async fn main() -> AppResult<()> {
414 // Load environment variables
415 dotenv::dotenv().ok();
416
417 // Load configuration
418 let config = Config::from_env()?;
419
420 // Initialize tracing
421 init_tracing(&config)?;
422
423 tracing::info!("Starting Custom MCP Server example with Cognito and DynamoDB storage...");
424
425 // Create Cognito OAuth configuration
426 let cognito_config = CognitoOAuthConfig {
427 client_id: config.cognito.client_id.clone(),
428 client_secret: config.cognito.client_secret.clone().unwrap_or_default(),
429 redirect_uri: format!(
430 "http://{}:{}/oauth/callback",
431 config.server.host, config.server.port
432 ),
433 scope: config.cognito.scope.clone(),
434 provider_name: "cognito".to_string(),
435 };
436
437 // Get DynamoDB configuration
438 let table_name =
439 env::var("DYNAMODB_TABLE_NAME").unwrap_or_else(|_| "oauth-storage".to_string());
440 let create_table = env::var("DYNAMODB_CREATE_TABLE")
441 .unwrap_or_else(|_| "true".to_string())
442 .parse::<bool>()
443 .unwrap_or(true);
444
445 // Log configuration
446 log_startup_info(&config, &table_name, create_table);
447
448 // Create DynamoDB storage
449 let (storage, client_manager) = create_dynamodb_storage(
450 table_name.clone(),
451 create_table,
452 Some("expires_at".to_string()),
453 )
454 .await
455 .map_err(|e| {
456 remote_mcp_kernel::error::AppError::Internal(format!(
457 "Failed to create DynamoDB storage: {}",
458 e
459 ))
460 })?;
461
462 // Create Cognito OAuth provider with DynamoDB storage
463 let oauth_handler = oauth_provider_rs::CognitoOAuthHandler::new_simple(
464 storage,
465 client_manager,
466 cognito_config,
467 config.cognito.cognito_domain.clone(),
468 config.cognito.region.clone(),
469 config.cognito.user_pool_id.clone(),
470 );
471
472 let oauth_provider = OAuthProvider::new(oauth_handler);
473
474 // Create custom MCP server
475 let custom_mcp_server = CustomMcpServer::new("Custom File & System MCP Server".to_string());
476
477 // Build microkernel with custom MCP server using convenience methods
478 let microkernel = MicrokernelServer::new()
479 .with_oauth_provider(oauth_provider)
480 .with_mcp_streamable_handler(custom_mcp_server.clone())
481 .with_mcp_sse_handler(custom_mcp_server, SseHandlerConfig::default());
482
483 // Start the microkernel server
484 let bind_address = config.bind_socket_addr()?;
485 tracing::info!("🚀 Starting microkernel server on {}", bind_address);
486 microkernel.serve(bind_address).await?;
487
488 Ok(())
489}Trait Implementations§
Source§impl<P: OAuthProviderTrait<S, DefaultClientManager<S>>, S: OAuthStorage + Clone + 'static, M: McpServerHandler> Default for MicrokernelServer<P, S, M>
impl<P: OAuthProviderTrait<S, DefaultClientManager<S>>, S: OAuthStorage + Clone + 'static, M: McpServerHandler> Default for MicrokernelServer<P, S, M>
Auto Trait Implementations§
impl<P, S, M> Freeze for MicrokernelServer<P, S, M>
impl<P, S, M> RefUnwindSafe for MicrokernelServer<P, S, M>
impl<P, S, M> Send for MicrokernelServer<P, S, M>
impl<P, S, M> Sync for MicrokernelServer<P, S, M>
impl<P, S, M> Unpin for MicrokernelServer<P, S, M>
impl<P, S, M> UnwindSafe for MicrokernelServer<P, S, M>
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
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 moreCreates a shared type from an unshared type.