fix(mcp): reject unknown MCP tool inputs (#975)
* fix(mcp): reject unknown official tool inputs * fix(mcp): reject unknown native tool inputs * test(mcp): follow native contract module move * fix(mcp): reject unknown remaining tool inputs * fix(mcp): satisfy strict unknown and browser input schemas Remove obsolete approval fields from residual-unknown fixtures, project update inputs explicitly, and stop passing target_id to list-targets parsing. --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com>
This commit is contained in:
@@ -43,7 +43,6 @@ const input = (
|
||||
overrides: Partial<RecordUnknownInput> = {},
|
||||
): RecordUnknownInput =>
|
||||
recordUnknownInputSchema.parse({
|
||||
approved: true,
|
||||
question,
|
||||
severity: "high",
|
||||
domain: "protocol",
|
||||
@@ -60,7 +59,6 @@ const update = (
|
||||
overrides: Readonly<Record<string, unknown>> = {},
|
||||
) =>
|
||||
updateUnknownInputSchema.parse({
|
||||
approved: true,
|
||||
unknown_id: unknown.unknown_id,
|
||||
expected_revision: unknown.revision,
|
||||
status: "investigating",
|
||||
|
||||
@@ -129,7 +129,6 @@ describe("evidence ledger metadata imports", () => {
|
||||
});
|
||||
const created = ledger.recordUnknown(
|
||||
recordUnknownInputSchema.parse({
|
||||
approved: true,
|
||||
question: "Which path is current?",
|
||||
severity: "high",
|
||||
domain: "fixture",
|
||||
@@ -241,7 +240,6 @@ describe("evidence bundle imports", () => {
|
||||
result: { action: "record" },
|
||||
});
|
||||
const unknown = recordUnknownInputSchema.parse({
|
||||
approved: true,
|
||||
question: "What remains unresolved?",
|
||||
severity: "high",
|
||||
domain: "atomic-test",
|
||||
|
||||
@@ -101,9 +101,18 @@ describe("investigation record ownership", () => {
|
||||
);
|
||||
if (!created.ok) throw created.error;
|
||||
const input = updateUnknownInputSchema.parse({
|
||||
...created.value,
|
||||
unknown_id: created.value.unknown_id,
|
||||
expected_revision: created.value.revision,
|
||||
status: "investigating",
|
||||
severity: created.value.severity,
|
||||
supporting_evidence_ids: created.value.supporting_evidence_ids,
|
||||
contradicting_evidence_ids: created.value.contradicting_evidence_ids,
|
||||
required_authority: created.value.required_authority,
|
||||
required_confidence: created.value.required_confidence,
|
||||
required_environment: created.value.required_environment,
|
||||
recommended_probes: created.value.recommended_probes,
|
||||
relationships: created.value.relationships,
|
||||
resolution: created.value.resolution,
|
||||
});
|
||||
const updated = records.updateUnknown(input, target);
|
||||
expect(updated).toMatchObject({
|
||||
|
||||
@@ -7,7 +7,7 @@ import { requireOutputSchema } from "../toolOutputSchemaPrimitives.js";
|
||||
import { isAbsoluteLocalPath } from "../../domain/localPath.js";
|
||||
|
||||
/** Exact caller boundary for execution-free PE/CLI triage and identity. */
|
||||
const managedTargetInputSchema = z.object({
|
||||
const managedTargetInputSchema = z.strictObject({
|
||||
path: z
|
||||
.string()
|
||||
.min(1)
|
||||
|
||||
@@ -30,12 +30,13 @@ const native = <Name extends string, Schema extends z.ZodObject>(
|
||||
inputSchema: Schema,
|
||||
) => {
|
||||
const outputSchema = requireOutputSchema(nativeOutputSchemas, name);
|
||||
const strictInputSchema = inputSchema.strict();
|
||||
return {
|
||||
name,
|
||||
...toolContractMetadata(name),
|
||||
description,
|
||||
kind: "native-provider",
|
||||
inputSchema,
|
||||
inputSchema: strictInputSchema,
|
||||
outputSchema,
|
||||
examples: [
|
||||
{
|
||||
@@ -45,7 +46,7 @@ const native = <Name extends string, Schema extends z.ZodObject>(
|
||||
.parse(examples[name] ?? {}),
|
||||
},
|
||||
],
|
||||
} satisfies ToolContract<Name, Schema, typeof outputSchema>;
|
||||
} satisfies ToolContract<Name, typeof strictInputSchema, typeof outputSchema>;
|
||||
};
|
||||
|
||||
/** Ordered single-line symbols; `swift-demangle` ends each result with LF. */
|
||||
|
||||
@@ -24,16 +24,18 @@ const official = <Name extends string, Schema extends z.ZodObject>(
|
||||
name: Name,
|
||||
description: string,
|
||||
inputSchema: Schema,
|
||||
) =>
|
||||
({
|
||||
) => {
|
||||
const strictInputSchema = inputSchema.strict();
|
||||
return {
|
||||
name,
|
||||
...toolContractMetadata(name),
|
||||
description,
|
||||
kind: "official-proxy",
|
||||
inputSchema,
|
||||
inputSchema: strictInputSchema,
|
||||
outputSchema: requireOutputSchema(officialOutputSchemas, name),
|
||||
examples: examplesFor(name, inputSchema),
|
||||
}) satisfies ToolContract<Name, Schema>;
|
||||
examples: examplesFor(name, strictInputSchema),
|
||||
} satisfies ToolContract<Name, typeof strictInputSchema>;
|
||||
};
|
||||
|
||||
/** Bridge operations exposed without additional application composition. */
|
||||
export const OFFICIAL_TOOL_CONTRACTS = [
|
||||
|
||||
@@ -28,7 +28,7 @@ const binaryTargetPathSchema = z
|
||||
);
|
||||
|
||||
/** Input contract for opening a target with an optional staged snapshot. */
|
||||
export const openBinaryInputSchema = z.object({
|
||||
export const openBinaryInputSchema = z.strictObject({
|
||||
path: binaryTargetPathSchema,
|
||||
format: executableFormatHintSchema
|
||||
.optional()
|
||||
@@ -40,7 +40,7 @@ export const openBinaryInputSchema = z.object({
|
||||
});
|
||||
|
||||
/** Input contract for closing a target after an optional atomic snapshot. */
|
||||
export const closeBinaryInputSchema = z.object({
|
||||
export const closeBinaryInputSchema = z.strictObject({
|
||||
snapshot_path: snapshotPathSchema.optional(),
|
||||
overwrite: z.boolean().default(false),
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@ import { z } from "zod";
|
||||
import { isAbsoluteLocalPath } from "../domain/localPath.js";
|
||||
|
||||
/** Optional expectations used to compare the live session with its caller. */
|
||||
export const binarySessionInputSchema = z.object({
|
||||
export const binarySessionInputSchema = z.strictObject({
|
||||
expected_package_version: z.string().min(1).optional(),
|
||||
expected_catalog_digest: z
|
||||
.string()
|
||||
|
||||
@@ -94,7 +94,7 @@ const browserInput = {
|
||||
};
|
||||
|
||||
/** Public input for complete discovery, optionally filtered by exact origin. */
|
||||
export const listBrowserTargetsInputSchema = z.object({
|
||||
export const listBrowserTargetsInputSchema = z.strictObject({
|
||||
...browserInput,
|
||||
});
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ export const parseCallPathAddress = (input: unknown): string =>
|
||||
inputAddressSchema.parse(input);
|
||||
|
||||
/** Strict input for explicit call-path reconstruction from complete dossiers. */
|
||||
export const callPathInputSchema = z.object({
|
||||
export const callPathInputSchema = z.strictObject({
|
||||
functions: z.array(evidenceSchema).min(1),
|
||||
start: z.object({ address: inputAddressSchema }).strict(),
|
||||
goal: z.object({ address: inputAddressSchema }).strict(),
|
||||
|
||||
@@ -19,7 +19,7 @@ import { prefixedDigestSchema } from "./../domain/digests.js";
|
||||
const evidenceIdSchema = prefixedDigestSchema("ev");
|
||||
|
||||
/** Input for aggregating existing comparison Evidence. */
|
||||
export const changedBehaviorInputSchema = z.object({
|
||||
export const changedBehaviorInputSchema = z.strictObject({
|
||||
comparisons: z.array(evidenceSchema).default([]),
|
||||
});
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ const makeUnknown = (
|
||||
dependency?: string,
|
||||
) => {
|
||||
const input = recordUnknownInputSchema.parse({
|
||||
approved: true,
|
||||
question,
|
||||
severity: "medium",
|
||||
domain: "bundle-projection",
|
||||
@@ -95,7 +94,6 @@ describe("evidenceBundleForTarget", () => {
|
||||
const unknowns = [foreignRoot.unknown, middle.unknown];
|
||||
for (let index = 0; index < 125_000; index += 1) {
|
||||
const input = recordUnknownInputSchema.parse({
|
||||
approved: true,
|
||||
question: `Target child ${index}`,
|
||||
severity: "medium",
|
||||
domain: "bundle-projection",
|
||||
|
||||
@@ -167,12 +167,13 @@ export const recordUnknownInputSchema = residualUnknownObjectSchema
|
||||
.extend({
|
||||
supporting_evidence_ids: z.array(evidenceIdSchema).default([]),
|
||||
contradicting_evidence_ids: z.array(evidenceIdSchema).default([]),
|
||||
});
|
||||
})
|
||||
.strict();
|
||||
|
||||
export type RecordUnknownInput = z.infer<typeof recordUnknownInputSchema>;
|
||||
|
||||
/** Explicit optimistic-concurrency update command for one unknown. */
|
||||
export const updateUnknownInputSchema = z.object({
|
||||
export const updateUnknownInputSchema = z.strictObject({
|
||||
unknown_id: unknownIdSchema,
|
||||
expected_revision: z.number().int().min(1),
|
||||
status: residualUnknownObjectSchema.shape.status,
|
||||
|
||||
Reference in New Issue
Block a user