豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit b204ad7

Browse files
authored
build: update verify server.json (#759)
move download to the script, run script without deleting server.json
1 parent 8f3fcf6 commit b204ad7

File tree

8 files changed

+116
-44
lines changed

8 files changed

+116
-44
lines changed

.github/workflows/pre-release.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Pre-release
33
permissions: read-all
44

55
on:
6+
workflow_dispatch:
67
push:
78
branches:
89
- release-please-*
@@ -23,10 +24,5 @@ jobs:
2324
cache: npm
2425
node-version-file: '.nvmrc'
2526

26-
- name: Install MCP Publisher
27-
run: |
28-
export OS=$(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')
29-
curl -L "https://github.com/modelcontextprotocol/registry/releases/latest/download/mcp-publisher_${OS}.tar.gz" | tar xz mcp-publisher
30-
3127
- name: Verify server.json
3228
run: npm run verify-server-json-version

GEMINI.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Instructions
22

3-
- use `npm run build` to run tsc and test build
4-
- use `npm run test` to run tests, run all tests to verify correctness
3+
- use `npm run build` to run tsc and test build.
4+
- use `npm run test` to run tests, run all tests to verify correctness.
5+
- use only scripts from `package.json` to run commands.

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export default defineConfig([
6060
name: 'TypeScript rules',
6161
rules: {
6262
'@local/check-license': 'error',
63+
curly: ['error', 'all'],
6364

6465
'no-undef': 'off',
6566
'no-unused-vars': 'off',

scripts/generate-docs.ts

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,23 @@ function getZodTypeInfo(schema: ZodSchema): TypeInfo {
213213
defaultValue = def.defaultValue();
214214
}
215215
const next = def.innerType || def.schema;
216-
if (!next) break;
216+
if (!next) {
217+
break;
218+
}
217219
schema = next;
218220
def = schema._def;
219-
if (!description && schema.description) description = schema.description;
221+
if (!description && schema.description) {
222+
description = schema.description;
223+
}
220224
}
221225

222226
const result: TypeInfo = {type: 'unknown'};
223-
if (description) result.description = description;
224-
if (defaultValue !== undefined) result.default = defaultValue;
227+
if (description) {
228+
result.description = description;
229+
}
230+
if (defaultValue !== undefined) {
231+
result.default = defaultValue;
232+
}
225233

226234
switch (def.typeName) {
227235
case 'ZodString':
@@ -254,7 +262,9 @@ function getZodTypeInfo(schema: ZodSchema): TypeInfo {
254262
function isRequired(schema: ZodSchema): boolean {
255263
let def = schema._def;
256264
while (def.typeName === 'ZodEffects') {
257-
if (!def.schema) break;
265+
if (!def.schema) {
266+
break;
267+
}
258268
schema = def.schema;
259269
def = schema._def;
260270
}
@@ -325,9 +335,15 @@ async function generateToolDocumentation(): Promise<void> {
325335
const aIndex = categoryOrder.indexOf(a);
326336
const bIndex = categoryOrder.indexOf(b);
327337
// Put known categories first, unknown categories last
328-
if (aIndex === -1 && bIndex === -1) return a.localeCompare(b);
329-
if (aIndex === -1) return 1;
330-
if (bIndex === -1) return -1;
338+
if (aIndex === -1 && bIndex === -1) {
339+
return a.localeCompare(b);
340+
}
341+
if (aIndex === -1) {
342+
return 1;
343+
}
344+
if (bIndex === -1) {
345+
return -1;
346+
}
331347
return aIndex - bIndex;
332348
});
333349

@@ -386,8 +402,12 @@ async function generateToolDocumentation(): Promise<void> {
386402
const propertyNames = Object.keys(properties).sort((a, b) => {
387403
const aRequired = required.includes(a);
388404
const bRequired = required.includes(b);
389-
if (aRequired && !bRequired) return -1;
390-
if (!aRequired && bRequired) return 1;
405+
if (aRequired && !bRequired) {
406+
return -1;
407+
}
408+
if (!aRequired && bRequired) {
409+
return 1;
410+
}
391411
return a.localeCompare(b);
392412
});
393413
for (const propName of propertyNames) {

scripts/verify-server-json-version.ts

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,72 @@
66

77
import {execSync} from 'node:child_process';
88
import fs from 'node:fs';
9+
import os from 'node:os';
10+
import path from 'node:path';
911

10-
const serverJsonFilePath = './server.json';
12+
const serverJsonFilePath = path.join(process.cwd(), 'server.json');
1113
const serverJson = JSON.parse(fs.readFileSync(serverJsonFilePath, 'utf-8'));
12-
fs.unlinkSync(serverJsonFilePath);
1314

14-
// Create the new server.json
15-
execSync('./mcp-publisher init');
15+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'mcp-verify-'));
1616

17-
const newServerJson = JSON.parse(fs.readFileSync(serverJsonFilePath, 'utf-8'));
18-
19-
const propertyToVerify = ['$schema'];
20-
const diffProps = [];
17+
try {
18+
const osName = os.platform();
19+
const arch = os.arch();
20+
let platform = '';
21+
if (osName === 'darwin') {
22+
platform = 'darwin';
23+
} else if (osName === 'linux') {
24+
platform = 'linux';
25+
}
26+
// mcp-publisher does not support windows
27+
else {
28+
throw new Error(`Unsupported platform: ${osName}`);
29+
}
2130

22-
for (const prop of propertyToVerify) {
23-
if (serverJson[prop] !== newServerJson[prop]) {
24-
diffProps.push(prop);
31+
let archName = '';
32+
if (arch === 'x64') {
33+
archName = 'amd64';
34+
} else if (arch === 'arm64') {
35+
archName = 'arm64';
36+
} else {
37+
throw new Error(`Unsupported architecture: ${arch}`);
2538
}
26-
}
2739

28-
fs.writeFileSync('./server.json', JSON.stringify(serverJson, null, 2));
40+
const osArch = `${platform}_${archName}`;
41+
const binName = 'mcp-publisher';
42+
const downloadUrl = `https://github.com/modelcontextprotocol/registry/releases/latest/download/${binName}_${osArch}.tar.gz`;
43+
44+
console.log(`Downloading ${binName} from ${downloadUrl}`);
45+
const downloadCmd = `curl -L "${downloadUrl}" | tar xz -C "${tmpDir}" ${binName}`;
46+
execSync(downloadCmd, {stdio: 'inherit'});
47+
48+
const publisherPath = path.join(tmpDir, binName);
49+
fs.chmodSync(publisherPath, 0o755);
50+
console.log(`Downloaded to ${publisherPath}`);
2951

30-
if (diffProps.length) {
31-
throw new Error(
32-
`The following props did not match the latest init value:\n${diffProps.map(
33-
prop => `- "${prop}": "${newServerJson[prop]}"`,
34-
)}`,
35-
);
52+
// Create the new server.json in the temporary directory
53+
execSync(`${publisherPath} init`, {cwd: tmpDir, stdio: 'inherit'});
54+
55+
const newServerJsonPath = path.join(tmpDir, 'server.json');
56+
const newServerJson = JSON.parse(fs.readFileSync(newServerJsonPath, 'utf-8'));
57+
58+
const propertyToVerify = ['$schema'];
59+
const diffProps = [];
60+
61+
for (const prop of propertyToVerify) {
62+
if (serverJson[prop] !== newServerJson[prop]) {
63+
diffProps.push(prop);
64+
}
65+
}
66+
67+
if (diffProps.length) {
68+
throw new Error(
69+
`The following props in ${serverJsonFilePath} did not match the latest init value:\n${diffProps.map(
70+
prop =>
71+
`- "${prop}": expected "${newServerJson[prop]}", got "${serverJson[prop]}"`,
72+
)}`,
73+
);
74+
}
75+
} finally {
76+
fs.rmSync(tmpDir, {recursive: true, force: true});
3677
}

server.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-10-17/server.schema.json",
2+
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
33
"name": "io.github.ChromeDevTools/chrome-devtools-mcp",
44
"title": "Chrome DevTools MCP",
55
"description": "MCP server for Chrome DevTools",

src/McpResponse.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,11 @@ export class McpResponse implements Response {
259259
};
260260
} else if (message instanceof DevTools.AggregatedIssue) {
261261
const mappedIssueMessage = mapIssueToMessageObject(message);
262-
if (!mappedIssueMessage)
262+
if (!mappedIssueMessage) {
263263
throw new Error(
264264
"Can't provide detals for the msgid " + consoleMessageStableId,
265265
);
266+
}
266267
consoleData = {
267268
consoleMessageStableId,
268269
...mappedIssueMessage,
@@ -321,7 +322,9 @@ export class McpResponse implements Response {
321322
}
322323
if (item instanceof DevTools.AggregatedIssue) {
323324
const mappedIssueMessage = mapIssueToMessageObject(item);
324-
if (!mappedIssueMessage) return null;
325+
if (!mappedIssueMessage) {
326+
return null;
327+
}
325328
return {
326329
consoleMessageStableId,
327330
...mappedIssueMessage,

src/formatters/consoleFormatter.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ export function formatIssue(
8484
if (processedMarkdown?.startsWith('# ')) {
8585
processedMarkdown = processedMarkdown.substring(2).trimStart();
8686
}
87-
if (processedMarkdown) result.push(processedMarkdown);
87+
if (processedMarkdown) {
88+
result.push(processedMarkdown);
89+
}
8890

8991
const links = issue.getDescription()?.links;
9092
if (links && links.length > 0) {
@@ -102,7 +104,9 @@ export function formatIssue(
102104
}> = [];
103105
for (const singleIssue of issues) {
104106
const details = singleIssue.details();
105-
if (!details) continue;
107+
if (!details) {
108+
continue;
109+
}
106110

107111
// We send the remaining details as untyped JSON because the DevTools
108112
// frontend code is currently not re-usable.
@@ -152,17 +156,23 @@ export function formatIssue(
152156
result.push(
153157
...affectedResources.map(item => {
154158
const details = [];
155-
if (item.uid) details.push(`uid=${item.uid}`);
159+
if (item.uid) {
160+
details.push(`uid=${item.uid}`);
161+
}
156162
if (item.request) {
157163
details.push(
158164
(typeof item.request === 'number' ? `reqid=` : 'url=') + item.request,
159165
);
160166
}
161-
if (item.data) details.push(`data=${JSON.stringify(item.data)}`);
167+
if (item.data) {
168+
details.push(`data=${JSON.stringify(item.data)}`);
169+
}
162170
return details.join(' ');
163171
}),
164172
);
165-
if (result.length === 0) return 'No affected resources found';
173+
if (result.length === 0) {
174+
return 'No affected resources found';
175+
}
166176
return result.join('\n');
167177
}
168178

0 commit comments

Comments
 (0)