chrome-devtools-mcp的使用案例:连接一个远程运行的chrome实例

news/2025/11/29 15:25:05/文章来源:https://www.cnblogs.com/xy-ouyang/p/19286550

chrome-devtools-mcp的使用案例:连接一个远程运行的chrome实例

1、连接一个远程运行的chrome实例

以windwos系统为例

1.1、启动chrome实例

查看本地chrome程序的安装路径

图片

 

图片

cmd运行,将会在本地以--remote-debugging-port=9222 打开chrome

图片

 

1.2、案例

以spring-AI为例

图片

 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.4.5</version><relativePath/></parent><groupId>com.example</groupId><artifactId>ai-mcp-fileserver</artifactId><version>0.0.1-SNAPSHOT</version><name>Spring AI - Model Context Protocol - Fileserver</name><description>Simple AI Application using MCP client to chat with FileServer</description><properties><java.version>17</java.version></properties><dependencyManagement><dependencies><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-bom</artifactId><version>1.1.0-SNAPSHOT</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-starter-model-openai</artifactId></dependency><!-- 阿里的灵积<dependency><groupId>com.alibaba.cloud.ai</groupId><artifactId>spring-ai-alibaba-starter-dashscope</artifactId><version>1.0.0.2</version></dependency>--><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-starter-mcp-client</artifactId></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build><repositories><repository><id>spring-milestones</id><name>Spring Milestones</name><url>https://repo.spring.io/milestone</url><snapshots><enabled>false</enabled></snapshots></repository><repository><id>spring-snapshots</id><name>Spring Snapshots</name><url>https://repo.spring.io/snapshot</url><releases><enabled>false</enabled></releases></repository><repository><id>central-portal-snapshots</id><name>Central Portal Snapshots</name><url>https://central.sonatype.com/repository/maven-snapshots/</url><releases><enabled>false</enabled></releases><snapshots><enabled>true</enabled></snapshots></repository></repositories></project>
View Code

application.properties

spring.application.name=mcp
spring.main.web-application-type=NONE
server.port=8086
server.servlet.context-path=/spring.ai.chat.client.enabled=false#spring.ai.openai.base-url=https://api.deepseek.com/
#spring.ai.openai.api-key=sk-xxx
#spring.ai.openai.chat.options.model=deepseek-chat
#spring.ai.openai.chat.options.max_completion_tokens=8000
#spring.ai.openai.chat.options.temperature=0.1
spring.ai.openai.base-url=https://dashscope.aliyuncs.com/compatible-mode
spring.ai.openai.api-key=sk-xxx
spring.ai.openai.chat.options.model=qwen3-max#spring.ai.dashscope.base-url=https://dashscope.aliyuncs.com/compatible-mode/v1
#spring.ai.dashscope.api-key=sk-xxx
#spring.ai.dashscope.chat.options.model=qwen3-vl-plusspring.ai.mcp.client.toolcallback.enabled=true
spring.ai.mcp.client.stdio.servers-configuration= classpath:mcp-servers-config.jsonlogging.level.io.modelcontextprotocol.client=DEBUG
logging.level.io.modelcontextprotocol.spec=DEBUG

 

LLMConfig类

package com.example;import io.modelcontextprotocol.client.McpSyncClient;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.mcp.SyncMcpToolCallbackProvider;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;import java.util.List;@Configuration
public class LLMConfig {@Beanpublic ChatClient.Builder openAiChatClient(@Qualifier("openAiChatModel") ChatModel openAiChatModel,List<McpSyncClient> mcpSyncClients) {return ChatClient.builder(openAiChatModel).defaultToolCallbacks(new SyncMcpToolCallbackProvider(mcpSyncClients));}//    @Bean
//    public ChatClient.Builder dashscopeChatClient(@Qualifier("dashscopeChatModel") ChatModel openAiChatModel) {
//        return ChatClient.builder(openAiChatModel);
//    }
}

 

Application类

package com.example;import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;@SpringBootApplication
public class Application {public static void main(String[] args) {SpringApplication.run(Application.class, args);}@Beanpublic CommandLineRunner predefinedQuestions(@Qualifier("openAiChatClient") ChatClient.Builder chatClientBuilder,//List<McpSyncClient> mcpSyncClients,
                                                 ConfigurableApplicationContext context) {return args -> {var chatClient = chatClientBuilder//.defaultToolCallbacks(new SyncMcpToolCallbackProvider(mcpSyncClients))
                    .build();String question = "打开http://localhost:8001/index.html";System.out.println("QUESTION: " + question);System.out.println("ASSISTANT: " + chatClient.prompt(question).call().content());System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~任务完成~~~~~~~~~~~~~~~~~~~~~~~~~~");context.close();};}}

 

下面的内容摘录自 https://github.com/ChromeDevTools/chrome-devtools-mcp

1、Getting started

Add the following config to your MCP client:

{"mcpServers": {"chrome-devtools": {"command": "npx","args": ["-y", "chrome-devtools-mcp@latest"]}}
}

2、Configuration

The Chrome DevTools MCP server supports the following configuration option:

--browserUrl, -u Connect to a running Chrome instance using port forwarding. For more details see: https://developer.chrome.com/docs/devtools/remote-debugging/local-server.Type: string--wsEndpoint, -w WebSocket endpoint to connect to a running Chrome instance (e.g., ws://127.0.0.1:9222/devtools/browser/). Alternative to --browserUrl.Type: string--wsHeaders Custom headers for WebSocket connection in JSON format (e.g., '{"Authorization":"Bearer token"}'). Only works with --wsEndpoint.Type: string--headless Whether to run in headless (no UI) mode.Type: booleanDefault: false--executablePath, -e Path to custom Chrome executable.Type: string--isolated If specified, creates a temporary user-data-dir that is automatically cleaned up after the browser is closed. Defaults to false.Type: boolean--userDataDir Path to the user data directory for Chrome. Default is $HOME/.cache/chrome-devtools-mcp/chrome-profile$CHANNEL_SUFFIX_IF_NON_STABLEType: string--channel Specify a different Chrome channel that should be used. The default is the stable channel version.Type: stringChoices: stable, canary, beta, dev--logFile Path to a file to write debug logs to. Set the env variable DEBUG to * to enable verbose logs. Useful for submitting bug reports.Type: string--viewport Initial viewport size for the Chrome instances started by the server. For example, 1280x720. In headless mode, max size is 3840x2160px.Type: string--proxyServer Proxy server configuration for Chrome passed as --proxy-server when launching the browser. See https://www.chromium.org/developers/design-documents/network-settings/ for details.Type: string--acceptInsecureCerts If enabled, ignores errors relative to self-signed and expired certificates. Use with caution.Type: boolean--chromeArg Additional arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.Type: array--categoryEmulation Set to false to exclude tools related to emulation.Type: booleanDefault: true--categoryPerformance Set to false to exclude tools related to performance.Type: booleanDefault: true--categoryNetwork Set to false to exclude tools related to network.Type: booleanDefault: true

Pass them via the args property in the JSON configuration. For example:

{"mcpServers": {"chrome-devtools": {"command": "npx","args": ["chrome-devtools-mcp@latest","--channel=canary","--headless=true","--isolated=true"]}}
}

 

3、Connecting via WebSocket with custom headers

You can connect directly to a Chrome WebSocket endpoint and include custom headers (e.g., for authentication):

{"mcpServers": {"chrome-devtools": {"command": "npx","args": ["chrome-devtools-mcp@latest","--wsEndpoint=ws://127.0.0.1:9222/devtools/browser/<id>","--wsHeaders={\"Authorization\":\"Bearer YOUR_TOKEN\"}"]}}
}

To get the WebSocket endpoint from a running Chrome instance, visit http://127.0.0.1:9222/json/version and look for the webSocketDebuggerUrl field.

You can also run npx chrome-devtools-mcp@latest --help to see all available configuration options.

4、User data directory

chrome-devtools-mcp starts a Chrome's stable channel instance using the following user data directory:

    Linux / macOS: $HOME/.cache/chrome-devtools-mcp/chrome-profile-$CHANNELWindows: %HOMEPATH%/.cache/chrome-devtools-mcp/chrome-profile-$CHANNEL

The user data directory is not cleared between runs and shared across all instances of chrome-devtools-mcp. Set the isolated option to true to use a temporary user data dir instead which will be cleared automatically after the browser is closed.

 

5、Connecting to a running Chrome instance

You can connect to a running Chrome instance by using the --browser-url option. This is useful if you want to use your existing Chrome profile or if you are running the MCP server in a sandboxed environment that does not allow starting a new Chrome instance.

Here is a step-by-step guide on how to connect to a running Chrome Stable instance:

Step 1: Configure the MCP client

Add the --browser-url option to your MCP client configuration. The value of this option should be the URL of the running Chrome instance. http://127.0.0.1:9222 is a common default.

{"mcpServers": {"chrome-devtools": {"command": "npx","args": ["chrome-devtools-mcp@latest","--browser-url=http://127.0.0.1:9222"]}}
}

Step 2: Start the Chrome browser

Start the Chrome browser with the remote debugging port enabled. Make sure to close any running Chrome instances before starting a new one with the debugging port enabled. The port number you choose must be the same as the one you specified in the --browser-url option in your MCP client configuration.

For security reasons, Chrome requires you to use a non-default user data directory when enabling the remote debugging port. You can specify a custom directory using the --user-data-dir flag. This ensures that your regular browsing profile and data are not exposed to the debugging session.

macOS

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222 --user-data-dir=/tmp/chrome-profile-stable

Linux

/usr/bin/google-chrome --remote-debugging-port=9222 --user-data-dir=/tmp/chrome-profile-stable

Windows

"C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222 --user-data-dir="%TEMP%\chrome-profile-stable"

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/980884.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

11.29新开始

看了台剧十六个夏天,男主人公在得知自己患有癌症的时候,开了个博客去记录自己的抗癌症生活和对女主人公不敢说的话,我觉得挺有意义的。之前就想开个博客,一直拖延着,现在还是觉得要尽早开,所以在2025年11月29号,…

擦擦视频去字幕水印」深度介绍:数字媒体领域的高效去水印解决方案

一、引言部分 数字媒体行业近年来保持快速增长态势,据相关数据显示,2023 年数字媒体市场规模突破 [X] 亿元,随着短视频、影视剪辑等应用的爆发式普及,用户对视频去水印及字幕处理的需求急剧攀升,同时面临去水印耗…

哈尔滨一站式家居设备推荐TOP5权威测评:甄选可靠服务商,破

家居装修中,设备选购与安装是品质生活的核心环节,但用户常陷品类分散奔波多店隐性收费难预估安装不规范致设备报废等痛点——据2024年龙江家居服务投诉数据,超60%投诉集中于多店对比耗时高价低质售后响应慢三大问题…

2025年pvdf车棚定做厂家排行榜单

2025年PVDF车棚定做厂家排行榜单榜单前言随着膜结构行业的快速发展,PVDF车棚凭借其优异的耐候性、自洁性和美观度,成为市场主流选择。以下是2025年度PVDF车棚定制厂家的权威排名,为您的采购决策提供参考。综合实力排…

2025比较好的美团点评代运营专业公司:助力汽服门店线上精准

线上流量竞争白热化的当下,美团点评作为本地生活服务核心入口,已成为汽服门店拓客的关键阵地。但市场调研显示,超60%的汽服门店因代运营公司选择不当遭遇割韭菜——要么投流成本超预期3倍,要么私信回复延迟导致客户…

效果-风格化组

--本篇导航--CC RepeTile动态拼贴马赛克查找边缘发光CC RepeTile 可以直接对涂层对象进行上下左右的复制扩充。 动态拼贴 是在图层对象的内部进行复制扩展,可以随意移动,类似于套了一个图层对象大小的蒙版。但可以向…

批量添加文件夹内exe防火墙规则(禁止出站)

环境 win10 PowerShell 场景 完全不想联网的工具型软件 原理 高级安全Windows Defender防火墙设置出站规则(直接禁止向外发送请求,达到禁网的目的) 过程创建 PowerShell 脚本 wall.ps1点击查看代码 # SCRIPT: Batch…

Asp.net证书配置

一、在asp.net中使用 app.UseHsts(); app.UseHttpsRedirection();配置时,在生成环境提示重定向安全连接问题 HTTP redirection to HTTPS causes ERR_INVALID_REDIRECT on the CORS preflight request 参考: Enforce …

【AI白皮书】AI应用开发框架

3.1 智能体的定义与主流开发范式 3.1.1 什么是智能体 智能体(Agent)可以理解为一个具备自主理解、规划、记忆和工具使用能力的数字化实体。 我们在前面了解到LLM、MCP,它们和Agent是啥关系呢?LLM是“大脑”,Agent…

2025年哈尔滨舒适家居设备服务商TOP5推荐:盛通舒适+基

本榜单依托哈尔滨本地市场调研与真实用户口碑,深度筛选出五家标杆舒适家居服务商,为龙江家庭选型提供客观依据,助力精准匹配适配的服务伙伴。 TOP1 推荐:哈尔滨盛通环境工程有限公司 推荐指数:★★★★★ 口碑评分…

2025年南京、武汉、杭州、合肥、福州资质齐全的美团点评代运

本榜单依托全维度市场调研与真实行业口碑,深度筛选出五家标杆企业,为南京、武汉、杭州、合肥、福州地区的企业选型提供客观依据,助力精准匹配适配的服务伙伴。 TOP1 推荐:武汉车视界信息服务有限公司 推荐指数:…

2025年锌钢阳台护栏订做厂家权威推荐榜单:不锈钢锌钢护栏/锌钢防护栏‌/组装锌钢护栏‌源头厂家精选

随着建筑安全标准不断提升,中国锌钢护栏市场规模预计在2025年将达到685亿元,年增长率稳定在8.5%,其中定制化阳台护栏需求增长尤为显著。 锌钢阳台护栏作为建筑安全防护的重要部件,其质量和性能直接关系到用户的安全…

2025年石墨回收厂家最新推荐:临漳县译晨新材料,河北石墨回收、河北石墨电极回收、邯郸石墨回收、邯郸石墨电极回收再生新标准

随着新能源、冶金、化工等行业快速发展,石墨材料需求持续增长,石墨资源循环利用价值日益凸显。2025年,在环保政策趋严和资源再生利用需求提升的双重驱动下,石墨回收行业迎来新的发展机遇。然而市场上石墨回收企业技…

2025/11/28 今天学习的内容是stl的vector的使用

2025/11/28 今天学习的内容是stl的vector的使用队列的创建 vector v; 队列的赋值 v={1,2,3,4,5} v.push_back(6); vector v1=v; 也可通过迭代器来赋值vector v2; v2=v.assign(v.begin(),v.end()); 队列的调整 调整…

2025年PP/PE板材生产线制造商权威推荐榜单:TPE汽车脚垫设备/钙素板设备/石塑包装箱生产线源头厂家精选

PP/PE板材作为包装、建筑、汽车等领域的核心材料,其生产线技术精度与稳定性直接影响板材成品率及性能。据2024年塑料机械行业报告显示,中国塑料板材生产线市场规模已达86亿元,其中PP/PE板材设备占比37%,高端生产线…

2025年河北石墨回收厂家TOP5推荐:石墨电极回收、河北石墨回收、河北石墨电极回收、邯郸石墨回收、邯郸石墨电极回收、从区域覆盖到规范回收的务实之选

随着工业制造与新能源产业的发展,石墨材料的循环利用需求日益增长,专业的石墨回收服务成为企业降低成本、践行环保的重要选择。然而,面对市场上各类回收机构,如何挑选资质合规、服务高效的合作伙伴,成为工业企业的…

成都系统开发软件开发公司推荐 口碑好有实力的软件开发品牌

选择合适的软件开发公司对于企业的成功至关重要。四川推来客网络科技有限公司凭借其高性价比、专业技术团队和丰富的行业经验,成为众多企业的首选。同时,源码世纪软件也以其强大的项目执行能力和广泛的服务获得客户的…

2025年BIPV防水光伏支架定做厂家权威推荐榜单:BIPV楼面光伏支架/BIPV光伏支架‌/BIPV建筑光伏支架‌源头厂家精选

在建筑节能改造与绿色能源应用加速普及的背景下,全球BIPV(建筑一体化光伏)防水太阳能支架市场正迎来快速增长期,2031年全球市场销售额预计将达到数百亿元规模。 BIPV防水光伏支架作为实现建筑与光伏系统深度融合的…

和为S的两个数字

和为S的两个数字题目描述:输入一个递增排序的数组和一个数字S,在数组中查找两个数,是的他们的和正好是S,如果有多对数字的和等于S,输出两个数的乘积最小的。对应每个测试案例,输出两个数,小的先输出。 思路:数…

5-18 Hashing - Hard Version (30分)

5-18 Hashing - Hard Version (30分)#include <iostream> #include <vector> #include <queue>using namespace std;struct node {int key, index;bool operator < (const node &nod) const{…