fix: address review findings on SDK godoc and nil guard

- pkg/kit: remove internal package paths from exported godoc on
  ParseTemplate and the ToolKind* constants (SDK doc surface must not
  reference internal packages)
- internal/tools: guard marshalToolResult against a nil CallToolResult
  (json.Marshal(nil) succeeds as 'null', then result.IsError panics if
  a client returns nil result with nil error)

Skipped the TreeNode Children deep-copy suggestion: the slice already
comes from TreeManager.GetChildren which returns a fresh copy per call
into a throwaway intermediate, so no internal state is exposed.
This commit is contained in:
Ed Zynda
2026-06-11 16:03:50 +03:00
parent 086d9334c8
commit 03d78dfa65
3 changed files with 7 additions and 3 deletions
+3
View File
@@ -737,6 +737,9 @@ func (m *MCPToolManager) withOAuthRetry(ctx context.Context, serverName, toolNam
// marshalToolResult converts an MCP CallToolResult into the JSON-encoded
// MCPToolResult shape returned to the agent.
func marshalToolResult(result *mcp.CallToolResult) (*MCPToolResult, error) {
if result == nil {
return nil, errors.New("mcp tool call returned nil result")
}
marshaled, err := json.Marshal(result)
if err != nil {
return nil, fmt.Errorf("failed to marshal mcp tool result: %w", err)
+2 -2
View File
@@ -106,8 +106,8 @@ type Event interface {
// for execute tools) and file trackers to identify which results contain
// modifications.
//
// The canonical classification lives in internal/extensions; these constants
// re-export it so SDK events and extension events always agree.
// These constants re-export the canonical classification used by extension
// events, so SDK events and extension events always agree.
const (
ToolKindExecute = extensions.ToolKindExecute // Shell execution (bash)
ToolKindEdit = extensions.ToolKindEdit // File modification (edit, write)
+2 -1
View File
@@ -16,7 +16,8 @@ import (
// ---------------------------------------------------------------------------
// ParseTemplate extracts {{variables}} from template content. The template
// grammar is shared with skill prompt templates (see internal/skills).
// grammar is shared with skill prompt templates, so a template parses
// identically regardless of which API loads it.
func ParseTemplate(name, content string) extensions.PromptTemplate {
tpl := skills.NewPromptTemplate(name, content)
vars := tpl.Variables