Skip to content

refactor(api): expose BaseConfig to tool and prompt handlers#916

Merged
matzew merged 2 commits intocontainers:mainfrom
marcnuri-forks:refactor/rename-extended-config-provider-to-config-provider
Mar 13, 2026
Merged

refactor(api): expose BaseConfig to tool and prompt handlers#916
matzew merged 2 commits intocontainers:mainfrom
marcnuri-forks:refactor/rename-extended-config-provider-to-config-provider

Conversation

@manusa
Copy link
Copy Markdown
Member

@manusa manusa commented Mar 12, 2026

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 of ExtendedConfigProvider) in ToolHandlerParams and PromptHandlerParams. Since BaseConfig already composes ClusterProvider (which provides GetClusterProviderStrategy()) and ExtendedConfigProvider, 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 — Embed BaseConfig instead of ExtendedConfigProvider in handler params
  • pkg/mcp/gosdk.go / pkg/mcp/prompts_gosdk.go — Update field assignment
  • pkg/mcp/mcp_config_provider_test.go — Behavioral tests verifying strategy access from tool/prompt handlers and config reload

Refs #836

@manusa manusa requested a review from Cali0707 March 12, 2026 09:18
@manusa manusa added this to the 0.1.0 milestone Mar 12, 2026
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>
@manusa manusa force-pushed the refactor/rename-extended-config-provider-to-config-provider branch from 1041165 to b93fade Compare March 12, 2026 09:20
Comment thread pkg/api/config.go
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)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we wanna change this to just Config? Or wanna keep the ExtendedConfig here and below?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ah, I see that just actually retunrs the extended config - nervemind

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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:

// Config holds Kiali toolset configuration
type Config struct {
Url string `toml:"url"`
Insecure bool `toml:"insecure,omitempty"`
CertificateAuthority string `toml:"certificate_authority,omitempty"`
}

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:

if cfg, ok := configProvider.GetToolsetConfig("kiali"); ok {
if kc, ok := cfg.(*Config); ok && kc != nil {
kiali.kialiURL = kc.Url
kiali.kialiInsecure = kc.Insecure
kiali.certificateAuthority = kc.CertificateAuthority
}
}

This basically makes the config extensible by toolsets in a decoupled way.

Comment thread pkg/api/config.go Outdated
// 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 {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Rename to better communicate that this is the build-in config provider, rather than something that was intentially extending it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

@matzew
Copy link
Copy Markdown
Collaborator

matzew commented Mar 12, 2026

LGTM

Copy link
Copy Markdown
Collaborator

@Cali0707 Cali0707 left a comment

Choose a reason for hiding this comment

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

LGTM

Comment thread pkg/api/config.go Outdated
// 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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, there is :) I had that flagged.

Another option is to revert the changes to the api package, and actually expose the api.BaseConfig interface instead of api.ConfigProvider.

I'll add this as a second commit and let you folks decide what's best (@matzew @Cali0707)

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>
@manusa manusa requested review from Cali0707 and matzew March 13, 2026 04:46
@matzew
Copy link
Copy Markdown
Collaborator

matzew commented Mar 13, 2026

LGTM

I think renaming of ExtendedConfigProvider to BaseConfig is fine. Should the PR title cover that too?

@manusa
Copy link
Copy Markdown
Member Author

manusa commented Mar 13, 2026

LGTM

I think renaming of ExtendedConfigProvider to BaseConfig is fine. Should the PR title cover that too?

🤦 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.

@manusa manusa changed the title refactor(api): rename ExtendedConfigProvider to ConfigProvider refactor(api): expose BaseConfig to tool and prompt handlers Mar 13, 2026
Copy link
Copy Markdown
Collaborator

@Cali0707 Cali0707 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @manusa !

@matzew matzew merged commit d6a661c into containers:main Mar 13, 2026
8 checks passed
@manusa manusa deleted the refactor/rename-extended-config-provider-to-config-provider branch March 13, 2026 14:29
matzew pushed a commit to matzew/kubernetes-mcp-server that referenced this pull request Mar 13, 2026
…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>
matzew added a commit to matzew/kubernetes-mcp-server that referenced this pull request Mar 13, 2026
Signed-off-by: Matthias Wessendorf <mwessend@redhat.com>
matzew added a commit to matzew/kubernetes-mcp-server that referenced this pull request Mar 13, 2026
Signed-off-by: Matthias Wessendorf <mwessend@redhat.com>
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