mcp: add logs tool to retrieve deployed Function logs#3819
mcp: add logs tool to retrieve deployed Function logs#3819Ankitsinghsisodya wants to merge 2 commits into
Conversation
- Introduced a new 'logs' tool to fetch recent logs from deployed functions. - Updated documentation to include usage instructions for the logs command. - Added tests to ensure correct argument handling and mutual exclusivity between path and name parameters. This enhancement allows users to diagnose function behavior by accessing logs, improving the overall usability of the MCP tools.
…xclusivity - Revised the logs tool description to clarify the usage of the 'since' argument. - Updated error message in logsHandler to indicate that 'path' and 'name' are mutually exclusive, allowing for at most one instead of exactly one. These changes enhance the clarity of the tool's documentation and improve user feedback on input errors.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Ankitsinghsisodya The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @Ankitsinghsisodya. Thanks for your PR. I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with Tip We noticed you've done this a few times! Consider joining the org to skip this step and gain Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a new MCP “logs” tool to retrieve Knative Function logs, including server wiring, documentation updates, and test coverage for argument handling.
Changes:
- Introduces
logsMCP tool, handler, and argument mapping (path/name,namespace,since,verbose) - Registers the tool and help resource in the MCP server
- Adds documentation and unit tests for logs tool behavior (args + mutual exclusivity)
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/mcp/tools_logs.go | Adds the logs tool definition, input/output types, and handler implementation |
| pkg/mcp/tools_logs_test.go | Adds tests validating argument translation and mutual exclusivity behavior |
| pkg/mcp/mcp.go | Registers the new tool and adds a help resource entry |
| pkg/mcp/instructions.md | Documents how/when to use the logs tool and its parameters |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| func (s *Server) logsHandler(ctx context.Context, r *mcp.CallToolRequest, input LogsInput) (result *mcp.CallToolResult, output LogsOutput, err error) { | ||
| if input.Path != nil && input.Name != nil { | ||
| err = fmt.Errorf("'path' and 'name' are mutually exclusive: provide at most one") | ||
| return | ||
| } | ||
|
|
||
| out, err := s.executor.Execute(ctx, "logs", input.Args()...) | ||
| if err != nil { | ||
| err = fmt.Errorf("%w\n%s", err, string(out)) |
| result, err := client.CallTool(t.Context(), &mcp.CallToolParams{ | ||
| Name: "logs", | ||
| Arguments: buildInputArgs(stringFlags, boolFlags), | ||
| }) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if result.IsError { | ||
| t.Fatalf("unexpected error result: %v", result) | ||
| } |
Summary
Adds a
logsMCP tool that lets agents retrieve logs from a deployed Function. This closes the observe gap in the agentic workflow: an agent can now deploy a Function, invoke it, and immediately inspect its logs without leaving the MCP context.Changes
pkg/mcp/tools_logs.go— newlogstool withLogsInput/LogsOutputtypes andlogsHandler. Supports identification bypath(readsfunc.yaml) or byname, with optionalnamespace,since(time window, e.g.5m,1h), andverboseflags. Enforces mutual exclusion ofpathandnameat the handler level. MarkedReadOnlyHint: trueandDestructiveHint: false.pkg/mcp/tools_logs_test.go— four unit tests following the existing tool test pattern:TestTool_Logs_Args_ByPath— all flags via pathTestTool_Logs_Args_ByName— identification by function nameTestTool_Logs_MutuallyExclusive— bothpath+name→ errorTestTool_Logs_NoArgs— no args falls through to CLI default (server cwd)pkg/mcp/mcp.go— registers thelogstool and thefunc://help/logshelp resource alongside the existing tools.pkg/mcp/instructions.md— adds### logsagent guidance andfunc://help/logsto the pre-invocation checklist.Test plan
make testpassesmake checkpassesfunc mcp start→ calllogstool with a deployed Function path and confirm log output is returnedlogswith bothpathandnameset → confirm error is returned without executing the command