@@ -1406,22 +1406,28 @@ async def register_connector_for_prompt(
14061406 name = gateway_name , url = connector .url , transport = transport , visibility = "public" , auth_config = auth_config
14071407 )
14081408
1409+ gateway_id = gateway_response .get ("id" , gateway_response .get ("gateway_id" ))
1410+ gateway_slug = gateway_response .get ("slug" )
1411+
14091412 logger .debug (
14101413 f"Successfully created gateway for connector { connector_id } and prompt { budprompt_id } " ,
1411- gateway_id = gateway_response .get ("id" , gateway_response .get ("gateway_id" )),
1414+ gateway_id = gateway_id ,
1415+ gateway_slug = gateway_slug ,
14121416 )
14131417
14141418 # Create GatewayResponse object
14151419 gateway = GatewayResponse (
1416- gateway_id = gateway_response . get ( "id" , gateway_response . get ( " gateway_id" )) ,
1420+ gateway_id = gateway_id ,
14171421 name = gateway_name ,
14181422 url = connector .url ,
14191423 transport = "SSE" ,
14201424 visibility = "public" ,
14211425 )
14221426
14231427 # Store MCP tool configuration in Redis via budprompt service
1424- await self ._store_mcp_tool_config (budprompt_id , connector_id , gateway .gateway_id , version , permanent )
1428+ await self ._store_mcp_tool_config (
1429+ budprompt_id , connector_id , gateway .gateway_id , gateway_slug , version , permanent
1430+ )
14251431
14261432 # Update PromptVersion metadata with gateway_id (if prompt and version exist in DB)
14271433 try :
@@ -1760,6 +1766,10 @@ async def disconnect_connector_from_prompt(
17601766 # Step 5: Update gateway_config - remove connector
17611767 del gateway_config [connector_id ]
17621768
1769+ # Step 5b: Update gateway_slugs - remove connector's slug
1770+ gateway_slugs = mcp_tool .get ("gateway_slugs" , {})
1771+ gateway_slugs .pop (connector_id , None )
1772+
17631773 # Step 6: Update server_config - remove connector's tools
17641774 server_config .pop (connector_id , None )
17651775
@@ -1794,6 +1804,7 @@ async def disconnect_connector_from_prompt(
17941804 else :
17951805 # Update MCP tool config (connectors still remain)
17961806 mcp_tool ["gateway_config" ] = gateway_config
1807+ mcp_tool ["gateway_slugs" ] = gateway_slugs
17971808 mcp_tool ["server_config" ] = server_config
17981809 mcp_tool ["allowed_tools" ] = updated_allowed_tools
17991810 mcp_tool ["allowed_tool_names" ] = updated_allowed_tool_names
@@ -1930,6 +1941,7 @@ async def _store_mcp_tool_config(
19301941 budprompt_id : str ,
19311942 connector_id : str ,
19321943 gateway_id : str ,
1944+ gateway_slug : Optional [str ] = None ,
19331945 version : Optional [int ] = None ,
19341946 permanent : bool = False ,
19351947 ) -> None :
@@ -1939,13 +1951,15 @@ async def _store_mcp_tool_config(
19391951 budprompt_id: The bud prompt ID (can be UUID or draft prompt ID)
19401952 connector_id: The connector ID
19411953 gateway_id: The gateway ID from MCP Foundry
1954+ gateway_slug: The gateway slug from MCP Foundry (used for tool name shortening)
19421955 version: Optional version to update. If None, updates default version
19431956 permanent: Store configuration permanently without expiration
19441957
19451958 Raises:
19461959 ClientException: If storing configuration fails
19471960 """
19481961 # 1. Create MCPToolConfig using Pydantic schema
1962+ gateway_slugs = {connector_id : gateway_slug } if gateway_slug else {}
19491963 mcp_tool = MCPToolConfig (
19501964 type = "mcp" ,
19511965 server_label = None ,
@@ -1955,6 +1969,7 @@ async def _store_mcp_tool_config(
19551969 allowed_tools = [],
19561970 connector_id = None , # Set to None as requested
19571971 gateway_config = {connector_id : gateway_id },
1972+ gateway_slugs = gateway_slugs ,
19581973 )
19591974 mcp_tool_dict = mcp_tool .model_dump (exclude_none = True )
19601975
@@ -2011,6 +2026,12 @@ async def _store_mcp_tool_config(
20112026 gateway_config [connector_id ] = gateway_id
20122027 existing_mcp_tool ["gateway_config" ] = gateway_config
20132028
2029+ # Also merge gateway_slugs for tool name shortening
2030+ gateway_slugs_dict = existing_mcp_tool .get ("gateway_slugs" , {})
2031+ if gateway_slug :
2032+ gateway_slugs_dict [connector_id ] = gateway_slug
2033+ existing_mcp_tool ["gateway_slugs" ] = gateway_slugs_dict
2034+
20142035 # Also update server_config to maintain consistency
20152036 server_config = existing_mcp_tool .get ("server_config" , {})
20162037 # Note: server_config is updated separately when tools are added
0 commit comments