ask_logan is the chat in messages — a Vercel Edge Function calling OpenAI gpt-4.1 with function-calling tools, defended in depth, and also exposed as a local Model Context Protocol server. This page documents the moving parts.
A POST to /api/ask runs through six stages on Vercel Edge before responding with a typed SSE stream.
HMAC-SHA256(uuid, SESSION_SECRET) signed cookie. HttpOnly, SameSite=Lax, 30-day Max-Age. Verified or re-issued per request.omni-moderation-latest pre-screen on the latest user turn. Flagged content returns 400 content_policy without spending an LLM completion.INCR + EXPIRE. Three windows per request — session/day (10), IP/day (50), session/minute (3).gpt-4.1, stream_options.include_usage, six tools declared. System prompt: ~3K-token curated knowledge base + nine absolute rules.All six tools share the OpenAI function-calling schema and the MCP server schema — one source of truth in api/_knowledge.js.
/api/contact → Resend. Tagged via:chat or via:mcp.text-embedding-3-small) and cosine-searches an Upstash Vector index of 90 filings. Falls back to token overlap if vector store is unavailable.No single layer is bulletproof. Together they raise the cost of abuse well above the value of bypassing them.
Strip control + zero-width unicode. Cap length. Annotate (don't refuse) on prompt-injection signal words so the model is on notice.
Nine absolute rules appended last in the prompt (highest recency). Cover prompt-leak refusal, third-person enforcement, no fabrication, scope limits.
OpenAI moderations API. Reject abusive content before the LLM is invoked. Adds ~30ms; near-zero cost.
Mid-stream and final-output regex pass. Catches leaked prompt content or first-person Logan impersonation. Replaces with fallback.
Three sliding budgets via Upstash Redis. 10/session/day, 50/IP/day, 3/session/minute.
Explicit origin allowlist. Pinned to loganlabs.ai + www.loganlabs.ai + localhost. Cross-origin requests outside the list return 403.
The same six tools are also published over the Model Context Protocol so any MCP host (Claude Desktop, Claude Code, etc.) can attach.
mcp-server/server.js.api/_knowledge.js directly. No duplication; tool definitions and search logic stay in sync.ask-logan://knowledge for hosts that prefer reading over calling.mcp-server/README.md.gpt-4.1 for chat · text-embedding-3-small for vector · omni-moderation-latest for moderation./api/contact endpoint tagged with provenance (chat / mcp / direct).