Skip to content

mcp: reject relative paths in tool handlers - #3694

Merged
knative-prow[bot] merged 6 commits into
knative:mainfrom
Shrey327:mcp-validate-absolute-path
Oct 29, 2026
Merged

knative-prow[bot] merged 6 commits into
knative:mainfrom
Shrey327:mcp-validate-absolute-path

Conversation

@Shrey327

Copy link
Copy Markdown
Contributor

Description

Adds validatePath() to the MCP server that rejects non-absolute path arguments before shelling out to the func CLI. Since cmd.Dir is never set in the executor, relative paths silently resolved against the MCP server's working directory instead of the user's project turning a wrong directory failure into a silent misbehavior. This change turns that into an actionable error, matching the guidance already documented in instructions.md.All existing tests updated to use t.TempDir() and a TestValidatePath unit test added.

@knative-prow
knative-prow Bot requested review from dsimansk and jrangelramos May 10, 2026 14:24
@linux-foundation-easycla

linux-foundation-easycla Bot commented May 10, 2026 •

Copy link
Copy Markdown

CLA Signed

The committers listed above are authorized under a signed CLA.

@knative-prow knative-prow Bot added the size/L 🤖 PR changes 100-499 lines, ignoring generated files. label May 10, 2026
@knative-prow

knative-prow Bot commented May 10, 2026

Copy link
Copy Markdown

Welcome @Shrey327! It looks like this is your first PR to knative/func 🎉

@knative-prow knative-prow Bot added the needs-ok-to-test 🤖 Needs an org member to approve testing label May 10, 2026
@knative-prow

knative-prow Bot commented May 10, 2026

Copy link
Copy Markdown

Hi @Shrey327. 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.

@lkingland lkingland left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR. Just two small suggestions.

Comment thread pkg/mcp/tools.go Resolved
Comment thread pkg/mcp/tools_test.go Resolved
@codecov

codecov Bot commented May 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 57.10%. Comparing base (584c11e) to head (e777f09).
⚠️ Report is 166 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3694      +/-   ##
==========================================
+ Coverage   57.03%   57.10%   +0.07%     
==========================================
  Files         182      182              
  Lines       21376    21421      +45     
==========================================
+ Hits        12191    12233      +42     
- Misses       7953     7955       +2     
- Partials     1232     1233       +1     
Flag Coverage Δ
e2e 35.72% <0.00%> (-0.09%) ⬇️
e2e go 31.35% <0.00%> (-0.07%) ⬇️
e2e node 27.19% <0.00%> (-0.06%) ⬇️
e2e python 31.72% <0.00%> (-0.07%) ⬇️
e2e quarkus 27.31% <0.00%> (-0.06%) ⬇️
e2e rust 26.71% <0.00%> (-0.07%) ⬇️
e2e springboot 25.26% <0.00%> (-0.06%) ⬇️
e2e typescript 27.30% <0.00%> (-0.06%) ⬇️
e2e-config-ci 28.10% <0.00%> (-0.06%) ⬇️
integration 17.15% <0.00%> (-0.03%) ⬇️
unit macos-14 45.19% <100.00%> (+0.10%) ⬆️
unit macos-latest 45.19% <100.00%> (+0.10%) ⬆️
unit ubuntu-24.04-arm 45.45% <100.00%> (+0.11%) ⬆️
unit ubuntu-latest 46.14% <100.00%> (+0.10%) ⬆️
unit windows-latest 45.24% <100.00%> (+0.10%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 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.

@gauron99

Copy link
Copy Markdown
Contributor

/ok-to-test

@knative-prow knative-prow Bot added ok-to-test 🤖 Non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test 🤖 Needs an org member to approve testing labels May 11, 2026
@knative-prow knative-prow Bot added the lgtm 🤖 PR is ready to be merged. label May 16, 2026
@knative-prow

knative-prow Bot commented May 16, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lkingland, Shrey327

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

The pull request process is described 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 the approved 🤖 PR has been approved by an approver from all required OWNERS files. label May 16, 2026
@knative-prow-robot knative-prow-robot added the needs-rebase Cannot be merged due to conflicts with HEAD. label May 16, 2026
@Shrey327
Shrey327 force-pushed the mcp-validate-absolute-path branch from 766fda2 to 7995a39 Compare May 17, 2026 05:04
@knative-prow knative-prow Bot removed the lgtm 🤖 PR is ready to be merged. label May 17, 2026
@knative-prow-robot knative-prow-robot removed the needs-rebase Cannot be merged due to conflicts with HEAD. label May 17, 2026
@lkingland lkingland moved this to New in Functions Traige Jun 2, 2026
@knative-prow-robot knative-prow-robot added the needs-rebase Cannot be merged due to conflicts with HEAD. label Jun 12, 2026
@lkingland

Copy link
Copy Markdown
Member

Thanks @Shrey327.

Both my points were addressed. However, since this was submitted, several new tools taking a path have landed on main (config_ci, config_git, invoke, run, run_stop).

Please rebase, extend validatePath() to those new tools as well, and we can merge this.

One suggestion to keep this from regressing again: rather than per-tool tests alone, a single test that iterates over all registered tools with a path input and asserts a relative path is rejected would catch any future tool that forgets the check. Feel free to include that more advanced approach in this PR, or a separate one, at your discretion.

Shrey327 and others added 6 commits October 29, 2026 17:20
…ed tests

Signed-off-by: Shrey327 <shreyansh.pathak273@gmail.com>
Signed-off-by: Shrey327 <shreyansh.pathak273@gmail.com>
Signed-off-by: Shrey327 <shreyansh.pathak273@gmail.com>
Tools that landed after knative#3694 (config_ci, config_git, invoke,
run, run_stop) now reject relative paths before they shell out. describe
and logs are included so a registry-wide test can walk every tool whose
schema has a path input and fail if a future tool skips the check.

Success-path tests that still passed "." now use an absolute directory.

Signed-off-by: Luke Kingland <luke@lukekingland.com>
woke flags the previous name as insensitive.

Signed-off-by: Luke Kingland <luke@lukekingland.com>
filepath.IsAbs rejects POSIX literals such as /home/user/myfunc on Windows,
so the new validatePath checks failed the Windows unit job. Tests now use
testAbsPath, which joins os.TempDir.

Signed-off-by: Luke Kingland <luke@lukekingland.com>
@lkingland
lkingland force-pushed the mcp-validate-absolute-path branch from e777f09 to 7eb46f8 Compare October 29, 2026 08:23
@knative-prow-robot knative-prow-robot removed the needs-rebase Cannot be merged due to conflicts with HEAD. label Oct 29, 2026
@lkingland

Copy link
Copy Markdown
Member

Rebased onto main, extended validatePath() to the newer path-taking tools (config_ci, config_git, invoke, run, run_stop, plus describe/logs), and added a registry-wide relative-path test. Thanks @Shrey327!

/lgtm

@knative-prow knative-prow Bot added the lgtm 🤖 PR is ready to be merged. label Oct 29, 2026
@knative-prow
knative-prow Bot merged commit 4fa6c16 into knative:main Oct 29, 2026
45 checks passed
@github-project-automation github-project-automation Bot moved this from New to Done in Functions Traige Oct 29, 2026
@Shrey327

Copy link
Copy Markdown
Contributor Author

Thanks @lkingland for rebasing and extending the checks to the new tools! I’ll be quicker on follow-ups next time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved 🤖 PR has been approved by an approver from all required OWNERS files. lgtm 🤖 PR is ready to be merged. ok-to-test 🤖 Non-member PR verified by an org member that is safe to test. size/L 🤖 PR changes 100-499 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants