Skip to content

feat(resources): add gotemplate parameter for resources_list and resources_get#918

Open
edcdavid wants to merge 2 commits intocontainers:mainfrom
edcdavid:go-template-upstream
Open

feat(resources): add gotemplate parameter for resources_list and resources_get#918
edcdavid wants to merge 2 commits intocontainers:mainfrom
edcdavid:go-template-upstream

Conversation

@edcdavid
Copy link
Copy Markdown

@edcdavid edcdavid commented Mar 12, 2026

Adds an optional gotemplate parameter (same syntax as oc get -o go-template) that lets callers extract specific fields server-side instead of returning full YAML.

Why: LLMs currently receive entire resource YAML even when they only need one field. This wastes context window tokens and slows down responses. With gotemplate, the LLM declares exactly what it needs and the server returns only that — easily 10-100x fewer tokens for targeted queries.

Benefits:

Token efficiency — {{.status.phase}} returns a single value instead of hundreds of YAML lines
CLI parity — uses the same Go template syntax as oc get -o go-template, so templates are portable between CLI and MCP workflows
Server-side projection — iteration, conditionals, and field extraction run on the server, not in the LLM
Backward compatible — parameter is optional; omitting it preserves existing full-YAML behavior

Examples:

resources_list(kind="Pod", gotemplate="{{range .items}}{{.metadata.name}}\n{{end}}")
resources_get(kind="Application", name="my-app", gotemplate="{{.spec.source.repoURL}}")

Assisted by: Cursor

…urces_get

- Enhanced the resources_list and resources_get tools to support an optional gotemplate parameter, allowing users to extract specific fields from Kubernetes resources instead of returning full YAML.
- Updated descriptions in the input schemas to reflect the new functionality.
- Implemented applyGoTemplate function to handle template execution and error management.
- Updated the resourcesList function to correctly handle the gotemplate parameter by ensuring that the output is formatted as a table only when the gotemplate is not used.
- Enhanced the data structure returned when a gotemplate is specified, ensuring that the items are properly formatted within the response object.

This change improves the functionality and output consistency of the resourcesList tool.
@edcdavid edcdavid force-pushed the go-template-upstream branch from a0a077c to 14bbaa4 Compare March 12, 2026 14:37
@edcdavid edcdavid force-pushed the go-template-upstream branch from 1cb6f1f to 481e1d0 Compare March 12, 2026 14:57
@manusa
Copy link
Copy Markdown
Member

manusa commented Mar 12, 2026

#877

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.

2 participants