Repository navigation
feat(mcp): gate task tools with persisted ranked selections #2323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
335e78a
feat(mcp): gate task tools with persisted ranked selections
edelauna 42101ae
fix(mcp): preserve selections across concurrent history saves
edelauna 7a02469
fix(mcp): preserve restored selections and cancel condensation safely
edelauna 25a538a
fix(task): clear condensation indicator on cancellation
edelauna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # MCP dynamic tool loading | ||
|
|
||
| Issue #578 adds a task-scoped gate to API tool declarations. When the tools | ||
| allowed by the current mode and tool policy exceed `mcp.dynamicLoad.threshold` | ||
| (default 50), the task initially attaches up to `mcp.dynamicLoad.initialK` | ||
| (default 30) ranked tools. Images-only tasks use the first distinct scoped | ||
| tools because there is no initial text to rank. | ||
|
|
||
| The selection is stored in task history. Missing or invalid selections are | ||
| initialized on demand; a valid empty selection remains initialized. Restored | ||
| nonempty selections are checked against scoped definitions before use; selections | ||
| with no available names are ranked again. MCP names | ||
| already used in conversation history are retained for provider compatibility, | ||
| so resumed tasks can require more than `initialK` declarations. This is an | ||
| initial selection limit, not a lifetime cap. Historical names accumulate during | ||
| a task and are not trimmed, since removing their definitions can cause providers | ||
| to reject conversation history. Current server, mode, and tool-policy | ||
| restrictions still apply. | ||
|
|
||
| If saving fails, the task retains its in-memory selection and continues. Later | ||
| normal history saves retry persistence. History writes union attached names under | ||
| the disk lock, preserving newer historical names when an older save arrives late. | ||
| Storage errors do not trigger API | ||
| stream retries. | ||
|
|
||
| The gate limits advertised definitions; it does not add an execution permission | ||
| boundary. Existing tool authorization still applies to calls by name. | ||
|
|
||
| The settings schema and extension-state round trip are implemented. SettingsView | ||
| controls and replacement of the legacy catalog-wide warning are deferred to | ||
| #581. The legacy warning uses its own catalog advisory threshold; it does not | ||
| report the scoped tool count for a running task. The `mcp_load` escape hatch is | ||
| deferred to #579. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/core/task-persistence/__tests__/mcpAttachments.integration.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import * as fs from "fs/promises" | ||
| import * as os from "os" | ||
| import * as path from "path" | ||
| import { TaskHistoryStore } from "../TaskHistoryStore" | ||
| import { taskMetadata } from "../taskMetadata" | ||
|
|
||
| describe("MCP attachment history round trip", () => { | ||
| it.each([false, true])( | ||
| "retains historical names after a delayed stale save (separate store: %s)", | ||
| async (separateStore) => { | ||
| const directory = await fs.mkdtemp(path.join(os.tmpdir(), "mcp-attachments-race-")) | ||
| const store = new TaskHistoryStore(directory) | ||
| const peer = new TaskHistoryStore(directory) | ||
| const restored = new TaskHistoryStore(directory) | ||
| try { | ||
| const { historyItem } = await taskMetadata({ | ||
| taskId: "attachment-task", | ||
| taskNumber: 1, | ||
| messages: [], | ||
| workspace: directory, | ||
| globalStoragePath: directory, | ||
| attachedMcpToolNames: ["mcp--catalog--initial"], | ||
| }) | ||
| await store.initialize() | ||
| await store.upsert(historyItem) | ||
| await peer.initialize() | ||
| let release = () => {} | ||
| const gate = new Promise<void>((resolve) => { | ||
| release = resolve | ||
| }) | ||
| const olderSave = gate.then(() => | ||
| (separateStore ? peer : store).upsert({ | ||
| ...historyItem, | ||
| attachedMcpToolNames: separateStore ? [] : historyItem.attachedMcpToolNames, | ||
| }), | ||
| ) | ||
| await store.upsert({ | ||
| ...historyItem, | ||
| attachedMcpToolNames: ["mcp--catalog--initial", "mcp--catalog--historical"], | ||
| }) | ||
| release() | ||
| await olderSave | ||
| await restored.initialize() | ||
| expect(restored.get(historyItem.id)?.attachedMcpToolNames).toEqual([ | ||
| "mcp--catalog--initial", | ||
| "mcp--catalog--historical", | ||
| ]) | ||
| } finally { | ||
| store.dispose() | ||
| peer.dispose() | ||
| restored.dispose() | ||
| await fs.rm(directory, { recursive: true, force: true }) | ||
| } | ||
| }, | ||
| ) | ||
|
|
||
| it.each([{ names: undefined }, { names: [] }, { names: ["mcp--github--issues"] }])( | ||
| "preserves $names across a store restart", | ||
| async ({ names }) => { | ||
| const directory = await fs.mkdtemp(path.join(os.tmpdir(), "mcp-attachments-")) | ||
| const store = new TaskHistoryStore(directory) | ||
| const restored = new TaskHistoryStore(directory) | ||
| try { | ||
| const { historyItem } = await taskMetadata({ | ||
| taskId: "attachment-task", | ||
| taskNumber: 1, | ||
| messages: [], | ||
| workspace: directory, | ||
| globalStoragePath: directory, | ||
| attachedMcpToolNames: names, | ||
| }) | ||
| await store.initialize() | ||
| await store.upsert(historyItem) | ||
| store.dispose() | ||
| await restored.initialize() | ||
| expect(restored.get(historyItem.id)?.attachedMcpToolNames).toEqual(names) | ||
| } finally { | ||
| store.dispose() | ||
| restored.dispose() | ||
| await fs.rm(directory, { recursive: true, force: true }) | ||
| } | ||
| }, | ||
| ) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this lookup use the enabled, project-priority, mode-scoped, deduplicated catalog that advertised the tool?