Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ mod infra_routes;
mod infra_sqlite;
mod kube_routes;
mod llm_routes;
mod mcp_brand;
mod mcp_oauth;
mod mcp_routes;
mod memory_routes;
Expand Down Expand Up @@ -438,6 +439,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.merge(llm_routes::router())
.merge(mcp_routes::router())
.merge(mcp_oauth::router())
.merge(mcp_brand::router())
.merge(runner_routes::router())
.merge(actions_routes::router())
.merge(git_routes::router())
Expand Down
191 changes: 191 additions & 0 deletions apps/server/src/mcp_brand.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
//! Logo public du connecteur MCP DevForge.
//!
//! Grok (Bot et application) et les clients MCP 2025-06-18 lisent l’icône :
//! - avant la session, dans `logo_uri` des métadonnées OAuth (serveur d’autorisation
//! et ressource protégée) ;
//! - après `initialize`, dans `serverInfo.icons` (URLs absolues).
//!
//! Le `logo_uri` d’une réponse DCR (RFC 7591) est le logo du *client* qui s’enregistre.
//! Il est renvoyé tel quel s’il a été fourni : ce n’est pas le logo DevForge.
//!
//! Les PNG viennent de `brand/` (même fichier que `apps/web/public/brand/icon-512.png`).
//! Le SVG est le logo vectoriel déjà référencé par les plugins
//! (`cursor-plugin/*/assets/logo.svg`). `brand/icon.svg` est un PNG encapsulé, trop
//! lourd pour une carte de connecteur.

use axum::body::Body;
use axum::http::{header, HeaderValue, StatusCode};
use axum::response::Response;
use axum::routing::get;
use axum::Router;
use serde_json::{json, Value};

use crate::state::AppState;

const PNG_512: &[u8] = include_bytes!("../../../brand/icon-512.png");
const PNG_256: &[u8] = include_bytes!("../../../brand/icon-256.png");
const SVG: &[u8] = include_bytes!("../../../cursor-plugin/devforge/assets/logo.svg");

pub fn router() -> Router<AppState> {
icon_router()
}

fn icon_router<S>() -> Router<S>
where
S: Clone + Send + Sync + 'static,
{
Router::new()
.route("/icons/devforge-512.png", get(icon_512))
.route("/icons/devforge-256.png", get(icon_256))
.route("/icons/devforge.svg", get(icon_svg))
}

/// URL absolue annoncée comme `logo_uri` (PNG 512, fond opaque).
pub fn logo_uri(base: &str) -> String {
format!(
"{}/icons/devforge-512.png",
base.trim().trim_end_matches('/')
)
}

/// Icônes au format MCP (`serverInfo.icons`).
pub fn icons_json(base: &str) -> Value {
let b = base.trim().trim_end_matches('/');
json!([
{ "src": format!("{b}/icons/devforge-512.png"), "mimeType": "image/png", "sizes": ["512x512"] },
{ "src": format!("{b}/icons/devforge-256.png"), "mimeType": "image/png", "sizes": ["256x256"] },
{ "src": format!("{b}/icons/devforge.svg"), "mimeType": "image/svg+xml", "sizes": ["any"] }
])
}

pub fn server_info(base: &str) -> Value {
let base = base.trim().trim_end_matches('/');
let mut info = json!({
"name": "devforge",
"title": "DevForge",
"version": env!("CARGO_PKG_VERSION"),
});
if !base.is_empty() {
info["websiteUrl"] = json!(base);
info["icons"] = icons_json(base);
}
info
}

fn icon(bytes: &'static [u8], mime: &'static str) -> Response {
Response::builder()
.status(StatusCode::OK)
.header(header::CONTENT_TYPE, HeaderValue::from_static(mime))
.header(
header::CACHE_CONTROL,
HeaderValue::from_static("public, max-age=86400"),
)
.header(
header::ACCESS_CONTROL_ALLOW_ORIGIN,
HeaderValue::from_static("*"),
)
.header(
"x-content-type-options",
HeaderValue::from_static("nosniff"),
)
.body(Body::from(bytes))
.expect("réponse icône")
}

async fn icon_512() -> Response {
icon(PNG_512, "image/png")
}

async fn icon_256() -> Response {
icon(PNG_256, "image/png")
}

async fn icon_svg() -> Response {
icon(SVG, "image/svg+xml")
}

#[cfg(test)]
mod tests {
use super::*;
use axum::body::to_bytes;
use axum::http::header;
use tower::ServiceExt;

fn png_dims(b: &[u8]) -> (u32, u32) {
assert!(b.len() >= 24, "PNG trop court");
assert_eq!(&b[..8], b"\x89PNG\r\n\x1a\n");
(
u32::from_be_bytes(b[16..20].try_into().unwrap()),
u32::from_be_bytes(b[20..24].try_into().unwrap()),
)
}

#[test]
fn embedded_icons_match_announced_sizes() {
assert_eq!(png_dims(PNG_512), (512, 512));
assert_eq!(png_dims(PNG_256), (256, 256));
let svg = std::str::from_utf8(SVG).unwrap();
assert!(svg.contains("<svg"));
assert!(svg.contains("viewBox"));
}

#[test]
fn icons_are_absolute_under_public_base() {
let base = "https://web.jeser.app";
let icons = icons_json(base);
assert_eq!(
icons[0]["src"],
"https://web.jeser.app/icons/devforge-512.png"
);
assert_eq!(icons[0]["sizes"], json!(["512x512"]));
assert_eq!(icons[1]["mimeType"], "image/png");
assert_eq!(icons[2]["mimeType"], "image/svg+xml");
assert_eq!(
logo_uri(base),
"https://web.jeser.app/icons/devforge-512.png"
);
assert_eq!(logo_uri("https://web.jeser.app/"), logo_uri(base));

let info = server_info(base);
assert_eq!(info["title"], "DevForge");
assert_eq!(info["websiteUrl"], base);
assert_eq!(info["icons"][0]["src"], logo_uri(base));
assert!(server_info("").get("icons").is_none());
}

#[tokio::test]
async fn icon_routes_are_public_png_and_svg() {
let app = icon_router::<()>();
for (uri, mime, png) in [
("/icons/devforge-512.png", "image/png", true),
("/icons/devforge-256.png", "image/png", true),
("/icons/devforge.svg", "image/svg+xml", false),
] {
let res = app
.clone()
.oneshot(
axum::http::Request::builder()
.uri(uri)
.body(Body::empty())
.unwrap(),
)
.await
.unwrap();
assert_eq!(res.status(), StatusCode::OK, "{uri}");
assert_eq!(res.headers()[header::CONTENT_TYPE], mime, "{uri}");
assert!(res.headers()[header::CACHE_CONTROL]
.to_str()
.unwrap()
.contains("max-age=86400"));
assert_eq!(res.headers()[header::ACCESS_CONTROL_ALLOW_ORIGIN], "*");
let bytes = to_bytes(res.into_body(), 1024 * 1024).await.unwrap();
if png {
let (w, h) = png_dims(&bytes);
assert_eq!(w, h);
assert!(w == 512 || w == 256, "{uri} {w}");
} else {
assert!(bytes.starts_with(b"<svg"));
}
}
}
}
3 changes: 3 additions & 0 deletions apps/server/src/mcp_oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ pub fn protected_resource_doc(base: &str, mcp_path: &str) -> Value {
"bearer_methods_supported": ["header"],
"resource_name": "DevForge",
"resource_documentation": base,
"logo_uri": crate::mcp_brand::logo_uri(base),
})
}

Expand All @@ -255,6 +256,8 @@ pub fn authorization_server_doc(base: &str) -> Value {
"client_id_metadata_document_supported": true,
"authorization_response_iss_parameter_supported": true,
"service_documentation": base,
"client_uri": base,
"logo_uri": crate::mcp_brand::logo_uri(base),
})
}

Expand Down
4 changes: 4 additions & 0 deletions apps/server/src/mcp_oauth_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ fn metadata_documents_use_public_https_base() {
);
assert_eq!(asm["code_challenge_methods_supported"], json!(["S256"]));
assert_eq!(asm["client_id_metadata_document_supported"], true);
let logo = "https://web.jeser.app/icons/devforge-512.png";
assert_eq!(prm["logo_uri"], logo);
assert_eq!(asm["logo_uri"], logo);
assert_eq!(asm["client_uri"], BASE);
}

#[test]
Expand Down
16 changes: 8 additions & 8 deletions apps/server/src/mcp_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,10 +573,13 @@ async fn mcp_jsonrpc(
}
};

let base = resolve_public_base_url(&state, &headers)
.await
.unwrap_or_default();
if let Value::Array(items) = parsed {
let mut out = Vec::new();
for item in items {
if let Some(resp) = mcp_handle_one(&state, &abilities, &workspace, item).await {
if let Some(resp) = mcp_handle_one(&state, &abilities, &workspace, &base, item).await {
out.push(resp);
}
}
Expand All @@ -585,7 +588,7 @@ async fn mcp_jsonrpc(
}
return Json(Value::Array(out)).into_response();
}
match mcp_handle_one(&state, &abilities, &workspace, parsed).await {
match mcp_handle_one(&state, &abilities, &workspace, &base, parsed).await {
Some(resp) => Json(resp).into_response(),
None => axum::http::StatusCode::ACCEPTED.into_response(),
}
Expand All @@ -596,6 +599,7 @@ async fn mcp_handle_one(
state: &AppState,
abilities: &[String],
workspace: &str,
public_base: &str,
raw: Value,
) -> Option<Value> {
let body: JsonRpcRequest = match serde_json::from_value(raw) {
Expand Down Expand Up @@ -637,11 +641,7 @@ async fn mcp_handle_one(
rpc_ok(json!({
"protocolVersion": negotiate_protocol_version(requested),
"capabilities": { "tools": { "listChanged": false } },
"serverInfo": {
"name": "devforge",
"title": "DevForge",
"version": env!("CARGO_PKG_VERSION"),
},
"serverInfo": crate::mcp_brand::server_info(public_base),
"instructions": "DevForge : PaaS auto-hébergé. Outils pour lister les projets, lire/écrire des fichiers, déployer, lire les logs et vérifier la santé des applications.",
}))
}
Expand Down Expand Up @@ -1655,7 +1655,7 @@ async fn oauth_client_metadata(
"grant_types": ["authorization_code", "refresh_token"],
"response_types": ["code"],
"client_uri": app_url,
"logo_uri": format!("{}/favicon.ico", app_url),
"logo_uri": crate::mcp_brand::logo_uri(&app_url),
})))
}

Expand Down
Loading