@hypothesi/tauri-mcp-server 0.3.0 → 0.4.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.
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
|
|
38
38
|
if (element) {
|
|
39
39
|
const outerHTML = element.outerHTML;
|
|
40
|
-
// Truncate long HTML to avoid overwhelming output
|
|
41
|
-
const truncated = outerHTML.length >
|
|
42
|
-
? outerHTML.substring(0,
|
|
40
|
+
// Truncate very long HTML to avoid overwhelming output
|
|
41
|
+
const truncated = outerHTML.length > 5000
|
|
42
|
+
? outerHTML.substring(0, 5000) + '...'
|
|
43
43
|
: outerHTML;
|
|
44
44
|
return 'Found element: ' + truncated;
|
|
45
45
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { getPluginClient, connectPlugin } from './plugin-client.js';
|
|
3
|
+
import { createMcpLogger } from '../logger.js';
|
|
3
4
|
import { buildScreenshotScript, buildScreenshotCaptureScript, getHtml2CanvasSource, HTML2CANVAS_SCRIPT_ID, } from './scripts/html2canvas-loader.js';
|
|
4
5
|
import { registerScript, isScriptRegistered } from './script-manager.js';
|
|
5
6
|
/**
|
|
@@ -15,6 +16,7 @@ import { registerScript, isScriptRegistered } from './script-manager.js';
|
|
|
15
16
|
// Auto-Initialization System
|
|
16
17
|
// ============================================================================
|
|
17
18
|
let isInitialized = false;
|
|
19
|
+
const driverLogger = createMcpLogger('DRIVER');
|
|
18
20
|
/**
|
|
19
21
|
* Ensures the MCP server is fully initialized and ready to use.
|
|
20
22
|
* This is called automatically by all tool functions.
|
|
@@ -302,7 +304,7 @@ export async function captureScreenshot(options = {}) {
|
|
|
302
304
|
catch (nativeError) {
|
|
303
305
|
// Log the native error for debugging, then fall back
|
|
304
306
|
const nativeMsg = nativeError instanceof Error ? nativeError.message : String(nativeError);
|
|
305
|
-
|
|
307
|
+
driverLogger.error(`Native screenshot failed: ${nativeMsg}, falling back to html2canvas`);
|
|
306
308
|
}
|
|
307
309
|
// Fallback 1: Use html2canvas library for high-quality DOM rendering
|
|
308
310
|
// Try to use the script manager to register html2canvas for persistence
|
|
@@ -56,7 +56,9 @@ export const GetStylesSchema = WindowTargetSchema.extend({
|
|
|
56
56
|
.describe('Whether to get styles for all matching elements (true) or just the first (false)'),
|
|
57
57
|
});
|
|
58
58
|
export const ExecuteJavaScriptSchema = WindowTargetSchema.extend({
|
|
59
|
-
script: z.string().describe('JavaScript code to execute in the webview context'
|
|
59
|
+
script: z.string().describe('JavaScript code to execute in the webview context. ' +
|
|
60
|
+
'If returning a value, it must be JSON-serializable. ' +
|
|
61
|
+
'For functions that return values, use IIFE syntax: "(() => { return value; })()" not "() => { return value; }"'),
|
|
60
62
|
args: z.array(z.unknown()).optional().describe('Arguments to pass to the script'),
|
|
61
63
|
});
|
|
62
64
|
export const FocusElementSchema = WindowTargetSchema.extend({
|
package/dist/index.js
CHANGED
|
@@ -9,11 +9,13 @@ import { dirname, join } from 'path';
|
|
|
9
9
|
// Import the single source of truth for all tools and prompts
|
|
10
10
|
import { TOOLS, TOOL_MAP } from './tools-registry.js';
|
|
11
11
|
import { PROMPTS, PROMPT_MAP } from './prompts-registry.js';
|
|
12
|
+
import { createMcpLogger } from './logger.js';
|
|
12
13
|
/* eslint-disable no-process-exit */
|
|
13
14
|
// Read version from package.json
|
|
14
15
|
const currentDir = dirname(fileURLToPath(import.meta.url));
|
|
15
16
|
const packageJson = JSON.parse(readFileSync(join(currentDir, '..', 'package.json'), 'utf-8'));
|
|
16
17
|
const VERSION = packageJson.version;
|
|
18
|
+
const serverLogger = createMcpLogger('SERVER');
|
|
17
19
|
// Initialize server
|
|
18
20
|
const server = new Server({
|
|
19
21
|
name: 'mcp-server-tauri',
|
|
@@ -33,7 +35,7 @@ server.onerror = (error) => {
|
|
|
33
35
|
process.exit(0);
|
|
34
36
|
}
|
|
35
37
|
// For other errors, log to stderr (will be captured by MCP client)
|
|
36
|
-
|
|
38
|
+
serverLogger.error(message);
|
|
37
39
|
};
|
|
38
40
|
// Handle connection close - exit gracefully
|
|
39
41
|
server.onclose = () => {
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function createMcpLogger(scope) {
|
|
2
|
+
return {
|
|
3
|
+
info: (...args) => {
|
|
4
|
+
console.log('[MCP][' + scope + '][INFO]', ...args);
|
|
5
|
+
},
|
|
6
|
+
warn: (...args) => {
|
|
7
|
+
console.warn('[MCP][' + scope + '][WARN]', ...args);
|
|
8
|
+
},
|
|
9
|
+
error: (...args) => {
|
|
10
|
+
console.error('[MCP][' + scope + '][ERROR]', ...args);
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
}
|
package/dist/tools-registry.js
CHANGED
|
@@ -228,6 +228,8 @@ export const TOOLS = [
|
|
|
228
228
|
name: 'tauri_webview_execute_js',
|
|
229
229
|
description: '[Tauri Apps Only] Execute JavaScript in a Tauri app\'s webview context. ' +
|
|
230
230
|
'Requires active tauri_driver_session. Has access to window.__TAURI__. ' +
|
|
231
|
+
'If you need a return value, it must be JSON-serializable. ' +
|
|
232
|
+
'For functions that return values, use an IIFE: "(() => { return 5; })()" not "() => { return 5; }". ' +
|
|
231
233
|
'For browser JS execution, use Chrome DevTools MCP instead.',
|
|
232
234
|
category: TOOL_CATEGORIES.UI_AUTOMATION,
|
|
233
235
|
schema: ExecuteJavaScriptSchema,
|