Skip to content

mcp: add logs tool to retrieve deployed Function logs#3794

Closed
Ankitsinghsisodya wants to merge 2 commits into
knative:mainfrom
Ankitsinghsisodya:feat/mcp-logs-tool
Closed

mcp: add logs tool to retrieve deployed Function logs#3794
Ankitsinghsisodya wants to merge 2 commits into
knative:mainfrom
Ankitsinghsisodya:feat/mcp-logs-tool

Conversation

@Ankitsinghsisodya
Copy link
Copy Markdown
Contributor

Summary

Adds a logs MCP 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 — new logs tool with LogsInput /
    LogsOutput types and logsHandler. Supports identification by
    path (reads func.yaml) or by name, with optional namespace,
    since (time window, e.g. 5m, 1h), and verbose flags.
    Enforces mutual exclusion of path and name at the handler level.
    Marked ReadOnlyHint: true and DestructiveHint: false.

  • pkg/mcp/tools_logs_test.go — four unit tests following the
    existing tool test pattern:

    • TestTool_Logs_Args_ByPath — all flags via path
    • TestTool_Logs_Args_ByName — identification by function name
    • TestTool_Logs_MutuallyExclusive — both path + name → error
    • TestTool_Logs_NoArgs — no args falls through to CLI default (server cwd)
  • pkg/mcp/mcp.go — registers the logs tool and the
    func://help/logs help resource alongside the existing tools.

  • pkg/mcp/instructions.md — adds ### logs agent guidance and
    func://help/logs to the pre-invocation checklist.

Test plan

  • make test passes
  • make check passes
  • Manual: func mcp start → call logs tool with a deployed
    Function path and confirm log output is returned
  • Manual: call logs with both path and name set → confirm
    error is returned without executing the command

- 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.
Copilot AI review requested due to automatic review settings May 20, 2026 17:48
@knative-prow knative-prow Bot requested review from dsimansk and jrangelramos May 20, 2026 17:49
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 20, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Ankitsinghsisodya
Once this PR has been reviewed and has the lgtm label, please assign lkingland for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow Bot added size/L 🤖 PR changes 100-499 lines, ignoring generated files. needs-ok-to-test 🤖 Needs an org member to approve testing labels May 20, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 20, 2026

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a new MCP tool (logs) to retrieve deployed Function logs via the server’s executor, along with help/resource wiring and documentation updates.

Changes:

  • Introduces logs tool implementation (LogsInput → CLI args; handler executes func logs)
  • Registers the tool and a corresponding help resource in the MCP server
  • Adds tool usage documentation and comprehensive argument-passing tests

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 Implements the logs tool, input/output types, and handler logic.
pkg/mcp/tools_logs_test.go Adds tests covering args by path/name, mutual exclusivity, and no-args behavior.
pkg/mcp/mcp.go Registers the logs tool and adds a help/logs resource.
pkg/mcp/instructions.md Documents how/when to use the new logs tool.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/mcp/tools_logs.go Outdated
Comment thread pkg/mcp/tools_logs.go Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

❌ Patch coverage is 85.71429% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.28%. Comparing base (f305f89) to head (28dd744).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
pkg/mcp/tools_logs.go 84.61% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3794      +/-   ##
==========================================
+ Coverage   45.41%   54.28%   +8.86%     
==========================================
  Files         200      201       +1     
  Lines       23426    23794     +368     
==========================================
+ Hits        10640    12916    +2276     
+ Misses      11843     9613    -2230     
- Partials      943     1265     +322     
Flag Coverage Δ
e2e 33.66% <0.00%> (+12.02%) ⬆️
e2e go 29.62% <0.00%> (?)
e2e node 25.93% <0.00%> (?)
e2e python 29.96% <0.00%> (?)
e2e quarkus 26.04% <0.00%> (?)
e2e rust 25.50% <0.00%> (?)
e2e springboot 24.18% <0.00%> (?)
e2e typescript 26.02% <0.00%> (?)
e2e-config-ci 26.74% <0.00%> (?)
integration 15.73% <0.00%> (?)
unit macos-14 43.23% <86.95%> (+1.02%) ⬆️
unit macos-latest 43.23% <86.95%> (+1.02%) ⬆️
unit ubuntu-24.04-arm 43.57% <85.71%> (+1.06%) ⬆️
unit ubuntu-latest 44.07% <86.95%> (+1.00%) ⬆️
unit windows-latest 43.26% <86.95%> (+1.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ok-to-test 🤖 Needs an org member to approve testing size/L 🤖 PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants