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
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
feat(screenpipe-mcp): expose team telemetry tools when sk_ent_… present
Louis Beaumont3d780d6c7a6a
diff --git a/packages/screenpipe-mcp/package.json b/packages/screenpipe-mcp/package.jsonindex 7c7da0fec..425558144 100644--- a/packages/screenpipe-mcp/package.json+++ b/packages/screenpipe-mcp/package.json@@ -1,6 +1,6 @@{"name": "screenpipe-mcp",- "version": "0.18.2",+ "version": "0.18.3","description": "MCP server for screenpipe - search your screen recordings and audio transcriptions","main": "dist/index.js","bin": {diff --git a/packages/screenpipe-mcp/src/index.ts b/packages/screenpipe-mcp/src/index.tsindex 38a10c267..aff3c547a 100644--- a/packages/screenpipe-mcp/src/index.ts+++ b/packages/screenpipe-mcp/src/index.ts@@ -194,6 +194,49 @@ function discoverApiKey(): string {const API_KEY = discoverApiKey();+// Enterprise team token — when present, this MCP additionally registers+// `team-*` tools that query the org-wide telemetry control plane+// (https://screenpi.pe/api/enterprise/v1/*) instead of just the local+// recordings. Same audience: an enterprise admin running screenpipe-mcp+// inside Claude Desktop / Cursor / Windsurf wants to ask "what did MY+// machine do" AND "what did MY TEAM do" without juggling two MCPs.+//+// Resolution order matches discoverApiKey() in spirit:+// 1. SCREENPIPE_ENTERPRISE_TOKEN env var (Claude config, terminal)+// 2. team_api_token field in ~/.screenpipe/enterprise.json (written by+// the desktop app's Settings → Privacy → Admin Team API Token)+//+// Token format is `sk_ent_…`. Empty / missing → team tools are not+// registered; non-admin users of screenpipe-mcp see exactly what they+// see today.+function discoverTeamToken(): string {+ const envTok = process.env.SCREENPIPE_ENTERPRISE_TOKEN;+ if (envTok && envTok.startsWith("sk_ent_")) return envTok;+ try {+ const entPath = path.join(os.homedir(), ".screenpipe", "enterprise.json");+ if (fs.existsSync(entPath)) {+ const raw = fs.readFileSync(entPath, "utf-8");+ const parsed = JSON.parse(raw);+ const tok = typeof parsed?.team_api_token === "string" ? parsed.team_api_token : "";+ if (tok && tok.startsWith("sk_ent_")) return tok;+ }+ } catch {}+ return "";+}++const TEAM_TOKEN = discoverTeamToken();+const TEAM_API = "https://screenpi.pe/api/enterprise/v1";++async function fetchTeam(p: string, init: RequestInit = {}): Promise<Response> {+ return fetch(`${TEAM_API}${p}`, {+ ...init,+ headers: {+ Authorization: `Bearer ${TEAM_TOKEN}`,+ ...(init.headers || {}),+ },+ });+}+// Read version from package.json (single source of truth)// eslint-disable-next-line @typescript-eslint/no-var-requiresconst PKG_VERSION: string = require("../package.json").version;@@ -598,8 +641,74 @@ const TOOLS: Tool[] = [},];+// ---------------------------------------------------------------------------+// Enterprise team tools — registered only when a team API token is present.+// Same endpoint surface as the desktop `screenpipe-team` pi-agent skill:+// proxy GETs to https://screenpi.pe/api/enterprise/v1/* with Bearer auth.+//+// Naming convention: every team tool is `team-*` so it's obvious at a glance+// which scope (just-me vs the-whole-org) any given call is hitting.+// ---------------------------------------------------------------------------+const TEAM_TOOLS: Tool[] = [+ {+ name: "team-search",+ description:+ "Substring-search across the ENTIRE ORG's telemetry (every enrolled " ++ "device). Use when the question is about the team or another teammate " ++ "(\"what did engineering work on yesterday\", \"did alice touch the auth code\"). " ++ "For your own machine only, use search-content. " ++ "Auth: enterprise admin token (sk_ent_…). " ++ "Defaults: since=now-24h, limit=50. Returns matched records with device + timestamp.",+ annotations: { title: "Team Search", readOnlyHint: true, openWorldHint: true, idempotentHint: true },+ inputSchema: {+ type: "object",+ properties: {+ q: { type: "string", description: "Substring to match (case-insensitive). Empty = all records in window." },+ device_id: { type: "string", description: "Restrict to one device. Get the ID from team-devices." },+ app_name: { type: "string", description: "Restrict to records whose app_name equals this (case-insensitive)." },+ since: { type: "string", description: "ISO 8601 lower bound. Default = now - 24h." },+ until: { type: "string", description: "ISO 8601 upper bound. Default = now." },+ since_hours_ago: { type: "integer", description: "Convenience: equivalent to since=now-N*h." },+ limit: { type: "integer", description: "Max records (default 50, max 200).", default: 50 },+ },+ },+ },+ {+ name: "team-devices",+ description:+ "List all devices enrolled under this org's license — hostname, OS, " ++ "app version, last-seen timestamp. Use to discover device IDs to pass " ++ "to team-search or team-records, or to spot stale machines.",+ annotations: { title: "Team Devices", readOnlyHint: true, openWorldHint: true, idempotentHint: true },+ inputSchema: { type: "object", properties: {} },+ },+ {+ name: "team-records",+ description:+ "Chronological raw dump of the org's telemetry for a time window. " ++ "Returns oldest → newest (vs team-search which is recency-ranked). " ++ "Use for ETL or \"walk me through X from Y to Z\" — NOT for question-answering, use team-search for that. " ++ "Auth: enterprise admin token.",+ annotations: { title: "Team Records", readOnlyHint: true, openWorldHint: true, idempotentHint: true },+ inputSchema: {+ type: "object",+ properties: {+ device_id: { type: "string", description: "Restrict to one device (optional)." },+ kind: { type: "string", enum: ["frame", "audio", "all"], description: "Record kind filter. Default: all.", default: "all" },+ since: { type: "string", description: "ISO 8601 lower bound." },+ until: { type: "string", description: "ISO 8601 upper bound." },+ since_hours_ago: { type: "integer", description: "Convenience: equivalent to since=now-N*h." },+ limit: { type: "integer", description: "Max records (default 50, max 200).", default: 50 },+ },+ },+ },+];+server.setRequestHandler(ListToolsRequestSchema, async () => {- return { tools: TOOLS };+ // Team tools only surface when an enterprise token was discovered at boot.+ // No token = consumer / non-admin user; their MCP looks identical to today.+ const tools = TEAM_TOKEN ? [...TOOLS, ...TEAM_TOOLS] : TOOLS;+ return { tools };});// ---------------------------------------------------------------------------@@ -1515,6 +1624,54 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {};}+ // ---------------------------------------------------------------------+ // Enterprise team tools — only callable when TEAM_TOKEN is set at boot.+ // If we got this far without one, the tool wasn't in the listed set the+ // host saw, but a misbehaving client could still try to call it. Fail+ // loudly so the host surfaces the misconfiguration.+ // ---------------------------------------------------------------------+ case "team-search":+ case "team-devices":+ case "team-records": {+ if (!TEAM_TOKEN) {+ return {+ content: [+ {+ type: "text",+ text:+ `team-* tools require an enterprise admin token. Set ` ++ `SCREENPIPE_ENTERPRISE_TOKEN in your MCP env, or mint one ` ++ `at https://screenpi.pe/enterprise → API Tokens and paste ` ++ `it into Settings → Privacy → Admin Team API Token in the ` ++ `screenpipe desktop app.`,+ },+ ],+ };+ }+ // Map MCP tool name → /api/enterprise/v1 path+ const subpath =+ name === "team-search" ? "/search"+ : name === "team-devices" ? "/devices"+ : "/records";+ // Forward every primitive arg as a query param. The server validates;+ // unknown params are ignored, so we don't need to gatekeep here.+ const params = new URLSearchParams();+ for (const [k, v] of Object.entries(args)) {+ if (v !== null && v !== undefined && v !== "") {+ params.append(k, String(v));+ }+ }+ const query = params.toString();+ const response = await fetchTeam(`${subpath}${query ? `?${query}` : ""}`);+ const body = await response.text();+ if (!response.ok) {+ throw new Error(+ `${name} failed: HTTP ${response.status} ${response.statusText} — ${body.slice(0, 300)}`+ );+ }+ return { content: [{ type: "text", text: body }] };+ }+default:throw new Error(`Unknown tool: ${name}`);}