Repository navigation
Description
Problem
An LLM called list_resources with the combined Kubernetes manifest apiVersion value in the tool's version field, omitting group. mkp accepted the arguments and sent a malformed API request, returning a misleading RBAC error instead of explaining the input problem.
Observed with mkp 0.4.5 in a hosted demo where the service account is bound to the built-in view ClusterRole. Namespace listing worked, making the failure look like missing permissions for other resources.
Reproduction
Call list_resources with:
{
"resource_type": "namespaced",
"version": "apps/v1",
"resource": "deployments",
"namespace": "observability",
"limit": 50
}The reported error was:
Failed to list resources: v1 "namespaces" is forbidden: User "system:serviceaccount:mcp-workloads:mkp-sa" cannot get resource "v1/observability" in API group "" at the cluster scope
The handler passes group (defaulting to an empty string) and version directly into schema.GroupVersionResource. The dynamic client consequently builds /api/apps/v1/namespaces/observability/deployments, which Kubernetes interprets as a request for resource v1, name namespaces, and subresource observability in the core API group. This explains the unrelated-looking authorization failure.
The intended arguments are group: "apps" and version: "v1", producing /apis/apps/v1/namespaces/observability/deployments.
Suggested improvement
mkp already publishes an input schema, but these fields are unrestricted strings. Tighten the schema, descriptions, and server-side validation together:
- Make
resource_typean enum ofclusteredandnamespaced. - Constrain
versionto a nonempty value without/and reject path separators ingroupas well. - Explain explicitly that
groupandversionare separate, unlike the combinedapiVersionfield in Kubernetes manifests. Include examples for deployments (group: "apps",version: "v1") and core resources such as pods (group: "",version: "v1"). - Validate before issuing a Kubernetes request, even when the client does not enforce the schema. For this case, return an actionable tool error such as
version must not contain "/". For deployments, use group="apps", version="v1". - Apply consistent validation and descriptions to the other tools accepting these fields. Reject ambiguous combined values rather than silently splitting them when an explicit group could conflict.
Acceptance: malformed group/version arguments produce a corrective input error without contacting Kubernetes; valid core and named-group requests continue to work. Add regression coverage for the example above, an explicit conflicting group, and valid core/named-group inputs.
The same unrestricted schema and direct GVR construction are still present on main at filing time in pkg/mcp/tools.go and pkg/mcp/list_resources.go. This diagnosis is based on the observed error and source tracing; the hosted cluster was not independently retested.
Activity