@@ -3,8 +3,8 @@ package inventory
33import (
44 "context"
55 "encoding/json"
6- "fmt"
76
7+ "github.com/github/github-mcp-server/pkg/octicons"
88 "github.com/modelcontextprotocol/go-sdk/mcp"
99)
1010
@@ -33,29 +33,10 @@ type ToolsetMetadata struct {
3333 Icon string
3434}
3535
36- // OcticonURL returns the CDN URL for a GitHub Octicon SVG. Size should be 16 or 24.
37- func OcticonURL (name string , size int ) string {
38- return fmt .Sprintf ("https://raw.githubusercontent.com/primer/octicons/main/icons/%s-%d.svg" , name , size )
39- }
40-
4136// Icons returns MCP Icon objects for this toolset, or nil if no icon is set.
4237// Icons are provided in both 16x16 and 24x24 sizes.
4338func (tm ToolsetMetadata ) Icons () []mcp.Icon {
44- if tm .Icon == "" {
45- return nil
46- }
47- return []mcp.Icon {
48- {
49- Source : OcticonURL (tm .Icon , 16 ),
50- MIMEType : "image/svg+xml" ,
51- Sizes : []string {"16x16" },
52- },
53- {
54- Source : OcticonURL (tm .Icon , 24 ),
55- MIMEType : "image/svg+xml" ,
56- Sizes : []string {"24x24" },
57- },
58- }
39+ return octicons .Icons (tm .Icon )
5940}
6041
6142// ServerTool represents an MCP tool with metadata and a handler generator function.
@@ -112,14 +93,17 @@ func (st *ServerTool) Handler(deps any) mcp.ToolHandler {
11293
11394// RegisterFunc registers the tool with the server using the provided dependencies.
11495// Icons are automatically applied from the toolset metadata if not already set.
96+ // A shallow copy of the tool is made to avoid mutating the original ServerTool.
11597// Panics if the tool has no handler - all tools should have handlers.
11698func (st * ServerTool ) RegisterFunc (s * mcp.Server , deps any ) {
11799 handler := st .Handler (deps ) // This will panic if HandlerFunc is nil
100+ // Make a shallow copy of the tool to avoid mutating the original
101+ toolCopy := st .Tool
118102 // Apply icons from toolset metadata if tool doesn't have icons set
119- if len (st . Tool .Icons ) == 0 {
120- st . Tool .Icons = st .Toolset .Icons ()
103+ if len (toolCopy .Icons ) == 0 {
104+ toolCopy .Icons = st .Toolset .Icons ()
121105 }
122- s .AddTool (& st . Tool , handler )
106+ s .AddTool (& toolCopy , handler )
123107}
124108
125109// NewServerTool creates a ServerTool from a tool definition, toolset metadata, and a typed handler function.
0 commit comments