@hypothesi/tauri-mcp-server 0.8.3 → 0.10.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/README.md +16 -2
- package/dist/api.d.ts +2 -0
- package/dist/api.js +2 -0
- package/dist/config.d.ts +35 -0
- package/dist/driver/app-discovery.d.ts +75 -0
- package/dist/driver/element-picker.d.ts +42 -0
- package/dist/driver/element-picker.js +272 -0
- package/dist/driver/plugin-client.d.ts +100 -0
- package/dist/driver/plugin-commands.d.ts +163 -0
- package/dist/driver/protocol.d.ts +128 -0
- package/dist/driver/script-manager.d.ts +91 -0
- package/dist/driver/scripts/aria-api-loader.d.ts +17 -0
- package/dist/driver/scripts/element-picker.js +395 -0
- package/dist/driver/scripts/html2canvas-loader.d.ts +25 -0
- package/dist/driver/scripts/index.d.ts +37 -0
- package/dist/driver/scripts/index.js +1 -0
- package/dist/driver/session-manager.d.ts +76 -0
- package/dist/driver/webview-executor.d.ts +122 -0
- package/dist/driver/webview-interactions.d.ts +349 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -119
- package/dist/logger.d.ts +16 -0
- package/dist/manager/mobile.d.ts +6 -0
- package/dist/monitor/logs.d.ts +32 -0
- package/dist/prompts-registry.d.ts +30 -0
- package/dist/prompts-registry.js +46 -0
- package/dist/server.d.ts +13 -0
- package/dist/server.js +110 -0
- package/dist/tools-registry.d.ts +73 -0
- package/dist/tools-registry.js +51 -0
- package/dist/types/window.d.ts +30 -0
- package/dist/version.d.ts +15 -0
- package/package.json +9 -1
package/dist/server.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
3
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, ListPromptsRequestSchema, GetPromptRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
4
|
+
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
5
|
+
import { TOOLS, TOOL_MAP } from './tools-registry.js';
|
|
6
|
+
import { PROMPTS, PROMPT_MAP } from './prompts-registry.js';
|
|
7
|
+
import { createMcpLogger } from './logger.js';
|
|
8
|
+
/* eslint-disable no-process-exit */
|
|
9
|
+
const serverLogger = createMcpLogger('SERVER');
|
|
10
|
+
export function getCliToolDefinitions() {
|
|
11
|
+
return TOOLS.map((tool) => {
|
|
12
|
+
return {
|
|
13
|
+
name: tool.name,
|
|
14
|
+
description: tool.description,
|
|
15
|
+
inputSchema: zodToJsonSchema(tool.schema),
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function toolResultToContent(result) {
|
|
20
|
+
if (typeof result === 'string') {
|
|
21
|
+
return [{ type: 'text', text: result }];
|
|
22
|
+
}
|
|
23
|
+
if (Array.isArray(result)) {
|
|
24
|
+
return result.map(contentToMcp);
|
|
25
|
+
}
|
|
26
|
+
return [contentToMcp(result)];
|
|
27
|
+
}
|
|
28
|
+
function contentToMcp(content) {
|
|
29
|
+
if (content.type === 'text') {
|
|
30
|
+
return { type: 'text', text: content.text };
|
|
31
|
+
}
|
|
32
|
+
return { type: 'image', data: content.data, mimeType: content.mimeType };
|
|
33
|
+
}
|
|
34
|
+
export function createMcpServer(info) {
|
|
35
|
+
const server = new Server({
|
|
36
|
+
name: info.name,
|
|
37
|
+
version: info.version,
|
|
38
|
+
}, {
|
|
39
|
+
capabilities: {
|
|
40
|
+
tools: {},
|
|
41
|
+
prompts: {},
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
server.onerror = (error) => {
|
|
45
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
46
|
+
if (message.includes('broken pipe') || message.includes('EPIPE')) {
|
|
47
|
+
process.exit(0);
|
|
48
|
+
}
|
|
49
|
+
serverLogger.error(message);
|
|
50
|
+
};
|
|
51
|
+
server.onclose = () => {
|
|
52
|
+
process.exit(0);
|
|
53
|
+
};
|
|
54
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
55
|
+
return {
|
|
56
|
+
tools: TOOLS.map((tool) => {
|
|
57
|
+
return {
|
|
58
|
+
name: tool.name,
|
|
59
|
+
description: tool.description,
|
|
60
|
+
inputSchema: zodToJsonSchema(tool.schema),
|
|
61
|
+
annotations: tool.annotations,
|
|
62
|
+
};
|
|
63
|
+
}),
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
67
|
+
try {
|
|
68
|
+
const tool = TOOL_MAP.get(request.params.name);
|
|
69
|
+
if (!tool) {
|
|
70
|
+
throw new Error(`Unknown tool: ${request.params.name}`);
|
|
71
|
+
}
|
|
72
|
+
const output = await tool.handler(request.params.arguments);
|
|
73
|
+
return { content: toolResultToContent(output) };
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
77
|
+
return {
|
|
78
|
+
content: [{ type: 'text', text: `Error: ${message}` }],
|
|
79
|
+
isError: true,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
server.setRequestHandler(ListPromptsRequestSchema, async () => {
|
|
84
|
+
return {
|
|
85
|
+
prompts: PROMPTS.map((prompt) => {
|
|
86
|
+
return {
|
|
87
|
+
name: prompt.name,
|
|
88
|
+
description: prompt.description,
|
|
89
|
+
arguments: prompt.arguments,
|
|
90
|
+
};
|
|
91
|
+
}),
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
server.setRequestHandler(GetPromptRequestSchema, async (request) => {
|
|
95
|
+
const prompt = PROMPT_MAP.get(request.params.name);
|
|
96
|
+
if (!prompt) {
|
|
97
|
+
throw new Error(`Unknown prompt: ${request.params.name}`);
|
|
98
|
+
}
|
|
99
|
+
const args = (request.params.arguments || {});
|
|
100
|
+
return {
|
|
101
|
+
description: prompt.description,
|
|
102
|
+
messages: prompt.handler(args),
|
|
103
|
+
};
|
|
104
|
+
});
|
|
105
|
+
return server;
|
|
106
|
+
}
|
|
107
|
+
export async function startStdioServer(info) {
|
|
108
|
+
const transport = new StdioServerTransport(), server = createMcpServer(info);
|
|
109
|
+
await server.connect(transport);
|
|
110
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single source of truth for all MCP tool definitions
|
|
3
|
+
* This file defines all available tools and their metadata
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
/**
|
|
7
|
+
* Content types that tools can return.
|
|
8
|
+
* Text content is the default, image content is used for screenshots.
|
|
9
|
+
*/
|
|
10
|
+
export interface TextContent {
|
|
11
|
+
type: 'text';
|
|
12
|
+
text: string;
|
|
13
|
+
}
|
|
14
|
+
export interface ImageContent {
|
|
15
|
+
type: 'image';
|
|
16
|
+
data: string;
|
|
17
|
+
mimeType: string;
|
|
18
|
+
}
|
|
19
|
+
export type ToolContent = TextContent | ImageContent;
|
|
20
|
+
/**
|
|
21
|
+
* Tool result can be a string (legacy, converted to TextContent) or structured content.
|
|
22
|
+
*/
|
|
23
|
+
export type ToolResult = string | ToolContent | ToolContent[];
|
|
24
|
+
export type ToolHandler = (args: unknown) => Promise<ToolResult>;
|
|
25
|
+
/**
|
|
26
|
+
* Tool annotations that help the AI understand when and how to use tools.
|
|
27
|
+
* These follow the MCP specification for ToolAnnotations.
|
|
28
|
+
*/
|
|
29
|
+
export interface ToolAnnotations {
|
|
30
|
+
title?: string;
|
|
31
|
+
readOnlyHint?: boolean;
|
|
32
|
+
destructiveHint?: boolean;
|
|
33
|
+
idempotentHint?: boolean;
|
|
34
|
+
openWorldHint?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface ToolDefinition {
|
|
37
|
+
name: string;
|
|
38
|
+
description: string;
|
|
39
|
+
category: string;
|
|
40
|
+
schema: z.ZodSchema;
|
|
41
|
+
handler: ToolHandler;
|
|
42
|
+
annotations?: ToolAnnotations;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Tool categories for organization
|
|
46
|
+
*/
|
|
47
|
+
export declare const TOOL_CATEGORIES: {
|
|
48
|
+
readonly SETUP: "Setup & Configuration";
|
|
49
|
+
readonly MOBILE_DEVELOPMENT: "Mobile Development";
|
|
50
|
+
readonly UI_AUTOMATION: "UI Automation & WebView Interaction";
|
|
51
|
+
readonly IPC_PLUGIN: "IPC & Plugin Tools (via MCP Bridge)";
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Complete registry of all available tools
|
|
55
|
+
* This is the single source of truth for tool definitions
|
|
56
|
+
*/
|
|
57
|
+
export declare const TOOLS: ToolDefinition[];
|
|
58
|
+
/**
|
|
59
|
+
* Get all tool names for type checking
|
|
60
|
+
*/
|
|
61
|
+
export type ToolName = typeof TOOLS[number]['name'];
|
|
62
|
+
/**
|
|
63
|
+
* Get tools grouped by category
|
|
64
|
+
*/
|
|
65
|
+
export declare function getToolsByCategory(): Record<string, ToolDefinition[]>;
|
|
66
|
+
/**
|
|
67
|
+
* Get total tool count
|
|
68
|
+
*/
|
|
69
|
+
export declare function getToolCount(): number;
|
|
70
|
+
/**
|
|
71
|
+
* Create a Map for fast tool lookup by name
|
|
72
|
+
*/
|
|
73
|
+
export declare const TOOL_MAP: Map<string, ToolDefinition>;
|
package/dist/tools-registry.js
CHANGED
|
@@ -8,6 +8,7 @@ import { manageDriverSession, ManageDriverSessionSchema, } from './driver/sessio
|
|
|
8
8
|
import { readLogs, ReadLogsSchema } from './monitor/logs.js';
|
|
9
9
|
import { executeIPCCommand, manageIPCMonitoring, getIPCEvents, emitTestEvent, getBackendState, manageWindow, ExecuteIPCCommandSchema, ManageIPCMonitoringSchema, GetIPCEventsSchema, EmitTestEventSchema, GetBackendStateSchema, ManageWindowSchema, } from './driver/plugin-commands.js';
|
|
10
10
|
import { interact, screenshot, keyboard, waitFor, getStyles, executeJavaScript, findElement, domSnapshot, InteractSchema, ScreenshotSchema, KeyboardSchema, WaitForSchema, GetStylesSchema, ExecuteJavaScriptSchema, FindElementSchema, DomSnapshotSchema, } from './driver/webview-interactions.js';
|
|
11
|
+
import { selectElement, getPointedElement, SelectElementSchema, GetPointedElementSchema, } from './driver/element-picker.js';
|
|
11
12
|
import { PLUGIN_VERSION_CARGO } from './version.js';
|
|
12
13
|
/**
|
|
13
14
|
* Standard multi-app description for webview tools.
|
|
@@ -409,6 +410,56 @@ export const TOOLS = [
|
|
|
409
410
|
});
|
|
410
411
|
},
|
|
411
412
|
},
|
|
413
|
+
// Element Picker Tools
|
|
414
|
+
{
|
|
415
|
+
name: 'webview_select_element',
|
|
416
|
+
description: '[Tauri Apps Only] Activates an element picker overlay in the Tauri app. ' +
|
|
417
|
+
'The user visually selects an element by clicking it, and the tool returns ' +
|
|
418
|
+
'rich element metadata (tag, id, classes, attributes, text, bounding rect, ' +
|
|
419
|
+
'CSS selector, computed styles, parent chain) plus an annotated screenshot ' +
|
|
420
|
+
'with the element highlighted. ' +
|
|
421
|
+
'Requires active driver_session. ' +
|
|
422
|
+
MULTI_APP_DESC,
|
|
423
|
+
category: TOOL_CATEGORIES.UI_AUTOMATION,
|
|
424
|
+
schema: SelectElementSchema,
|
|
425
|
+
annotations: {
|
|
426
|
+
title: 'Select Element (Visual Picker)',
|
|
427
|
+
readOnlyHint: true,
|
|
428
|
+
openWorldHint: false,
|
|
429
|
+
},
|
|
430
|
+
handler: async (args) => {
|
|
431
|
+
const parsed = SelectElementSchema.parse(args);
|
|
432
|
+
return await selectElement({
|
|
433
|
+
timeout: parsed.timeout,
|
|
434
|
+
windowId: parsed.windowId,
|
|
435
|
+
appIdentifier: parsed.appIdentifier,
|
|
436
|
+
});
|
|
437
|
+
},
|
|
438
|
+
},
|
|
439
|
+
{
|
|
440
|
+
name: 'webview_get_pointed_element',
|
|
441
|
+
description: '[Tauri Apps Only] Retrieves element metadata for an element the user previously ' +
|
|
442
|
+
'pointed at via Alt+Shift+Click in the Tauri app. Returns the same rich metadata ' +
|
|
443
|
+
'as webview_select_element (tag, id, classes, attributes, text, bounding rect, ' +
|
|
444
|
+
'CSS selector, computed styles, parent chain) plus an annotated screenshot. ' +
|
|
445
|
+
'The user must Alt+Shift+Click an element first before calling this tool. ' +
|
|
446
|
+
'Requires active driver_session. ' +
|
|
447
|
+
MULTI_APP_DESC,
|
|
448
|
+
category: TOOL_CATEGORIES.UI_AUTOMATION,
|
|
449
|
+
schema: GetPointedElementSchema,
|
|
450
|
+
annotations: {
|
|
451
|
+
title: 'Get Pointed Element',
|
|
452
|
+
readOnlyHint: true,
|
|
453
|
+
openWorldHint: false,
|
|
454
|
+
},
|
|
455
|
+
handler: async (args) => {
|
|
456
|
+
const parsed = GetPointedElementSchema.parse(args);
|
|
457
|
+
return await getPointedElement({
|
|
458
|
+
windowId: parsed.windowId,
|
|
459
|
+
appIdentifier: parsed.appIdentifier,
|
|
460
|
+
});
|
|
461
|
+
},
|
|
462
|
+
},
|
|
412
463
|
// IPC & Plugin Tools
|
|
413
464
|
{
|
|
414
465
|
name: 'ipc_execute_command',
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Window type definitions for multi-webview support.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Information about a webview window.
|
|
6
|
+
*/
|
|
7
|
+
export interface WindowInfo {
|
|
8
|
+
label: string;
|
|
9
|
+
title?: string;
|
|
10
|
+
url?: string;
|
|
11
|
+
focused: boolean;
|
|
12
|
+
visible: boolean;
|
|
13
|
+
isMain: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Response from the list_windows command.
|
|
17
|
+
*/
|
|
18
|
+
export interface ListWindowsResponse {
|
|
19
|
+
windows: WindowInfo[];
|
|
20
|
+
defaultWindow: string;
|
|
21
|
+
totalCount: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Context about which window was used for an operation.
|
|
25
|
+
*/
|
|
26
|
+
export interface WindowContext {
|
|
27
|
+
windowLabel: string;
|
|
28
|
+
totalWindows: number;
|
|
29
|
+
warning?: string;
|
|
30
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Version information for the MCP Bridge plugin.
|
|
3
|
+
*
|
|
4
|
+
* Reads the version from this package's package.json at runtime.
|
|
5
|
+
* Both packages share the same version (monorepo single-version policy).
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Full version string (e.g., "0.6.5")
|
|
9
|
+
*/
|
|
10
|
+
export declare const PLUGIN_VERSION_FULL: string;
|
|
11
|
+
/**
|
|
12
|
+
* Cargo-compatible version string for Cargo.toml dependencies (e.g., "0.6")
|
|
13
|
+
* This is the major.minor version used in Cargo.toml dependency specifications.
|
|
14
|
+
*/
|
|
15
|
+
export declare const PLUGIN_VERSION_CARGO: string;
|
package/package.json
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hypothesi/tauri-mcp-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"mcpName": "io.github.hypothesi/mcp-server-tauri",
|
|
5
5
|
"description": "A Model Context Protocol server for use with Tauri v2 applications",
|
|
6
6
|
"type": "module",
|
|
7
|
+
"main": "./dist/api.js",
|
|
8
|
+
"types": "./dist/api.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/api.js",
|
|
12
|
+
"types": "./dist/api.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
7
15
|
"bin": {
|
|
8
16
|
"mcp-server-tauri": "./dist/index.js"
|
|
9
17
|
},
|