@@ -6,7 +6,7 @@ use fs_err as fs;
66use futures:: future:: BoxFuture ;
77use goose:: acp:: { PermissionDecision , ACP_CURRENT_MODEL } ;
88use goose:: agents:: extension:: { Envs , PLATFORM_EXTENSIONS } ;
9- use goose:: agents:: mcp_client:: McpClientTrait ;
9+ use goose:: agents:: mcp_client:: { GooseMcpHostInfo , McpClientTrait } ;
1010use goose:: agents:: platform_extensions:: developer:: DeveloperClient ;
1111use goose:: agents:: { Agent , AgentConfig , ExtensionConfig , GoosePlatform , SessionConfig } ;
1212use goose:: builtin_extension:: register_builtin_extensions;
@@ -47,6 +47,7 @@ use sacp::{
4747 Agent as SacpAgent , ByteStreams , Client , ConnectionTo , Dispatch , HandleDispatchFrom , Handled ,
4848 Responder ,
4949} ;
50+ use serde:: Deserialize ;
5051use std:: collections:: HashMap ;
5152use std:: sync:: Arc ;
5253use strum:: { EnumMessage , VariantNames } ;
@@ -120,12 +121,14 @@ pub struct GooseAcpAgent {
120121 builtins : Vec < String > ,
121122 client_fs_capabilities : OnceCell < FileSystemCapabilities > ,
122123 client_terminal : OnceCell < bool > ,
124+ client_mcp_host_info : OnceCell < GooseMcpHostInfo > ,
123125 config_dir : std:: path:: PathBuf ,
124126 session_manager : Arc < SessionManager > ,
125127 thread_manager : Arc < goose:: session:: ThreadManager > ,
126128 permission_manager : Arc < PermissionManager > ,
127129 goose_mode : GooseMode ,
128130 disable_session_naming : bool ,
131+ goose_platform : GoosePlatform ,
129132}
130133
131134fn extract_timeout_from_meta ( meta : & Option < Meta > ) -> Option < u64 > {
@@ -134,6 +137,52 @@ fn extract_timeout_from_meta(meta: &Option<Meta>) -> Option<u64> {
134137 . and_then ( |v| v. as_u64 ( ) )
135138}
136139
140+ #[ derive( Debug , Default , Deserialize ) ]
141+ struct GooseClientMetaEnvelope {
142+ #[ serde( default ) ]
143+ goose : Option < GooseClientMeta > ,
144+ }
145+
146+ #[ derive( Debug , Default , Deserialize ) ]
147+ struct GooseClientMeta {
148+ #[ serde( rename = "mcpHostCapabilities" , default ) ]
149+ mcp_host_capabilities : Option < GooseMcpHostCapabilities > ,
150+ }
151+
152+ #[ derive( Debug , Default , Deserialize ) ]
153+ struct GooseMcpHostCapabilities {
154+ #[ serde( default ) ]
155+ extensions : Option < rmcp:: model:: ExtensionCapabilities > ,
156+ }
157+
158+ fn extract_goose_client_meta ( meta : & Meta ) -> Option < GooseClientMetaEnvelope > {
159+ serde_json:: from_value ( serde_json:: Value :: Object ( meta. clone ( ) ) ) . ok ( )
160+ }
161+
162+ fn extract_client_mcp_host_info ( args : & InitializeRequest ) -> GooseMcpHostInfo {
163+ let host_capabilities = args
164+ . client_capabilities
165+ . meta
166+ . as_ref ( )
167+ . and_then ( extract_goose_client_meta)
168+ . and_then ( |meta| meta. goose )
169+ . and_then ( |goose| goose. mcp_host_capabilities ) ;
170+ let explicit_extensions = host_capabilities
171+ . as_ref ( )
172+ . and_then ( |capabilities| capabilities. extensions . as_ref ( ) )
173+ . is_some ( ) ;
174+ let extensions = host_capabilities
175+ . and_then ( |capabilities| capabilities. extensions )
176+ . unwrap_or_default ( ) ;
177+
178+ GooseMcpHostInfo {
179+ explicit_extensions,
180+ extensions,
181+ client_name : args. client_info . as_ref ( ) . map ( |info| info. name . clone ( ) ) ,
182+ client_version : args. client_info . as_ref ( ) . map ( |info| info. version . clone ( ) ) ,
183+ }
184+ }
185+
137186fn mcp_server_to_extension_config ( mcp_server : McpServer ) -> Result < ExtensionConfig , String > {
138187 match mcp_server {
139188 McpServer :: Stdio ( stdio) => {
@@ -608,6 +657,7 @@ impl GooseAcpAgent {
608657 config_dir : std:: path:: PathBuf ,
609658 goose_mode : GooseMode ,
610659 disable_session_naming : bool ,
660+ goose_platform : GoosePlatform ,
611661 ) -> Result < Self > {
612662 let session_manager = Arc :: new ( SessionManager :: new ( data_dir) ) ;
613663 let thread_manager = Arc :: new ( goose:: session:: ThreadManager :: new (
@@ -621,12 +671,14 @@ impl GooseAcpAgent {
621671 builtins,
622672 client_fs_capabilities : OnceCell :: new ( ) ,
623673 client_terminal : OnceCell :: new ( ) ,
674+ client_mcp_host_info : OnceCell :: new ( ) ,
624675 config_dir,
625676 session_manager,
626677 thread_manager,
627678 permission_manager,
628679 goose_mode,
629680 disable_session_naming,
681+ goose_platform,
630682 } )
631683 }
632684
@@ -672,19 +724,24 @@ impl GooseAcpAgent {
672724 . cloned ( )
673725 . unwrap_or_default ( ) ;
674726 let client_terminal = self . client_terminal . get ( ) . copied ( ) . unwrap_or ( false ) ;
727+ let client_mcp_host_info = self . client_mcp_host_info . get ( ) . cloned ( ) ;
675728 let provider_factory = Arc :: clone ( & self . provider_factory ) ;
676729 let disable_session_naming = self . disable_session_naming ;
730+ let goose_platform = self . goose_platform . clone ( ) ;
677731
678732 tokio:: spawn ( async move {
679733 let result: Result < ( ) , String > = async {
680- let agent = Arc :: new ( Agent :: with_config ( AgentConfig :: new (
681- session_manager,
682- permission_manager,
683- None ,
684- goose_mode,
685- disable_session_naming,
686- GoosePlatform :: GooseCli ,
687- ) ) ) ;
734+ let agent = Arc :: new ( Agent :: with_config (
735+ AgentConfig :: new (
736+ session_manager,
737+ permission_manager,
738+ None ,
739+ goose_mode,
740+ disable_session_naming,
741+ goose_platform,
742+ )
743+ . with_mcp_host_info ( client_mcp_host_info) ,
744+ ) ) ;
688745
689746 let config_path = config_dir. join ( CONFIG_YAML_NAME ) ;
690747 let mut extensions = Config :: new ( & config_path, "goose" )
@@ -1236,6 +1293,9 @@ impl GooseAcpAgent {
12361293 . client_fs_capabilities
12371294 . set ( args. client_capabilities . fs . clone ( ) ) ;
12381295 let _ = self . client_terminal . set ( args. client_capabilities . terminal ) ;
1296+ let _ = self
1297+ . client_mcp_host_info
1298+ . set ( extract_client_mcp_host_info ( & args) ) ;
12391299
12401300 let capabilities = AgentCapabilities :: new ( )
12411301 . load_session ( true )
@@ -2901,6 +2961,7 @@ pub async fn run(builtins: Vec<String>) -> Result<()> {
29012961 builtins,
29022962 data_dir : Paths :: data_dir ( ) ,
29032963 config_dir : Paths :: config_dir ( ) ,
2964+ goose_platform : GoosePlatform :: GooseCli ,
29042965 } ) ;
29052966 let agent = server. create_agent ( ) . await ?;
29062967 serve ( agent, incoming, outgoing) . await
0 commit comments