2025-03-25 14:46:39 -07:00
|
|
|
/**
|
|
|
|
* Copyright (c) Microsoft Corporation.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { createServerWithTools } from './server';
|
2025-04-04 15:22:00 -07:00
|
|
|
import common from './tools/common';
|
2025-04-04 17:14:30 -07:00
|
|
|
import files from './tools/files';
|
2025-04-04 15:22:00 -07:00
|
|
|
import install from './tools/install';
|
|
|
|
import keyboard from './tools/keyboard';
|
|
|
|
import navigate from './tools/navigate';
|
|
|
|
import pdf from './tools/pdf';
|
|
|
|
import snapshot from './tools/snapshot';
|
|
|
|
import tabs from './tools/tabs';
|
|
|
|
import screen from './tools/screen';
|
2025-04-04 17:14:30 -07:00
|
|
|
import { console as consoleResource } from './resources/console';
|
2025-03-25 14:46:39 -07:00
|
|
|
|
2025-04-04 17:14:30 -07:00
|
|
|
import type { Tool, ToolCapability } from './tools/tool';
|
2025-03-25 14:46:39 -07:00
|
|
|
import type { Resource } from './resources/resource';
|
|
|
|
import type { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
|
|
import type { LaunchOptions } from 'playwright';
|
|
|
|
|
|
|
|
const snapshotTools: Tool[] = [
|
2025-04-04 15:22:00 -07:00
|
|
|
...common,
|
2025-04-04 17:14:30 -07:00
|
|
|
...files(true),
|
2025-04-04 15:22:00 -07:00
|
|
|
...install,
|
|
|
|
...keyboard(true),
|
|
|
|
...navigate(true),
|
|
|
|
...pdf,
|
|
|
|
...snapshot,
|
|
|
|
...tabs(true),
|
2025-03-25 14:46:39 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
const screenshotTools: Tool[] = [
|
2025-04-04 15:22:00 -07:00
|
|
|
...common,
|
2025-04-04 17:14:30 -07:00
|
|
|
...files(false),
|
2025-04-04 15:22:00 -07:00
|
|
|
...install,
|
|
|
|
...keyboard(false),
|
|
|
|
...navigate(false),
|
|
|
|
...pdf,
|
|
|
|
...screen,
|
|
|
|
...tabs(false),
|
2025-03-25 14:46:39 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
const resources: Resource[] = [
|
2025-04-04 17:14:30 -07:00
|
|
|
consoleResource,
|
2025-03-25 14:46:39 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
type Options = {
|
2025-04-01 10:26:48 -07:00
|
|
|
browserName?: 'chromium' | 'firefox' | 'webkit';
|
2025-03-26 15:02:45 -07:00
|
|
|
userDataDir?: string;
|
2025-03-25 14:46:39 -07:00
|
|
|
launchOptions?: LaunchOptions;
|
2025-03-30 09:05:58 -07:00
|
|
|
cdpEndpoint?: string;
|
2025-03-26 15:02:45 -07:00
|
|
|
vision?: boolean;
|
2025-04-04 17:14:30 -07:00
|
|
|
capabilities?: ToolCapability[];
|
2025-03-25 14:46:39 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
const packageJSON = require('../package.json');
|
|
|
|
|
|
|
|
export function createServer(options?: Options): Server {
|
2025-04-04 17:14:30 -07:00
|
|
|
const allTools = options?.vision ? screenshotTools : snapshotTools;
|
|
|
|
const tools = allTools.filter(tool => !options?.capabilities || tool.capability === 'core' || options.capabilities.includes(tool.capability));
|
2025-03-26 15:02:45 -07:00
|
|
|
return createServerWithTools({
|
|
|
|
name: 'Playwright',
|
|
|
|
version: packageJSON.version,
|
|
|
|
tools,
|
|
|
|
resources,
|
2025-04-01 10:26:48 -07:00
|
|
|
browserName: options?.browserName,
|
2025-03-26 15:02:45 -07:00
|
|
|
userDataDir: options?.userDataDir ?? '',
|
|
|
|
launchOptions: options?.launchOptions,
|
2025-03-30 09:05:58 -07:00
|
|
|
cdpEndpoint: options?.cdpEndpoint,
|
2025-03-26 15:02:45 -07:00
|
|
|
});
|
2025-03-25 14:46:39 -07:00
|
|
|
}
|