Skip to content

Commit 52e083e

Browse files
eyalzhCopilot
andauthored
Add token-based auth (#1)
* Add token-based auth * Update mcp-server/browser-api.ts Co-authored-by: Copilot <[email protected]> * Fix socket readystate check --------- Co-authored-by: Copilot <[email protected]>
1 parent 34e14ef commit 52e083e

File tree

16 files changed

+228
-187
lines changed

16 files changed

+228
-187
lines changed

.gitignore

Lines changed: 2 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,10 @@ yarn-error.log*
77
lerna-debug.log*
88
.pnpm-debug.log*
99

10-
# Diagnostic reports (https://nodejs.org/api/report.html)
11-
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12-
13-
# Runtime data
14-
pids
15-
*.pid
16-
*.seed
17-
*.pid.lock
18-
19-
# Directory for instrumented libs generated by jscoverage/JSCover
20-
lib-cov
21-
22-
# Coverage directory used by tools like istanbul
23-
coverage
24-
*.lcov
25-
26-
# nyc test coverage
27-
.nyc_output
28-
29-
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30-
.grunt
31-
32-
# Bower dependency directory (https://bower.io/)
33-
bower_components
34-
35-
# node-waf configuration
36-
.lock-wscript
37-
38-
# Compiled binary addons (https://nodejs.org/api/addons.html)
39-
build/Release
40-
4110
# Dependency directories
4211
node_modules/
4312
jspm_packages/
4413

45-
# Snowpack dependency directory (https://snowpack.dev/)
46-
web_modules/
47-
4814
# TypeScript cache
4915
*.tsbuildinfo
5016

@@ -57,74 +23,18 @@ web_modules/
5723
# Optional stylelint cache
5824
.stylelintcache
5925

60-
# Microbundle cache
61-
.rpt2_cache/
62-
.rts2_cache_cjs/
63-
.rts2_cache_es/
64-
.rts2_cache_umd/
65-
66-
# Optional REPL history
67-
.node_repl_history
68-
69-
# Output of 'npm pack'
70-
*.tgz
71-
72-
# Yarn Integrity file
73-
.yarn-integrity
74-
75-
# dotenv environment variable files
26+
# dotenv environment variable files and config files
7627
.env
7728
.env.development.local
7829
.env.test.local
7930
.env.production.local
8031
.env.local
8132

82-
# parcel-bundler cache (https://parceljs.org/)
83-
.cache
84-
.parcel-cache
85-
86-
# Next.js build output
87-
.next
88-
out
89-
90-
# Nuxt.js build / generate output
91-
.nuxt
9233
dist
9334

94-
# Gatsby files
95-
.cache/
96-
# Comment in the public line in if your project uses Gatsby and not Next.js
97-
# https://nextjs.org/blog/next-9-1#public-directory-support
98-
# public
99-
100-
# vuepress build output
101-
.vuepress/dist
102-
103-
# vuepress v2.x temp and cache directory
10435
.temp
10536
.cache
10637

107-
# vitepress build output
108-
**/.vitepress/dist
109-
110-
# vitepress cache directory
111-
**/.vitepress/cache
112-
113-
# Docusaurus cache and generated files
114-
.docusaurus
115-
116-
# Serverless directories
117-
.serverless/
118-
119-
# FuseBox cache
120-
.fusebox/
121-
122-
# DynamoDB Local files
123-
.dynamodb/
124-
125-
# TernJS port file
126-
.tern-port
127-
12838
# Stores VSCode versions used for testing VSCode extensions
12939
.vscode-test
13040

@@ -137,4 +47,4 @@ dist
13747

13848
.nx
13949

140-
.DS_Store
50+
.DS_Store

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ npm install --prefix firefox-extension
2727
npm run build
2828
```
2929

30+
The final `npm run build` command should be executed in the main repository directory, as it also generates a shared `config.json` file used by both the server and the extension.
31+
32+
3033
### Usage with Claude Desktop:
3134

3235
Add the following configuration to `claude_desktop_config.json` (use the Edit Config button in Claude Desktop Developer settings):
@@ -51,9 +54,11 @@ Make sure to restart Claude Desktop.
5154

5255
The browser-control-mcp extension was developed for Firefox.
5356

54-
To install the extension, simply go to `about:debugging` in Firefox, click on "This Firefox", click on "Load Temporary Add-on...", and select the `manifest.json` file under the `firefox-extension` folder in this project.
55-
56-
If you are already using Firefox, then *it is recommended you download a separate instance of Firefox* (e.g. Firefox Developer's edition - https://www.mozilla.org/en-US/firefox/developer/) and install the browser-control extension on it, not on your personal browser.
57+
To install the extension:
5758

58-
While you can install the extension on your personal browser, this will expose your browsing history to the MCP client (e.g. Claude), as well as allow the client to access pages or to invoke requests with your existing browser sessions.
59+
1. Type `about:debugging` in the Firefox URL bar
60+
2. Click on "This Firefox"
61+
3. click on "Load Temporary Add-on..."
62+
4. Select the `manifest.json` file under the `firefox-extension` folder in this project
5963

64+
If you prefer not to run the extension on your personal Firefox browser, an alternative is to download a separate Firefox instance (such as Firefox Developer Edition, available at https://www.mozilla.org/en-US/firefox/developer/).

common/resources.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ export interface TabContentResourceMessage extends ResourceMessageBase {
1111
}
1212

1313
export interface BrowserTab {
14-
id: string;
15-
url: string;
16-
title: string;
14+
id?: number;
15+
url?: string;
16+
title?: string;
1717
}
1818

1919
export interface TabsResourceMessage extends ResourceMessageBase {
@@ -23,13 +23,13 @@ export interface TabsResourceMessage extends ResourceMessageBase {
2323

2424
export interface OpenedTabIdResourceMessage extends ResourceMessageBase {
2525
resource: "opened-tab-id";
26-
tabId: number;
26+
tabId: number | undefined;
2727
}
2828

2929
export interface BrowserHistoryItem {
30-
url: string;
31-
title: string;
32-
lastVisitTime: number;
30+
url?: string;
31+
title?: string;
32+
lastVisitTime?: number;
3333
}
3434

3535
export interface BrowserHistoryResourceMessage extends ResourceMessageBase {

firefox-extension/auth.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
function buf2hex(buffer: ArrayBuffer) {
2+
return Array.from(new Uint8Array(buffer))
3+
.map((x) => x.toString(16).padStart(2, "0"))
4+
.join("");
5+
}
6+
7+
export async function getMessageSignature(
8+
message: string,
9+
secretKey: string
10+
): Promise<string> {
11+
if (secretKey.length === 0) {
12+
throw new Error("Secret key is empty");
13+
}
14+
15+
const encoder = new TextEncoder();
16+
const keyData = encoder.encode(secretKey);
17+
const messageData = encoder.encode(message);
18+
19+
const key = await crypto.subtle.importKey(
20+
"raw",
21+
keyData,
22+
{ name: "HMAC", hash: "SHA-256" },
23+
false,
24+
["sign"]
25+
);
26+
27+
const rawSignature = await crypto.subtle.sign(
28+
{ name: "HMAC" },
29+
key,
30+
messageData
31+
);
32+
33+
return buf2hex(rawSignature);
34+
}

0 commit comments

Comments
 (0)