A FastMCP server that wraps the Factory.ai Droid Swarm API, deployed as a Cloudflare Worker. Designed for use as a Composio MCP tool (factory_droid_swarm) integrated with Perplexity.
-
Environment secrets (set via
wrangler secret put):FACTORY_API_KEY— Your Factory.ai API key (stored in Doppler)FACTORY_SHIM_URL— Base URL for the Legion shim (e.g.https://<...>.trycloudflare.com)FACTORY_SHIM_SECRET— Shared HMAC secret used to sign shim requestsMCP_CLIENTS— KV namespace binding for registered OAuth clients, auth codes, and tokens
-
Deploy (Cloudflare Workers):
npx wrangler deploy
-
Endpoint:
https://<your-worker>.workers.dev/mcp
This worker now exposes a minimal authorization server for Perplexity custom MCP connectors:
GET /.well-known/oauth-authorization-serverGET /.well-known/oauth-protected-resourcePOST /registerGET /authorize(single-user auto-approve mode)POST /token
Flow:
- Connector reads OAuth metadata from
/.well-known/oauth-authorization-server. - Connector dynamically registers with
POST /registerand receivesclient_id+client_secret(confidential client default:token_endpoint_auth_method=client_secret_post). - Connector sends user to
GET /authorizewith PKCE (code_challenge_method=S256). - Worker auto-approves (single-user mode) and redirects with
code. - Connector exchanges code at
POST /tokenforaccess_token+refresh_tokenusing eitherclient_secret_post(form body) orclient_secret_basic(HTTP Basic auth). POST /mcprequiresAuthorization: Bearer <access_token>and validates token from KV.
The shim HMAC flow (factory_exec -> FACTORY_SHIM_URL) is unchanged.
List all connected Factory Droid computers (execution hosts).
- Returns: computer IDs, names, provider types, and status.
- No parameters.
Launch a new Factory Droid session.
prompt(string, required) — Task prompt for the droid.computerId(string, optional) — Target computer (defaults to first active).model(string, optional) — Model to use (e.g.claude-opus-4-7,claude-sonnet-4-6,gpt-5).autonomy(enum, optional) —off,low,medium,high.reasoningEffort(enum, optional) —none,minimal,low,medium,high,xhigh,max.
Launch multiple droids in parallel (fan-out).
prompts(string[], required) — List of 1–50 prompt strings.computerId(string, optional).model(string, optional).autonomy(enum, optional).
Spawn a droid, poll until it completes (goes idle), then return the full message log. Single-call alternative to spawn + poll + fetch messages.
prompt(string, required) — Task prompt for the droid.model(string, optional).autonomy(enum, optional).reasoningEffort(enum, optional).computerId(string, optional).pollIntervalSeconds(number, optional, default 15) — Seconds between status polls (5–60).timeoutSeconds(number, optional, default 600) — Max seconds to wait (30–3600).
List recent droid sessions with full session UUIDs.
status(enum, optional) — Filter byidle,pending, orrunning.limit(number, optional, default 20, max 100) — Max sessions to return.
Get all currently active (pending/running) droid sessions.
- Full session IDs, current status, message count, last message preview, and elapsed time.
- No parameters.
Get detailed status and recent messages for a specific droid session.
sessionId(string, required) — Droid session ID to fetch.
Get ALL messages from a droid session (not just recent ones), with role labels (user/assistant) and timestamps.
sessionId(string, required) — Droid session ID.maxMessages(number, optional, default 200, max 500) — Max messages to return.
Send a message to a running droid session.
sessionId(string, required) — Target droid session ID.text(string, required) — Message text to send.
Continue a dead (idle) session by fetching its full message log and spawning a NEW droid with that context plus a follow-up prompt.
sessionId(string, required) — Completed session ID to resume from.followupPrompt(string, required) — Follow-up task for the new droid.model(string, optional).autonomy(enum, optional).computerId(string, optional).
Interrupt a running droid session. Idempotent — safe to call on already-idle droids.
sessionId(string, required) — Droid session ID to interrupt.
Execute a prompt through the Legion shim endpoint (POST /factory/exec) with HMAC-SHA256 request signing and streamed SSE output aggregation.
prompt(string, required) — Prompt to execute.cwd(string, optional) — Working directory hint forwarded to shim.auto(enum, optional) —high,medium,off(mapped to shim modesauto-high,auto-medium,normal).mission(string, optional) — Forwarded asmissionandsession_idfor mission/session continuity.
Call Legion shim health endpoint (GET /healthz).
- No parameters.
- Returns raw shim health JSON/text.
Base URL: https://api.factory.ai/api/v0
| Endpoint | Method | Description |
|---|---|---|
/computers |
GET | List computers |
/sessions |
GET | List sessions (supports ?limit=N) |
/sessions |
POST | Create a new session |
/sessions/:id |
GET | Get session details |
/sessions/:id/messages |
GET | Get messages (supports ?limit=N) |
/sessions/:id/messages |
POST | Send a message to a session |
/sessions/:id/interrupt |
POST | Interrupt a running session |
ISC