Skip to main content

⚡ Add this skill

One command

Add the Autoplay Dify skill for an existing Dify AI support agent setup.
View the docs →

Agent onboarding

Fetch this skill when a customer already uses Dify and wants its AI support agent to consume Autoplay live user activity.
View the skill →
Your Dify Agent pulls a user’s recent in-app activity on demand via the Autoplay MCP server — the agent calls it the moment it needs context to answer. One MCP connection, one tool (get_live_user_activity), and a user id wired through the agent’s input variables so the right user’s activity is always fetched.

🎬 End-to-end walkthrough


🔌 Add the Autoplay MCP server

In your Dify workspace, go to Tools (top navigation) → MCP tab → Add MCP Server (HTTP). In the modal that appears, fill in:
  • Server URL: https://mcp.autoplay.ai/mcp
  • Name & Icon: Autoplay live activity
  • Server Identifier: autoplay-live-activity (lowercase letters, numbers, underscores, hyphens — up to 24 characters)
Then click the Headers tab and click + Add Header to add the Bearer token:
KeyValue
AuthorizationBearer YOUR_MCP_KEY
Click Add & Authorize. Dify connects to the server and shows it as Authorized with 1 tool includedget_live_user_activity.

🤖 Create an Agent app

In Studio, click Create from Blank → select Agent as the app type. Give it a name (e.g. Support Agent) and create it. Inside the Agent’s Orchestrate view, find the Tools section and add get_live_user_activity from your Autoplay live activity MCP server. The tool’s parameters (product_id, user_id, limit) come from the MCP server definition — no manual configuration needed.

💬 Set the Agent instructions

The Instructions field (the system prompt) is where you tell the agent when to call the tool and how to use the activity data. Replace or append with:
Replace YOUR_PRODUCT_ID with your actual product id from your Activity provider dashboard. The {{user_id}} placeholder is a Dify input variable — see Identity below.

🔐 Identity — wire the user id into the agent

The agent needs the current user’s stable id to pass as user_id to the MCP tool. In Dify, you do this with an input variable.

1. Add the input variable

In the Agent’s Orchestrate view, find Variables (or Inputs) and add:
  • Variable name: user_id
  • Type: String

2. Reference it in the instructions

The {{user_id}} and {{product_id}} in the instructions above is how Dify substitutes the real value at runtime. The agent reads it and passes it as the user_id and product_id parameter when calling the tool. After that publish the agent.

3. Pass it when calling the Dify API

When your frontend calls the Dify API to start or continue a conversation, include user_id in the inputs object:
The value in inputs.user_id must exactly equal the id your activity source identifies the user with:
How the pieces fit: your frontend identifies the user in your activity source → Autoplay stores activity under that id → your frontend passes that same id as inputs.user_id in the Dify API call → the agent reads {{user_id}} from inputs and passes it to the MCP tool → the buckets match.
Do not use email as user_id unless email is literally the stable id your activity source uses. Activity is stored under the stable id — a mismatch means the agent fetches an empty bucket.

✅ Test the full loop

  1. Log in to your app as a test user — fires your activity source’s identify call.
  2. Click around — visit a couple of pages, click a button, submit a form.
  3. Open the Agent (via your frontend or Dify’s Preview panel) passing the matching user_id in inputs.
  4. Ask the agent: “What have I been doing in the app recently?”
  5. The agent calls get_live_user_activity and answers with what you actually just did.
Common issues:
  • 401 / Unauthorized → the Authorization header is missing or the token is wrong — revisit Add the Autoplay MCP server above.
  • Empty activity returned → identity is working but that user has no recent activity yet. Browse around in your app first, then re-test.
  • Wrong user’s activity → the user_id in inputs doesn’t match the id your activity source uses. Check both are identical.
“No recent activity” = identity mismatch. Confirm the same value in all three:
  1. the stable id your activity source identifies the user with (PostHog: posthog.identify(id), Amplitude: amplitude.setUserId(id)),
  2. the user_id passed in inputs when calling the Dify API,
  3. the {{user_id}} variable referenced in the agent instructions.
If they don’t match, activity is stored under one key and fetched with another, and the lookup comes back empty.
Once the agent is answering with real activity, jump into our Discord — we’ll confirm the tool is pulling activity cleanly and help you tune the instructions.
Next: Step 2 — Define proactive triggers