Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 1 addition & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,5 @@ export const scenario: TestScenario = {

## Restrictions on JSON schema

- no .nullable(), no .object() types.
- no .nullable(), no .object() types. Enforced by the `@local/enforce-zod-schema` ESLint rule.
- represent complex object as a short formatted string.

TODO: implement eslint for schema https://github.com/ChromeDevTools/chrome-devtools-mcp/issues/1076
7 changes: 7 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ export default defineConfig([
],
},
},
{
name: 'Tools definitions',
files: ['src/tools/**/*.ts'],
rules: {
'@local/enforce-zod-schema': 'error',
},
},
{
name: 'Tests',
files: ['**/*.test.ts'],
Expand Down
62 changes: 62 additions & 0 deletions scripts/eslint_rules/enforce-zod-schema-rule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

export default {
name: 'enforce-zod-schema',
meta: {
type: 'problem',
docs: {
description:
'Disallow .nullable() and .object() in tool schemas. Use optional strings to represent complex objects.',
},
schema: [],
messages: {
noNullable:
'Do not use .nullable() in tool schemas. Use .optional() instead.',
noObject:
'Do not use .object() in tool schemas. Represent complex objects as a short formatted string.',
},
},
defaultOptions: [],
create(context) {
return {
CallExpression(node) {
if (
node.callee.type !== 'MemberExpression' ||
node.callee.property.type !== 'Identifier'
) {
return;
}

const methodName = node.callee.property.name;

// We don't validate that .nullable() is called on a ZodObject
// specifically - this intentionally catches all .nullable() calls
// in tool schema files.
if (methodName === 'nullable') {
context.report({
Comment thread
OrKoN marked this conversation as resolved.
node: node.callee.property,
messageId: 'noNullable',
});
}

if (methodName === 'object') {
// Only flag zod.object() calls, not arbitrary .object() calls.
const obj = node.callee.object;
if (
obj.type === 'Identifier' &&
(obj.name === 'zod' || obj.name === 'z')
) {
context.report({
node: node.callee.property,
messageId: 'noObject',
});
}
}
},
};
},
};
8 changes: 7 additions & 1 deletion scripts/eslint_rules/local-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@
*/

import checkLicenseRule from './check-license-rule.js';
import enforceZodSchemaRule from './enforce-zod-schema-rule.js';

export default {rules: {'check-license': checkLicenseRule}};
export default {
rules: {
'check-license': checkLicenseRule,
'enforce-zod-schema': enforceZodSchemaRule,
},
};
1 change: 1 addition & 0 deletions src/tools/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ export const fillForm = definePageTool({
schema: {
elements: zod
.array(
// eslint-disable-next-line @local/enforce-zod-schema
zod.object({
uid: zod.string().describe('The uid of the element to fill out'),
value: zod.string().describe('Value for the element'),
Expand Down