feat: enhance MCP tool name and description handling for security

- Updated the tool name format to use service ID instead of service name, preventing name collisions across MCP services.
- Modified the tool description to indicate external sources, reducing the risk of indirect prompt injection.
- Added a prefix to the MCP tool output to treat it as untrusted data, further mitigating security risks.
This commit is contained in:
wizardchen
2026-02-06 14:42:01 +08:00
committed by lyingbug
parent a39c9dab9b
commit 67fba0679a
2 changed files with 22 additions and 9 deletions
+8 -2
View File
@@ -21,9 +21,15 @@ func NewToolRegistry() *ToolRegistry {
}
}
// RegisterTool adds a tool to the registry
// RegisterTool adds a tool to the registry.
// If a tool with the same name is already registered, the existing one is kept
// (first-wins) to prevent tool execution hijacking via name collision (GHSA-67q9-58vj-32qx).
func (r *ToolRegistry) RegisterTool(tool types.Tool) {
r.tools[tool.Name()] = tool
name := tool.Name()
if _, exists := r.tools[name]; exists {
return
}
r.tools[name] = tool
}
// GetTool retrieves a tool by name