@@ -23,7 +23,7 @@ func (s *Sever) initPods() {
2323 ), podsListInNamespace )
2424 s .server .AddTool (mcp .NewTool (
2525 "pods_get" ,
26- mcp .WithDescription ("Get a Kubernetes Pod in the current namespace with the provided name" ),
26+ mcp .WithDescription ("Get a Kubernetes Pod in the current or provided namespace with the provided name" ),
2727 mcp .WithString ("namespace" ,
2828 mcp .Description ("Namespace to get the Pod from" ),
2929 ),
@@ -32,6 +32,17 @@ func (s *Sever) initPods() {
3232 mcp .Required (),
3333 ),
3434 ), podsGet )
35+ s .server .AddTool (mcp .NewTool (
36+ "pods_log" ,
37+ mcp .WithDescription ("Get the logs of a Kubernetes Pod in the current or provided namespace with the provided name" ),
38+ mcp .WithString ("namespace" ,
39+ mcp .Description ("Namespace to get the Pod logs from" ),
40+ ),
41+ mcp .WithString ("name" ,
42+ mcp .Description ("Name of the Pod" ),
43+ mcp .Required (),
44+ ),
45+ ), podsLog )
3546}
3647
3748func podsListInAllNamespaces (ctx context.Context , _ mcp.CallToolRequest ) (* mcp.CallToolResult , error ) {
@@ -81,3 +92,23 @@ func podsGet(ctx context.Context, ctr mcp.CallToolRequest) (*mcp.CallToolResult,
8192 }
8293 return NewTextResult (ret , err ), nil
8394}
95+
96+ func podsLog (ctx context.Context , ctr mcp.CallToolRequest ) (* mcp.CallToolResult , error ) {
97+ k , err := kubernetes .NewKubernetes ()
98+ if err != nil {
99+ return NewTextResult ("" , fmt .Errorf ("failed to get pod log: %v" , err )), nil
100+ }
101+ ns := ctr .Params .Arguments ["namespace" ]
102+ if ns == nil {
103+ ns = ""
104+ }
105+ name := ctr .Params .Arguments ["name" ]
106+ if name == nil {
107+ return NewTextResult ("" , errors .New ("failed to get pod log, missing argument name" )), nil
108+ }
109+ ret , err := k .PodsLog (ctx , ns .(string ), name .(string ))
110+ if err != nil {
111+ return NewTextResult ("" , fmt .Errorf ("failed to get pod %s log in namespace %s: %v" , name , ns , err )), nil
112+ }
113+ return NewTextResult (ret , err ), nil
114+ }
0 commit comments