Skip to content

Commit a26c099

Browse files
committed
wip
0 parents  commit a26c099

File tree

7 files changed

+479
-0
lines changed

7 files changed

+479
-0
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Python-generated files
2+
__pycache__/
3+
*.py[oc]
4+
build/
5+
dist/
6+
wheels/
7+
*.egg-info
8+
9+
# Virtual environments
10+
.venv

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12

README.md

Whitespace-only changes.

main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def main():
2+
print("Hello from browser-mcp-server!")
3+
4+
5+
if __name__ == "__main__":
6+
main()

pyproject.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[project]
2+
name = "browser-mcp-server"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
requires-python = ">=3.12"
7+
dependencies = [
8+
"httpx>=0.28.1",
9+
"mcp[cli]>=1.9.0",
10+
]

server.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import sqlite3
2+
import os
3+
from contextlib import AsyncIterator
4+
from contextlib import asynccontextmanager
5+
from dataclasses import dataclass
6+
import logging
7+
from mcp.server.fastmcp import FastMCP, Context
8+
9+
10+
FIREFOX_PROFILE_DIR = "`/Users/eleanor.mazzarella/Library/Application Support/Firefox/Profiles/l42msng6.default-release`"
11+
12+
PATH_TO_FIREFOX_HISTORY = os.path.join(FIREFOX_PROFILE_DIR, "places.sqlite")
13+
14+
logging.basicConfig(level=logging.INFO)
15+
16+
logger = logging.getLogger("browser-storage-mcp")
17+
18+
mcp = FastMCP("firefox-history")
19+
20+
@dataclass
21+
class AppContext:
22+
db: sqlite3.Connection
23+
24+
@asynccontextmanager
25+
async def app_lifespan(server: FastMCP) -> AsyncIterator[AppContext]:
26+
"""Manage application lifecycle with type-safe context"""
27+
# initialize on startup
28+
db = sqlite3.connect(PATH_TO_FIREFOX_HISTORY)
29+
try:
30+
yield AppContext(db=db)
31+
finally:
32+
db.close()
33+
34+
35+
# pass lifespan to server
36+
mcp = FastMCP("firefox-history", lifespan=app_lifespan)
37+
38+
@mcp.prompt()
39+
def explore_firefox_history() -> str:
40+
"""Create a prompt to explore the Firefox history"""
41+
return """
42+
I can help you explore your Firefox history.
43+
44+
Here are some of the things I can do:
45+
- I can list all of the sites you visited today or in the last week.
46+
"""
47+
48+
@mcp.prompt()
49+
def analyze_firefox_history(number_of_days: int) -> str:
50+
"""Analyze the Firefox history"""
51+
return f"""
52+
I can analyze the Firefox history from the past '{number_of_days}' days.
53+
54+
I can help you understand:
55+
- What sites you visited the most
56+
- What common themes arise from your browsing history
57+
- Areas you have been focusing on in the past {number_of_days} days
58+
"""
59+
60+
@mcp.prompt()
61+
def create_firefox_history_report(number_of_days: int) -> str:
62+
"""Create a report of the Firefox history"""
63+
return f"""
64+
I can create a report of the Firefox history from the past '{number_of_days}' days.
65+
66+
The report will be in markdown with a clear structure, and will be saved to a file in the current directory.
67+
"""
68+
69+
70+
71+
@mcp.tool()
72+
async def get_history(context: AppContext, query: str) -> list[str]:
73+
"""Get history from Firefox"""
74+
cursor = context.db.cursor()
75+
cursor.execute("SELECT url FROM moz_places WHERE url LIKE ?", (f"%{query}%",))
76+
return [row[0] for row in cursor.fetchall()]

uv.lock

Lines changed: 376 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)