Skip to content

fix(code): run MCP login during a run, queue the restart - #4643

Merged
Mason Daugherty (mdrxy) merged 6 commits into
mainfrom
mdrxy/code/mcp-login-during-generation
Jul 14, 2026
Merged

fix(code): run MCP login during a run, queue the restart#4643
Mason Daugherty (mdrxy) merged 6 commits into
mainfrom
mdrxy/code/mcp-login-during-generation

Conversation

@mdrxy

@mdrxy Mason Daugherty (mdrxy) commented Jul 10, 2026

Copy link
Copy Markdown
Member

/mcp login now runs during an active generation instead of waiting for it to finish; if you accept the reconnect, the server restart is queued and applied automatically once the current task completes.


/mcp login previously deferred the entire OAuth flow until an active agent or shell task finished. But only the final server restart (_restart_server_for_mcp_refresh_respawn_server) actually conflicts with a live run — the OAuth handshake and on-disk token write never touch the running server. This starts login immediately even during a generation and queues only the restart, so the user can authenticate without waiting for the turn to end.

When the user accepts "reconnect" on the post-login prompt while a run is active, the restart is queued as a new mcp_reconnect deferred action (drained by the existing _maybe_drain_deferred on agent/shell cleanup) instead of tearing down the in-flight generation. The reconnect is marked pending in the meantime so /mcp reconnect and the splash banner stay accurate, and the queued action re-checks the pending flag to avoid a redundant restart if a manual /mcp reconnect already ran. When idle, behavior is unchanged (immediate restart).

Made by Open SWE

Previously `/mcp login` deferred the entire OAuth flow until the active
agent/shell task finished. Only the final server restart actually
conflicts with a live run, so start login immediately and queue just the
restart via a new `mcp_reconnect` deferred action that drains once idle.

Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
@github-actions github-actions Bot added dcode Related to `deepagents-code` feature New feature/enhancement or request for one internal User is a member of the `langchain-ai` GitHub organization size: S 50-199 LOC labels Jul 10, 2026
@mdrxy
Mason Daugherty (mdrxy) marked this pull request as ready for review July 10, 2026 21:40

@open-swe open-swe Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Open SWE Review found 1 potential issue.

Open in WebView Open SWE trace

Comment thread libs/code/deepagents_code/app.py
@mdrxy
Mason Daugherty (mdrxy) marked this pull request as draft July 13, 2026 13:35
@mdrxy
Mason Daugherty (mdrxy) marked this pull request as ready for review July 14, 2026 03:30
@github-actions github-actions Bot added size: M 200-499 LOC and removed size: S 50-199 LOC labels Jul 14, 2026
@mdrxy Mason Daugherty (mdrxy) changed the title feat(code): run MCP login during a run, queue the restart fix(code): run MCP login during a run, queue the restart Jul 14, 2026
@github-actions github-actions Bot added fix A bug fix (PATCH) and removed feature New feature/enhancement or request for one labels Jul 14, 2026
@mdrxy
Mason Daugherty (mdrxy) merged commit 65e1ee8 into main Jul 14, 2026
62 checks passed
@mdrxy
Mason Daugherty (mdrxy) deleted the mdrxy/code/mcp-login-during-generation branch July 14, 2026 04:12
Mason Daugherty (mdrxy) added a commit that referenced this pull request Jul 14, 2026
> [!CAUTION]
> Merging this PR will automatically publish to **PyPI** and create a
**GitHub release**.

For the full release process, see
[`.github/RELEASING.md`](https://github.com/langchain-ai/deepagents/blob/main/.github/RELEASING.md).

---

_Release notes preview: keep this section in sync with the package
`CHANGELOG.md`. The published GitHub release body is extracted from the
merged `CHANGELOG.md` by `release.yml`, not from this PR description._

---


##
[0.1.38](deepagents-code==0.1.37...deepagents-code==0.1.38)
(2026-07-14)

### Features

* Improve `/goal` criteria UX
([#4694](#4694))
([06f46ff](06f46ff))
* Add interactive goal management
([#4693](#4693))
([64205e2](64205e2))
* Conditionally drop `TodoListMiddleware`
([#4685](#4685))
([d3a3077](d3a3077))
* Add `memory.auto_save` config flag
([#4700](#4700))
([55b60ca](55b60ca))
* Trace experimental mode in metadata
([#4705](#4705))
([22d5045](22d5045))

### Bug Fixes

* Align context diff rows with changed rows
([#4714](#4714))
([f9915db](f9915db))
* Hydrate virtualized transcript on scroll offset changes
([#4646](#4646))
([f77eeb0](f77eeb0))
* Keep TODO and edit tools expanded
([#4704](#4704))
([1d549d3](1d549d3))
* Make `/goal` completion and grading reliable
([#4691](#4691))
([9da63c6](9da63c6))
* Preflight Ollama host reachability before discovery probe
([#4702](#4702))
([96fe71a](96fe71a))
* Quiet expected non-repo `git ls-files` logging
([#4701](#4701))
([3d499db](3d499db))
* Rename `ls_agent_kind` to `ls_agent_purpose`
([#4708](#4708))
([2678b16](2678b16))
* Run MCP login during a run, queue the restart
([#4643](#4643))
([65e1ee8](65e1ee8))
* Show "Took &lt;duration&gt;" when `task` tool completes
([#4638](#4638))
([19538e0](19538e0))
* Support unambiguous `read_file` gutters
([#4711](#4711))
([2089b54](2089b54))

---

_End release notes preview._

---

> [!NOTE]
> A **New Contributors** section is appended to the GitHub release notes
automatically at publish time (see [Release
Pipeline](https://github.com/langchain-ai/deepagents/blob/main/.github/RELEASING.md#release-pipeline),
step 2).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Mason Daugherty <github@mdrxy.com>
Marcelo5444 pushed a commit to Marcelo5444/deepagents that referenced this pull request Jul 30, 2026
…i#4643)

`/mcp login` now runs during an active generation instead of waiting for
it to finish; if you accept the reconnect, the server restart is queued
and applied automatically once the current task completes.

---

`/mcp login` previously deferred the *entire* OAuth flow until an active
agent or shell task finished. But only the final server restart
(`_restart_server_for_mcp_refresh` → `_respawn_server`) actually
conflicts with a live run — the OAuth handshake and on-disk token write
never touch the running server. This starts login immediately even
during a generation and queues only the restart, so the user can
authenticate without waiting for the turn to end.

When the user accepts "reconnect" on the post-login prompt while a run
is active, the restart is queued as a new `mcp_reconnect` deferred
action (drained by the existing `_maybe_drain_deferred` on agent/shell
cleanup) instead of tearing down the in-flight generation. The reconnect
is marked pending in the meantime so `/mcp reconnect` and the splash
banner stay accurate, and the queued action re-checks the pending flag
to avoid a redundant restart if a manual `/mcp reconnect` already ran.
When idle, behavior is unchanged (immediate restart).

Made by [Open
SWE](https://openswe.vercel.app/agents/4defa6fb-fe26-d47b-9fa0-10b5a9c29dcd)

---------

Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
Marcelo5444 pushed a commit to Marcelo5444/deepagents that referenced this pull request Jul 30, 2026
> [!CAUTION]
> Merging this PR will automatically publish to **PyPI** and create a
**GitHub release**.

For the full release process, see
[`.github/RELEASING.md`](https://github.com/langchain-ai/deepagents/blob/main/.github/RELEASING.md).

---

_Release notes preview: keep this section in sync with the package
`CHANGELOG.md`. The published GitHub release body is extracted from the
merged `CHANGELOG.md` by `release.yml`, not from this PR description._

---


##
[0.1.38](langchain-ai/deepagents@deepagents-code==0.1.37...deepagents-code==0.1.38)
(2026-07-14)

### Features

* Improve `/goal` criteria UX
([langchain-ai#4694](langchain-ai#4694))
([06f46ff](langchain-ai@06f46ff))
* Add interactive goal management
([langchain-ai#4693](langchain-ai#4693))
([64205e2](langchain-ai@64205e2))
* Conditionally drop `TodoListMiddleware`
([langchain-ai#4685](langchain-ai#4685))
([d3a3077](langchain-ai@d3a3077))
* Add `memory.auto_save` config flag
([langchain-ai#4700](langchain-ai#4700))
([55b60ca](langchain-ai@55b60ca))
* Trace experimental mode in metadata
([langchain-ai#4705](langchain-ai#4705))
([22d5045](langchain-ai@22d5045))

### Bug Fixes

* Align context diff rows with changed rows
([langchain-ai#4714](langchain-ai#4714))
([f9915db](langchain-ai@f9915db))
* Hydrate virtualized transcript on scroll offset changes
([langchain-ai#4646](langchain-ai#4646))
([f77eeb0](langchain-ai@f77eeb0))
* Keep TODO and edit tools expanded
([langchain-ai#4704](langchain-ai#4704))
([1d549d3](langchain-ai@1d549d3))
* Make `/goal` completion and grading reliable
([langchain-ai#4691](langchain-ai#4691))
([9da63c6](langchain-ai@9da63c6))
* Preflight Ollama host reachability before discovery probe
([langchain-ai#4702](langchain-ai#4702))
([96fe71a](langchain-ai@96fe71a))
* Quiet expected non-repo `git ls-files` logging
([langchain-ai#4701](langchain-ai#4701))
([3d499db](langchain-ai@3d499db))
* Rename `ls_agent_kind` to `ls_agent_purpose`
([langchain-ai#4708](langchain-ai#4708))
([2678b16](langchain-ai@2678b16))
* Run MCP login during a run, queue the restart
([langchain-ai#4643](langchain-ai#4643))
([65e1ee8](langchain-ai@65e1ee8))
* Show "Took &lt;duration&gt;" when `task` tool completes
([langchain-ai#4638](langchain-ai#4638))
([19538e0](langchain-ai@19538e0))
* Support unambiguous `read_file` gutters
([langchain-ai#4711](langchain-ai#4711))
([2089b54](langchain-ai@2089b54))

---

_End release notes preview._

---

> [!NOTE]
> A **New Contributors** section is appended to the GitHub release notes
automatically at publish time (see [Release
Pipeline](https://github.com/langchain-ai/deepagents/blob/main/.github/RELEASING.md#release-pipeline),
step 2).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Mason Daugherty <github@mdrxy.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dcode Related to `deepagents-code` fix A bug fix (PATCH) internal User is a member of the `langchain-ai` GitHub organization size: M 200-499 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant