Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b759414
fix(mcp): sanitize MCP JSON schemas for Moonshot MFJS validator and m…
Sep 7, 2026
c285628
Merge branch 'main' into fix/mcp-schema-limits
creatiVision Sep 8, 2026
57754ea
Merge branch 'main' into fix/mcp-schema-limits
creatiVision Sep 9, 2026
c561f26
Merge branch 'main' into fix/mcp-schema-limits
creatiVision Sep 12, 2026
8b01448
fix(agent-core-v2): normalize coexisting union types and preserve boo…
creatiVision Sep 12, 2026
ae291f4
Merge branch 'main' into fix/mcp-schema-limits
creatiVision Sep 15, 2026
2006db8
Merge branch 'main' into fix/mcp-schema-limits
creatiVision Sep 21, 2026
e79be78
Merge branch 'main' into fix/mcp-schema-limits
creatiVision Sep 22, 2026
31066ad
Merge branch 'main' into fix/mcp-schema-limits
creatiVision Sep 24, 2026
7ac49de
Merge remote-tracking branch 'origin/main' into fix/mcp-schema-limits
creatiVision Sep 29, 2026
7228e16
revert: remove accidental edits to compactionHandoff and runner.test
creatiVision Sep 29, 2026
3374898
Merge branch 'main' into fix/mcp-schema-limits
creatiVision Sep 29, 2026
a24e2b6
fix(agent-core-v2): sanitize boolean items, prefixItems, and non-obje…
creatiVision Sep 29, 2026
177cd93
Merge branch 'main' into fix/mcp-schema-limits
creatiVision Oct 11, 2026
ea6d861
fix(agent-core/mcp): address review on items, combinators, ref siblin…
creatiVision Oct 11, 2026
552724e
fix(agent-core/mcp): clamp maxItems, preserve boolean combinators, re…
creatiVision Oct 11, 2026
3c2bfa4
fix(agent-core/mcp): conjoin ref sibling bounds and retain prefixItem…
creatiVision Oct 11, 2026
9bca8dc
fix(agent-core/mcp): address review on ref activity, enum equality, d…
creatiVision Oct 11, 2026
d1b440d
Merge branch 'main' into fix/mcp-schema-limits
creatiVision Oct 18, 2026
c61021c
Merge branch 'main' into fix/mcp-schema-limits
creatiVision Oct 24, 2026
8a522bc
Merge remote-tracking branch 'origin/main' into fix/mcp-schema-limits
creatiVision Oct 25, 2026
dada019
fix(agent-core/mcp): conjoin closed ref siblings, retain recursive co…
creatiVision Oct 25, 2026
5a4d9f3
fix(agent-core/mcp): preserve empty contradictory enums, replace nest…
creatiVision Oct 25, 2026
ffbebea
Merge origin/main into fix/mcp-schema-limits
creatiVision Oct 31, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/mfjs-schema-sanitize.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@moonshot-ai/agent-core-v2": patch
"@moonshot-ai/kimi-code": patch
---

Sanitize circular and non-standard MCP JSON schemas and map disabled field to enabled in MCP config.
2 changes: 1 addition & 1 deletion packages/agent-core-v2/src/human/eventStore/journal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async function* readBranchChain(branch: Branch, tree: Tree): AsyncIterable<Journ
: undefined;
upto = parentSeq ?? null;
}
for (const segment of chain.reverse()) {
for (const segment of chain.toReversed()) {
for (const entry of segment.entries) {
yield {
branch: segment.name,
Expand Down
4 changes: 2 additions & 2 deletions packages/agent-core-v2/src/human/llm-requester/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const MAX_DELAY_MS = 32_000;
const RETRY_FACTOR = 2;
const JITTER_FACTOR = 0.25;

const RETRYABLE_STATUS_CODES: readonly number[] = [408, 409, 429, 500, 502, 503, 504, 529];
const RETRYABLE_STATUS_CODES: readonly number[] = new Set([408, 409, 429, 500, 502, 503, 504, 529]);

export interface LlmRetryOptions {
readonly maxAttemptsPerStep?: number;
Expand Down Expand Up @@ -50,7 +50,7 @@ export function isRetryableError(error: LlmErrorMessage): boolean {
case 'empty_response':
return error.finishReason !== 'filtered';
case 'status':
return RETRYABLE_STATUS_CODES.includes(error.statusCode);
return RETRYABLE_STATUS_CODES.has(error.statusCode);
default:
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/agent-core-v2/src/human/llm/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ export function createMessageAccumulator(): MessageAccumulator {
return undefined;
}
flush();
return message.toolCalls[message.toolCalls.length - 1];
return message.toolCalls.at(-1);
},
finish(): AssistantMessage {
flush();
Expand Down
4 changes: 2 additions & 2 deletions packages/agent-core-v2/src/human/persist/v2/fold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ function truncateTextToTokensFromEnd(text: string, maxTokens: number): string {
let start = text.length;
for (let i = text.length - 1; i >= 0; i--) {
let isAscii = false;
const code = text.charCodeAt(i);
const code = text.codePointAt(i);
if (code >= 0xdc00 && code <= 0xdfff && i > 0) {
const high = text.charCodeAt(i - 1);
const high = text.codePointAt(i - 1);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Detect surrogate pairs by code unit when truncating

When compaction retains a suffix beginning at a non-BMP character, the reverse scan first lands on its low surrogate, but codePointAt(i - 1) returns the combined code point rather than the high-surrogate code unit. The pair is therefore counted twice and, with a one-token budget, an input such as 😀 is returned as the lone surrogate \ude00, silently corrupting the folded context; use code-unit access for this pair check or iterate code points backward.

AGENTS.md reference: AGENTS.md:L133-L133

Useful? React with 👍 / 👎.

if (high >= 0xd800 && high <= 0xdbff) {
i--;
}
Expand Down
5 changes: 4 additions & 1 deletion packages/agent-core-v2/src/mcpCore/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ const McpServerConfigDiscriminatedSchema = z.discriminatedUnion('transport', [

export const McpServerConfigSchema = z.preprocess((raw) => {
if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) return raw;
const obj = raw as Record<string, unknown>;
const obj = { ...(raw as Record<string, unknown>) };
if ('disabled' in obj && !('enabled' in obj) && typeof obj['disabled'] === 'boolean') {
obj['enabled'] = !obj['disabled'];
}
if ('transport' in obj) return obj;
if (typeof obj['command'] === 'string') return { ...obj, transport: 'stdio' };
if (typeof obj['url'] === 'string') return { ...obj, transport: 'http' };
Expand Down
3 changes: 2 additions & 1 deletion packages/agent-core-v2/src/mcpCore/connection-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from './client-shared';
import { StdioMcpClient } from './client-stdio';
import type { McpOAuthService } from '#/mcpCore/oauth/service';
import { sanitizeMcpSchema } from './schema-sanitize';
import { assertMcpInputSchema, type MCPClient, type MCPToolDefinition } from './types';

export type McpServerStatus = 'pending' | 'connected' | 'failed' | 'disabled' | 'needs-auth' | 'removed';
Expand Down Expand Up @@ -869,7 +870,7 @@ export class McpConnectionManager implements McpConnectionView {
tools: mcpTools.map((mcpTool) => ({
name: mcpTool.name,
description: mcpTool.description,
parameters: assertMcpInputSchema(mcpTool.name, mcpTool.inputSchema),
parameters: sanitizeMcpSchema(assertMcpInputSchema(mcpTool.name, mcpTool.inputSchema)),
})),
};
} catch (error) {
Expand Down
Loading