fix: use service name for MCP tool naming with collision protection (#715)

- Use service.Name instead of service.ID (UUID) for stable tool names
  across MCP server reconnections
- Add (tenant_id, name) unique index on MCPService to prevent name
  collisions at the DB level
- Add collision detection logging in RegisterMCPTools for defense-in-depth
- Improve truncation logic to prioritize keeping the tool name intact

Security: first-wins policy in ToolRegistry + unique name constraint
prevents tool hijacking (GHSA-67q9-58vj-32qx).
This commit is contained in:
lyingbug
2026-03-20 22:30:52 +00:00
committed by lyingbug
parent e3ab971430
commit da9f7b43b6
2 changed files with 33 additions and 14 deletions
+2 -2
View File
@@ -21,8 +21,8 @@ const (
// MCPService represents an MCP (Model Context Protocol) service configuration
type MCPService struct {
ID string `json:"id" gorm:"type:varchar(36);primaryKey"`
TenantID uint64 `json:"tenant_id" gorm:"index"`
Name string `json:"name" gorm:"type:varchar(255);not null"`
TenantID uint64 `json:"tenant_id" gorm:"uniqueIndex:idx_tenant_name"`
Name string `json:"name" gorm:"type:varchar(255);not null;uniqueIndex:idx_tenant_name"`
Description string `json:"description" gorm:"type:text"`
Enabled bool `json:"enabled" gorm:"default:true;index"`
TransportType MCPTransportType `json:"transport_type" gorm:"type:varchar(50);not null"`