Skip to content

Commit cd1ff88

Browse files
committed
Merge origin/v2/main into v2/fix/5555-filesystem-move-into-own-subtree
Catch up before merge: v2/main moved under this PR.
2 parents 37a1f2f + 0b16177 commit cd1ff88

27 files changed

Lines changed: 963 additions & 80 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@modelcontextprotocol/server-filesystem": patch
3+
---
4+
5+
On Windows, `list_directory`, `list_directory_with_sizes`, `directory_tree` and `search_files` now check the directory they list before and after reading it: its path must have no junction or symlink on it and must name the same directory both times, or the call is refused with "Access denied - a directory on the path changed during the operation". A directory swapped for a junction after the path was validated is no longer listed. A swap made and undone while the directory is being read is still not detected; the README's "Limit on Windows" entry says what holds. macOS and Linux are unchanged.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@modelcontextprotocol/server-filesystem": patch
3+
---
4+
5+
`search_files` no longer answers a search that matched nothing with a bare `No matches found`. The result still begins with those words, and now names the pattern and the directory searched, says the pattern is a case-sensitive glob over names relative to that directory (never file contents), and, for a pattern with no `**`, suggests the `**/` form that reaches subdirectories.

‎.claude/skills/local-dev/SKILL.md‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,18 @@ node src/filesystem/dist/index.js --transport streamable-http /tmp/scratch # d
8888
(cd src/time && uv run mcp-server-time --transport streamable-http)
8989
```
9090

91-
Each one's endpoint is stateless for 2025-era clients (a fresh server per
92-
request; GET and DELETE answer 405), so nothing the server asks of the client
93-
mid-session (filesystem's Roots) reaches it over HTTP.
91+
What a 2025-era client gets from that endpoint differs by language (#5593):
92+
93+
- **`memory`, `filesystem`, `sequentialthinking` (TypeScript) are stateless**: a
94+
fresh server per request, no `Mcp-Session-Id` on the `initialize` response,
95+
and GET and DELETE answer 405. So nothing the server asks of the client
96+
mid-session (filesystem's Roots) reaches it over HTTP.
97+
- **`fetch`, `git`, `time` (Python) keep a session**, through the SDK's
98+
Streamable HTTP app. `initialize` returns an `Mcp-Session-Id` header and
99+
every later request must carry it: without it a POST, GET or DELETE answers
100+
400 "Missing session ID". With it, GET opens the session's stream and DELETE
101+
ends the session, after which its id answers 404. A hand-written `curl`
102+
probe therefore sends `initialize` first and passes the header on.
94103

95104
## Run the local package the way a user would
96105

‎.claude/skills/pr-flow/SKILL.md‎

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ gh pr view "$PR" --repo modelcontextprotocol/servers \
252252
```
253253

254254
The link does **not** make the issue close on merge into `v2/main`; that is
255-
still done by hand in step 9.
255+
still done by hand in step 10.
256256

257257
Then move the card to **In Review** (`/board-ops`). The PR itself never goes on
258258
the board.
@@ -407,6 +407,108 @@ the PR shows why the loop ended.
407407
408408
Merging is a maintainer's decision. Do not merge on your own initiative.
409409
410+
### Before the merge: catch up if `v2/main` moved
411+
412+
The rule is in `AGENTS.md` **Issue-driven work style**: a PR is caught up and
413+
re-tested before it merges when `v2/main` moved in a way that can interact
414+
with it. CI here runs on **push**, on the branch's head commit, and the gate
415+
ran in your worktree, so neither has seen anything that landed on `v2/main`
416+
after the branch last took it in. GitHub's "no conflicts with the base branch"
417+
compares text and tests nothing: #5564 and #5567 were each green and cleanly
418+
mergeable, merged ten minutes apart, and left `v2/main` failing `ruff check`
419+
(#5569).
420+
421+
**1. List what the PR's head lacks.** From any checkout of this repo:
422+
423+
```sh
424+
PR=<PR>
425+
git fetch origin v2/main "refs/pull/$PR/head"
426+
HEAD_SHA=$(gh pr view "$PR" --repo modelcontextprotocol/servers \
427+
--json headRefOid --jq .headRefOid)
428+
429+
# Commits on v2/main that the head does not hold. Nothing printed: the PR was
430+
# tested on the current tip, so there is nothing to catch up.
431+
git log --oneline "$HEAD_SHA..origin/v2/main"
432+
433+
# The files each side changed since the two diverged.
434+
LANDED=$(git diff --name-only "$HEAD_SHA...origin/v2/main")
435+
MINE=$(git diff --name-only "origin/v2/main...$HEAD_SHA")
436+
437+
# Check A: servers that both sides touched.
438+
comm -12 <(grep -oE '^src/[^/]+/' <<<"$LANDED" | sort -u) \
439+
<(grep -oE '^src/[^/]+/' <<<"$MINE" | sort -u)
440+
441+
# Check B: repository-wide configuration, on either side: a root manifest,
442+
# lockfile, config file or dotfile, scripts/, or a workflow.
443+
WIDE='^([^/]+\.(json|js|mjs|cjs|ts|toml|ya?ml)|\.[^/]+|scripts/.*|\.github/workflows/.*)$'
444+
grep -E "$WIDE" <<<"$LANDED" | sed 's/^/landed: /'
445+
grep -E "$WIDE" <<<"$MINE" | sed 's/^/mine: /'
446+
```
447+
448+
**2. Decide.**
449+
450+
| The listing shows | Then |
451+
| --- | --- |
452+
| No commits | Nothing to do. Merge on green CI |
453+
| Commits, and checks A and B both print nothing | What landed cannot interact with the PR. No catch-up needed |
454+
| Check A prints a server, or check B prints any path | **Catch up** (below) |
455+
| Anything you are unsure of | **Catch up**. The checks are deliberately coarse, and a gate run is cheaper than a red `v2/main` |
456+
457+
A server's own configuration (`pyproject.toml`, `uv.lock`, `tsconfig.json`,
458+
`vitest.config.ts`) is inside its directory, so check A covers it: that is the
459+
#5569 case, where a `requires-python` bump changed which lint rules applied to
460+
code another PR was adding.
461+
462+
**3. Catch up**, in the PR's worktree:
463+
464+
```sh
465+
git fetch origin v2/main
466+
git merge --no-edit origin/v2/main
467+
npm install # the merge may have moved package-lock.json
468+
npm run local:gate && git push # the push runs only on a green gate
469+
```
470+
471+
- **Merge, never rebase.** A rebase rewrites the commits that were reviewed,
472+
outdates every review thread and needs a force-push. The merge commit is
473+
exempt from the DCO check (step 3).
474+
- **The gate runs on the merged tree before the push**, as before any push
475+
(step 4), and a red gate pushes nothing. A red stage here is the interaction
476+
this step exists to find: fix it on the branch, signed off, and run that
477+
last line again.
478+
- **Then wait for CI on the new head**, with one backgrounded command, as
479+
`AGENTS.md` **Waiting on long-running work** says. The `sleep` gives the push
480+
runs time to register; `--watch` on a head with no checks yet exits at once.
481+
482+
```sh
483+
sleep 60; gh pr checks "$PR" --repo modelcontextprotocol/servers \
484+
--watch --interval 30; echo "EXIT=$?"
485+
```
486+
487+
- **A catch-up that merged without conflicts and passed the gate unchanged
488+
needs no new Copilot round.** Nothing the PR adds changed. One that needed a
489+
conflict resolved or a fix pushed changed the PR, so request a round (step 9).
490+
- **If `v2/main` moves again before the merge, run step 1 again.** It costs
491+
one fetch, and most of the time it prints nothing that interacts.
492+
493+
**Fan-outs.** When several PRs for one server are open at once, a PR that
494+
changes that server's **configuration** (a language floor, lint or compiler
495+
settings, a dependency major) interacts with every one of them. Merge it
496+
**last**, after catching it up on the others, or merge it first and catch up
497+
and re-test each of the others after it. The open PRs that touch a server:
498+
499+
```sh
500+
gh pr list --repo modelcontextprotocol/servers --base v2/main --state open \
501+
--limit 200 --json number,title,files \
502+
--jq '.[] | select(any(.files[]; .path | startswith("src/fetch/")))
503+
| "\(.number) \(.title)"'
504+
```
505+
506+
Nothing enforces this step: `v2/main`'s ruleset requires no status checks, so
507+
it is done by hand by whoever merges. Whether a merge queue or a required
508+
up-to-date check should take it over is #5588.
509+
510+
### After the merge
511+
410512
**On merge into `v2/main`, close the issue by hand and move its card to
411513
Done**, since auto-close does not fire there:
412514

‎.claude/skills/pr-flow/evals/evals.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
"prompt": "My PR into v2/main just merged. What do I still need to do to close it out?",
2424
"expect": "pr-flow"
2525
},
26+
{
27+
"prompt": "My PR is green and GitHub says it has no conflicts, but another PR for the same server merged into v2/main ten minutes ago. What do I have to do before it can merge?",
28+
"expect": "pr-flow"
29+
},
2630
{
2731
"prompt": "What does this regex match? /^[a-z]+$/",
2832
"expect": null

‎AGENTS.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,19 @@ here.
600600
declined finding that is worth doing gets its own issue, linked in the
601601
reply. The rule is under
602602
[Responding to code reviews](#responding-to-code-reviews).
603+
- **Before a PR merges, it is caught up and re-tested if `v2/main` moved in a
604+
way that can interact with it.** GitHub reporting no conflicts is not that
605+
test: it compares text, and the gate and CI ran on the PR's head, which
606+
holds nothing that landed on `v2/main` after the branch last took it in. Two
607+
fetch PRs that were each green left `v2/main` red that way (#5569). What
608+
landed **can interact** when it touches a server directory
609+
(`src/<server>/`) the PR also touches, or when either side touches
610+
repository-wide configuration: a root manifest, lockfile or configuration
611+
file, `scripts/`, or `.github/workflows/`. When in doubt, re-test. Catching
612+
up is a merge of `origin/v2/main` into the branch, never a rebase, then the
613+
gate, a push, and green CI on the new head. `v2/main`'s ruleset requires no
614+
status checks, so this is on whoever merges. The recipe is the `pr-flow`
615+
skill (step 10).
603616
- **If new tasks are discovered during development, create issues** for them
604617
and put them on the board, rather than widening the current PR.
605618

‎src/everything/__tests__/modern.test.ts‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* roots.test.ts), `requestState` carried across the multi-step tool's
1414
* rounds on both eras, with retries after missing or bad input, and the
1515
* SDK refusing an embedded request whose capability the request did not
16-
* declare (-32021) or a tampered state (-32602).
16+
* declare (-32021) or a tampered or expired state (-32602).
1717
* - Per-request log levels (`trigger-log-messages`) against the 2025-era
1818
* session level.
1919
* - Change notifications (`trigger-list-changed`, `trigger-resource-update`)
@@ -336,6 +336,35 @@ describe("multi-round-trip requests on 2026-07-28", () => {
336336
requestState: expect.any(String),
337337
});
338338
});
339+
340+
it("refuses an untampered requestState with -32602 once its 600-second TTL has passed", async () => {
341+
// Freeze the clock before the state is minted, so only the test moves it.
342+
vi.useFakeTimers({ toFake: ["Date"] });
343+
raw = await connectRaw({ elicitation: {} });
344+
const mintedAt = Date.now();
345+
const first = await raw.call("trigger-multi-step-elicitation");
346+
const answerTheName = {
347+
name: "trigger-multi-step-elicitation",
348+
arguments: {},
349+
requestState: (first as { requestState: string }).requestState,
350+
inputResponses: {
351+
name: { action: "accept", content: { name: "Ada" } },
352+
},
353+
};
354+
355+
// Inside the TTL the state is accepted, so the refusal below is the
356+
// expiry and nothing else about this continuation.
357+
vi.setSystemTime(mintedAt + 599_000);
358+
expect(await raw.result("tools/call", answerTheName)).toMatchObject({
359+
resultType: "input_required",
360+
inputRequests: { color: { method: "elicitation/create" } },
361+
});
362+
363+
// Past it, the same state is refused: only the clock has moved.
364+
vi.setSystemTime(mintedAt + 601_000);
365+
const response = await raw.request("tools/call", answerTheName);
366+
expect(response.error).toMatchObject({ code: -32602 });
367+
});
339368
});
340369

341370
describe("trigger-multi-step-elicitation", () => {

‎src/filesystem/README.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ The server's directory access control follows this flow:
128128
- A path is checked and then used, so on macOS and Linux each write, each read of a file's content or metadata, and each directory listing (`list_directory`, `list_directory_with_sizes`, `directory_tree`, `search_files`) acts from inside the directory that was checked. If a directory on the path is replaced in between, the call is refused with "Access denied - a directory on the path changed during the operation" rather than following the replacement. A listing therefore needs to enter the directory it lists: a directory the server can read but not enter (read permission without execute) is refused with `EACCES`, as an unreadable one is
129129
- On Windows, a path naming an NTFS alternate data stream (`file.txt:stream`, `file.txt::$DATA`) is refused with "Access denied - NTFS alternate data stream paths are not supported", even inside an allowed directory: a colon is accepted only as a drive letter's (`C:\`, `\\?\C:\`). A stream holds data that no directory listing or diff of the file shows. On macOS and Linux a colon is an ordinary file-name character and is not refused
130130
- On Windows, a path any of whose components is a reserved device name (`CON`, `PRN`, `AUX`, `NUL`, `COM1`-`COM9`, `LPT1`-`LPT9`, in any case and with or without an extension, such as `NUL.txt`) is refused with "Access denied - Windows reserved device names ... are not supported", and one any of whose components ends in a dot or a space (`file.txt.`, `dir \file.txt`) with "Access denied - Windows path components ending in a dot or a space are not supported". Windows opens the device rather than a file in the directory, and strips trailing dots and spaces so the name refers to a different file. `.` and `..` are not affected. On macOS and Linux these are ordinary file names and are not refused
131-
- **Limit on Windows: a parent directory swapped during an operation.** A path is checked and then used, and a directory on it could be replaced in between. On Linux and macOS the server anchors every write, and every read of a file's content or metadata, to the directory it validated, so a directory replaced with a symlink after the check cannot redirect the operation. **On Windows it cannot do that, and the operation is not protected**: a second local process that can already write inside an allowed directory can replace a parent directory with a junction (or a directory symlink) between the server's check and its open, and so redirect a read or a write outside the allowed directories. The server still checks the final component there (a write refuses a symlink or junction at the file's own name, and the file opened must be the one the directory holds at that name afterwards), which narrows the window without closing it
131+
- **Limit on Windows: a parent directory swapped during an operation.** A path is checked and then used, and a directory on it could be replaced in between. On Linux and macOS the server anchors every write, every read of a file's content or metadata, and every directory listing, to the directory it validated, so a directory replaced with a symlink after the check cannot redirect the operation. **On Windows it cannot do that, and the operation is not protected**: a second local process that can already write inside an allowed directory can replace a parent directory with a junction (or a directory symlink) between the server's check and its open, and so redirect a read, a write or a directory listing outside the allowed directories. The server still checks the final component there (a write refuses a symlink or junction at the file's own name, and the file opened must be the one the directory holds at that name afterwards), which narrows the window without closing it. A directory listing (`list_directory`, `list_directory_with_sizes`, `directory_tree`, `search_files`) is checked on both sides of the read instead: before and after it, the listed path must have no junction or symlink on it and must name the same directory, or the call is refused with "Access denied - a directory on the path changed during the operation". That refuses a replacement still in place when the read starts or when it ends. One made and undone in between is not detected, and returns the entry names of the directory it pointed to, so this too narrows the window without closing it
132132
- **What it takes**: a concurrent local process with write access inside an allowed directory, winning a race against the server. No tool of this server creates a junction or a symlink, so it cannot be set up through the server alone
133133
- **Guidance**: on Windows, do not allow a directory that untrusted local processes or users can write to
134134
- **Why it is not fixed**: closing the window needs opens relative to a directory handle, which Node does not expose, so it would take native code, and that is out of scope for a reference server ([#5260](https://github.com/modelcontextprotocol/servers/issues/5260)). It may be revisited when Node ships a stable built-in FFI under this package's `engines` floor
@@ -300,6 +300,10 @@ Files inside the allowed directories are also [resources](https://modelcontextpr
300300
entirely.
301301
- Glob-style pattern matching
302302
- Returns full paths to matches
303+
- When nothing matches, the result begins `No matches found` and goes on to
304+
name the pattern and the directory searched and to say how the pattern is
305+
read. For a pattern with no `**`, which only matches at one depth, it also
306+
suggests the `**/` form that matches at any depth
303307
- Bounded: see [Slow and very large trees](#slow-and-very-large-trees)
304308
- A subdirectory that cannot be read (no permission, say) is skipped, and the
305309
result says so: after the matches, a note that the search is incomplete

‎src/filesystem/__tests__/exclude-glob-prunes-dir.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ describe('excludePatterns ending in "/**" (#5445)', () => {
140140
excludePatterns: ["**/node_modules/**"],
141141
});
142142
expect(result.isError).toBeFalsy();
143-
expect(textOf(result)).toBe("No matches found");
143+
expect(textOf(result)).toMatch(/^No matches found for pattern /);
144144
});
145145

146146
it("directory_tree does not list the excluded directory, even as empty", async () => {

0 commit comments

Comments
 (0)