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 ()]
0 commit comments