@@ -10,24 +10,21 @@ export const MCP_APPS_EXTENSION = "io.modelcontextprotocol/ui";
1010const MCP_APPS_MARKER_TTL_SECONDS = 24 * 60 * 60 ;
1111
1212/**
13- * Whether a JSON-RPC payload (single message or batch) is an initialize that
14- * declares MCP Apps support. The route layer uses this to record the client
15- * capability, because the stateless streamable-HTTP transport does not expose
16- * it to later requests .
13+ * Whether a JSON-RPC payload is a standalone initialize request that declares
14+ * MCP Apps support. The route layer records capability only for standalone
15+ * initialize requests so a mixed batch cannot self-attest and invoke app-only
16+ * tools in the same HTTP call .
1717 */
1818export function initializeDeclaresMcpApps ( body : unknown ) : boolean {
19- const messages = Array . isArray ( body ) ? body : [ body ] ;
20- return messages . some ( ( message ) => {
21- if ( ! message || typeof message !== "object" ) return false ;
22- const request = message as {
23- method ?: unknown ;
24- params ?: { capabilities ?: { extensions ?: Record < string , unknown > } } ;
25- } ;
26- return (
27- request . method === "initialize" &&
28- Boolean ( request . params ?. capabilities ?. extensions ?. [ MCP_APPS_EXTENSION ] )
29- ) ;
30- } ) ;
19+ if ( ! body || typeof body !== "object" || Array . isArray ( body ) ) return false ;
20+ const request = body as {
21+ method ?: unknown ;
22+ params ?: { capabilities ?: { extensions ?: Record < string , unknown > } } ;
23+ } ;
24+ return (
25+ request . method === "initialize" &&
26+ Boolean ( request . params ?. capabilities ?. extensions ?. [ MCP_APPS_EXTENSION ] )
27+ ) ;
3128}
3229
3330/**
0 commit comments