Skip to content

Commit 8aab37e

Browse files
committed
Merge origin/v2/main into v2/fix/5520-git-windows-junction
Catch up before merge: v2/main moved under this PR.
2 parents 7660d00 + 3b31264 commit 8aab37e

39 files changed

Lines changed: 2312 additions & 98 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@modelcontextprotocol/server-everything": minor
3+
---
4+
5+
The Streamable HTTP transport now evicts a 2025-era session that has been idle for 30 minutes: one with no request in flight and no stream open. Until now a session whose client never sent a DELETE stayed in memory, with its server instance, for the life of the process. An evicted session's next request is answered `404 Session not found`, the spec's signal for the client to initialize again. Set the new `SESSION_IDLE_TIMEOUT_MILLIS` environment variable to change the timeout, or to `0` to keep sessions until their client ends them. 2026-07-28 clients have no sessions and are unaffected. Thanks to [Pierpaolo1223](https://github.com/Pierpaolo1223) for the report and the measurements in [#5558](https://github.com/modelcontextprotocol/servers/issues/5558).
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+
`move_file` now refuses to move a directory into itself with `Cannot move a directory into itself: <destination> is inside <source>`, instead of reporting `Parent directory does not exist` for a destination directory that does exist.
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/README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ Both HTTP transports (Streamable HTTP and HTTP+SSE) listen on the loopback inter
133133
| --- | --- | --- |
134134
| `PORT` | `3001` | The port the HTTP transport listens on |
135135
| `HOST` | `127.0.0.1` | The address it binds; `0.0.0.0` (or `::`) for every interface |
136+
| `SESSION_IDLE_TIMEOUT_MILLIS` | `1800000` (30 minutes) | Streamable HTTP only: how long a 2025-era session may sit idle before the server ends it; `0` never ends one |
137+
138+
A 2025-era Streamable HTTP session normally ends when its client sends a `DELETE`. One whose client goes away without doing so is ended by the server once it has been idle for `SESSION_IDLE_TIMEOUT_MILLIS`: its server instance is closed and its timers and subscriptions are released. Idle means no request in flight and no stream open, so a client that keeps its `GET` stream open, or is waiting on a long tool call, is never timed out; the clock starts when the session's last response closes, and idle sessions are looked for every tenth of the timeout (no less than a second and no more than a minute apart), so one is ended that much late at most. A request for a session the server has ended is answered `404 Not Found` (`Session not found`), which is the [specification's signal](https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#session-management) for the client to start a new session with a fresh `initialize`. Set a short timeout to exercise that path in a client under test, or `0` to keep every session until its client ends it. A value that is not a non-negative number is ignored in favor of the default. 2026-07-28 clients have no sessions, and an HTTP+SSE session ends when its stream's connection closes, so neither is affected.
136139

137140
Both HTTP transports (Streamable HTTP and HTTP+SSE) accept browser requests only from a localhost origin: an `Origin` header whose host is `localhost`, `127.0.0.1` or `[::1]`, on any port, such as the MCP Inspector's. A request carrying any other `Origin` is refused with `403 Forbidden`. Clients that send no `Origin` header, which is every non-browser client, are unaffected.
138141

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
/**
2+
* The timing of idle-session eviction (#5558), with fake timers and no HTTP:
3+
* what `SESSION_IDLE_TIMEOUT_MILLIS` is read as, that a session is evicted
4+
* once, only after it has had no open response for the timeout, and that a
5+
* timeout of 0 and `stop()` both end the watching. A response is an
6+
* `EventEmitter` here, since "close" is all the module listens for. What
7+
* eviction does to a real session is in `streamable-http.test.ts`.
8+
*/
9+
import { EventEmitter } from "node:events";
10+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
11+
import {
12+
DEFAULT_SESSION_IDLE_TIMEOUT_MILLIS,
13+
sessionIdleTimeoutMillis,
14+
watchIdleSessions,
15+
} from "../transports/idle-sessions.js";
16+
17+
describe("sessionIdleTimeoutMillis", () => {
18+
afterEach(() => {
19+
vi.unstubAllEnvs();
20+
});
21+
22+
it("defaults to 30 minutes", () => {
23+
expect(DEFAULT_SESSION_IDLE_TIMEOUT_MILLIS).toBe(1_800_000);
24+
expect(sessionIdleTimeoutMillis(undefined)).toBe(1_800_000);
25+
});
26+
27+
it("reads SESSION_IDLE_TIMEOUT_MILLIS from the environment", () => {
28+
vi.stubEnv("SESSION_IDLE_TIMEOUT_MILLIS", "5000");
29+
expect(sessionIdleTimeoutMillis()).toBe(5000);
30+
});
31+
32+
it("takes a number of milliseconds, and 0 as disabled", () => {
33+
expect(sessionIdleTimeoutMillis("60000")).toBe(60_000);
34+
expect(sessionIdleTimeoutMillis(" 250 ")).toBe(250);
35+
expect(sessionIdleTimeoutMillis("0")).toBe(0);
36+
});
37+
38+
it.each(["", " ", "-1", "soon", "Infinity"])(
39+
"falls back to the default for %j",
40+
(value) => {
41+
expect(sessionIdleTimeoutMillis(value)).toBe(
42+
DEFAULT_SESSION_IDLE_TIMEOUT_MILLIS,
43+
);
44+
},
45+
);
46+
});
47+
48+
describe("watchIdleSessions", () => {
49+
beforeEach(() => {
50+
vi.useFakeTimers();
51+
});
52+
53+
afterEach(() => {
54+
vi.useRealTimers();
55+
});
56+
57+
it("evicts a session once, after it has been idle for the timeout", () => {
58+
const evict = vi.fn();
59+
const idle = watchIdleSessions(5000, evict);
60+
idle.add("a");
61+
vi.advanceTimersByTime(4999);
62+
expect(evict).not.toHaveBeenCalled();
63+
vi.advanceTimersByTime(1);
64+
expect(evict).toHaveBeenCalledExactlyOnceWith("a");
65+
vi.advanceTimersByTime(60_000);
66+
expect(evict).toHaveBeenCalledOnce();
67+
idle.stop();
68+
});
69+
70+
it("keeps a session with an open response, and times it from when the response closes", () => {
71+
const evict = vi.fn();
72+
const idle = watchIdleSessions(5000, evict);
73+
idle.add("active");
74+
idle.add("abandoned");
75+
const stream = new EventEmitter();
76+
const call = new EventEmitter();
77+
idle.hold("active", stream);
78+
idle.hold("active", call);
79+
vi.advanceTimersByTime(5000);
80+
expect(evict).toHaveBeenCalledExactlyOnceWith("abandoned");
81+
82+
// One of two responses closing leaves the session in use.
83+
call.emit("close");
84+
vi.advanceTimersByTime(60_000);
85+
expect(evict).toHaveBeenCalledOnce();
86+
87+
// The clock starts when the last one closes, not when it opened.
88+
stream.emit("close");
89+
vi.advanceTimersByTime(4999);
90+
expect(evict).toHaveBeenCalledOnce();
91+
vi.advanceTimersByTime(1);
92+
expect(evict).toHaveBeenLastCalledWith("active");
93+
expect(evict).toHaveBeenCalledTimes(2);
94+
idle.stop();
95+
});
96+
97+
it("restarts a session's clock on each request", () => {
98+
const evict = vi.fn();
99+
const idle = watchIdleSessions(5000, evict);
100+
idle.add("a");
101+
for (let i = 0; i < 4; i++) {
102+
vi.advanceTimersByTime(4000);
103+
const res = new EventEmitter();
104+
idle.hold("a", res);
105+
res.emit("close");
106+
}
107+
expect(evict).not.toHaveBeenCalled();
108+
idle.stop();
109+
});
110+
111+
it("does not evict a session that was removed, or hold one it does not watch", () => {
112+
const evict = vi.fn();
113+
const idle = watchIdleSessions(5000, evict);
114+
idle.add("ended");
115+
idle.remove("ended");
116+
const res = new EventEmitter();
117+
idle.hold("unknown", res);
118+
expect(res.listenerCount("close")).toBe(0);
119+
vi.advanceTimersByTime(60_000);
120+
expect(evict).not.toHaveBeenCalled();
121+
idle.stop();
122+
});
123+
124+
it("looks for idle sessions every tenth of the timeout", () => {
125+
const evict = vi.fn();
126+
const idle = watchIdleSessions(50_000, evict);
127+
// Idle from 2 s in: past the timeout at 52 s, and seen at the 55 s look.
128+
vi.advanceTimersByTime(2000);
129+
idle.add("a");
130+
vi.advanceTimersByTime(52_999);
131+
expect(evict).not.toHaveBeenCalled();
132+
vi.advanceTimersByTime(1);
133+
expect(evict).toHaveBeenCalledExactlyOnceWith("a");
134+
idle.stop();
135+
});
136+
137+
it("looks at least every minute, however long the timeout", () => {
138+
const evict = vi.fn();
139+
const idle = watchIdleSessions(30 * 60_000, evict);
140+
vi.advanceTimersByTime(60_000);
141+
idle.add("a");
142+
// Idle from 1:00, so past the timeout at 31:00, the next look.
143+
vi.advanceTimersByTime(30 * 60_000 - 1);
144+
expect(evict).not.toHaveBeenCalled();
145+
vi.advanceTimersByTime(1);
146+
expect(evict).toHaveBeenCalledExactlyOnceWith("a");
147+
idle.stop();
148+
});
149+
150+
it("looks no more often than once a second when the timeout is shorter", () => {
151+
const evict = vi.fn();
152+
const idle = watchIdleSessions(10, evict);
153+
idle.add("a");
154+
vi.advanceTimersByTime(999);
155+
expect(evict).not.toHaveBeenCalled();
156+
vi.advanceTimersByTime(1);
157+
expect(evict).toHaveBeenCalledExactlyOnceWith("a");
158+
idle.stop();
159+
});
160+
161+
it("never evicts, and runs no timer, when the timeout is 0", () => {
162+
const evict = vi.fn();
163+
const idle = watchIdleSessions(0, evict);
164+
expect(vi.getTimerCount()).toBe(0);
165+
idle.add("a");
166+
vi.advanceTimersByTime(24 * 60 * 60 * 1000);
167+
expect(evict).not.toHaveBeenCalled();
168+
idle.stop();
169+
});
170+
171+
it("stops looking once stopped", () => {
172+
const evict = vi.fn();
173+
const idle = watchIdleSessions(5000, evict);
174+
idle.add("a");
175+
idle.stop();
176+
expect(vi.getTimerCount()).toBe(0);
177+
vi.advanceTimersByTime(60_000);
178+
expect(evict).not.toHaveBeenCalled();
179+
});
180+
});

0 commit comments

Comments
 (0)