feat: add built-in MCP service support

This commit is contained in:
AndyYang
2026-03-05 20:31:29 +08:00
committed by lyingbug
parent ead6712955
commit 6dde1330c2
14 changed files with 257 additions and 9 deletions
@@ -25,10 +25,12 @@ func (r *mcpServiceRepository) Create(ctx context.Context, service *types.MCPSer
}
// GetByID retrieves an MCP service by ID and tenant ID
// Builtin MCP services are visible to all tenants
func (r *mcpServiceRepository) GetByID(ctx context.Context, tenantID uint64, id string) (*types.MCPService, error) {
var service types.MCPService
err := r.db.WithContext(ctx).
Where("id = ? AND tenant_id = ?", id, tenantID).
Where("id = ?", id).
Where("tenant_id = ? OR is_builtin = true", tenantID).
First(&service).Error
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
@@ -41,10 +43,11 @@ func (r *mcpServiceRepository) GetByID(ctx context.Context, tenantID uint64, id
}
// List retrieves all MCP services for a tenant
// Includes builtin MCP services visible to all tenants
func (r *mcpServiceRepository) List(ctx context.Context, tenantID uint64) ([]*types.MCPService, error) {
var services []*types.MCPService
err := r.db.WithContext(ctx).
Where("tenant_id = ?", tenantID).
Where("tenant_id = ? OR is_builtin = true", tenantID).
Order("created_at DESC").
Find(&services).Error
if err != nil {
@@ -55,10 +58,11 @@ func (r *mcpServiceRepository) List(ctx context.Context, tenantID uint64) ([]*ty
}
// ListEnabled retrieves all enabled MCP services for a tenant
// Includes enabled builtin MCP services visible to all tenants
func (r *mcpServiceRepository) ListEnabled(ctx context.Context, tenantID uint64) ([]*types.MCPService, error) {
var services []*types.MCPService
err := r.db.WithContext(ctx).
Where("tenant_id = ? AND enabled = ?", tenantID, true).
Where("(tenant_id = ? OR is_builtin = true) AND enabled = ?", tenantID, true).
Order("created_at DESC").
Find(&services).Error
if err != nil {
@@ -69,6 +73,7 @@ func (r *mcpServiceRepository) ListEnabled(ctx context.Context, tenantID uint64)
}
// ListByIDs retrieves MCP services by multiple IDs for a tenant
// Includes builtin MCP services visible to all tenants
func (r *mcpServiceRepository) ListByIDs(
ctx context.Context,
tenantID uint64,
@@ -80,7 +85,7 @@ func (r *mcpServiceRepository) ListByIDs(
var services []*types.MCPService
err := r.db.WithContext(ctx).
Where("tenant_id = ? AND id IN ?", tenantID, ids).
Where("(tenant_id = ? OR is_builtin = true) AND id IN ?", tenantID, ids).
Find(&services).Error
if err != nil {
return nil, err
+16 -2
View File
@@ -81,8 +81,12 @@ func (s *mcpServiceService) ListMCPServices(ctx context.Context, tenantID uint64
}
// Mask sensitive data for list view
for _, service := range services {
service.MaskSensitiveData()
for i, service := range services {
if service.IsBuiltin {
services[i] = service.HideSensitiveInfo()
} else {
service.MaskSensitiveData()
}
}
return services, nil
@@ -118,6 +122,11 @@ func (s *mcpServiceService) UpdateMCPService(ctx context.Context, service *types
return fmt.Errorf("MCP service not found")
}
// Builtin MCP services cannot be updated
if existing.IsBuiltin {
return fmt.Errorf("builtin MCP services cannot be updated")
}
// Determine the final transport type after merge
finalTransportType := existing.TransportType
if service.TransportType != "" {
@@ -232,6 +241,11 @@ func (s *mcpServiceService) DeleteMCPService(ctx context.Context, tenantID uint6
return fmt.Errorf("MCP service not found")
}
// Builtin MCP services cannot be deleted
if existing.IsBuiltin {
return fmt.Errorf("builtin MCP services cannot be deleted")
}
// Close client connection
s.mcpManager.CloseClient(id)