Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix: revert crash-causing objc calls, always show shortcut text

Louis Beaumontd16e9cef520a
diff --git a/screenpipe-app-tauri/app/shortcut-reminder/page.tsx b/screenpipe-app-tauri/app/shortcut-reminder/page.tsx
index c4f0e67b6..82960e428 100644
--- a/screenpipe-app-tauri/app/shortcut-reminder/page.tsx
+++ b/screenpipe-app-tauri/app/shortcut-reminder/page.tsx
@@ -11,7 +11,6 @@ export default function ShortcutReminderPage() {
const { isMac, isLoading } = usePlatform();
const [shortcut, setShortcut] = useState<string | null>(null);
const [rawShortcut, setRawShortcut] = useState<string | null>(null);
- const [hovered, setHovered] = useState(false);
// Load shortcut from store on mount
useEffect(() => {
@@ -77,16 +76,12 @@ export default function ShortcutReminderPage() {
>
<div
onMouseDown={handleMouseDown}
- onMouseEnter={() => setHovered(true)}
- onMouseLeave={() => setHovered(false)}
className="select-none"
style={{ cursor: "grab" }}
>
<div className="relative">
{/* Subtle glow */}
- <div
- className={`absolute inset-0 bg-pink-500/20 rounded-full blur-md transition-opacity duration-300 ${hovered ? 'opacity-100' : 'opacity-40'}`}
- />
+ <div className="absolute inset-0 bg-pink-500/20 rounded-full blur-md opacity-40" />
{/* Main pill */}
<div
@@ -105,14 +100,8 @@ export default function ShortcutReminderPage() {
{shortcut ?? "..."}
</span>
- {/* Expanded text on hover */}
- <span
- className={`
- text-[9px] text-white/50 whitespace-nowrap overflow-hidden
- transition-all duration-300 ease-out
- ${hovered ? 'max-w-[100px] opacity-100' : 'max-w-0 opacity-0'}
- `}
- >
+ {/* Always show text - hover unreliable on unfocused windows */}
+ <span className="text-[9px] text-white/50 whitespace-nowrap">
open screenpipe
</span>
</div>
diff --git a/screenpipe-app-tauri/components/rewind/search-command.tsx b/screenpipe-app-tauri/components/rewind/search-command.tsx
index 99bdeb76c..156f80b65 100644
--- a/screenpipe-app-tauri/components/rewind/search-command.tsx
+++ b/screenpipe-app-tauri/components/rewind/search-command.tsx
@@ -22,47 +22,56 @@ import { CommandShortcut } from "./ui/command";
import { commands } from "@/lib/utils/tauri";
import { Button } from "@/components/ui/button";
import { useSettings } from "@/lib/hooks/use-settings";
+import { useMcpClient } from "@/lib/hooks/use-mcp-client";
import { Badge } from "./ui/badge";
import ReactMarkdown from "react-markdown";
const SCREENPIPE_API = "http://localhost:3030";
const VERTEX_PROXY = "https://ai-proxy.i-f9f.workers.dev";
-// Tool definitions for Claude
+// Tool definitions for Claude - matches screenpipe-mcp search_content tool
const TOOLS = [
{
- name: "search_screenpipe",
+ name: "search_content",
description:
- "Search through the user's screen recordings, audio transcriptions, and UI elements. " +
- "Returns timestamped results with app context. Use this to find what the user was doing, " +
- "what they saw on screen, what was said in meetings, etc.",
+ "Search screenpipe's recorded content: screen text (OCR), audio transcriptions, and UI elements. " +
+ "Returns timestamped results with app context. " +
+ "Call with no parameters to get recent activity.",
input_schema: {
type: "object" as const,
properties: {
q: {
type: "string",
- description: "Search query text. Optional - omit to get recent activity.",
+ description: "Search query. Optional - omit to return all recent content.",
},
content_type: {
type: "string",
enum: ["all", "ocr", "audio", "ui"],
- description: "Type of content to search. 'ocr' for screen text, 'audio' for transcriptions, 'ui' for UI elements. Default: 'all'",
+ description: "Content type filter. Default: 'all'",
},
limit: {
type: "integer",
- description: "Maximum number of results to return. Default: 10",
+ description: "Max results. Default: 10",
+ },
+ offset: {
+ type: "integer",
+ description: "Skip N results for pagination. Default: 0",
},
start_time: {
type: "string",
- description: "ISO 8601 UTC start time filter (e.g., 2024-01-15T10:00:00Z)",
+ description: "ISO 8601 UTC start time (e.g., 2024-01-15T10:00:00Z)",
},
end_time: {
type: "string",
- description: "ISO 8601 UTC end time filter (e.g., 2024-01-15T18:00:00Z)",
+ description: "ISO 8601 UTC end time (e.g., 2024-01-15T18:00:00Z)",
},
app_name: {
type: "string",
- description: "Filter by application name (e.g., 'Google Chrome', 'Slack', 'zoom.us')",
+ description: "Filter by app (e.g., 'Google Chrome', 'Slack', 'zoom.us')",
+ },
+ window_name: {
+ type: "string",
+ description: "Filter by window title",
},
},
},
@@ -91,6 +100,7 @@ export function SearchCommand() {
const [open, setOpen] = React.useState(false);
const { settings } = useSettings();
const user = settings.user;
+ const { callTool: mcpCallTool, isConnected: mcpConnected } = useMcpClient();
const [state] = useQueryStates(queryParser);
const [options, setOptions] = useState<QueryParser>(
@@ -190,48 +200,55 @@ export function SearchCommand() {
}
}
- // Execute search tool for AI
+ // Execute search tool via MCP SDK client
async function executeSearchTool(args: Record<string, unknown>): Promise<string> {
try {
- const params = new URLSearchParams();
- if (args.q) params.append("q", String(args.q));
- if (args.content_type && args.content_type !== "all") {
- params.append("content_type", String(args.content_type));
- }
- if (args.limit) params.append("limit", String(args.limit));
- else params.append("limit", "10");
- if (args.start_time) params.append("start_time", String(args.start_time));
- if (args.end_time) params.append("end_time", String(args.end_time));
- if (args.app_name) params.append("app_name", String(args.app_name));
+ // Use MCP SDK client to call search_content tool
+ const result = await mcpCallTool("search_content", args);
+ return result || "No results found.";
+ } catch (error) {
+ console.error("MCP search error:", error);
+ // Fallback to direct API call if MCP server is not running
+ try {
+ const params = new URLSearchParams();
+ if (args.q) params.append("q", String(args.q));
+ if (args.content_type && args.content_type !== "all") {
+ params.append("content_type", String(args.content_type));
+ }
+ if (args.limit) params.append("limit", String(args.limit));
+ else params.append("limit", "10");
+ if (args.start_time) params.append("start_time", String(args.start_time));
+ if (args.end_time) params.append("end_time", String(args.end_time));
+ if (args.app_name) params.append("app_name", String(args.app_name));
- const response = await fetch(`${SCREENPIPE_API}/search?${params.toString()}`);
- if (!response.ok) throw new Error(`Search failed: ${response.status}`);
+ const response = await fetch(`${SCREENPIPE_API}/search?${params.toString()}`);
+ if (!response.ok) throw new Error(`Search failed: ${response.status}`);
- const data = await response.json();
- const searchResults = data.data || [];
+ const data = await response.json();
+ const searchResults = data.data || [];
- if (searchResults.length === 0) {
- return "No results found. Try broader search terms or a wider time range.";
- }
+ if (searchResults.length === 0) {
+ return "No results found. Try broader search terms or a wider time range.";
+ }
- const formatted = searchResults.map((result: SearchResult) => {
- const content = result.content;
- if (!content) return null;
+ const formatted = searchResults.map((result: SearchResult) => {
+ const content = result.content;
+ if (!content) return null;
- if (result.type === "OCR") {
- return `[Screen - ${content.app_name || "Unknown"}] ${content.timestamp}\n${content.text || ""}`;
- } else if (result.type === "Audio") {
- return `[Audio - ${content.device_name || "Unknown"}] ${content.timestamp}\n${content.transcription || ""}`;
- } else if (result.type === "UI") {
- return `[UI - ${content.app_name || "Unknown"}] ${content.timestamp}\n${content.text || ""}`;
- }
- return null;
- }).filter(Boolean);
+ if (result.type === "OCR") {
+ return `[Screen - ${content.app_name || "Unknown"}] ${content.timestamp}\n${content.text || ""}`;
+ } else if (result.type === "Audio") {
+ return `[Audio - ${content.device_name || "Unknown"}] ${content.timestamp}\n${content.transcription || ""}`;
+ } else if (result.type === "UI") {
+ return `[UI - ${content.app_name || "Unknown"}] ${content.timestamp}\n${content.text || ""}`;
+ }
+ return null;
+ }).filter(Boolean);
- return `Found ${searchResults.length} results:\n\n${formatted.join("\n\n---\n\n")}`;
- } catch (error) {
- console.error("Search error:", error);
- return `Search failed: ${error instanceof Error ? error.message : "Unknown error"}`;
+ return `Found ${searchResults.length} results:\n\n${formatted.join("\n\n---\n\n")}`;
+ } catch (fallbackError) {
+ return `Search failed: ${fallbackError instanceof Error ? fallbackError.message : "Unknown error"}`;
+ }
}
}
diff --git a/screenpipe-app-tauri/lib/hooks/use-mcp-client.ts b/screenpipe-app-tauri/lib/hooks/use-mcp-client.ts
new file mode 100644
index 000000000..4dd38f19d
--- /dev/null
+++ b/screenpipe-app-tauri/lib/hooks/use-mcp-client.ts
@@ -0,0 +1,121 @@
+"use client";
+
+import { useState, useEffect, useCallback, useRef } from "react";
+import { Client } from "@modelcontextprotocol/sdk/client/index.js";
+import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
+
+const MCP_URL = "http://localhost:3031/mcp";
+
+interface McpClientState {
+ isConnected: boolean;
+ isConnecting: boolean;
+ error: string | null;
+}
+
+export function useMcpClient() {
+ const [state, setState] = useState<McpClientState>({
+ isConnected: false,
+ isConnecting: false,
+ error: null,
+ });
+ const clientRef = useRef<Client | null>(null);
+ const transportRef = useRef<StreamableHTTPClientTransport | null>(null);
+
+ // Connect to MCP server
+ const connect = useCallback(async () => {
+ if (clientRef.current || state.isConnecting) return;
+
+ setState((prev) => ({ ...prev, isConnecting: true, error: null }));
+
+ try {
+ const transport = new StreamableHTTPClientTransport(new URL(MCP_URL));
+ transportRef.current = transport;
+
+ const client = new Client(
+ { name: "screenpipe-app", version: "1.0.0" },
+ { capabilities: {} }
+ );
+
+ await client.connect(transport);
+ clientRef.current = client;
+
+ setState({ isConnected: true, isConnecting: false, error: null });
+ } catch (error) {
+ console.error("MCP connection error:", error);
+ setState({
+ isConnected: false,
+ isConnecting: false,
+ error: error instanceof Error ? error.message : "Failed to connect to MCP server",
+ });
+ }
+ }, [state.isConnecting]);
+
+ // Disconnect from MCP server
+ const disconnect = useCallback(async () => {
+ if (transportRef.current) {
+ await transportRef.current.close();
+ transportRef.current = null;
+ }
+ clientRef.current = null;
+ setState({ isConnected: false, isConnecting: false, error: null });
+ }, []);
+
+ // Call a tool on the MCP server
+ const callTool = useCallback(
+ async (name: string, args: Record<string, unknown>): Promise<string> => {
+ if (!clientRef.current) {
+ // Try to connect first
+ await connect();
+ if (!clientRef.current) {
+ throw new Error("MCP client not connected");
+ }
+ }
+
+ try {
+ const result = await clientRef.current.callTool({
+ name,
+ arguments: args,
+ });
+
+ // Extract text content from result
+ const textContent = result.content
+ ?.filter((block: any) => block.type === "text")
+ .map((block: any) => block.text)
+ .join("\n");
+
+ return textContent || "No results";
+ } catch (error) {
+ console.error("MCP tool call error:", error);
+ throw error;
+ }
+ },
+ [connect]
+ );
+
+ // List available tools
+ const listTools = useCallback(async () => {
+ if (!clientRef.current) {
+ await connect();
+ if (!clientRef.current) {
+ throw new Error("MCP client not connected");
+ }
+ }
+
+ return await clientRef.current.listTools();
+ }, [connect]);
+
+ // Cleanup on unmount
+ useEffect(() => {
+ return () => {
+ disconnect();
+ };
+ }, [disconnect]);
+
+ return {
+ ...state,
+ connect,
+ disconnect,
+ callTool,
+ listTools,
+ };
+}
diff --git a/screenpipe-app-tauri/src-tauri/src/commands.rs b/screenpipe-app-tauri/src-tauri/src/commands.rs
index eed9217b5..d9bd1f378 100644
--- a/screenpipe-app-tauri/src-tauri/src/commands.rs
+++ b/screenpipe-app-tauri/src-tauri/src/commands.rs
@@ -429,8 +429,6 @@ pub async fn show_shortcut_reminder(
// Use to_panel() on window_clone directly instead of get_webview_panel
// This avoids race conditions with panel registration
if let Ok(panel) = window_clone.to_panel() {
- use tauri_nspanel::objc::{msg_send, sel, sel_impl};
-
// Level 1001 = above CGShieldingWindowLevel, shows over fullscreen
panel.set_level(1001);
panel.set_style_mask(0);
@@ -440,18 +438,6 @@ pub async fn show_shortcut_reminder(
NSWindowCollectionBehavior::NSWindowCollectionBehaviorFullScreenAuxiliary |
NSWindowCollectionBehavior::NSWindowCollectionBehaviorStationary
);
- // Enable hover/mouse events without requiring focus
- unsafe {
- use std::ops::Deref;
- use tauri_nspanel::cocoa::base::YES;
- let panel_ptr = panel.deref() as *const _ as *mut objc::runtime::Object;
- let _: () = msg_send![panel_ptr, setFloatingPanel: YES];
- let _: () = msg_send![panel_ptr, setAcceptsMouseMovedEvents: YES];
- let _: () = msg_send![panel_ptr, setBecomesKeyOnlyIfNeeded: YES];
- // Allow first click to work without activating
- let content_view: *mut objc::runtime::Object = msg_send![panel_ptr, contentView];
- let _: () = msg_send![content_view, setAcceptsFirstMouse: YES];
- }
// Order front regardless to show above fullscreen
panel.order_front_regardless();
info!("Panel configured for fullscreen support");
diff --git a/screenpipe-integrations/screenpipe-mcp/package.json b/screenpipe-integrations/screenpipe-mcp/package.json
index c38431384..fb40d31fa 100644
--- a/screenpipe-integrations/screenpipe-mcp/package.json
+++ b/screenpipe-integrations/screenpipe-mcp/package.json
@@ -9,7 +9,9 @@
"scripts": {
"build": "tsc",
"start": "node dist/index.js",
+ "start:http": "node dist/http-server.js",
"dev": "ts-node src/index.ts",
+ "dev:http": "ts-node src/http-server.ts",
"test": "vitest run",
"test:watch": "vitest",
"prepublishOnly": "npm run build"
diff --git a/screenpipe-integrations/screenpipe-mcp/src/http-server.ts b/screenpipe-integrations/screenpipe-mcp/src/http-server.ts
new file mode 100644
index 000000000..dad560c9f
--- /dev/null
+++ b/screenpipe-integrations/screenpipe-mcp/src/http-server.ts
@@ -0,0 +1,243 @@
+#!/usr/bin/env node
+
+/**
+ * HTTP Server for Screenpipe MCP
+ *
+ * This allows web apps to call MCP tools over HTTP instead of stdio.
+ * Run with: npx ts-node src/http-server.ts --port 3031
+ */
+
+import { createServer } from "http";
+import { Server } from "@modelcontextprotocol/sdk/server/index.js";
+import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
+import {
+ CallToolRequestSchema,
+ ListToolsRequestSchema,
+} from "@modelcontextprotocol/sdk/types.js";
+
+// Parse command line arguments
+const args = process.argv.slice(2);
+let mcpPort = 3031;
+let screenpipePort = 3030;
+
+for (let i = 0; i < args.length; i++) {
+ if (args[i] === "--port" && args[i + 1]) {
+ mcpPort = parseInt(args[i + 1], 10);
+ }
+ if (args[i] === "--screenpipe-port" && args[i + 1]) {
+ screenpipePort = parseInt(args[i + 1], 10);
+ }
+}
+
+const SCREENPIPE_API = `http://localhost:${screenpipePort}`;
+
+// Tool definitions
+const TOOLS = [
+ {
+ name: "search_content",
+ description:
+ "Search screenpipe's recorded content: screen text (OCR), audio transcriptions, and UI elements. " +
+ "Returns timestamped results with app context. " +
+ "Call with no parameters to get recent activity.",
+ inputSchema: {
+ type: "object" as const,
+ properties: {
+ q: {
+ type: "string",
+ description: "Search query. Optional - omit to return all recent content.",
+ },
+ content_type: {
+ type: "string",
+ enum: ["all", "ocr", "audio", "ui"],
+ description: "Content type filter. Default: 'all'",
+ },
+ limit: {
+ type: "integer",
+ description: "Max results. Default: 10",
+ },
+ offset: {
+ type: "integer",
+ description: "Skip N results for pagination. Default: 0",
+ },
+ start_time: {
+ type: "string",
+ description: "ISO 8601 UTC start time (e.g., 2024-01-15T10:00:00Z)",
+ },
+ end_time: {
+ type: "string",
+ description: "ISO 8601 UTC end time (e.g., 2024-01-15T18:00:00Z)",
+ },
+ app_name: {
+ type: "string",
+ description: "Filter by app (e.g., 'Google Chrome', 'Slack', 'zoom.us')",
+ },
+ window_name: {
+ type: "string",
+ description: "Filter by window title",
+ },
+ },
+ },
+ },
+];
+
+// Helper function to make HTTP requests
+async function fetchAPI(endpoint: string, options: RequestInit = {}): Promise<Response> {
+ const url = `${SCREENPIPE_API}${endpoint}`;
+ return fetch(url, {
+ ...options,
+ headers: {
+ "Content-Type": "application/json",
+ ...options.headers,
+ },
+ });
+}
+
+// Create MCP server
+const server = new Server(
+ {
+ name: "screenpipe-http",
+ version: "0.1.0",
+ },
+ {
+ capabilities: {
+ tools: {},
+ },
+ }
+);
+
+// List tools handler
+server.setRequestHandler(ListToolsRequestSchema, async () => {
+ return { tools: TOOLS };
+});
+
+// Call tool handler
+server.setRequestHandler(CallToolRequestSchema, async (request) => {
+ const { name, arguments: args } = request.params;
+
+ if (!args) {
+ throw new Error("Missing arguments");
+ }
+
+ if (name === "search_content") {
+ const params = new URLSearchParams();
+ for (const [key, value] of Object.entries(args)) {
+ if (value !== null && value !== undefined) {
+ params.append(key, String(value));
+ }
+ }
+
+ const response = await fetchAPI(`/search?${params.toString()}`);
+ if (!response.ok) {
+ throw new Error(`HTTP error: ${response.status}`);
+ }
+
+ const data = await response.json();
+ const results = data.data || [];
+ const pagination = data.pagination || {};
+
+ if (results.length === 0) {
+ return {
+ content: [
+ {
+ type: "text",
+ text: "No results found. Try: broader search terms, different content_type, or wider time range.",
+ },
+ ],
+ };
+ }
+
+ const formattedResults: string[] = [];
+ for (const result of results) {
+ const content = result.content;
+ if (!content) continue;
+
+ if (result.type === "OCR") {
+ formattedResults.push(
+ `[OCR] ${content.app_name || "?"} | ${content.window_name || "?"}\n` +
+ `${content.timestamp || ""}\n` +
+ `${content.text || ""}`
+ );
+ } else if (result.type === "Audio") {
+ formattedResults.push(
+ `[Audio] ${content.device_name || "?"}\n` +
+ `${content.timestamp || ""}\n` +
+ `${content.transcription || ""}`
+ );
+ } else if (result.type === "UI") {
+ formattedResults.push(
+ `[UI] ${content.app_name || "?"} | ${content.window_name || "?"}\n` +
+ `${content.timestamp || ""}\n` +
+ `${content.text || ""}`
+ );
+ }
+ }
+
+ const header = `Results: ${results.length}/${pagination.total || "?"}` +
+ (pagination.total > results.length ? ` (use offset=${(pagination.offset || 0) + results.length} for more)` : "");
+
+ return {
+ content: [
+ {
+ type: "text",
+ text: header + "\n\n" + formattedResults.join("\n---\n"),
+ },
+ ],
+ };
+ }
+
+ throw new Error(`Unknown tool: ${name}`);
+});
+
+// Create HTTP server with MCP transport
+const transports = new Map<string, StreamableHTTPServerTransport>();
+
+const httpServer = createServer(async (req, res) => {
+ // CORS headers
+ res.setHeader("Access-Control-Allow-Origin", "*");
+ res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
+ res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization, mcp-session-id");
+
+ if (req.method === "OPTIONS") {
+ res.writeHead(204);
+ res.end();
+ return;
+ }
+
+ // Health check
+ if (req.url === "/health") {
+ res.writeHead(200, { "Content-Type": "application/json" });
+ res.end(JSON.stringify({ status: "ok" }));
+ return;
+ }
+
+ // MCP endpoint
+ if (req.url === "/mcp" || req.url?.startsWith("/mcp?")) {
+ const sessionId = req.headers["mcp-session-id"] as string | undefined;
+
+ let transport = sessionId ? transports.get(sessionId) : undefined;
+
+ if (!transport) {
+ transport = new StreamableHTTPServerTransport({
+ sessionIdGenerator: () => crypto.randomUUID(),
+ });
+
+ await server.connect(transport);
+
+ if (transport.sessionId) {
+ transports.set(transport.sessionId, transport);
+ }
+ }
+
+ await transport.handleRequest(req, res);
+ return;
+ }
+
+ res.writeHead(404, { "Content-Type": "application/json" });
+ res.end(JSON.stringify({ error: "Not found" }));
+});
+
+httpServer.listen(mcpPort, () => {
+ console.log(`Screenpipe MCP HTTP server running on http://localhost:${mcpPort}`);
+ console.log(`MCP endpoint: http://localhost:${mcpPort}/mcp`);
+ console.log(`Health check: http://localhost:${mcpPort}/health`);
+});