feat: Enhance MCP service configuration with stdio transport support
- Added support for stdio transport type in MCP service configuration, allowing command execution via standard input/output. - Updated MCPService interface to include optional stdio_config and env_vars fields for managing command arguments and environment variables. - Enhanced frontend components to handle stdio transport, including dynamic form fields for command and arguments. - Implemented validation logic for stdio configuration in the service update process, ensuring proper handling of required fields. - Updated backend logic to manage stdio transport connections and ensure proper client lifecycle management.
This commit is contained in:
@@ -108,8 +108,14 @@ func (r *mcpServiceRepository) Update(ctx context.Context, service *types.MCPSer
|
||||
if service.TransportType != "" {
|
||||
updateMap["transport_type"] = service.TransportType
|
||||
}
|
||||
if service.URL != "" {
|
||||
updateMap["url"] = service.URL
|
||||
if service.URL != nil {
|
||||
updateMap["url"] = *service.URL
|
||||
}
|
||||
if service.StdioConfig != nil {
|
||||
updateMap["stdio_config"] = service.StdioConfig
|
||||
}
|
||||
if service.EnvVars != nil {
|
||||
updateMap["env_vars"] = service.EnvVars
|
||||
}
|
||||
if service.Headers != nil {
|
||||
updateMap["headers"] = service.Headers
|
||||
|
||||
@@ -127,9 +127,15 @@ func (s *mcpServiceService) UpdateMCPService(ctx context.Context, service *types
|
||||
if service.TransportType != "" {
|
||||
existing.TransportType = service.TransportType
|
||||
}
|
||||
if service.URL != "" {
|
||||
if service.URL != nil {
|
||||
existing.URL = service.URL
|
||||
}
|
||||
if service.StdioConfig != nil {
|
||||
existing.StdioConfig = service.StdioConfig
|
||||
}
|
||||
if service.EnvVars != nil {
|
||||
existing.EnvVars = service.EnvVars
|
||||
}
|
||||
if service.Headers != nil {
|
||||
existing.Headers = service.Headers
|
||||
}
|
||||
@@ -149,9 +155,19 @@ func (s *mcpServiceService) UpdateMCPService(ctx context.Context, service *types
|
||||
return fmt.Errorf("failed to update MCP service: %w", err)
|
||||
}
|
||||
|
||||
// Check if critical configuration changed (URL, transport type, or auth config)
|
||||
// Check if critical configuration changed (URL/StdioConfig, transport type, or auth config)
|
||||
configChanged := false
|
||||
if service.URL != "" && service.URL != existing.URL {
|
||||
if service.URL != nil && existing.URL != nil && *service.URL != *existing.URL {
|
||||
configChanged = true
|
||||
} else if (service.URL != nil) != (existing.URL != nil) {
|
||||
configChanged = true
|
||||
}
|
||||
if service.StdioConfig != nil && existing.StdioConfig != nil {
|
||||
if service.StdioConfig.Command != existing.StdioConfig.Command ||
|
||||
!equalStringSlices(service.StdioConfig.Args, existing.StdioConfig.Args) {
|
||||
configChanged = true
|
||||
}
|
||||
} else if (service.StdioConfig != nil) != (existing.StdioConfig != nil) {
|
||||
configChanged = true
|
||||
}
|
||||
if service.TransportType != "" && service.TransportType != existing.TransportType {
|
||||
@@ -322,3 +338,16 @@ func (s *mcpServiceService) GetMCPServiceResources(ctx context.Context, tenantID
|
||||
|
||||
return resources, nil
|
||||
}
|
||||
|
||||
// equalStringSlices compares two string slices for equality
|
||||
func equalStringSlices(a, b []string) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
for i := range a {
|
||||
if a[i] != b[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user