refactor(api): expose BaseConfig to tool and prompt handlers#916
Conversation
Expose GetClusterProviderStrategy() to tool and prompt handlers at execution time via the new ConfigProvider interface. This allows toolsets to access the cluster provider strategy when invoked, rather than only at initialization through GetTools(). The approach is compatible with dynamic config reload — subsequent tool calls always see the current strategy value. Refs containers#836 Signed-off-by: Marc Nuri <marc@marcnuri.com>
1041165 to
b93fade
Compare
| GetClusterProviderStrategy() string | ||
| // GetProviderConfig returns the extended configuration for the given provider strategy. | ||
| // The boolean return value indicates whether the configuration was found. | ||
| GetProviderConfig(strategy string) (ExtendedConfig, bool) |
There was a problem hiding this comment.
we wanna change this to just Config? Or wanna keep the ExtendedConfig here and below?
There was a problem hiding this comment.
Ah, I see that just actually retunrs the extended config - nervemind
There was a problem hiding this comment.
ExtendedConfig is something else altogether.
The idea is that toolset implementers can provide custom Config entries in the toml file (hence the extended).
You can check how Kiali deals with this:
kubernetes-mcp-server/pkg/kiali/config.go
Lines 17 to 22 in 4f0ed3e
By having an extended config, users can the provide specific values to configure the toolset:
[toolset_configs.kiali]
url = "https://kiali.example/"
certificate_authority = "ca.crt"And then consumed through:
kubernetes-mcp-server/pkg/kiali/kiali.go
Lines 29 to 35 in b93fade
This basically makes the config extensible by toolsets in a decoupled way.
| // ConfigProvider provides read-only access to configuration from tool and prompt handlers. | ||
| // This interface is embedded in ToolHandlerParams and PromptHandlerParams, allowing | ||
| // toolsets to access configuration at execution time (not just at initialization). | ||
| type ConfigProvider interface { |
There was a problem hiding this comment.
Rename to better communicate that this is the build-in config provider, rather than something that was intentially extending it?
There was a problem hiding this comment.
I'm not sure I'm following, do you mean to rename to BuiltinConfigProvider?
Basically the api interface here is just exposing the Config values (those we've decided to make public) instead of completely exposing the StaticConfig.
Any Config value that needs to be accessed by toolsets would need to be explicitly exposed here.
|
LGTM |
| // toolsets to access configuration at execution time (not just at initialization). | ||
| type ConfigProvider interface { | ||
| // GetClusterProviderStrategy returns the cluster provider strategy (e.g. "kubeconfig", "in-cluster"). | ||
| GetClusterProviderStrategy() string |
There was a problem hiding this comment.
@manusa is there any concern about this method being duplicated between this interface and the ClusterProvider interface which also goes into BaseConfig ?
This all compiles fine and is concretely backed by a single func, so i guess maybe it is fine?
There was a problem hiding this comment.
Replace the ConfigProvider interface with the existing BaseConfig interface in ToolHandlerParams and PromptHandlerParams. This avoids duplicating GetClusterProviderStrategy() across two interfaces and reuses the already composed BaseConfig which includes ClusterProvider and ExtendedConfigProvider. Reverts changes to pkg/api/config.go and pkg/kiali/kiali.go since no new interface is needed. Refs containers#836 Signed-off-by: Marc Nuri <marc@marcnuri.com>
|
LGTM I think renaming of |
🤦 forgot to update the PR title and description. Thanks for catching that. Technically it's not renaming but exposing BaseConfig as part of the tools and prompt handler params. |
…ers#916) * refactor(api): rename ExtendedConfigProvider to ConfigProvider Expose GetClusterProviderStrategy() to tool and prompt handlers at execution time via the new ConfigProvider interface. This allows toolsets to access the cluster provider strategy when invoked, rather than only at initialization through GetTools(). The approach is compatible with dynamic config reload — subsequent tool calls always see the current strategy value. Refs containers#836 Signed-off-by: Marc Nuri <marc@marcnuri.com> * refactor(api): expose BaseConfig to tool and prompt handlers Replace the ConfigProvider interface with the existing BaseConfig interface in ToolHandlerParams and PromptHandlerParams. This avoids duplicating GetClusterProviderStrategy() across two interfaces and reuses the already composed BaseConfig which includes ClusterProvider and ExtendedConfigProvider. Reverts changes to pkg/api/config.go and pkg/kiali/kiali.go since no new interface is needed. Refs containers#836 Signed-off-by: Marc Nuri <marc@marcnuri.com> --------- Signed-off-by: Marc Nuri <marc@marcnuri.com>
Signed-off-by: Matthias Wessendorf <mwessend@redhat.com>
Signed-off-by: Matthias Wessendorf <mwessend@redhat.com>
Summary
PR #836 identified the need to expose the cluster provider strategy to toolsets. As some toolsets now call non-kube-API-server endpoints (e.g. Prometheus), they need to know the strategy to determine TLS and authentication configuration.
The approach in #836 expanded the
GetTools()parameter, but this is evaluated at server startup — if the strategy changes via drop-in configuration support, toolsets would still see the stale value. Additionally,GetTools()should eventually take no parameters.This PR takes an alternative approach: embed
BaseConfig(instead ofExtendedConfigProvider) inToolHandlerParamsandPromptHandlerParams. SinceBaseConfigalready composesClusterProvider(which providesGetClusterProviderStrategy()) andExtendedConfigProvider, no new interface is needed. Toolsets can access the strategy at execution time — always reflecting the current configuration, even after a drop-in config reload.Downstream consumers (e.g. openshift/openshift-mcp-server#124) can now call
params.GetClusterProviderStrategy()in their tool handlers to determine TLS/auth behavior, following the same pattern Kiali already uses for its configuration.Changes
pkg/api/toolsets.go/pkg/api/prompts.go— EmbedBaseConfiginstead ofExtendedConfigProviderin handler paramspkg/mcp/gosdk.go/pkg/mcp/prompts_gosdk.go— Update field assignmentpkg/mcp/mcp_config_provider_test.go— Behavioral tests verifying strategy access from tool/prompt handlers and config reloadRefs #836