|
| 1 | +--- |
| 2 | +title: "Publishing Dify Apps as MCP Servers" |
| 3 | +--- |
| 4 | + |
| 5 | +Dify now supports exposing your applications as [MCP](https://modelcontextprotocol.io/introduction) (Model Context Protocol) servers, enabling seamless integration with AI assistants like Claude Desktop and development environments like Cursor. This allows these tools to directly interact with your Dify apps as if they were native extensions. |
| 6 | + |
| 7 | +<Note> |
| 8 | + If you're looking to use MCP tools within Dify workflows & agents, see [here](/en/guides/tools/mcp). |
| 9 | +</Note> |
| 10 | + |
| 11 | +## Configuring Your Dify App as an MCP Server |
| 12 | + |
| 13 | +Navigate to your application's configuration interface in Dify. You'll find a new MCP Server configuration module. The feature is disabled by default to maintain security. When you toggle it on, Dify generates a unique MCP Server address for your application. This address serves as the connection point for external tools. |
| 14 | + |
| 15 | +The configuration interface allows you to define how your app appears to external systems. You can customize the tool description that explains what your app does, making it clear to Claude or Cursor when and how to use it. Parameter descriptions are equally important—they tell the AI assistant what inputs your app expects and in what format. |
| 16 | + |
| 17 | +## Integration with Claude Desktop |
| 18 | + |
| 19 | +To connect your Dify app to Claude Desktop, you'll need to edit Claude's configuration file. On macOS, this is located at `~/Library/Application Support/Claude/claude_desktop_config.json`. On Windows, find it at `%APPDATA%\Claude\claude_desktop_config.json`. |
| 20 | + |
| 21 | +Add your Dify app to the `mcpServers` section: |
| 22 | + |
| 23 | +``` |
| 24 | +json |
| 25 | +``` |
| 26 | + |
| 27 | +``` |
| 28 | +{ |
| 29 | + "mcpServers": { |
| 30 | + "dify-app-name": { |
| 31 | + "command": "npx", |
| 32 | + "args": ["-y", "dify-mcp-client", "YOUR_MCP_SERVER_URL"], |
| 33 | + "env": {} |
| 34 | + } |
| 35 | + } |
| 36 | +} |
| 37 | +``` |
| 38 | + |
| 39 | +Replace `YOUR_MCP_SERVER_URL` with the address shown in your Dify app's MCP configuration. After saving, restart Claude Desktop. Your Dify app will appear in Claude's available tools, and Claude can invoke it whenever relevant to your conversation. |
| 40 | + |
| 41 | +## Integration with Cursor |
| 42 | + |
| 43 | +Cursor's integration follows a similar pattern but within the IDE context. In Cursor's settings, navigate to the AI configuration section and add your Dify MCP server to the available tools. Cursor will then be able to call your Dify app during code generation, refactoring, or when you explicitly ask it to use the tool. |
| 44 | + |
| 45 | +The key advantage here is context-aware automation. For instance, if you have a Dify app that processes API documentation into code templates, Cursor can automatically invoke it when you're working on API integrations, without you having to switch contexts. |
| 46 | + |
| 47 | +## Practical Considerations |
| 48 | + |
| 49 | +- Access Control |
| 50 | + |
| 51 | + Your MCP Server URL contains authentication credentials, so treat it like an API key. If you suspect it's been compromised, use the regenerate function in Dify to create a new URL. The old one will immediately stop working. |
| 52 | +- Descriptiveness |
| 53 | + |
| 54 | + When designing your parameter descriptions, think about how an AI would interpret them. Clear, specific descriptions lead to better invocations. Instead of "input data," specify "JSON object containing user profile with required fields: name, email, preferences." |
| 55 | +- Latency |
| 56 | + |
| 57 | + The MCP protocol handles the communication layer, but your Dify app's performance still matters. If your app typically takes 30 seconds to process, that latency will be felt in the client application. Consider adding progress indicators or breaking complex workflows into smaller, faster operations. |
0 commit comments