Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(mcp): render exec info/schema with input-mode json schema (#70263)

posthog[bot]5576c9e40355
diff --git a/services/mcp/src/tools/exec.ts b/services/mcp/src/tools/exec.ts
index 3948169e068d..be5a24f72eff 100644
--- a/services/mcp/src/tools/exec.ts
+++ b/services/mcp/src/tools/exec.ts
@@ -334,7 +334,13 @@ export function createExecTool(
throw new Error('Usage: info [--json] <tool_name>')
}
const tool = findTool(allTools, infoArgs)
- const fullSchema = stripOutputFormatProperty(z.toJSONSchema(tool.schema) as Record<string, unknown>)
+ // `io: 'input'` mirrors the advertised `tools/list` schema and the executor's
+ // validation: fields with a Zod `.default()` (e.g. a query `kind` discriminator)
+ // are optional and auto-filled. The default `io: 'output'` would list them as
+ // required, misrepresenting them as mandatory input the caller must supply.
+ const fullSchema = stripOutputFormatProperty(
+ z.toJSONSchema(tool.schema, { io: 'input' }) as Record<string, unknown>
+ )
// YAML for the top shape, but inputSchema stays as a JSON
// string dumped inside the YAML — JSON Schema is conventionally
// JSON and converting it to YAML obscures `$ref`, `oneOf`, etc.
@@ -371,8 +377,10 @@ export function createExecTool(
}
const { verb: schemaToolName, rest: fieldPath } = parseCommand(rest)
const schemaTool = findTool(allTools, schemaToolName)
+ // See the `info` command: `io: 'input'` keeps this in sync with the advertised
+ // schema and validation, so `.default()` fields aren't shown as required.
const fullJsonSchema = stripOutputFormatProperty(
- z.toJSONSchema(schemaTool.schema) as Record<string, unknown>
+ z.toJSONSchema(schemaTool.schema, { io: 'input' }) as Record<string, unknown>
)
if (!fieldPath) {
diff --git a/services/mcp/tests/unit/exec.test.ts b/services/mcp/tests/unit/exec.test.ts
index cf0be5aa3652..1f04b65ec05a 100644
--- a/services/mcp/tests/unit/exec.test.ts
+++ b/services/mcp/tests/unit/exec.test.ts
@@ -625,6 +625,24 @@ describe('exec tool', () => {
expect(parsedSchema.properties.name.hint).toBeUndefined()
})
+ it('does not mark a defaulted discriminator field as required', async () => {
+ // Query wrappers carry a `kind` literal with a `.default()` (e.g. `TracesQuery`)
+ // that the executor auto-fills, so callers never supply it. Rendering the schema
+ // with `io: 'output'` used to list it in `required`, misrepresenting it as
+ // mandatory input and pushing agents to send an "undocumented" discriminator.
+ const tool = makeMockTool({
+ schema: z.object({
+ kind: z.literal('TracesQuery').default('TracesQuery'),
+ limit: z.number().default(100).optional(),
+ }),
+ })
+ const exec = createExec([tool])
+ const result = (await exec.handler(mockContext, { command: 'info --json mock-tool' })) as string
+ const parsed = JSON.parse(result)
+ expect(parsed.inputSchema.properties.kind.const).toBe('TracesQuery')
+ expect(parsed.inputSchema.required ?? []).not.toContain('kind')
+ })
+
it('throws usage error for bare info', async () => {
const exec = createExec()
await expect(exec.handler(mockContext, { command: 'info' })).rejects.toThrow(