Skip to content

🍒 fix: Restrict MCP Server Selections to Schedule Grants - #18420

Merged
danny-avila merged 1 commit into
devfrom
danny-avila/grant-narrow-wildcards
Nov 18, 2026
Merged

danny-avila merged 1 commit into
devfrom
danny-avila/grant-narrow-wildcards

Conversation

@danny-avila

Copy link
Copy Markdown
Collaborator

Summary

Under a schedule's grant, a run is meant to load only the MCP tools the owner allowed (#18260). The filter that does this looked only at keys naming one tool. An agent's tool list can also carry a key that stands for every tool on a server (sys__all__sys_mcp_<server>) or for the server alone (sys__server__sys_mcp_<server>), and those were loaded as they were.

Enrollment already refuses to offer a grant for an agent that holds such a key, and the readiness check refuses an enrolled run that reaches one, so this needs an agent edited after the grant was made and a load that is not preceded by that check. In that case the calls were still refused by the run policy and at call time, but the tools the owner left out were defined for the model and the server was connected to.

A key for every tool on a server is no longer loaded under a grant: the grant lists tools by name, and "every tool" names none of them. A key for the server alone is kept only where the grant lists at least one tool on that server for the agent. A run with no grant loads its tools as before.

The complete accessible-server list passed to tool loading (accessibleMcpServerNames) is left as it is. It is the set of names the loader checks for alias collisions between servers, not a list of servers to connect to, and narrowing it would weaken that check.

Related to #18260, #13824.

How it works

 const isGrantedKey = (agentId: string, toolKey: string): boolean => {
   const [selectionName, spelling] = splitMCPToolKey(toolKey, serverSpellings);
   const serverName = /* the granted server this spelling names, if any */;
-  return serverName != null && granted.get(serverName)?.get(agentId)?.has(selectionName) === true;
+  const tools = serverName == null ? undefined : granted.get(serverName)?.get(agentId);
+  if (!tools || selectionName === Constants.mcp_all) return false;
+  return selectionName === Constants.mcp_server ? tools.size > 0 : tools.has(selectionName);
 };
 …
-toolKeys.filter((key) => !isMCPToolSelection(key) || isGrantedKey(agentId, key))
+toolKeys.filter((key) => !key.includes(Constants.mcp_delimiter) || isGrantedKey(agentId, key))

Type of change

  • Bug fix

Testing

Tested environments/configuration: WSL2, Node.js 24. No external services.

Automated tests: packages/api/src/schedules/authorization/execution.spec.ts › "loads no key that stands for a whole server unless the grant lists a tool on it": for the granted agent the all-tools keys are dropped and the server key is kept only for the granted server; an agent the grant does not list keeps no MCP key. Letting the sys__ keys through again makes it fail.

npx tsc --noEmit is clean in packages/api; the src/schedules and agent initializer suites pass (25 suites).

Risk / compatibility

Only runs under a schedule's grant are affected, and schedule consent is off by default (interface.schedules.mcpConsent.enabled). No stored data or configuration changes.

Under a grant, a run loads only the MCP tools the owner allowed. The filter looked only
at keys naming one tool, so a key standing for every tool on a server, or for the server
alone, was loaded as it was. The run policy and the call-time check still refused the
calls, but the tools were defined for the model and the server was connected to.

A key for every tool on a server is no longer loaded under a grant, since the grant lists
tools by name. A key for the server alone is kept only where the grant lists a tool on
that server for the agent.
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review the latest head, final review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T16:51:12.126908Z c7442a5 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: c7442a578c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danny-avila
danny-avila marked this pull request as ready for review November 18, 2026 16:56
@lia-by-librechat lia-by-librechat Bot changed the title 🧹 fix: Narrow Whole-Server MCP Keys Under a Schedule's Grant 🍒 fix: Restrict MCP Server Selections to Schedule Grants Nov 18, 2026
@danny-avila
danny-avila merged commit d3bd91f into dev Nov 18, 2026
58 of 59 checks passed
@danny-avila
danny-avila deleted the danny-avila/grant-narrow-wildcards branch November 18, 2026 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant