@@ -163,6 +163,7 @@ type MCPServer struct {
163163 stderr io.Writer
164164 cmdFinder CommandFinder
165165 toolCmds map [string ]* Command
166+ toolFlags map [string ][]string // overrides flags for given commands
166167 resourceCmds map [string ]* Command
167168 resourceTemplates map [string ]* Command // Maps URI templates to commands
168169 initialized bool // Track if the server has been initialized
@@ -203,6 +204,7 @@ func NewMCPServer(rootCmd *Command, stdin io.Reader, stdout, stderr io.Writer) *
203204 stderr : stderr ,
204205 cmdFinder : DefaultCommandFinder ,
205206 toolCmds : make (map [string ]* Command ),
207+ toolFlags : make (map [string ][]string ),
206208 resourceCmds : make (map [string ]* Command ),
207209 resourceTemplates : make (map [string ]* Command ),
208210 protocolVersion : "2025-03-26" , // Default to latest version
@@ -212,6 +214,9 @@ func NewMCPServer(rootCmd *Command, stdin io.Reader, stdout, stderr io.Writer) *
212214 rootCmd .Walk (func (cmd * Command ) {
213215 if cmd .Tool != "" {
214216 server .toolCmds [cmd .Tool ] = cmd
217+ if len (cmd .ToolFlags ) > 0 {
218+ server .toolFlags [cmd .Tool ] = cmd .ToolFlags [:]
219+ }
215220 }
216221 if cmd .Resource != "" {
217222 if strings .Contains (cmd .Resource , "{" ) && strings .Contains (cmd .Resource , "}" ) {
@@ -502,6 +507,13 @@ func (s *MCPServer) handleCallTool(req JSONRPC2Request) {
502507 }
503508 }
504509
510+ // Finally, add any overridden flags at the tool level.
511+ if toolFlags , ok := s .toolFlags [params .Name ]; ok {
512+ for _ , flag := range toolFlags {
513+ cmdArgs = append (cmdArgs , flag )
514+ }
515+ }
516+
505517 inv .Args = cmdArgs
506518
507519 // Run the command
0 commit comments