Skip to content

Conversation

ioanarm
Copy link
Contributor

@ioanarm ioanarm commented Oct 3, 2025

Dynamic Toolset Discovery and Loading

Summary

Adds dynamic toolset functionality that allows clients to discover and selectively enable tool categories at runtime, significantly reducing context window usage by only loading tools when needed.

Motivation

MCP tool descriptions can consume substantial context window space. By enabling dynamic discovery, clients only load the tools they actually need, preserving context for more important data.

Implementation

New flag: --dynamic-toolsets enables dynamic toolset mode
Discovery tools: Added grafana_list_toolsets and grafana_enable_toolset meta-tools
Notification support: Sends tools/list_changed notification when toolsets are enabled, triggering client refresh

Integration with --enabled-tools:

  • No flag --> all toolsets discoverable
  • --enabled-tools="" --> no toolsets discoverable
  • --enabled-tools="datasources,dashboards" --> only specified toolsets discoverable

Limitations and client compatibility

Protocol Support:
stdio protocol - Fully supported
SSE (Server-Sent Events) - Not yet supported
Streamable HTTP - Not yet supported

Client Support
✅ Supported: Cursor, VSCode (support notifications)
❌ Not yet: Claude Desktop, Claude Code (no notification support) there are open issues though for it

Known Behavior

Slight delay expected: There may be a few seconds of delay between calling grafana_enable_toolset and the tools becoming available in the client, as the client needs to receive and process the tools/list_changed notification.

Note: This is opt-in via the --dynamic-toolsets flag. Existing static tool registration remains the default behavior.

How it works with Cursor.

Currently Sonnet 4.5 model selected - 1m tokens available for this conversation

Normal behavior all tools available:

  • At the beginning 13.9% of context used
    image

  • How many tools are available 14.1%
    image

  • List my prometheus datasources 14.8%
    image

Dynamic tool discovery enabled with all tools discoverable.

  • At the beginning 5.5% of context used
    image

  • List available toolsets - 5.9%
    image

  • Enable Datasource toolset
    image

  • List Datasources 7%
    image

@ioanarm ioanarm requested a review from a team as a code owner October 3, 2025 08:20
Copy link

@gerboland gerboland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: please update the README to reflect the new CLI flag & behaviour.

@sd2k sd2k self-requested a review October 6, 2025 10:57
@ioanarm
Copy link
Contributor Author

ioanarm commented Oct 6, 2025

Added a comment about supported protocols.
Thanks @gerboland for trying it.

@gerboland
Copy link

gerboland commented Oct 6, 2025

My Cursor is still struggling with this, while it can enable the datasource toolset, it fails to recognise the tools as callable.
image

I have verified the notifications/tools/list_changed event is being sent by mcp-grafana on toolset change:
image

So I think Cursor is the problem for me. Should it update the list of tools in its MCP settings UI on the notifications/tools/list_changed event?

Copy link
Collaborator

@sd2k sd2k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the idea!

Comment on lines +105 to +110
// ToolsetInfo provides information about a toolset
type ToolsetInfo struct {
Name string `json:"name" jsonschema:"required,description=The name of the toolset"`
Description string `json:"description" jsonschema:"description=Description of what the toolset provides"`
Enabled bool `json:"enabled" jsonschema:"description=Whether the toolset is currently enabled"`
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it would be worth including ToolNames []string here, as a more concrete hint of what tools this contains?

Comment on lines +285 to +287
-**stdio protocol** - Fully supported
-**SSE (Server-Sent Events)** - Not yet supported
-**Streamable HTTP** - Not yet supported
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, is this because notifications aren't as well supported over streamable HTTP?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants