# Dify.AI SDK MCP

> The Dify.AI SDK lets your agent programmatically interact with a specialized AI platform. You can send messages to published chatbots, run multi-step workflows using dynamic parameters, fetch historical chat records, and even submit model feedback for tuning. This gives you total control over the lifecycle of an AI application.

## Overview
- **Category:** developer-apis
- **Price:** Free
- **Tags:** dify, llm-ops, agent-orchestration, workflow, chatbot

## Description

Building complex applications often means more than just sending a prompt. It requires state management, background processing, and continuous improvement loops. With this MCP, your agent connects directly to Dify's core platform, giving it access to dozens of specialized functions. You can trigger multi-step workflows with precise JSON inputs, ensuring the AI executes logic beyond simple conversation. Need to track a user's journey? Use the tools here to retrieve entire conversation histories or simply list recent activity. The ability to manage chat sessions and even submit 'like/dislike' ratings means you can build complete agent pipelines—from initial query through execution, all the way to model refinement. Accessing this via Vinkius means your AI client handles the connection; you just tell it what needs to happen.

## Tools

### delete_conversation
Removes an entire conversation history from the platform.

### submit_feedback
Records user feedback (like or dislike) on an agent's message for model improvement.

### get_suggested_questions
Returns suggested follow-up questions after an agent sends a message, helping guide the conversation.

### chat_message
Sends text to a specific Dify Application and gets an immediate response.

### get_app_meta
Retrieves basic configuration details about a Dify application.

### get_conversation_messages
Fetches all the message content from a specific chat thread.

### get_conversations
Lists the most recent chats associated with your account.

### get_workflow_info
Gets general information and status details for a Dify workflow application.

### get_workflow_parameters
Retrieves the list of required inputs (parameters) needed to run a specific workflow.

### rename_conversation
Changes the title of an existing conversation thread.

### run_workflow
Executes a complex, parameterized Dify Workflow application to complete a task.

### send_completion
Sends a request to get the full generated text output from an AI model completion app.

### stop_chat_generation
Halts a chat response that is currently streaming in real-time.

### upload_file
Uploads a file using a URL so the AI can analyze its content, supporting multimodal tasks.

## Prompt Examples

**Prompt:** 
```
Check my recent Dify conversations and tell me the name of the last one.
```

**Response:** 
```
Your last conversation in Dify is titled 'Data Processing Bot' (ID: conv-123).
```

## Capabilities

### Manage Chat Interactions
Send new messages to a chatbot and retrieve past message threads for context.

### Execute Background Workflows
Trigger complex, multi-step AI processes using specific data parameters.

### Maintain Conversation State
List, rename, or delete conversation histories to keep records clean and organized.

### Improve Model Tuning
Submit user feedback (like/dislike) directly to the platform to improve model accuracy over time.

### Process External Data
Upload files via URL, allowing the AI agent to perform multimodal understanding on documents or images.

## Use Cases

### Analyzing User Support Tickets
A support engineer needs the system to process a user-uploaded PDF (via `upload_file`) and then run that data through a specialized internal knowledge base workflow (using `run_workflow`). The agent reads the file, executes the logic, and returns a summarized action plan.

### Building Stateful Chatbots
A financial service bot needs to remember details from earlier in the chat. It first calls `get_conversations` to confirm the user's identity, then uses `chat_message` for the main interaction, and finally uses `get_suggested_questions` to guide them to the next logical step.

### Automating Model Improvement
The product team wants to track how often users complain. After a chat exchange, the agent automatically prompts the user and then executes `submit_feedback`, recording whether the response was helpful or not for later tuning.

### Background Data Processing
A data pipeline needs to process a large dataset without waiting for a live chat. The system triggers a dedicated workflow using `run_workflow` with parameters like 'dataset_id' and 'processing_date', getting a final status report back.

## Benefits

- You gain granular control over conversation state, allowing your agent to use `get_conversations` and `get_conversation_messages` to build context-aware interactions.
- Instead of relying on single prompts, you can trigger multi-step logic by calling `run_workflow`, passing structured data parameters to achieve specific business outcomes.
- The ability to manage the lifecycle is key. Use `rename_conversation` or `delete_conversation` when cleanup or record maintenance becomes necessary.
- For model quality assurance, `submit_feedback` lets your application automatically capture user sentiment, feeding that data back into the AI training pipeline.
- Multimodality is built-in. The `upload_file` tool means your agent doesn't just read text; it can analyze documents or images you link to.

## How It Works

The bottom line is this: you pass structured instructions to your agent client, and the MCP handles the complex API calls required to make those instructions happen in Dify.AI.

1. First, your developer client needs an API key and a base URL for Dify.AI.
2. Next, you instruct your agent to call the necessary function, like `run_workflow`, providing all required parameters (e.g., workflow ID, input JSON).
3. The MCP executes the request, returning data—whether it's a chat response, a list of conversations, or confirmation that the process ran successfully.

## Frequently Asked Questions

**How do I check my chat history using get_conversations? **
You call `get_conversations` to pull a list of recent conversation IDs and titles. This provides the necessary context before you use `get_conversation_messages` to fetch the detailed content.

**Can I stop an AI response if it's too long? **
Yes, that's where `stop_chat_generation` comes in. It only works when the chat message is streaming, allowing your agent to interrupt the generation process mid-stream.

**What if I need to analyze a PDF file? **
First, you must use `upload_file`. This function handles uploading content from a URL so that subsequent tools, like workflow execution, can access and understand the document's contents.

**Does run_workflow need parameters? **
Yes. Before running any complex task, you should use `get_workflow_parameters` to see exactly which inputs your workflow requires. This prevents runtime errors.

**How do I set up my credentials when calling get_app_meta?**
Authentication requires an API key, which you must provide to your Vinkius client. The tool needs the Base URL and a valid API Key to successfully retrieve application configuration metadata.

**If I run into issues with my logic, how do I handle failures using run_workflow?**
The response from run_workflow includes detailed status codes and execution logs. Your agent reads these logs to pinpoint the failure point, allowing you to implement specific retry or fallback logic.

**When I use get_conversation_messages, how do I ensure I retrieve all necessary history?**
You must pass a conversation ID and optionally a time range. The tool retrieves the full message payload for that session, ensuring your agent has complete context beyond simple summaries.

**Are there any rate limits when sending messages with chat_message?**
Yes, Dify enforces standard API rate limits based on your account tier. If you hit a limit, the client receives an HTTP 429 error code, prompting you to implement backoff logic.

**Does this work with self-hosted Dify?**
Yes, simply replace the Base URL credential with your own domain (e.g. `https://dify.mycompany.com/v1`).