@@ -271,52 +271,46 @@ func (t *GraphQLClientTransport) RegisterToolProvider(
271
271
return nil , fmt .Errorf ("introspection failed: %w" , err )
272
272
}
273
273
274
- // Build tool list
274
+ // Build tool list with optional filtering by operation type/name
275
275
var toolsList []Tool
276
276
277
- // Register query fields
278
- for _ , f := range resp .Schema .QueryType .Fields {
277
+ opType := strings .ToLower (prov .OperationType )
278
+
279
+ // Helper to register a field if it matches the optional OperationName
280
+ addTool := func (fieldName string , descPtr * string ) {
281
+ if prov .OperationName != nil && * prov .OperationName != fieldName {
282
+ return
283
+ }
279
284
desc := ""
280
- if f . Description != nil {
281
- desc = * f . Description
285
+ if descPtr != nil {
286
+ desc = * descPtr
282
287
}
283
288
toolsList = append (toolsList , Tool {
284
- Name : fmt .Sprintf ("%s.%s" , prov .Name , f . Name ),
289
+ Name : fmt .Sprintf ("%s.%s" , prov .Name , fieldName ),
285
290
Description : desc ,
286
291
Inputs : ToolInputOutputSchema {Required : nil },
287
292
Provider : prov ,
288
293
})
289
294
}
290
295
296
+ // Register query fields
297
+ if opType == "" || opType == "query" {
298
+ for _ , f := range resp .Schema .QueryType .Fields {
299
+ addTool (f .Name , f .Description )
300
+ }
301
+ }
302
+
291
303
// Register mutation fields
292
- if resp .Schema .MutationType != nil {
304
+ if ( opType == "" || opType == "mutation" ) && resp .Schema .MutationType != nil {
293
305
for _ , f := range resp .Schema .MutationType .Fields {
294
- desc := ""
295
- if f .Description != nil {
296
- desc = * f .Description
297
- }
298
- toolsList = append (toolsList , Tool {
299
- Name : fmt .Sprintf ("%s.%s" , prov .Name , f .Name ),
300
- Description : desc ,
301
- Inputs : ToolInputOutputSchema {Required : nil },
302
- Provider : prov ,
303
- })
306
+ addTool (f .Name , f .Description )
304
307
}
305
308
}
306
309
307
310
// Register subscription fields
308
- if resp .Schema .SubscriptionType != nil {
311
+ if ( opType == "" || opType == "subscription" ) && resp .Schema .SubscriptionType != nil {
309
312
for _ , f := range resp .Schema .SubscriptionType .Fields {
310
- desc := ""
311
- if f .Description != nil {
312
- desc = * f .Description
313
- }
314
- toolsList = append (toolsList , Tool {
315
- Name : fmt .Sprintf ("%s.%s" , prov .Name , f .Name ),
316
- Description : desc ,
317
- Inputs : ToolInputOutputSchema {Required : nil },
318
- Provider : prov ,
319
- })
313
+ addTool (f .Name , f .Description )
320
314
}
321
315
}
322
316
return toolsList , nil
0 commit comments