Skip to content

feat: MCP cache-stable canonicalization — deterministic tool order and schema key sorting | MCP 缓存稳定化#2189

Merged
esengine merged 1 commit into
esengine:mainfrom
SivanCola:pr/2-mcp-canonicalization
May 29, 2026
Merged

feat: MCP cache-stable canonicalization — deterministic tool order and schema key sorting | MCP 缓存稳定化#2189
esengine merged 1 commit into
esengine:mainfrom
SivanCola:pr/2-mcp-canonicalization

Conversation

@SivanCola

Copy link
Copy Markdown
Collaborator

Summary

Stabilizes MCP tool specs before registration so the DeepSeek prefix cache fingerprint is deterministic across sessions. Tools are sorted by final registered name; schema object keys are recursively stabilized; set-like arrays (required, dependentRequired) are sorted while ordered arrays (enum, oneOf, anyOf, allOf) preserve their original order. Enabled by default with no user-facing config switch.

概述

在注册前稳定化 MCP tool specs,使 DeepSeek 前缀缓存指纹在会话间保持确定性。按最终注册名排序工具;递归稳定化 schema 对象键;排序 set-like 数组(required, dependentRequired),保留有序数组(enum, oneOf, anyOf, allOf)的原始顺序。默认启用,无用户配置开关。

Key Files

  • src/mcp/registry.tscanonicalizeMcpToolForCache(), canonicalizeSchemaForCache()
  • tests/mcp-cache-canonicalization.test.ts (new) — unit tests

Depends On / 依赖

This PR is #2 in a 5-PR series:

Test Plan

  • Tool sorting by final registered name
  • Schema key stabilization with recursive objects
  • Set-like array sorting (required, dependentRequired)
  • Enum/oneOf/anyOf/allOf order preservation
  • dependentRequired inner array sorting

Verification

npm run lint      → 0 errors
npx vitest run tests/mcp-cache-canonicalization.test.ts → 4 passed

@SivanCola SivanCola changed the title feat: MCP cache-stable canonicalization — deterministic tool order and schema key sorting feat: MCP cache-stable canonicalization — deterministic tool order and schema key sorting | MCP 缓存稳定化 May 28, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f520f05495

ℹ️ 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".

Comment thread src/tools/filesystem.ts Outdated
@SivanCola

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6426b6823f

ℹ️ 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".

Comment thread src/cli/ui/edit-tool-gate.ts Outdated
@SivanCola

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6212f5e0ea

ℹ️ 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".

Comment thread src/cli/ssh-remote.ts Outdated
@esengine

Copy link
Copy Markdown
Owner

Part of the #2188#2192 stack that currently shows the same cumulative +1740/-39 diff on all five PRs (all based on main but stacked on each other). See my comment on #2188 for the fix — please split into independent single-feature branches off main so each PR contains only its own change. I'll review this one (and especially the file-deleting / RFC ones) properly once it's isolated.

@esengine esengine left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Reviewed — semantically safe and squarely aligned with the cache-first design. canonicalizeSchemaForCache recursively sorts object keys (insignificant in JSON) and sorts only set-like scalar arrays (required/dependentRequired, where order carries no meaning), while leaving order-significant arrays like enum untouched — and tools are sorted by registered name. So tool/schema content is preserved; only the serialization order is stabilized, which is exactly what makes the DeepSeek prefix-cache fingerprint deterministic across sessions. Good win for cache hit rate. CI green, test added. Merging.

@esengine esengine merged commit 55fbb33 into esengine:main May 29, 2026
4 checks passed
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.

2 participants