use std::sync::Arc;
use jsonwebtoken::Algorithm;
use protocol_droid::adapters::primary::transport::http::{
AuthPolicy, HttpBuilder, OAuthAuthenticator, ServerConfig, SystemClock,
};
use protocol_droid::adapters::secondary::oauth::jwt::JwtSource;
use protocol_droid::application::oauth::NoScopes;
use protocol_droid::application::server::Server;
use protocol_droid::domain::ProtocolVersion;
use protocol_droid::domain::mcp::{ResourceMetadata, ResourceUri};
use protocol_droid::domain::registry::auth::{Scope, ScopeSet};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let source = JwtSource::new(
Arc::from("https://login.example.com/.well-known/jwks.json"),
vec![Algorithm::RS256],
);
let metadata = ResourceMetadata::new(ResourceUri::new("https://mcp.example/mcp")?)
.with_authorization_server("https://login.example.com")
.with_scope("mcp:read");
match metadata.challenge() {
Ok(challenge) => println!("a 401 would carry: {challenge}"),
Err(error) => println!("no challenge: {error}"),
}
let authenticator = Arc::new(OAuthAuthenticator::new(
source,
metadata.clone(),
ProtocolVersion::V2025_06_18,
NoScopes,
SystemClock,
));
let policy = AuthPolicy::Require(ScopeSet::empty().with(Scope::Read));
let config = ServerConfig::new()?.with_resource_metadata(metadata);
let server = Server::builder("mcp").build();
let _builder = HttpBuilder::new(server)
.config(config)
.with_authenticator(authenticator)
.with_policy(policy);
Ok(())
}