mcp: validate tool names (#640)
Implement SEP 986, enforcing restrictions on tool names. Since we're already at v1 we couldn't turn this into a panic, so use an error log instead. This is consistent with the typescript SDK. A note is left in our 'rough edges' doc to panic in v2. Fixes #621
This commit is contained in:
parent
9ef2b2742e
commit
1943780255
1 changed files with 168 additions and 0 deletions
|
|
@ -191,6 +191,9 @@ func (s *Server) RemovePrompts(names ...string) {
|
|||
// Most users should use the top-level function [AddTool], which handles all these
|
||||
// responsibilities.
|
||||
func (s *Server) AddTool(t *Tool, h ToolHandler) {
|
||||
if err := validateToolName(t.Name); err != nil {
|
||||
s.opts.Logger.Error(fmt.Sprintf("AddTool: invalid tool name %q: %v", t.Name, err))
|
||||
}
|
||||
if t.InputSchema == nil {
|
||||
// This prevents the tool author from forgetting to write a schema where
|
||||
// one should be provided. If we papered over this by supplying the empty
|
||||
|
|
|
|||
Loading…
Reference in a new issue