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
9 changes: 7 additions & 2 deletions plugins/rdk-camera-workshop/mcp/bridge.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node
/** Bounded stdio MCP transport for the reviewed d-obs camera tools. Node >= 22. */
import { constants, readFileSync } from 'node:fs';
import { constants, readFileSync, realpathSync } from 'node:fs';
import { createHash, randomUUID } from 'node:crypto';
import { access, mkdir, open, realpath, rename, rm, writeFile } from 'node:fs/promises';
import { homedir } from 'node:os';
Expand Down Expand Up @@ -813,6 +813,11 @@ export async function runBridge() {
else if (pending.length) await schedule(pending);
await Promise.all(active); await outputChain;
}
if (process.argv[1] && await realpath(process.argv[1]).catch(() => '') === modulePath) {
// The host may launch the server through an 8.3 short name or another letter case than the module URL, so only canonical forms may be compared.
export function sameModulePath(left, right) {
try { return path.relative(realpathSync.native(left), realpathSync.native(right)) === ''; } catch { return false; }
}
const isMainEntry = typeof import.meta.main === 'boolean' ? import.meta.main : Boolean(process.argv[1]) && sameModulePath(process.argv[1], modulePath);
if (isMainEntry) {
runBridge().catch(async () => { await output(rpcError(null, -32603, 'camera_bridge_stdio_failed')).catch(() => {}); process.exitCode = 1; });
}
25 changes: 23 additions & 2 deletions plugins/rdk-camera-workshop/mcp/bridge.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,38 @@ import { test } from 'node:test';
import { spawn } from 'node:child_process';
import { createHash } from 'node:crypto';
import { createServer } from 'node:http';
import { chmod, mkdtemp, readFile, readdir, rm, writeFile } from 'node:fs/promises';
import { chmod, mkdtemp, readFile, readdir, rm, symlink, writeFile } from 'node:fs/promises';
import { existsSync } from 'node:fs';
import { tmpdir } from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { resolveConfigPath } from './bridge.mjs';
import { resolveConfigPath, sameModulePath } from './bridge.mjs';

const bridge = fileURLToPath(new URL('./bridge.mjs', import.meta.url));
test('stdio bridge negotiates the MCP version used by older Studio clients', async () => {
const { responses } = await run([rpc(1, 'initialize', { protocolVersion: '2024-11-05' })], '/missing-camera-bridge-config');
assert.equal(responses[0].result.protocolVersion, '2024-11-05');
});
const caseInsensitiveVolume = existsSync(path.dirname(bridge).toUpperCase());
const casedBridge = path.join(path.dirname(bridge).toUpperCase(), path.basename(bridge));
test('the bridge starts when the launch path uses another letter case than the module file', { skip: caseInsensitiveVolume ? false : 'requires a case-insensitive volume' }, async () => {
const child = spawn(process.execPath, [casedBridge], { env: { ...process.env, RDK_CAMERA_WORKSHOP_CONFIG: '/missing-camera-bridge-config' }, stdio: ['pipe', 'pipe', 'pipe'] });
let stdout = ''; child.stdout.on('data', data => { stdout += data; });
child.stdin.on('error', () => {}); child.stdin.end(JSON.stringify(rpc(1, 'initialize', { protocolVersion: '2025-06-18' })) + '\n');
const code = await new Promise((resolve, reject) => { child.once('error', reject); child.once('close', resolve); });
assert.equal(code, 0); assert.match(stdout, /"serverInfo"/);
});
test('sameModulePath compares canonical paths so short names, symlinks and letter case cannot hide the entry module', async () => {
assert.equal(sameModulePath(bridge, bridge), true);
assert.equal(sameModulePath(casedBridge, bridge), caseInsensitiveVolume);
assert.equal(sameModulePath(bridge, path.join(path.dirname(bridge), 'setup.mjs')), false);
assert.equal(sameModulePath('/missing-camera-bridge-entry', bridge), false);
const directory = await mkdtemp(path.join(tmpdir(), 'camera-bridge-entry-'));
try {
await symlink(path.dirname(bridge), path.join(directory, 'link'));
assert.equal(sameModulePath(path.join(directory, 'link', path.basename(bridge)), bridge), true);
} finally { await rm(directory, { recursive: true, force: true }); }
});
const endpoint = '/dobs/api/ops/vision-workshop/mcp';
const secret = 'fixture-camera-private-credential-never-printed';
const rpc = (id, method, params = {}) => ({ jsonrpc: '2.0', id, method, params });
Expand Down
6 changes: 3 additions & 3 deletions plugins/vision-workshop-packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
{
"kind": "studio",
"name": "RDK Camera AI",
"version": "1.5.13",
"bytes": 1800525,
"sha256": "50e0cee7ede51d180d008fbda5ca201857369a349be9f5487dae98a4b37c28bf",
"version": "1.5.14",
"bytes": 1800702,
"sha256": "66c59670d589d207def8ac54bb023fcbbb231101818ceb3714a0faa3bb242c78",
"requirements": [
"Node.js 22+",
"RDK Studio 1.4+ 或兼容 MCP 宿主",
Expand Down
Binary file modified plugins/vision-workshop-packages/studio.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions tools/package-vision-distribution.mts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { visionCrc32 } from '../server/monitoring/vision-workshop-export.js';
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
export const CAMERA_ID = 'rdk-camera-workshop';
export const COURSE_ID = 'rdk-vision-workshop';
export const DEFAULT_STUDIO_VERSION = '1.5.13';
export const DEFAULT_STUDIO_VERSION = '1.5.14';
export const DEFAULT_CLASSROOM_VERSION = '1.5.9-rc.28';
const MAX_PACKAGE_BYTES = 32 * 1024 * 1024;
const SEMVER_PATTERN = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
Expand Down Expand Up @@ -832,7 +832,7 @@ function parseCli(argv: string[]) {
console.log(
[
'Usage:',
' npm run vision:package -- [--output <dir>] [--studio-version 1.5.13] [--classroom-version 1.5.9-rc.28] [--lesson-html <path>]',
' npm run vision:package -- [--output <dir>] [--studio-version 1.5.14] [--classroom-version 1.5.9-rc.28] [--lesson-html <path>]',
' npm run vision:verify -- [--dir <dir>]',
].join('\n'),
);
Expand Down
Loading