eslint-plugin-webmcp 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +151 -0
- package/dist/index.d.mts +44 -0
- package/dist/index.mjs +1251 -0
- package/package.json +89 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-PRESENT ntnyq <https://github.com/ntnyq>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# eslint-plugin-webmcp
|
|
2
|
+
|
|
3
|
+
[](https://github.com/ntnyq/eslint-plugin-webmcp/actions)
|
|
4
|
+
[](https://www.npmjs.com/package/eslint-plugin-webmcp)
|
|
5
|
+
[](https://github.com/ntnyq/eslint-plugin-webmcp/blob/main/LICENSE)
|
|
6
|
+
|
|
7
|
+
Conservative ESLint rules for browser WebMCP tool definitions and consumers. Includes **24 rules**, `recommended` and `strict` Flat Config presets, and two fixed API targets.
|
|
8
|
+
|
|
9
|
+
Requires ESLint 9 or 10 and Node.js `^22.13.0 || >=24.0.0`. ESM only. This initial implementation covers imperative JavaScript and TypeScript; it does not lint HTML or Vue templates.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
pnpm add -D eslint eslint-plugin-webmcp
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
For an unpublished checkout, run `pnpm install && pnpm build && pnpm pack` and install the generated tarball in the consuming project.
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
// eslint.config.mjs
|
|
23
|
+
import webmcp from 'eslint-plugin-webmcp'
|
|
24
|
+
|
|
25
|
+
export default [webmcp.configs.recommended]
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The presets select JS/TS file extensions and never replace your parser or enable type services. Supply a parser when linting TypeScript:
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
import parser from '@typescript-eslint/parser'
|
|
32
|
+
import webmcp from 'eslint-plugin-webmcp'
|
|
33
|
+
|
|
34
|
+
export default [
|
|
35
|
+
webmcp.configs.recommended,
|
|
36
|
+
{
|
|
37
|
+
files: ['**/*.{ts,mts,cts,tsx}'],
|
|
38
|
+
languageOptions: {
|
|
39
|
+
parser,
|
|
40
|
+
parserOptions: { ecmaFeatures: { jsx: true } },
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
]
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Install `@typescript-eslint/parser` separately. This checkout tests typescript-eslint 8.69 with TypeScript 6.0; follow your parser's supported TypeScript range.
|
|
47
|
+
|
|
48
|
+
## Fixed API targets
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
import { createConfig } from 'eslint-plugin-webmcp'
|
|
52
|
+
|
|
53
|
+
export default [
|
|
54
|
+
createConfig({
|
|
55
|
+
target: 'chrome-2026-09-01',
|
|
56
|
+
preset: 'strict',
|
|
57
|
+
files: ['src/**/*.{js,ts,tsx}'],
|
|
58
|
+
}),
|
|
59
|
+
]
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
| Target | Entry point | `executeTool` input |
|
|
63
|
+
| ---------------------------- | ----------------------- | --------------------------------- |
|
|
64
|
+
| `draft-2026-09-04` (default) | `document.modelContext` | Optional object, defaults to `{}` |
|
|
65
|
+
| `chrome-2026-09-01` | `document.modelContext` | Required JSON text |
|
|
66
|
+
|
|
67
|
+
Both snapshots use Promise-based registration, `options.signal` for unregistration and the `toolchange` event. The Chrome profile is backed by dated documentation and a fixed Chromium development commit; it does not claim that every Chrome release implements that snapshot. See [sources and snapshot details](docs/targets.md).
|
|
68
|
+
|
|
69
|
+
Manual configurations can set `settings: { webmcp: { target: 'draft-2026-09-04' } }`. Unknown targets, presets, invalid file lists and malformed wrapper settings produce configuration errors. There is no floating `latest` or partially supported legacy target.
|
|
70
|
+
|
|
71
|
+
## Rules and presets
|
|
72
|
+
|
|
73
|
+
`recommended` enables provable API errors and the empty-description warning. `strict` includes recommended and additional metadata, option, origin and description warnings. Team-specific naming, titles, length budgets and explicit hint requirements remain opt-in.
|
|
74
|
+
|
|
75
|
+
See the [complete rule table](docs/rules.md) for all 24 rules, defaults, examples and options. No rule automatically changes names, descriptions, callbacks, origins or registration lifetimes.
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
import webmcp from 'eslint-plugin-webmcp'
|
|
79
|
+
|
|
80
|
+
export default [
|
|
81
|
+
webmcp.configs.strict,
|
|
82
|
+
{
|
|
83
|
+
rules: {
|
|
84
|
+
'webmcp/valid-input-schema': [
|
|
85
|
+
'error',
|
|
86
|
+
{ mode: 'json-schema', dialect: '2020-12' },
|
|
87
|
+
],
|
|
88
|
+
'webmcp/tool-name-convention': [
|
|
89
|
+
'warn',
|
|
90
|
+
{
|
|
91
|
+
style: 'dot-separated',
|
|
92
|
+
segmentStyle: 'kebab-case',
|
|
93
|
+
prefix: 'catalog.',
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
'webmcp/require-explicit-annotations': [
|
|
97
|
+
'warn',
|
|
98
|
+
{ fields: ['readOnlyHint', 'consequentialHint'] },
|
|
99
|
+
],
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
]
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
By default, `valid-input-schema` checks only known platform boundary failures. Its opt-in JSON Schema mode validates the JSON representation against the 2020-12 meta-schema. It does not enforce object roots, closed properties or parameter descriptions, validate tool inputs at runtime, resolve remote references, or execute user code. Other explicitly declared dialects are skipped.
|
|
106
|
+
|
|
107
|
+
## Tool-definition wrappers
|
|
108
|
+
|
|
109
|
+
Recognize a project factory through its import binding, including renamed imports:
|
|
110
|
+
|
|
111
|
+
```js
|
|
112
|
+
export default [
|
|
113
|
+
webmcp.configs.recommended,
|
|
114
|
+
{
|
|
115
|
+
settings: {
|
|
116
|
+
webmcp: {
|
|
117
|
+
wrappers: [
|
|
118
|
+
{
|
|
119
|
+
module: '@app/webmcp',
|
|
120
|
+
imported: 'defineWebMcpTool',
|
|
121
|
+
toolArgument: 0,
|
|
122
|
+
kind: 'definition',
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
]
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Only named imports are recognized. Definition factories do not imply registration, cancellation or Promise semantics. Modules are never loaded by the analyzer.
|
|
132
|
+
|
|
133
|
+
## Analysis boundaries
|
|
134
|
+
|
|
135
|
+
Direct `document`, `window.document` and `globalThis.document` receivers, static computed keys, optional chaining, TypeScript wrappers, and limited const aliases are supported. Local bindings that shadow platform globals are excluded. Unknown spreads and computed keys invalidate preceding fields; later explicit fields remain analyzable. Getters, setters and `__proto__` providers cause the object to be skipped.
|
|
136
|
+
|
|
137
|
+
Object aliases must have a single read in the same execution scope and no writes, exports or escapes. Shared definitions and cross-function objects are intentionally skipped. This favors useful, predictable diagnostics over speculative data flow. See [analysis details](docs/analysis.md) and the [remaining design roadmap](docs/roadmap.md).
|
|
138
|
+
|
|
139
|
+
## Development
|
|
140
|
+
|
|
141
|
+
```sh
|
|
142
|
+
pnpm install --frozen-lockfile
|
|
143
|
+
pnpm release:check
|
|
144
|
+
pnpm pack --dry-run
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
`release:check` runs formatting, lint, type checks, RuleTester/integration tests, the declaration build and a JS/TS smoke test imported through the package export. It does not publish the package.
|
|
148
|
+
|
|
149
|
+
## License
|
|
150
|
+
|
|
151
|
+
[MIT](./LICENSE) License © 2026-PRESENT [ntnyq](https://github.com/ntnyq)
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ESLint, Linter } from "eslint";
|
|
2
|
+
//#region src/types.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Fixed upstream snapshots; the target is never inferred from the environment.
|
|
5
|
+
*/
|
|
6
|
+
type WebMcpTarget = 'draft-2026-09-04' | 'chrome-2026-09-01';
|
|
7
|
+
type WebMcpPreset = 'recommended' | 'strict';
|
|
8
|
+
interface WebMcpConfigOptions {
|
|
9
|
+
target?: WebMcpTarget;
|
|
10
|
+
preset?: WebMcpPreset;
|
|
11
|
+
files?: string[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* An explicitly trusted tool-definition factory, identified by its import binding.
|
|
15
|
+
*/
|
|
16
|
+
interface WebMcpWrapper {
|
|
17
|
+
module: string;
|
|
18
|
+
imported: string;
|
|
19
|
+
toolArgument: number;
|
|
20
|
+
kind: 'definition';
|
|
21
|
+
}
|
|
22
|
+
interface WebMcpSettings {
|
|
23
|
+
target?: WebMcpTarget;
|
|
24
|
+
wrappers?: WebMcpWrapper[];
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/index.d.ts
|
|
28
|
+
/**
|
|
29
|
+
* Native ESLint types keep consumer configs compatible with ESLint 9 and 10.
|
|
30
|
+
*/
|
|
31
|
+
export interface WebMcpPlugin extends ESLint.Plugin {
|
|
32
|
+
rules: NonNullable<ESLint.Plugin['rules']>;
|
|
33
|
+
configs: Record<WebMcpPreset, Linter.Config>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Create a parser-independent Flat Config for a fixed WebMCP API snapshot.
|
|
37
|
+
*
|
|
38
|
+
* @param options Target, preset and optional file globs
|
|
39
|
+
* @returns A standalone Flat Config referencing this plugin
|
|
40
|
+
*/
|
|
41
|
+
export declare function createConfig(options?: WebMcpConfigOptions): Linter.Config;
|
|
42
|
+
declare const webmcp: WebMcpPlugin;
|
|
43
|
+
//#endregion
|
|
44
|
+
export { type WebMcpConfigOptions, type WebMcpPreset, type WebMcpSettings, type WebMcpTarget, type WebMcpWrapper, webmcp as default };
|