@@ -278,11 +278,11 @@ class AuthenticationValues(BaseModelWithConfigDict):
278278 auth_value : Optional [str ] = Field (None , description = "Encoded Authentication values" )
279279
280280 # Only For tool read and view tool
281- username : str = Field ("" , description = "Username for basic authentication" )
282- password : str = Field ("" , description = "Password for basic authentication" )
283- token : str = Field ("" , description = "Bearer token for authentication" )
284- auth_header_key : str = Field ("" , description = "Key for custom headers authentication" )
285- auth_header_value : str = Field ("" , description = "Value for custom headers authentication" )
281+ username : Optional [ str ] = Field ("" , description = "Username for basic authentication" )
282+ password : Optional [ str ] = Field ("" , description = "Password for basic authentication" )
283+ token : Optional [ str ] = Field ("" , description = "Bearer token for authentication" )
284+ auth_header_key : Optional [ str ] = Field ("" , description = "Key for custom headers authentication" )
285+ auth_header_value : Optional [ str ] = Field ("" , description = "Value for custom headers authentication" )
286286
287287
288288class ToolCreate (BaseModel ):
@@ -294,7 +294,7 @@ class ToolCreate(BaseModel):
294294 name (str): Unique name for the tool.
295295 url (Union[str, AnyHttpUrl]): Tool endpoint URL.
296296 description (Optional[str]): Tool description.
297- integration_type (Literal["REST"]): Tool integration type for REST integrations .
297+ integration_type (Literal["REST", "MCP" ]): Tool integration type - REST for individual endpoints, MCP for gateway-discovered tools .
298298 request_type (Literal["GET", "POST", "PUT", "DELETE", "PATCH"]): HTTP method to be used for invoking the tool.
299299 headers (Optional[Dict[str, str]]): Additional headers to send when invoking the tool.
300300 input_schema (Optional[Dict[str, Any]]): JSON Schema for validating tool parameters. Alias 'inputSchema'.
@@ -309,7 +309,7 @@ class ToolCreate(BaseModel):
309309 name : str = Field (..., description = "Unique name for the tool" )
310310 url : Union [str , AnyHttpUrl ] = Field (None , description = "Tool endpoint URL" )
311311 description : Optional [str ] = Field (None , description = "Tool description" )
312- integration_type : Literal ["REST" ] = Field ("REST" , description = "'REST' for REST integrations " )
312+ integration_type : Literal ["REST" , "MCP" ] = Field ("REST" , description = "'REST' for individual endpoints, 'MCP' for gateway-discovered tools " )
313313 request_type : Literal ["GET" , "POST" , "PUT" , "DELETE" , "PATCH" , "SSE" , "STDIO" , "STREAMABLEHTTP" ] = Field ("SSE" , description = "HTTP method to be used for invoking the tool" )
314314 headers : Optional [Dict [str , str ]] = Field (None , description = "Additional headers to send when invoking the tool" )
315315 input_schema : Optional [Dict [str , Any ]] = Field (default_factory = lambda : {"type" : "object" , "properties" : {}}, description = "JSON Schema for validating tool parameters" , alias = "inputSchema" )
@@ -457,12 +457,16 @@ def validate_request_type(cls, v: str, info: ValidationInfo) -> str:
457457 >>> info = type('obj', (object,), {'data': {'integration_type': 'REST'}})
458458 >>> ToolCreate.validate_request_type('GET', info)
459459 'GET'
460- >>> ToolCreate.validate_request_type('POST', info)
461- 'POST'
460+
461+ >>> # Test MCP integration types with valid transport
462+ >>> info = type('obj', (object,), {'data': {'integration_type': 'MCP'}})
463+ >>> ToolCreate.validate_request_type('SSE', info)
464+ 'SSE'
462465
463466 >>> # Test invalid REST type
467+ >>> info_rest = type('obj', (object,), {'data': {'integration_type': 'REST'}})
464468 >>> try:
465- ... ToolCreate.validate_request_type('SSE', info )
469+ ... ToolCreate.validate_request_type('SSE', info_rest )
466470 ... except ValueError as e:
467471 ... "not allowed for REST" in str(e)
468472 True
@@ -478,12 +482,17 @@ def validate_request_type(cls, v: str, info: ValidationInfo) -> str:
478482
479483 integration_type = info .data .get ("integration_type" )
480484
481- if integration_type != "REST" :
485+ if integration_type not in [ "REST" , "MCP" ] :
482486 raise ValueError (f"Unknown integration type: { integration_type } " )
483487
484- allowed = ["GET" , "POST" , "PUT" , "DELETE" , "PATCH" ]
485- if v not in allowed :
486- raise ValueError (f"Request type '{ v } ' not allowed for REST. Only { allowed } methods are accepted." )
488+ if integration_type == "REST" :
489+ allowed = ["GET" , "POST" , "PUT" , "DELETE" , "PATCH" ]
490+ if v not in allowed :
491+ raise ValueError (f"Request type '{ v } ' not allowed for REST. Only { allowed } methods are accepted." )
492+ elif integration_type == "MCP" :
493+ allowed = ["SSE" , "STDIO" , "STREAMABLEHTTP" ]
494+ if v not in allowed :
495+ raise ValueError (f"Request type '{ v } ' not allowed for MCP. Only { allowed } transports are accepted." )
487496
488497 return v
489498
@@ -551,8 +560,37 @@ def assemble_auth(cls, values: Dict[str, Any]) -> Dict[str, Any]:
551560 encoded_auth = encode_auth ({"Authorization" : f"Bearer { values .get ('auth_token' , '' )} " })
552561 values ["auth" ] = {"auth_type" : "bearer" , "auth_value" : encoded_auth }
553562 elif auth_type .lower () == "authheaders" :
554- encoded_auth = encode_auth ({values .get ("auth_header_key" , "" ): values .get ("auth_header_value" , "" )})
555- values ["auth" ] = {"auth_type" : "authheaders" , "auth_value" : encoded_auth }
563+ header_key = values .get ("auth_header_key" , "" )
564+ header_value = values .get ("auth_header_value" , "" )
565+ if header_key and header_value :
566+ encoded_auth = encode_auth ({header_key : header_value })
567+ values ["auth" ] = {"auth_type" : "authheaders" , "auth_value" : encoded_auth }
568+ else :
569+ # Don't encode empty headers - leave auth empty
570+ values ["auth" ] = {"auth_type" : "authheaders" , "auth_value" : None }
571+ return values
572+
573+ @model_validator (mode = "before" )
574+ @classmethod
575+ def prevent_manual_mcp_creation (cls , values : Dict [str , Any ]) -> Dict [str , Any ]:
576+ """
577+ Prevent manual creation of MCP tools via API.
578+
579+ MCP tools should only be created by the gateway service when discovering
580+ tools from MCP servers. Users should add MCP servers via the Gateways interface.
581+
582+ Args:
583+ values: The input values
584+
585+ Returns:
586+ Dict[str, Any]: The validated values
587+
588+ Raises:
589+ ValueError: If attempting to manually create MCP integration type
590+ """
591+ integration_type = values .get ("integration_type" )
592+ if integration_type == "MCP" :
593+ raise ValueError ("Cannot manually create MCP tools. Add MCP servers via the Gateways interface - " "tools will be auto-discovered and registered with integration_type='MCP'." )
556594 return values
557595
558596
@@ -565,7 +603,7 @@ class ToolUpdate(BaseModelWithConfigDict):
565603 name : Optional [str ] = Field (None , description = "Unique name for the tool" )
566604 url : Optional [Union [str , AnyHttpUrl ]] = Field (None , description = "Tool endpoint URL" )
567605 description : Optional [str ] = Field (None , description = "Tool description" )
568- integration_type : Optional [Literal ["REST" ]] = Field (None , description = "Tool integration type" )
606+ integration_type : Optional [Literal ["REST" , "MCP" ]] = Field (None , description = "Tool integration type" )
569607 request_type : Optional [Literal ["GET" , "POST" , "PUT" , "DELETE" , "PATCH" ]] = Field (None , description = "HTTP method to be used for invoking the tool" )
570608 headers : Optional [Dict [str , str ]] = Field (None , description = "Additional headers to send when invoking the tool" )
571609 input_schema : Optional [Dict [str , Any ]] = Field (None , description = "JSON Schema for validating tool parameters" )
@@ -678,7 +716,13 @@ def validate_request_type(cls, v: str, values: Dict[str, Any]) -> str:
678716 """
679717
680718 integration_type = values .data .get ("integration_type" , "REST" )
681- allowed = ["GET" , "POST" , "PUT" , "DELETE" , "PATCH" ]
719+
720+ if integration_type == "REST" :
721+ allowed = ["GET" , "POST" , "PUT" , "DELETE" , "PATCH" ]
722+ elif integration_type == "MCP" :
723+ allowed = ["SSE" , "STDIO" , "STREAMABLEHTTP" ]
724+ else :
725+ raise ValueError (f"Unknown integration type: { integration_type } " )
682726
683727 if v not in allowed :
684728 raise ValueError (f"Request type '{ v } ' not allowed for { integration_type } integration" )
@@ -721,8 +765,37 @@ def assemble_auth(cls, values: Dict[str, Any]) -> Dict[str, Any]:
721765 encoded_auth = encode_auth ({"Authorization" : f"Bearer { values .get ('auth_token' , '' )} " })
722766 values ["auth" ] = {"auth_type" : "bearer" , "auth_value" : encoded_auth }
723767 elif auth_type .lower () == "authheaders" :
724- encoded_auth = encode_auth ({values .get ("auth_header_key" , "" ): values .get ("auth_header_value" , "" )})
725- values ["auth" ] = {"auth_type" : "authheaders" , "auth_value" : encoded_auth }
768+ header_key = values .get ("auth_header_key" , "" )
769+ header_value = values .get ("auth_header_value" , "" )
770+ if header_key and header_value :
771+ encoded_auth = encode_auth ({header_key : header_value })
772+ values ["auth" ] = {"auth_type" : "authheaders" , "auth_value" : encoded_auth }
773+ else :
774+ # Don't encode empty headers - leave auth empty
775+ values ["auth" ] = {"auth_type" : "authheaders" , "auth_value" : None }
776+ return values
777+
778+ @model_validator (mode = "before" )
779+ @classmethod
780+ def prevent_manual_mcp_update (cls , values : Dict [str , Any ]) -> Dict [str , Any ]:
781+ """
782+ Prevent updating tools to MCP integration type via API.
783+
784+ MCP tools should only be managed by the gateway service. Users should not
785+ be able to change a REST tool to MCP type or vice versa manually.
786+
787+ Args:
788+ values: The input values
789+
790+ Returns:
791+ Dict[str, Any]: The validated values
792+
793+ Raises:
794+ ValueError: If attempting to update to MCP integration type
795+ """
796+ integration_type = values .get ("integration_type" )
797+ if integration_type == "MCP" :
798+ raise ValueError ("Cannot update tools to MCP integration type. MCP tools are managed by the gateway service." )
726799 return values
727800
728801
0 commit comments