René's URL Explorer Experiment


Title: `session.disconnect()` does not kill stdio MCP server processes spawned for that session · Issue #3440 · github/copilot-cli · GitHub

Open Graph Title: `session.disconnect()` does not kill stdio MCP server processes spawned for that session · Issue #3440 · github/copilot-cli

X Title: `session.disconnect()` does not kill stdio MCP server processes spawned for that session · Issue #3440 · github/copilot-cli

Description: Describe the bug When a CopilotSession is created with mcpServers containing one or more stdio entries, the Copilot CLI spawns a child process for each server. When session.disconnect() is called, those child processes are not killed. Th...

Open Graph Description: Describe the bug When a CopilotSession is created with mcpServers containing one or more stdio entries, the Copilot CLI spawns a child process for each server. When session.disconnect() is called, ...

X Description: Describe the bug When a CopilotSession is created with mcpServers containing one or more stdio entries, the Copilot CLI spawns a child process for each server. When session.disconnect() is called, ...

Opengraph URL: https://github.com/github/copilot-cli/issues/3440

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`session.disconnect()` does not kill stdio MCP server processes spawned for that session","articleBody":"### Describe the bug\n\nWhen a `CopilotSession` is created with `mcpServers` containing one or more `stdio` entries, the Copilot CLI spawns a child process for each server. When `session.disconnect()` is called, those child processes are **not killed**. They only die when `CopilotClient.stop()` is eventually called.\n\nIn workloads that create many short-lived sessions sharing a single `CopilotClient` (e.g. eval/testing pipelines that run N prompts sequentially), this causes one orphaned MCP server process per session, leading to monotonically increasing memory consumption for the lifetime of the client.\n\n### Process hierarchy\n```\nnode (host process)\n  └── Copilot CLI subprocess          ← spawned by CopilotClient\n        └── node mcp-server.js        ← spawned by CLI when session sends first prompt\n        └── node mcp-server.js        ← spawned for next session, previous one still alive\n        └── ...                       ← accumulates until client.stop()\n```\n\n### Affected version\n\nGitHub Copilot CLI 1.0.49.\n\n### Steps to reproduce the behavior\n\nThe following two files are all that is needed. \n\n### `mcp-server.js` — a trivial stdio MCP server\n\n```js\nimport { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport { z } from \"zod\";\n\nconst server = new McpServer({ name: \"greeting-server\", version: \"0.1.0\" });\n\nserver.registerTool(\n  \"demo_get_greeting\",\n  {\n    description: \"Returns a greeting for the given name.\",\n    inputSchema: { name: z.string() },\n  },\n  async ({ name }) =\u003e ({ content: [{ type: \"text\", text: `Hello, ${name}!` }] }),\n);\n\nconst transport = new StdioServerTransport();\nserver.connect(transport);\n```\n\n### `repro-sdk-only.mjs` — the repro script\n\n```js\nimport { CopilotClient, approveAll } from \"@github/copilot-sdk\";\nimport { execFileSync } from \"node:child_process\";\nimport { fileURLToPath } from \"node:url\";\nimport { dirname, join } from \"node:path\";\n\nconst __dir = dirname(fileURLToPath(import.meta.url));\nconst MCP_SERVER = join(__dir, \"mcp-server.js\");\n\nfunction snapshotProcesses(label) {\n  let lines = \"\";\n  try {\n    lines = execFileSync(\n      \"powershell\",\n      [\n        \"-NoProfile\",\n        \"-Command\",\n        \"Get-CimInstance Win32_Process -EA SilentlyContinue\" +\n          \" | Where-Object { $_.Name -eq 'node.exe' -and $_.CommandLine -match 'mcp-server' }\" +\n          \" | ForEach-Object {\" +\n          \"   $m = [math]::Round((Get-Process -Id $_.ProcessId -EA 0).WorkingSet64/1MB,1);\" +\n          '   Write-Output \"  PID=$($_.ProcessId) Mem=${m}MB Cmd=$($_.CommandLine)\"' +\n          \" }\",\n      ],\n      { encoding: \"utf8\", timeout: 5_000 },\n    ).trim();\n  } catch { /* no processes or powershell unavailable */ }\n\n  const count = lines ? lines.split(\"\\n\").length : 0;\n  const status = count \u003e 0 ? `${count} process(es) still alive ← BUG` : \"0 process(es) alive ✓\";\n  console.log(`\\n[${label}] ${status}`);\n  if (lines) console.log(lines);\n}\n\nconst client = new CopilotClient();\n\n// Step 1 — create session\nconsole.log(\"[1] Creating session with stdio MCP server...\");\nconst session = await client.createSession({\n  mcpServers: {\n    \"greeting-server\": {\n      type: \"stdio\",\n      command: \"node\",\n      args: [MCP_SERVER],\n      tools: [\"*\"],\n    },\n  },\n  onPermissionRequest: approveAll,\n  streaming: false,\n  workingDirectory: process.cwd(),\n});\nconsole.log(`    Session created: ${session.sessionId}`);\nsnapshotProcesses(\"after createSession (before prompt)\");\n\n// Step 2 — send a prompt (this is when the CLI spawns the MCP process)\nconsole.log(\"\\n[2] Sending prompt...\");\nawait session.sendAndWait(\n  { prompt: \"Use the demo_get_greeting tool to greet Alice.\", mode: \"immediate\" },\n  60_000,\n);\nconsole.log(\"    sendAndWait returned.\");\nsnapshotProcesses(\"after sendAndWait — MCP process spawned\");\n\n// Step 3 — disconnect: MCP process should die here, but doesn't\nconsole.log(\"\\n[3] Calling session.disconnect()...\");\nawait session.disconnect();\nconsole.log(\"    session.disconnect() returned.\");\nsnapshotProcesses(\"after session.disconnect() — should be 0, is NOT ← BUG\");\n\n// Step 4 — stop the client: only now does the process die\nconsole.log(\"\\n[4] Calling client.stop()...\");\nawait client.stop();\nconsole.log(\"    client.stop() returned.\");\nsnapshotProcesses(\"after client.stop() — finally clean\");\n```\n\n### Run it\n\n```bash\nnode repro-sdk-only.mjs\n```\n\n### Observed results\n\n```\nStarting minimal repro for session.disconnect() MCP leak...\n\nMCP server: C:\\Evals\\evaluate\\tests\\evals\\mcp-process-leak\\mcp-server.js\n\n[1] Creating session with stdio MCP server...\n[CLI subprocess] (node:67688) ExperimentalWarning: SQLite is an experimental feature and might change at any time\n[CLI subprocess] (Use `node --trace-warnings ...` to show where the warning was created)\n    Session created: c9939bf6-b45f-41c0-aad9-607aa6ca489f\n\n[after createSession (before any prompt)] 0 process(es) alive ✓\n\n[2] Sending prompt (triggers MCP server spawn)...\n    sendAndWait returned.\n\n[after sendAndWait — MCP process now alive] 1 process(es) still alive ← BUG\nPID=51096 Mem=78.4MB Cmd=node C:\\Evals\\evaluate\\tests\\evals\\mcp-process-leak\\mcp-server.js\n\n[3] Calling session.disconnect()...\n    session.disconnect() returned.\n\n[after session.disconnect()] 1 process(es) still alive ← BUG\nPID=51096 Mem=67MB Cmd=node C:\\Evals\\evaluate\\tests\\evals\\mcp-process-leak\\mcp-server.js\n\n[4] Calling client.stop()...\n    client.stop() returned.\n\n[after client.stop() — processes finally gone] 0 process(es) alive ✓\n```\n\nKey observation: **the same PID survives `session.disconnect()` and only disappears after `client.stop()`**. The process is not a timing artifact — it persists indefinitely until the client is stopped.\n\n\u003e **Note:** `sendAndWait` fully resolves (the Promise settles and `\"sendAndWait returned.\"` is printed) **before** `session.disconnect()` is ever called. The leak is not caused by a pending or unresolved `sendAndWait` — the process survives even after all session work is entirely complete.\n\n\n### Expected behavior\n\n`session.disconnect()` should kill any stdio MCP server processes that were spawned for that session. Callers should not need to know whether a session used MCP servers in order to ensure clean process teardown.\n\n### Additional context\n\n- **`@github/copilot-sdk`**: latest\n- **OS**: Windows 11\n- **Node.js**: v22.22.2","author":{"url":"https://github.com/AlitzelMendez","@type":"Person","name":"AlitzelMendez"},"datePublished":"2026-05-21T00:21:32.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/3440/copilot-cli/issues/3440"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:ac447a61-ac3d-b18b-7b81-b063a38cbc4d
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE024:1F55B6:1658B3C:20B36B7:6A4E4DB9
html-safe-nonce7e56c4fe4a95f873397c61d124a0f64eafb24507a77b22622e83650c53bd5af4
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMDI0OjFGNTVCNjoxNjU4QjNDOjIwQjM2Qjc6NkE0RTREQjkiLCJ2aXNpdG9yX2lkIjoiODI4MDk2NDI4NDQxNTg4ODgyNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac44be56e49644e7ca25355c97d0ba9d8e686e03916dd3d18bae755bc0fedb5d9c
hovercard-subject-tagissue:4490762633
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/github/copilot-cli/3440/issue_layout
twitter:imagehttps://opengraph.githubassets.com/38521dc4044601dbdc7806dfd8642b954c728cf516c26cec5032e979f21d1bcc/github/copilot-cli/issues/3440
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/38521dc4044601dbdc7806dfd8642b954c728cf516c26cec5032e979f21d1bcc/github/copilot-cli/issues/3440
og:image:altDescribe the bug When a CopilotSession is created with mcpServers containing one or more stdio entries, the Copilot CLI spawns a child process for each server. When session.disconnect() is called, ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameAlitzelMendez
hostnamegithub.com
expected-hostnamegithub.com
None030096ee0db095447bfe77409d33bfac127ca7128299c58deef27c52eaa1b1f0
turbo-cache-controlno-preview
go-importgithub.com/github/copilot-cli git https://github.com/github/copilot-cli.git
octolytics-dimension-user_id9919
octolytics-dimension-user_logingithub
octolytics-dimension-repository_id585860664
octolytics-dimension-repository_nwogithub/copilot-cli
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id585860664
octolytics-dimension-repository_network_root_nwogithub/copilot-cli
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasee8506f6d0538364886e3f0153c154c410965e70d
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/github/copilot-cli/issues/3440#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgithub%2Fcopilot-cli%2Fissues%2F3440
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgithub%2Fcopilot-cli%2Fissues%2F3440
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=github%2Fcopilot-cli
Reloadhttps://github.com/github/copilot-cli/issues/3440
Reloadhttps://github.com/github/copilot-cli/issues/3440
Reloadhttps://github.com/github/copilot-cli/issues/3440
Please reload this pagehttps://github.com/github/copilot-cli/issues/3440
github https://github.com/github
copilot-clihttps://github.com/github/copilot-cli
Notifications https://github.com/login?return_to=%2Fgithub%2Fcopilot-cli
Fork 1.7k https://github.com/login?return_to=%2Fgithub%2Fcopilot-cli
Star 10.9k https://github.com/login?return_to=%2Fgithub%2Fcopilot-cli
Code https://github.com/github/copilot-cli
Issues 1.8k https://github.com/github/copilot-cli/issues
Pull requests 27 https://github.com/github/copilot-cli/pulls
Discussions https://github.com/github/copilot-cli/discussions
Actions https://github.com/github/copilot-cli/actions
Projects https://github.com/github/copilot-cli/projects
Models https://github.com/github/copilot-cli/models
Security and quality 2 https://github.com/github/copilot-cli/security
Insights https://github.com/github/copilot-cli/pulse
Code https://github.com/github/copilot-cli
Issues https://github.com/github/copilot-cli/issues
Pull requests https://github.com/github/copilot-cli/pulls
Discussions https://github.com/github/copilot-cli/discussions
Actions https://github.com/github/copilot-cli/actions
Projects https://github.com/github/copilot-cli/projects
Models https://github.com/github/copilot-cli/models
Security and quality https://github.com/github/copilot-cli/security
Insights https://github.com/github/copilot-cli/pulse
Bughttps://github.com/github/copilot-cli/issues?q=type:"Bug"
session.disconnect() does not kill stdio MCP server processes spawned for that sessionhttps://github.com/github/copilot-cli/issues/3440#top
https://github.com/AlitzelMendez
AlitzelMendezhttps://github.com/AlitzelMendez
on May 21, 2026https://github.com/github/copilot-cli/issues/3440#issue-4490762633
Bughttps://github.com/github/copilot-cli/issues?q=type:"Bug"
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.