@midscene/computer 1.5.3 → 1.5.4-beta-20260310030546.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/dist/es/index.mjs CHANGED
@@ -9,6 +9,7 @@ import { getDebug } from "@midscene/shared/logger";
9
9
  import screenshot_desktop from "screenshot-desktop";
10
10
  import { existsSync } from "node:fs";
11
11
  import { Agent } from "@midscene/core/agent";
12
+ import { BaseMidsceneTools } from "@midscene/shared/mcp";
12
13
  import { overrideAIConfig } from "@midscene/shared/env";
13
14
  const debugXvfb = getDebug('computer:xvfb');
14
15
  function checkXvfbInstalled() {
@@ -679,6 +680,82 @@ async function agentFromComputer(opts) {
679
680
  await device.connect();
680
681
  return new ComputerAgent(device, opts);
681
682
  }
683
+ const debug = getDebug('mcp:computer-tools');
684
+ class ComputerMidsceneTools extends BaseMidsceneTools {
685
+ createTemporaryDevice() {
686
+ return new ComputerDevice({});
687
+ }
688
+ async ensureAgent(displayId, headless) {
689
+ if (this.agent && displayId) {
690
+ try {
691
+ await this.agent.destroy?.();
692
+ } catch (error) {
693
+ debug('Failed to destroy agent during cleanup:', error);
694
+ }
695
+ this.agent = void 0;
696
+ }
697
+ if (this.agent) return this.agent;
698
+ debug('Creating Computer agent with displayId:', displayId || 'primary');
699
+ const opts = {
700
+ ...displayId ? {
701
+ displayId
702
+ } : {},
703
+ ...void 0 !== headless ? {
704
+ headless
705
+ } : {}
706
+ };
707
+ const agent = await agentFromComputer(Object.keys(opts).length > 0 ? opts : void 0);
708
+ this.agent = agent;
709
+ return agent;
710
+ }
711
+ preparePlatformTools() {
712
+ return [
713
+ {
714
+ name: 'computer_connect',
715
+ description: 'Connect to computer desktop. Provide displayId to connect to a specific display (use computer_list_displays to get available IDs). If not provided, uses the primary display.',
716
+ schema: {
717
+ displayId: z.string().optional().describe('Display ID (from computer_list_displays)'),
718
+ headless: z.boolean().optional().describe('Start virtual display via Xvfb (Linux only)')
719
+ },
720
+ handler: async ({ displayId, headless })=>{
721
+ const agent = await this.ensureAgent(displayId, headless);
722
+ const screenshot = await agent.interface.screenshotBase64();
723
+ return {
724
+ content: [
725
+ {
726
+ type: 'text',
727
+ text: `Connected to computer${displayId ? ` (Display: ${displayId})` : ' (Primary display)'}`
728
+ },
729
+ ...this.buildScreenshotContent(screenshot)
730
+ ]
731
+ };
732
+ }
733
+ },
734
+ {
735
+ name: 'computer_disconnect',
736
+ description: 'Disconnect from computer and release resources',
737
+ schema: {},
738
+ handler: this.createDisconnectHandler('computer')
739
+ },
740
+ {
741
+ name: 'computer_list_displays',
742
+ description: 'List all available displays/monitors',
743
+ schema: {},
744
+ handler: async ()=>{
745
+ const displays = await ComputerDevice.listDisplays();
746
+ return {
747
+ content: [
748
+ {
749
+ type: 'text',
750
+ text: `Available displays:\n${displays.map((d)=>`- ${d.name} (ID: ${d.id})${d.primary ? ' [PRIMARY]' : ''}`).join('\n')}`
751
+ }
752
+ ]
753
+ };
754
+ }
755
+ }
756
+ ];
757
+ }
758
+ }
682
759
  function checkAccessibilityPermission(promptIfNeeded = false) {
683
760
  if ('darwin' !== process.platform) return {
684
761
  hasPermission: true,
@@ -744,4 +821,4 @@ async function checkComputerEnvironment() {
744
821
  async function getConnectedDisplays() {
745
822
  return ComputerDevice.listDisplays();
746
823
  }
747
- export { ComputerAgent, ComputerDevice, agentFromComputer, checkAccessibilityPermission, checkComputerEnvironment, checkXvfbInstalled, getConnectedDisplays, needsXvfb, overrideAIConfig };
824
+ export { ComputerAgent, ComputerDevice, ComputerMidsceneTools, agentFromComputer, checkAccessibilityPermission, checkComputerEnvironment, checkXvfbInstalled, getConnectedDisplays, needsXvfb, overrideAIConfig };
package/dist/lib/index.js CHANGED
@@ -42,6 +42,7 @@ __webpack_require__.d(__webpack_exports__, {
42
42
  agentFromComputer: ()=>agentFromComputer,
43
43
  needsXvfb: ()=>needsXvfb,
44
44
  overrideAIConfig: ()=>env_namespaceObject.overrideAIConfig,
45
+ ComputerMidsceneTools: ()=>ComputerMidsceneTools,
45
46
  getConnectedDisplays: ()=>getConnectedDisplays,
46
47
  ComputerDevice: ()=>ComputerDevice,
47
48
  ComputerAgent: ()=>ComputerAgent
@@ -728,6 +729,83 @@ async function agentFromComputer(opts) {
728
729
  await device.connect();
729
730
  return new ComputerAgent(device, opts);
730
731
  }
732
+ const mcp_namespaceObject = require("@midscene/shared/mcp");
733
+ const debug = (0, logger_namespaceObject.getDebug)('mcp:computer-tools');
734
+ class ComputerMidsceneTools extends mcp_namespaceObject.BaseMidsceneTools {
735
+ createTemporaryDevice() {
736
+ return new ComputerDevice({});
737
+ }
738
+ async ensureAgent(displayId, headless) {
739
+ if (this.agent && displayId) {
740
+ try {
741
+ await this.agent.destroy?.();
742
+ } catch (error) {
743
+ debug('Failed to destroy agent during cleanup:', error);
744
+ }
745
+ this.agent = void 0;
746
+ }
747
+ if (this.agent) return this.agent;
748
+ debug('Creating Computer agent with displayId:', displayId || 'primary');
749
+ const opts = {
750
+ ...displayId ? {
751
+ displayId
752
+ } : {},
753
+ ...void 0 !== headless ? {
754
+ headless
755
+ } : {}
756
+ };
757
+ const agent = await agentFromComputer(Object.keys(opts).length > 0 ? opts : void 0);
758
+ this.agent = agent;
759
+ return agent;
760
+ }
761
+ preparePlatformTools() {
762
+ return [
763
+ {
764
+ name: 'computer_connect',
765
+ description: 'Connect to computer desktop. Provide displayId to connect to a specific display (use computer_list_displays to get available IDs). If not provided, uses the primary display.',
766
+ schema: {
767
+ displayId: core_namespaceObject.z.string().optional().describe('Display ID (from computer_list_displays)'),
768
+ headless: core_namespaceObject.z.boolean().optional().describe('Start virtual display via Xvfb (Linux only)')
769
+ },
770
+ handler: async ({ displayId, headless })=>{
771
+ const agent = await this.ensureAgent(displayId, headless);
772
+ const screenshot = await agent.interface.screenshotBase64();
773
+ return {
774
+ content: [
775
+ {
776
+ type: 'text',
777
+ text: `Connected to computer${displayId ? ` (Display: ${displayId})` : ' (Primary display)'}`
778
+ },
779
+ ...this.buildScreenshotContent(screenshot)
780
+ ]
781
+ };
782
+ }
783
+ },
784
+ {
785
+ name: 'computer_disconnect',
786
+ description: 'Disconnect from computer and release resources',
787
+ schema: {},
788
+ handler: this.createDisconnectHandler('computer')
789
+ },
790
+ {
791
+ name: 'computer_list_displays',
792
+ description: 'List all available displays/monitors',
793
+ schema: {},
794
+ handler: async ()=>{
795
+ const displays = await ComputerDevice.listDisplays();
796
+ return {
797
+ content: [
798
+ {
799
+ type: 'text',
800
+ text: `Available displays:\n${displays.map((d)=>`- ${d.name} (ID: ${d.id})${d.primary ? ' [PRIMARY]' : ''}`).join('\n')}`
801
+ }
802
+ ]
803
+ };
804
+ }
805
+ }
806
+ ];
807
+ }
808
+ }
731
809
  const env_namespaceObject = require("@midscene/shared/env");
732
810
  function checkAccessibilityPermission(promptIfNeeded = false) {
733
811
  if ('darwin' !== process.platform) return {
@@ -796,6 +874,7 @@ async function getConnectedDisplays() {
796
874
  }
797
875
  exports.ComputerAgent = __webpack_exports__.ComputerAgent;
798
876
  exports.ComputerDevice = __webpack_exports__.ComputerDevice;
877
+ exports.ComputerMidsceneTools = __webpack_exports__.ComputerMidsceneTools;
799
878
  exports.agentFromComputer = __webpack_exports__.agentFromComputer;
800
879
  exports.checkAccessibilityPermission = __webpack_exports__.checkAccessibilityPermission;
801
880
  exports.checkComputerEnvironment = __webpack_exports__.checkComputerEnvironment;
@@ -806,6 +885,7 @@ exports.overrideAIConfig = __webpack_exports__.overrideAIConfig;
806
885
  for(var __rspack_i in __webpack_exports__)if (-1 === [
807
886
  "ComputerAgent",
808
887
  "ComputerDevice",
888
+ "ComputerMidsceneTools",
809
889
  "agentFromComputer",
810
890
  "checkAccessibilityPermission",
811
891
  "checkComputerEnvironment",
@@ -1,10 +1,12 @@
1
1
  import { AbstractInterface } from '@midscene/core/device';
2
2
  import { Agent } from '@midscene/core/agent';
3
3
  import { AgentOpt } from '@midscene/core/agent';
4
+ import { BaseMidsceneTools } from '@midscene/shared/mcp';
4
5
  import { DeviceAction } from '@midscene/core';
5
6
  import { InterfaceType } from '@midscene/core';
6
7
  import { overrideAIConfig } from '@midscene/shared/env';
7
8
  import { Size } from '@midscene/core';
9
+ import { ToolDefinition } from '@midscene/shared/mcp';
8
10
 
9
11
  declare interface AccessibilityCheckResult {
10
12
  hasPermission: boolean;
@@ -111,6 +113,19 @@ export declare interface ComputerDeviceOpt {
111
113
  xvfbResolution?: string;
112
114
  }
113
115
 
116
+ /**
117
+ * Computer-specific tools manager
118
+ * Extends BaseMidsceneTools to provide desktop automation tools
119
+ */
120
+ export declare class ComputerMidsceneTools extends BaseMidsceneTools<ComputerAgent> {
121
+ protected createTemporaryDevice(): ComputerDevice;
122
+ protected ensureAgent(displayId?: string, headless?: boolean): Promise<ComputerAgent>;
123
+ /**
124
+ * Provide Computer-specific platform tools
125
+ */
126
+ protected preparePlatformTools(): ToolDefinition[];
127
+ }
128
+
114
129
  export declare interface DisplayInfo {
115
130
  id: string;
116
131
  name: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midscene/computer",
3
- "version": "1.5.3",
3
+ "version": "1.5.4-beta-20260310030546.0",
4
4
  "description": "Midscene.js Computer Desktop Automation",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -36,8 +36,8 @@
36
36
  "@computer-use/libnut": "^4.2.0",
37
37
  "clipboardy": "^4.0.0",
38
38
  "screenshot-desktop": "^1.15.3",
39
- "@midscene/core": "1.5.3",
40
- "@midscene/shared": "1.5.3"
39
+ "@midscene/core": "1.5.4-beta-20260310030546.0",
40
+ "@midscene/shared": "1.5.4-beta-20260310030546.0"
41
41
  },
42
42
  "optionalDependencies": {
43
43
  "node-mac-permissions": "2.5.0"