kubectl-ai icon indicating copy to clipboard operation
kubectl-ai copied to clipboard

Issue using mcp server tools with kubectl ai --mcp-client

Open vaib-2310 opened this issue 6 months ago • 10 comments

I am using kubectl ai as an MCP client with the --mcp-client flag, and I received the message:

Successfully connected to MCP server

However, when the MCP server attempts to use a tool, I encounter the following errors:

Error: executing action: calling MCP tool "sequentialthinking" on server "sequential-thinking": tool returned an error

Error: executing action: calling MCP tool "pods_list_in_namespace" on server "kubernetes-mcp-server": tool returned an error

Below is my mcp.yaml configuration:

servers:

  • name: sequential-thinking command: /usr/local/bin/start-mcp-docker.sh args: []
  • name: kubernetes-mcp-server command: uvx args:
    • "kubernetes-mcp-server@latest"

And /usr/local/bin/start-mcp-docker.sh contains: docker run --rm -i
-v "$HOME/.config/kubectl-ai:/root/.config/kubectl-ai"
-w /root
node:lts
npx -y @modelcontextprotocol/server-sequential-thinking

Image

vaib-2310 avatar Jun 17 '25 05:06 vaib-2310

/cc @tuannvm

droot avatar Jun 17 '25 06:06 droot

@vaib-2310 Hi there, I see that you’re running Sequential Thinking by starting the mcp server from Docker. Would you mind also sharing the logs that are printed from that Docker process? Thank you!

tuannvm avatar Jun 17 '25 15:06 tuannvm

@tuannvm

I have asked it to exclusively use sequentialthinking tool to answer my query and below are the logs for that:

can you use the sequentialthinking tool to find out Running: [MCP: sequential-thinking] sequentialthinking(arguments=map[is_revision:false next_thought_needed:true thought:I need to find the number of running replicas for an application that the user has identified as 'genericindexer'. My initial attempts to find a Deployment, DeploymentConfig, or StatefulSet with this exact name failed. I will start by re-verifying this, and then I will broaden my search. My first step is to get all deployments, deploymentconfigs, and statefulsets in the current namespace to see if I can find any resource that looks like it might be related to 'genericindexer'. thought_number:1 total_thoughts:5])

Do you want to proceed ?

  1. Yes
  2. Yes, and don't ask me again
  3. No Enter your choice (1,2,3): 1 Error: executing action: calling MCP tool "sequentialthinking" on server "sequential-thinking": tool returned an error

And below is the error printed in Docker process of sequential thinking:

{"result":{"content":[{"type":"text","text":"{\n "error": "Invalid thought: must be a string",\n "status": "failed"\n}"}],"isError":true},"jsonrpc":"2.0","id":5}

vaib-2310 avatar Jun 18 '25 05:06 vaib-2310

@tuannvm Logs from kubernetes-mcp-server

can you list down the pods in default project? Running: [MCP: kubernetes-mcp-server] pods_list_in_namespace(arguments=map[namespace:default])

Do you want to proceed ?

  1. Yes
  2. Yes, and don't ask me again
  3. No Enter your choice (1,2,3): 1 Error: executing action: calling MCP tool "pods_list_in_namespace" on server "kubernetes-mcp-server": tool returned an error

{"jsonrpc":"2.0","id":7,"result":{"content":[{"type":"text","text":"failed to list pods in namespace, missing argument namespace"}],"isError":true}}

vaib-2310 avatar Jun 18 '25 10:06 vaib-2310

>>> can you list down the pods in default project?
  Running: [MCP: kubernetes-mcp-server] pods_list_in_namespace(namespace=default)


  There are currently no pods running in the default namespace of your        
  Kubernetes cluster. If you need to deploy new workloads or want to check    
  another namespace, let me know!                                             


>>> use sequential thinking to understand the namespace convention
  Running: [MCP: sequential-thinking] sequentialthinking(branch_from_thought=<nil>, branch_id=<nil>, is_revision=false, needs_more_thoughts=false, next_thought_needed=true, revises_thought=<nil>, thought=Let's begin by analyzing the namespace names in the cluster to identify if there are any conventions or patterns being followed. We can look for naming structures, common prefixes or suffixes, and whether names reflect environments, applications, teams, or purposes. We'll also consider Kubernetes' built-in namespaces for contrast., thought_number=1, total_thoughts=5)

  Running: [MCP: sequential-thinking] sequentialthinking(branch_from_thought=<nil>, branch_id=<nil>, is_revision=false, needs_more_thoughts=false, next_thought_needed=true, revises_thought=<nil>, thought=Now, let's categorize the namespaces:
- System/Default: default, kube-system, kube-public, kube-node-lease
- Application/Project-specific: api, argo, consul, external-dns, grafana, grafana-agent, grafana-agent-operator, grafana-pod-logs, karpenter, kyverno, ops, spot-system, tailscale, vault, ws-prod-us-ea1f
Some namespaces have names that match applications directly (grafana, consul, vault). Others include terms like 'agent', 'operator', 'logs', or environment indicators (ws-prod-us-ea1f). This suggests a convention of naming after applications or their components, occasionally using suffixes to indicate roles or environments., thought_number=2, total_thoughts=5)

  Running: [MCP: sequential-thinking] sequentialthinking(branch_from_thought=<nil>, branch_id=<nil>, is_revision=false, needs_more_thoughts=false, next_thought_needed=true, revises_thought=<nil>, thought=Next, let's examine if any delimiters are used (such as hyphens) and how they are applied. For example, names like 'grafana-agent', 'grafana-pod-logs', or 'ws-prod-us-ea1f' use hyphens to separate words or indicate sub-components or environments. This hints at a hierarchical or descriptive convention., thought_number=3, total_thoughts=5)

  Running: [MCP: sequential-thinking] sequentialthinking(branch_from_thought=<nil>, branch_id=<nil>, is_revision=false, needs_more_thoughts=false, next_thought_needed=true, revises_thought=<nil>, thought=Looking deeper into namespaces like 'ws-prod-us-ea1f', this appears to be environment or tenant specific. 'prod' typically means production, 'us' could signify a region, and 'ea1f' may be a unique identifier. This suggests a convention for dynamic or multi-tenant environments where namespace names encode environment and location details., thought_number=4, total_thoughts=5)

  Running: [MCP: sequential-thinking] sequentialthinking(branch_from_thought=<nil>, branch_id=<nil>, is_revision=false, needs_more_thoughts=true, next_thought_needed=true, revises_thought=<nil>, thought=Let's also notice that some namespaces combine application names with roles or operators (e.g., 'grafana-agent', 'grafana-pod-logs', 'grafana-agent-operator'). These seem to follow an <application>-<function/role> convention, suggesting role-based separation of resources related to the same product., thought_number=5, total_thoughts=5)

  Running: [MCP: sequential-thinking] sequentialthinking(branch_from_thought=<nil>, branch_id=<nil>, is_revision=false, needs_more_thoughts=false, next_thought_needed=false, revises_thought=<nil>, thought=Reviewing the whole picture, the pattern seems to be:
- Core system namespaces use reserved, well-known names
- Application namespaces are derived from the application name, sometimes with suffixes or prefixes for role (agent/operator/logs)
- Environment or tenant namespaces encode environment, geography/region, and unique identifiers
- Hyphens are the main delimiter
Hypothesis: Namespace naming convention prioritizes clarity of ownership (application), role/function, and, when needed, environment/tenant context., thought_number=6, total_thoughts=6)


  Namespace naming in your cluster follows these conventions:                 
                                                                              
  1. System namespaces use reserved, well-known names (e.g., default, kube-   
  system).                                                                    
  2. Application namespaces are named after the application, sometimes with   
  suffixes indicating specific roles or components (e.g., grafana-agent,      
  grafana-pod-logs).                                                          
  3. Some namespaces encode environment/tenant information, often including   
  environment (prod), region (us), and unique identifiers (ea1f), as in ws-   
  prod-us-ea1f.                                                               
  4. Hyphens act as the primary delimiter, helping separate application,      
  function, and environment indicators.                                       
  5. The naming structure clarifies ownership (application), component/role,  
  and, as needed, environment or tenant context.                              
                                                                              
  This convention makes it easy to understand the purpose and scope of each   
  namespace at a glance.                                                      


>>>  

I’m using the latest version, v0.0.14. Could you try again with the latest version and let me know the result? I’m not sure why, in your case, the response doesn’t appear to be serialized.

tuannvm avatar Jun 19 '25 06:06 tuannvm

@tuannvm , issue still persists after updating it to latest version, v0.0.14

kubectl ai version version: 0.0.14 commit: bc554dfd71e2829cd8986223a35ec738b2686367 date: 2025-06-17T01:33:09Z [xxxxxxxx kubectl-ai]$ kubectl ai --mcp-client

MCP Server Status:

Successfully connected to 2 MCP server(s) (20 tools discovered)

• sequential-thinking (/usr/local/bin/start-mcp-sequential-docker.sh) -

Connected, Tools: sequentialthinking

• kubernetes-mcp-server (/usr/local/bin/start-mcp-kubernetes-docker.sh) -

Connected, Tools: configuration_view, events_list, helm_install, helm_list, helm_uninstall, namespaces_list, pods_delete, pods_exec, pods_get, pods_list, pods_list_in_namespace, pods_log, pods_run, pods_top, projects_list, resources_create_or_update, resources_delete, resources_get, resources_list

Hey there, what can I help you with today?

can you list down the pods in default namespace Running: [MCP: kubernetes-mcp-server] pods_list_in_namespace(arguments=map[namespace:default])

Do you want to proceed ?

  1. Yes
  2. Yes, and don't ask me again
  3. No Enter your choice (1,2,3): 1 E0619 08:40:20.766819 30227 conversation.go:336] "error executing action" err="calling MCP tool "pods_list_in_namespace" on server "kubernetes-mcp-server": tool returned an error" output=null Error: executing action: calling MCP tool "pods_list_in_namespace" on server "kubernetes-mcp-server": tool returned an error

can you list down the pods in default namespace using sequentialthinking tool Running: [MCP: sequential-thinking] sequentialthinking(arguments=map[thought:I need to list the pods in the default namespace. I can use the pods_list_in_namespace tool to achieve this.])

Do you want to proceed ?

  1. Yes
  2. Yes, and don't ask me again
  3. No Enter your choice (1,2,3): 1 E0619 08:41:47.795999 30227 conversation.go:336] "error executing action" err="calling MCP tool "sequentialthinking" on server "sequential-thinking": tool returned an error" output=null Error: executing action: calling MCP tool "sequentialthinking" on server "sequential-thinking": tool returned an error

vaib-2310 avatar Jun 19 '25 08:06 vaib-2310

There’s a slight difference in how the function call is formatted:

Yours:

Running: [MCP: kubernetes-mcp-server] pods_list_in_namespace(namespace=default) The arguments are passed in a function-style format, directly specifying namespace=default.

Mine:

Running: [MCP: kubernetes-mcp-server] pods_list_in_namespace(arguments=map[namespace:default]) The arguments are wrapped inside a map structure, passed as a single arguments parameter.

Same case with sequqntialthinking tool

vaib-2310 avatar Jun 19 '25 08:06 vaib-2310

@vaib-2310 see if this helps https://github.com/GoogleCloudPlatform/kubectl-ai/pull/365/files, make the toolCall a bit more deterministic

tuannvm avatar Jun 19 '25 13:06 tuannvm

@tuannvm , i have created kubectl-ai binary locally using your PR #365 , and here are the results:

can you please list down the pods in default namespace? Running: [MCP: kubernetes-mcp-server] pods_list_in_namespace(arguments=map[namespace:default])

Do you want to proceed ?

  1. Yes
  2. Yes, and don't ask me again
  3. No Enter your choice (1,2,3): 1 E0620 06:45:41.872265 4188 conversation.go:342] "error executing action" err="calling MCP tool "pods_list_in_namespace" on server "kubernetes-mcp-server": tool returned an error" output=null Error: executing action: calling MCP tool "pods_list_in_namespace" on server "kubernetes-mcp-server": tool returned an error

can you please list down the pods in default namespace using sequqntialthinking tool?

  1. Print: The output of the tool call will be a list of pods, which I will then print to the user.

can you list down the pods in default namespace using sequentialthinking tool Running: [MCP: sequential-thinking] sequentialthinking(arguments=map[thought:I need to list the pods in the default namespace.

  1. Search: The user wants to list pods in a specific namespace. The pods_list_in_namespace tool is suitable for this purpose.
  2. Parameters: The pods_list_in_namespace tool requires a namespace parameter. The user has specified default as the namespace.
  3. Function Call: I will call the pods_list_in_namespace tool with the namespace parameter set to default.
  4. Print: The output of the tool call will be a list of pods, which I will then print to the user.])

Do you want to proceed ?

  1. Yes
  2. Yes, and don't ask me again
  3. No Enter your choice (1,2,3): 1 E0620 06:49:50.770013 4188 conversation.go:342] "error executing action" err="calling MCP tool "sequentialthinking" on server "sequential-thinking": tool returned an error" output=null Error: executing action: calling MCP tool "sequentialthinking" on server "sequential-thinking": tool returned an error

can you list down all the projects Running: [MCP: kubernetes-mcp-server] projects_list(arguments=map[])

Do you want to proceed ?

  1. Yes
  2. Yes, and don't ask me again
  3. No Enter your choice (1,2,3): 1

Here are all the projects in the cluster:

default cert-manager ........

vaib-2310 avatar Jun 20 '25 06:06 vaib-2310

@tuannvm I started using an another mcp server called aws-cost-explorer , and encountered with errros like below with tool get_cost_and_usage and when it used another tool called get_today_date of same mcp server it fetched the results:

get_cost_and_usage tool:

Show me the monthly unblended cost for resources tagged Role:Openshift4 in June 2025. Running: [MCP: awslabs.cost-explorer-mcp-server] get_cost_and_usage(arguments=map[date_range:map[end_date:2025-06-30 start_date:2025-06-01] filter_expression:map[Tags:map[Key:Role MatchOptions:[EQUALS] Values:[Openshift4]]] granularity:MONTHLY metric:UnblendedCost])

Do you want to proceed ?

  1. Yes
  2. Yes, and don't ask me again
  3. No Enter your choice (1,2,3): 1 E0621 08:50:37.686516 29557 conversation.go:336] "error executing action" err="calling MCP tool "get_cost_and_usage" on server "awslabs.cost-explorer-mcp-server": tool returned an error" output=null Error: executing action: calling MCP tool "get_cost_and_usage" on server "awslabs.cost-explorer-mcp-server": tool returned an error

docker logs: CallToolRequest {"jsonrpc":"2.0","id":5,"result":{"content":[{"type":"text","text":"Error executing tool get_cost_and_usage: 1 validation error for get_cost_and_usageArguments\ndate_range\n Field required [type=missing, input_value={'arguments': {'date_rang...tric': 'UnblendedCost'}}, input_type=dict]\n For further information visit https://errors.pydantic.dev/2.11/v/missing"}],"isError":true}}

get_today_date tool:

Get EC2 services tagged Role:Openshift4 in eu-west-1

I can get you the costs for that. What date range are you interested in?

last 1 day Running: [MCP: awslabs.cost-explorer-mcp-server] get_today_date(arguments=map[])

Do you want to proceed ?

  1. Yes
  2. Yes, and don't ask me again
  3. No Enter your choice (1,2,3): 1

docker logs:

CallToolRequest {"jsonrpc":"2.0","id":7,"result":{"content":[{"type":"text","text":"{\n "today_date": "2025-06-21",\n "current_month": "2025-06"\n}"}],"isError":false}} [06/21/25 08:55:42] INFO Processing request of type server.py:523

vaib-2310 avatar Jun 21 '25 09:06 vaib-2310