diff --git a/docs.json b/docs.json index ac0224f0..57568179 100644 --- a/docs.json +++ b/docs.json @@ -17,10 +17,10 @@ "languages": [ { "language": "en", - "version": "v1.0.0", "dropdowns": [ { "dropdown": "Documentation", + "icon": "book-open", "pages": [ { "group": " ", @@ -29,8 +29,8 @@ "group": "Getting Started", "pages": [ "en/introduction", - "en/getting-started/readme/features-and-specifications", - "en/getting-started/readme/model-providers" + "en/getting-started/readme/fact-sheet", + "en/guides/workflow/key-concepts" ] }, { @@ -42,39 +42,14 @@ "en/guides/model-configuration/customizable-model", "en/guides/model-configuration/interfaces", "en/guides/model-configuration/schema", - "en/guides/model-configuration/load-balancing" + "en/guides/model-configuration/load-balancing", + "en/getting-started/readme/model-providers" ] }, { - "group": "Workflow", + "group": "Orchestrate", "pages": [ - "en/guides/workflow/README", - "en/guides/workflow/key-concepts", "en/guides/workflow/variables", - { - "group": "Node Description", - "pages": [ - "en/guides/workflow/node/start", - "en/guides/workflow/node/end", - "en/guides/workflow/node/answer", - "en/guides/workflow/node/llm", - "en/guides/workflow/node/knowledge-retrieval", - "en/guides/workflow/node/question-classifier", - "en/guides/workflow/node/ifelse", - "en/guides/workflow/node/code", - "en/guides/workflow/node/template", - "en/guides/workflow/node/doc-extractor", - "en/guides/workflow/node/list-operator", - "en/guides/workflow/node/variable-aggregator", - "en/guides/workflow/node/variable-assigner", - "en/guides/workflow/node/iteration", - "en/guides/workflow/node/parameter-extractor", - "en/guides/workflow/node/http-request", - "en/guides/workflow/node/agent", - "en/guides/workflow/node/tools", - "en/guides/workflow/node/loop" - ] - }, "en/guides/workflow/shortcut-key", "en/guides/workflow/orchestrate-node", "en/guides/workflow/file-upload", @@ -101,6 +76,30 @@ "en/guides/workflow/bulletin" ] }, + { + "group": "Nodes", + "pages": [ + "en/guides/workflow/node/start", + "en/guides/workflow/node/end", + "en/guides/workflow/node/answer", + "en/guides/workflow/node/llm", + "en/guides/workflow/node/knowledge-retrieval", + "en/guides/workflow/node/question-classifier", + "en/guides/workflow/node/ifelse", + "en/guides/workflow/node/code", + "en/guides/workflow/node/template", + "en/guides/workflow/node/doc-extractor", + "en/guides/workflow/node/list-operator", + "en/guides/workflow/node/variable-aggregator", + "en/guides/workflow/node/variable-assigner", + "en/guides/workflow/node/iteration", + "en/guides/workflow/node/parameter-extractor", + "en/guides/workflow/node/http-request", + "en/guides/workflow/node/agent", + "en/guides/workflow/node/tools", + "en/guides/workflow/node/loop" + ] + }, { "group": "Knowledge", "pages": [ @@ -156,6 +155,7 @@ "en/guides/application-publishing/launch-your-webapp-quickly/conversation-application" ] }, + "en/guides/application-publishing/publish-mcp", "en/guides/application-publishing/embedding-in-websites", "en/guides/application-publishing/developing-with-apis", "en/guides/application-publishing/based-on-frontend-templates" @@ -208,21 +208,10 @@ { "group": "Guides", "pages": [ - "en/workshop/README", - { - "group": "Basic", - "pages": [ - "en/workshop/basic/build-ai-image-generation-app" - ] - }, - { - "group": "Intermediate", - "pages": [ - "en/workshop/intermediate/article-reader", - "en/workshop/intermediate/customer-service-bot", - "en/workshop/intermediate/twitter-chatflow" - ] - } + "en/workshop/basic/build-ai-image-generation-app", + "en/workshop/intermediate/article-reader", + "en/workshop/intermediate/customer-service-bot", + "en/workshop/intermediate/twitter-chatflow" ] } ] @@ -231,6 +220,7 @@ }, { "dropdown": "Self Hosting", + "icon": "server", "group": "Getting Started", "pages": [ { @@ -252,8 +242,31 @@ "en/learn-more/faq/install-faq" ] }, + { + "dropdown": "API Reference", + "icon": "code", + "groups": [ + { + "group": "Chat and Agent", + "openapi": "en/openapi_chat.json" + }, + { + "group": "Chatflow", + "openapi": "en/openapi_chatflow.json" + }, + { + "group": "Workflow", + "openapi": "en/openapi_workflow.json" + }, + { + "group": "Text Completion", + "openapi": "en/openapi_completion.json" + } + ] + }, { "dropdown": "Develop", + "icon": "code-pull-request", "groups": [ { "group": "Concepts & Getting Started", @@ -517,33 +530,11 @@ ] } ] - }, - { - "dropdown": "API Reference", - "groups": [ - { - "group": "Chat and Agent", - "openapi": "en/openapi_chat.json" - }, - { - "group": "Chatflow", - "openapi": "en/openapi_chatflow.json" - }, - { - "group": "Workflow", - "openapi": "en/openapi_workflow.json" - }, - { - "group": "Text Completion", - "openapi": "en/openapi_completion.json" - } - ] } ] }, { "language": "zh-Hans", - "version": "v1.0.0", "dropdowns": [ { "dropdown": "使用文档", @@ -710,6 +701,7 @@ "group": "工具", "pages": [ "zh-hans/guides/tools/readme", + "zh-hans/guides/tools/mcp", "zh-hans/guides/tools/quick-tool-integration", "zh-hans/guides/tools/advanced-tool-integration", { @@ -742,6 +734,7 @@ "zh-hans/guides/application-publishing/launch-your-webapp-quickly/conversation-application" ] }, + "zh-hans/guides/application-publishing/publish-mcp", "zh-hans/guides/application-publishing/embedding-in-websites", "zh-hans/guides/application-publishing/developing-with-apis", "zh-hans/guides/application-publishing/based-on-frontend-templates" @@ -1206,7 +1199,6 @@ }, { "language": "jp", - "version": "v1.0.0", "dropdowns": [ { "dropdown": "ドキュメント", @@ -1379,6 +1371,7 @@ "ja-jp/guides/application-publishing/launch-your-webapp-quickly/conversation-application" ] }, + "ja-jp/guides/application-publishing/publish-mcp", "ja-jp/guides/application-publishing/embedding-in-websites", "ja-jp/guides/application-publishing/developing-with-apis", "ja-jp/guides/application-publishing/based-on-frontend-templates" @@ -1429,6 +1422,13 @@ } ] }, + { + "group": "ツール", + "pages": [ + "ja-jp/guides/tools/types-of-tools", + "ja-jp/guides/tools/mcp" + ] + }, { "group": "コラボレーション", "pages": [ @@ -1837,9 +1837,6 @@ "copy" ] }, - "styling": { - "eyebrows": "breadcrumbs" - }, "redirects": [ { "source": "plugins/schema-definition/model", diff --git a/en/getting-started/install-self-hosted/docker-compose.mdx b/en/getting-started/install-self-hosted/docker-compose.mdx index 01182549..4ad946ba 100644 --- a/en/getting-started/install-self-hosted/docker-compose.mdx +++ b/en/getting-started/install-self-hosted/docker-compose.mdx @@ -45,8 +45,7 @@ title: Deploy with Docker Compose Clone the Dify source code to your local machine: ```bash -# Assuming current latest version is 0.15.3 -git clone https://github.com/langgenius/dify.git --branch 0.15.3 +git clone --branch "$(curl -s https://api.github.com/repos/langgenius/dify/releases/latest | jq -r .tag_name)" https://github.com/langgenius/dify.git ``` ### Starting Dify diff --git a/en/getting-started/install-self-hosted/environments.mdx b/en/getting-started/install-self-hosted/environments.mdx index a43b489a..a2c9f1ab 100644 --- a/en/getting-started/install-self-hosted/environments.mdx +++ b/en/getting-started/install-self-hosted/environments.mdx @@ -103,7 +103,7 @@ Only effective when starting with docker image or docker-compose. - DIFY_BIND_ADDRESS: API service binding address, default: 0.0.0.0, i.e., all addresses can be accessed. - DIFY_PORT: API service binding port number, default to 5001. - SERVER_WORKER_AMOUNT: The number of API server workers, i.e., the number of gevent workers. Formula: `number of cpu cores x 2 + 1` - + Reference: [https://docs.gunicorn.org/en/stable/design.html#how-many-workers](https://docs.gunicorn.org/en/stable/design.html#how-many-workers) - SERVER_WORKER_CLASS: Defaults to gevent. If using windows, it can be switched to sync or solo. @@ -182,11 +182,11 @@ Used to store uploaded data set files, team/tenant encryption keys, and other fi Type of storage facility - local (default): Local file storage, if this option is selected, the following `STORAGE_LOCAL_PATH` configuration needs to be set. - + - s3: S3 object storage, if this option is selected, the following S3\_ prefixed configurations need to be set. - + - azure-blob: Azure Blob object storage, if this option is selected, the following AZURE_BLOB\_ prefixed configurations need to be set. - + - aliyun-oss: Alibaba Cloud OSS object storage, if this option is selected, the following ALIYUN_OSS\_ prefixed configurations need to be set. - huawei-obs: Huawei OBS object storage, if this option is selected, the following HUAWEI_OBS\_ prefixed configurations need to be set. @@ -466,6 +466,26 @@ Used to store uploaded data set files, team/tenant encryption keys, and other fi Specify whether to enable HybridSearch. [Sparse Vector Documentation](https://cloud.tencent.com/document/product/1709/110110). +- MATRIXONE_HOST + + The host of Matrixone database, default value is matrixone. + +- MATRIXONE_PORT + + The port of Matrixone database, default value is 6001. + +- MATRIXONE_USER + + The user of Matrixone database, default value is dump. + +- MATRIXONE_PASSWORD + + The password of Matrixone database, default value is 111. + +- MATRIXONE_DATABASE + + The database of Matrixone database, default value is dify. + - OPENGAUSS_HOST The hostname or IP address of the openGauss vector database. @@ -551,7 +571,7 @@ Notion integration configuration variables can be obtained by applying for Notio - resend - MAIL_DEFAULT_SEND_FROM: The sender's email name, such as: no-reply [no-reply@dify.ai](mailto:no-reply@dify.ai), not mandatory. - RESEND_API_KEY: API-Key for the Resend email provider, can be obtained from API-Key. - + - smtp - SMTP_SERVER: SMTP server address - SMTP_PORT: SMTP server port number @@ -560,6 +580,12 @@ Notion integration configuration variables can be obtained by applying for Notio - SMTP_USE_TLS: Whether to use TLS, default is false - MAIL_DEFAULT_SEND_FROM: The sender's email name, such as: no-reply [no-reply@dify.ai](mailto:no-reply@dify.ai), not mandatory. + - sendgrid + - SENDGRID_API_KEY: API key for the SendGrid email provider. + - MAIL_DEFAULT_SEND_FROM: The sender's email address, e.g., your_email@sendgrid.com. This field is required for SendGrid authentication. + +For more details about the SendGrid email provider, please refer to the [SendGrid documentation](https://sendgrid.com/docs/for-developers/sending-email/). + ### ModelProvider & Tool Position Configuration Used to specify the model providers and tools that can be used in the app. These settings allow you to customize which tools and model providers are available, as well as their order and inclusion/exclusion in the app's interface. @@ -666,7 +692,7 @@ Used to set the browser policy for session cookies used for identity verificatio ## Chunk Length Configuration -### INDEXING_MAX_SEGMENTATION_TOKENS_LENGTH +### INDEXING_MAX_SEGMENTATION_TOKENS_LENGTH Configuration for document chunk length. It is used to control the size of text segments when processing long documents. Default: 500. Maximum: 4000. @@ -691,4 +717,3 @@ It will be automatically generated by the script. --- [Edit this page](https://github.com/langgenius/dify-docs/edit/main/en/getting-started/install-self-hosted/environments.mdx) | [Report an issue](https://github.com/langgenius/dify-docs/issues/new?title=Documentation%20Issue%3A%20onme&body=%23%23%20Issue%20Description%0A%3C%21--%20Please%20briefly%20describe%20the%20issue%20you%20found%20--%3E%0A%0A%23%23%20Page%20Link%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fen/getting-started/install-self-hosted%2Fenvironments.mdx%0A%0A%23%23%20Suggested%20Changes%0A%3C%21--%20If%20you%20have%20specific%20suggestions%20for%20changes%2C%20please%20describe%20them%20here%20--%3E%0A%0A%3C%21--%20Thank%20you%20for%20helping%20improve%20our%20documentation%21%20--%3E) - diff --git a/en/getting-started/install-self-hosted/faqs.mdx b/en/getting-started/install-self-hosted/faqs.mdx index fcbc0ea9..22fdb50b 100644 --- a/en/getting-started/install-self-hosted/faqs.mdx +++ b/en/getting-started/install-self-hosted/faqs.mdx @@ -87,12 +87,50 @@ docker-compose restart Modify the `UPLOAD_FILE_SIZE_LIMIT` parameter in the `.env` file to adjust the default limit. Additionally, you should also sync the `NGINX_CLIENT_MAX_BODY_SIZE` parameter value to avoid potential issues. -{/* -Contributing Section -DO NOT edit this section! -It will be automatically generated by the script. -*/} +### 8. How to create a backup before upgrading? +Before upgrading, it is recommended to back up your current `dify` directory to prevent any potential data loss. You can create a backup with the following command: + +```bash +cp -r dify "dify.bak.$(date +%Y%m%d%H%M%S)" +``` + +This will create a timestamped backup copy, making it easy to restore if needed. + +### 9. How to install an older version of the Community Edition? + +In some cases, you may want to install a specific older version of the Community Edition, you can use the `--branch` flag to do this. For example, to install version `0.15.3`: + +```bash +git clone https://github.com/langgenius/dify.git --branch 0.15.3 +``` + +This will clone the repository at that version, and the rest of the setup is the same as installing the latest version. + +### 10. How to install the Community Edition using a ZIP archive? + +If you're on a network-restricted server or unable to use `git` for any reason, you can install Dify using a ZIP archive: + +```bash +wget -O dify.zip "$(curl -s https://api.github.com/repos/langgenius/dify/releases/latest | jq -r '.zipball_url')" +unzip dify.zip && rm dify.zip +``` + +The remaining installation steps are the same as in the standard setup. Alternatively, you can download the ZIP archive on another device and manually upload it to the target server. + +To upgrade later, download the latest archive and synchronize it with your existing installation: + +```bash +wget -O dify-latest.zip "$(curl -s https://api.github.com/repos/langgenius/dify/releases/latest | jq -r '.zipball_url')" +unzip dify-latest.zip && rm dify-latest.zip +rsync -a dify-latest/ dify/ +rm -rf dify-latest/ +cd dify/docker +docker compose pull +docker compose up -d +``` + +Make sure to back up your existing data before upgrading. Refer to [Question 8](#8) for details. --- [Edit this page](https://github.com/langgenius/dify-docs/edit/main/en/getting-started/install-self-hosted/faqs.mdx) | [Report an issue](https://github.com/langgenius/dify-docs/issues/new?title=Documentation%20Issue%3A%20&body=%23%23%20Issue%20Description%0A%3C%21--%20Please%20briefly%20describe%20the%20issue%20you%20found%20--%3E%0A%0A%23%23%20Page%20Link%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fen/getting-started/install-self-hosted%2Ffaqs.mdx%0A%0A%23%23%20Suggested%20Changes%0A%3C%21--%20If%20you%20have%20specific%20suggestions%20for%20changes%2C%20please%20describe%20them%20here%20--%3E%0A%0A%3C%21--%20Thank%20you%20for%20helping%20improve%20our%20documentation%21%20--%3E) diff --git a/en/getting-started/readme/features-and-specifications.mdx b/en/getting-started/readme/fact-sheet.mdx similarity index 99% rename from en/getting-started/readme/features-and-specifications.mdx rename to en/getting-started/readme/fact-sheet.mdx index 7391ecf9..69bbad1b 100644 --- a/en/getting-started/readme/features-and-specifications.mdx +++ b/en/getting-started/readme/fact-sheet.mdx @@ -1,5 +1,5 @@ --- -title: Features and Specifications +title: Technical Overview description: For those already familiar with LLM application tech stacks, this document serves as a shortcut to understand Dify's unique advantages --- @@ -165,7 +165,7 @@ We adopt transparent policies around product specifications to ensure decisions Vector Databases Supported - Qdrant (recommended), Weaviate, Zilliz/Milvus, Pgvector, Pgvector-rs, Chroma, OpenSearch, TiDB, Tencent Cloud VectorDB, Oracle, Relyt, Analyticdb, Couchbase, OceanBase, Tablestore, Lindorm, OpenGauss + Qdrant (recommended), Weaviate, Zilliz/Milvus, Pgvector, Pgvector-rs, Chroma, OpenSearch, TiDB, Tencent Cloud VectorDB, Oracle, Relyt, Analyticdb, Couchbase, OceanBase, Tablestore, Lindorm, OpenGauss, Matrixone Agent Technologies diff --git a/en/guides/application-publishing/README.mdx b/en/guides/application-publishing/README.mdx index ab844747..cec32e25 100644 --- a/en/guides/application-publishing/README.mdx +++ b/en/guides/application-publishing/README.mdx @@ -1,11 +1,11 @@ --- -title: Launching Dify Apps +title: "Launching Dify Apps" --- - For more detailed information, please refer to the following sections: - [Publish as a Single-page Webapp](launch-your-webapp-quickly/) +- [Publish as an MCP server](/en/guides/application-publishing/publish-mcp) - [Embedding In Websites](embedding-in-websites) - [Developing with APIs](developing-with-apis) - [Based on Frontend Templates](based-on-frontend-templates) diff --git a/en/guides/application-publishing/publish-mcp.mdx b/en/guides/application-publishing/publish-mcp.mdx new file mode 100644 index 00000000..8c7bf4b6 --- /dev/null +++ b/en/guides/application-publishing/publish-mcp.mdx @@ -0,0 +1,65 @@ +--- +title: "Publishing Dify Apps as MCP Servers" +--- + +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. + + + If you're looking to use MCP tools within Dify workflows & agents, see [here](/en/guides/tools/mcp). + + +## Configuring Your Dify App as an MCP Server + +Navigate to your application's configuration interface in Dify, you'll find an MCP Server configuration module. The feature is disabled by default. When you toggle it on, Dify generates an unique MCP Server address for your application. This address serves as the connection point for external tools. + + + Your MCP Server URL contains authentication credentials, so treat it like an API key. If you suspect it's been compromised, use the regenerate button to create a new URL. The old one will immediately stop working. + + +CleanShot 2025-07-07 at 08.18.02.png + +## Integration with Claude Desktop + +To connect your Dify app to Claude Desktop, you'll need to add a Claude integration. Go to your Claude Profile \> Settings \> Integrations \> Add integration. Replace the Integration URL with your Dify app's Server URL. + +## Integration with Cursor + +For Cursor, create or edit the `.cursor/mcp.json` file in your project root: + +```json +{ + "mcpServers": { + "your-server-name": { + "url": "your-server-url" + } + } +} +``` + +Simply replace the URL with your Dify app's MCP Server address. Cursor will automatically detect this configuration and make your Dify app available as a tool. You can add multiple Dify apps by including additional entries in the `mcpServers` object. + +## Practical Considerations + +- Descriptiveness + + When designing descriptions for your tool and its input parameters, 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." +- Latency + + 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. + +{/* +Contributing Section +DO NOT edit this section! +It will be automatically generated by the script. +*/} + +--- + +[Edit this page](https://github.com/langgenius/dify-docs/edit/main/en/guides/application-publishing/publish-mcp.mdx) | [Report an issue](https://github.com/langgenius/dify-docs/issues/new?title=Documentation%20Issue%3A%20sh-&body=%23%23%20Issue%20Description%0A%3C%21--%20Please%20briefly%20describe%20the%20issue%20you%20found%20--%3E%0A%0A%23%23%20Page%20Link%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fen/guides/application-publishing%2Fpublish-mcp.mdx%0A%0A%23%23%20Suggested%20Changes%0A%3C%21--%20If%20you%20have%20specific%20suggestions%20for%20changes%2C%20please%20describe%20them%20here%20--%3E%0A%0A%3C%21--%20Thank%20you%20for%20helping%20improve%20our%20documentation%21%20--%3E) + diff --git a/en/guides/extension/README.mdx b/en/guides/extension/README.mdx deleted file mode 100644 index c2c8af52..00000000 --- a/en/guides/extension/README.mdx +++ /dev/null @@ -1,25 +0,0 @@ ---- -title: Extension ---- - - -In the process of creating AI applications, developers face constantly changing business needs and complex technical challenges. Effectively leveraging extension capabilities can not only enhance the flexibility and functionality of applications but also ensure the security and compliance of enterprise data. Dify offers the following two methods of extension: - - - api-based-extension - - - - code-based-extension - - -{/* -Contributing Section -DO NOT edit this section! -It will be automatically generated by the script. -*/} - ---- - -[Edit this page](https://github.com/langgenius/dify-docs/edit/main/en/guides/extension/README.mdx) | [Report an issue](https://github.com/langgenius/dify-docs/issues/new?title=Documentation%20Issue%3A%20&body=%23%23%20Issue%20Description%0A%3C%21--%20Please%20briefly%20describe%20the%20issue%20you%20found%20--%3E%0A%0A%23%23%20Page%20Link%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fen/guides/extension%2FREADME.mdx%0A%0A%23%23%20Suggested%20Changes%0A%3C%21--%20If%20you%20have%20specific%20suggestions%20for%20changes%2C%20please%20describe%20them%20here%20--%3E%0A%0A%3C%21--%20Thank%20you%20for%20helping%20improve%20our%20documentation%21%20--%3E) - diff --git a/en/guides/extension/api-based-extension/README.mdx b/en/guides/extension/api-based-extension/README.mdx deleted file mode 100644 index c7ae5544..00000000 --- a/en/guides/extension/api-based-extension/README.mdx +++ /dev/null @@ -1,298 +0,0 @@ ---- -title: API-Based Extension ---- - -Developers can extend module capabilities through the API extension module. Currently supported module extensions include: - -* `moderation` -* `external_data_tool` - -Before extending module capabilities, prepare an API and an API Key for authentication, which can also be automatically generated by Dify. In addition to developing the corresponding module capabilities, follow the specifications below so that Dify can invoke the API correctly. - -![Add API Extension](https://assets-docs.dify.ai/dify-enterprise-mintlify/en/guides/extension/api-based-extension/ae289aeca0b29222a4e36820f76e3c5c.png) - -## API Specifications - -Dify will invoke your API according to the following specifications: - -``` -POST {Your-API-Endpoint} -``` - -### Header - - - - - - - - - - - - - - - - - - - - - -
HeaderValueDesc
`Content-Type`application/jsonThe request content is in JSON format.
`Authorization`Bearer `{api_key}`The API Key is transmitted as a token. You need to parse the `api_key` and verify if it matches the provided API Key to ensure API security.
- -### Request Body - -```BASH -{ - "point": string, // Extension point, different modules may contain multiple extension points - "params": { - ... // Parameters passed to each module's extension point - } -} -``` - -### API Response - -```BASH -{ - ... // For the content returned by the API, see the specific module's design specifications for different extension points. -} - -``` - -## Check - -When configuring API-based Extension in Dify, Dify will send a request to the API Endpoint to verify the availability of the API. When the API Endpoint receives `point=ping`, the API should return `result=pong`, as follows: - -### Header - -```BASH -Content-Type: application/json -Authorization: Bearer {api_key} -``` - -### Request Body - -```BASH -{ - "point": "ping" -} -``` - -### Expected API response - -```BASH -{ - "result": "pong" -} -``` - - -## For Example - -Here we take the external data tool as an example, where the scenario is to retrieve external weather information based on the region as context. - -### API Specifications - -`POST https://fake-domain.com/api/dify/receive` - -### **Header** - -```BASH -Content-Type: application/json -Authorization: Bearer 123456 -``` - -### **Request Body** - -```BASH -{ - "point": "app.external_data_tool.query", - "params": { - "app_id": "61248ab4-1125-45be-ae32-0ce91334d021", - "tool_variable": "weather_retrieve", - "inputs": { - "location": "London" - }, - "query": "How's the weather today?" - } -} -``` - -### **API Response** - -```BASH -{ - "result": "City: London\nTemperature: 10°C\nRealFeel®: 8°C\nAir Quality: Poor\nWind Direction: ENE\nWind Speed: 8 km/h\nWind Gusts: 14 km/h\nPrecipitation: Light rain" -} -``` - -### Code demo - -The code is based on the Python FastAPI framework. - -#### **Install dependencies.** - -```bash -pip install 'fastapi[all]' uvicorn -``` - -#### Write code according to the interface specifications. - -```python -from fastapi import FastAPI, Body, HTTPException, Header -from pydantic import BaseModel - -app = FastAPI() - - -class InputData(BaseModel): - point: str - params: dict - - -@app.post("/api/dify/receive") -async def dify_receive(data: InputData = Body(...), authorization: str = Header(None)): - """ - Receive API query data from Dify. - """ - expected_api_key = "123456" # TODO Your API key of this API - auth_scheme, _, api_key = authorization.partition(' ') - - if auth_scheme.lower() != "bearer" or api_key != expected_api_key: - raise HTTPException(status_code=401, detail="Unauthorized") - - point = data.point - - # for debug - print(f"point: {point}") - - if point == "ping": - return { - "result": "pong" - } - if point == "app.external_data_tool.query": - return handle_app_external_data_tool_query(params=data.params) - # elif point == "{point name}": - # TODO other point implementation here - - raise HTTPException(status_code=400, detail="Not implemented") - - -def handle_app_external_data_tool_query(params: dict): - app_id = params.get("app_id") - tool_variable = params.get("tool_variable") - inputs = params.get("inputs") - query = params.get("query") - - # for debug - print(f"app_id: {app_id}") - print(f"tool_variable: {tool_variable}") - print(f"inputs: {inputs}") - print(f"query: {query}") - - # TODO your external data tool query implementation here, - # return must be a dict with key "result", and the value is the query result - if inputs.get("location") == "London": - return { - "result": "City: London\nTemperature: 10°C\nRealFeel®: 8°C\nAir Quality: Poor\nWind Direction: ENE\nWind " - "Speed: 8 km/h\nWind Gusts: 14 km/h\nPrecipitation: Light rain" - } - else: - return {"result": "Unknown city"} -``` - -#### Launch the API service. - -The default port is 8000. The complete address of the API is: `http://127.0.0.1:8000/api/dify/receive`with the configured API Key '123456'. - -```code -uvicorn main:app --reload --host 0.0.0.0 -``` - -#### Configure this API in Dify. - -![](https://assets-docs.dify.ai/dify-enterprise-mintlify/en/guides/extension/api-based-extension/ae289aeca0b29222a4e36820f76e3c5c.png) - -#### Select this API extension in the App. - -![](https://assets-docs.dify.ai/dify-enterprise-mintlify/en/guides/extension/api-based-extension/ae289aeca0b29222a4e36820f76e3c5c.png) - -When debugging the App, Dify will request the configured API and send the following content (example): - -```BASH -{ - "point": "app.external_data_tool.query", - "params": { - "app_id": "61248ab4-1125-45be-ae32-0ce91334d021", - "tool_variable": "weather_retrieve", - "inputs": { - "location": "London" - }, - "query": "How's the weather today?" - } -} -``` - -API Response: - -```BASH -{ - "result": "City: London\nTemperature: 10°C\nRealFeel®: 8°C\nAir Quality: Poor\nWind Direction: ENE\nWind Speed: 8 km/h\nWind Gusts: 14 km/h\nPrecipitation: Light rain" -} -``` - -### Local debugging - -Since Dify's cloud version can't access internal network API services, you can use Ngrok to expose your local API service endpoint to the public internet for cloud-based debugging of local code. The steps are: - -1. Visit the Ngrok official website at [https://ngrok.com](https://ngrok.com/), register, and download the Ngrok file. - -![](https://assets-docs.dify.ai/2025/04/118605d17313d1f39a5b5c2408452614.png) - -2. After downloading, go to the download directory. Unzip the package and run the initialization script as instructed: - -```bash -$ unzip /path/to/ngrok.zip -$ ./ngrok config add-authtoken 你的Token -``` - -3. Check the port of your local API service. - -![](https://assets-docs.dify.ai/dify-enterprise-mintlify/en/guides/extension/api-based-extension/5d3cf23074d5411ffd8571de28a07774.webp) - -Run the following command to start: - -```bash -$ ./ngrok http [port number] -``` - -Upon successful startup, you'll see something like the following: - -![](https://assets-docs.dify.ai/dify-enterprise-mintlify/en/guides/extension/api-based-extension/4357f9c0dc1e494b3718b56ae9253e6a.jpeg) - -4. Find the 'Forwarding' address, like the sample domain `https://177e-159-223-41-52.ngrok-free.app`, and use it as your public domain. - -* For example, to expose your locally running service, replace the example URL `http://127.0.0.1:8000/api/dify/receive` with `https://177e-159-223-41-52.ngrok-free.app/api/dify/receive`. - -Now, this API endpoint is accessible publicly. You can configure this endpoint in Dify for local debugging. For the configuration steps, consult the appropriate documentation or guide. - -### Deploy API extension with Cloudflare Workers - -We recommend that you use Cloudflare Workers to deploy your API extension, because Cloudflare Workers can easily provide a public address and can be used for free. - -[Deploy API Tools with Cloudflare Workers](cloudflare-workers) - -{/* -Contributing Section -DO NOT edit this section! -It will be automatically generated by the script. -*/} - ---- - -[Edit this page](https://github.com/langgenius/dify-docs/edit/main/en/guides/extension/api-based-extension/README.mdx) | [Report an issue](https://github.com/langgenius/dify-docs/issues/new?title=Documentation%20Issue%3A%20&body=%23%23%20Issue%20Description%0A%3C%21--%20Please%20briefly%20describe%20the%20issue%20you%20found%20--%3E%0A%0A%23%23%20Page%20Link%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fen/guides/extension/api-based-extension%2FREADME.mdx%0A%0A%23%23%20Suggested%20Changes%0A%3C%21--%20If%20you%20have%20specific%20suggestions%20for%20changes%2C%20please%20describe%20them%20here%20--%3E%0A%0A%3C%21--%20Thank%20you%20for%20helping%20improve%20our%20documentation%21%20--%3E) - diff --git a/en/guides/extension/api-based-extension/cloudflare-workers.mdx b/en/guides/extension/api-based-extension/cloudflare-workers.mdx deleted file mode 100644 index 3d7ac404..00000000 --- a/en/guides/extension/api-based-extension/cloudflare-workers.mdx +++ /dev/null @@ -1,148 +0,0 @@ ---- -title: Deploy API Tools with Cloudflare Workers ---- - - -## Getting Started - -Since the Dify API Extension requires a publicly accessible internet address as an API Endpoint, we need to deploy our API extension to a public internet address. Here, we use Cloudflare Workers for deploying our API extension. - -Clone the [Example GitHub Repository](https://github.com/crazywoola/dify-extension-workers), which contains a simple API extension. We can modify this as a base. - -```bash -git clone https://github.com/crazywoola/dify-extension-workers.git -cp wrangler.toml.example wrangler.toml -``` - -Open the `wrangler.toml` file, and modify `name` and `compatibility_date` to your application's name and compatibility date. - -An important configuration here is the `TOKEN` in `vars`, which you will need to provide when adding the API extension in Dify. For security reasons, it's recommended to use a random string as the Token. You should not write the Token directly in the source code but pass it via environment variables. Thus, do not commit your wrangler.toml to your code repository. - -```toml -name = "dify-extension-example" -compatibility_date = "2023-01-01" - -[vars] -TOKEN = "bananaiscool" -``` - -This API extension returns a random Breaking Bad quote. You can modify the logic of this API extension in `src/index.ts`. This example shows how to interact with a third-party API. - -```typescript -// ⬇️ implement your logic here ⬇️ -// point === "app.external_data_tool.query" -// https://api.breakingbadquotes.xyz/v1/quotes -const count = params?.inputs?.count ?? 1; -const url = `https://api.breakingbadquotes.xyz/v1/quotes/${count}`; -const result = await fetch(url).then(res => res.text()) -// ⬆️ implement your logic here ⬆️ -``` - -This repository simplifies all configurations except for business logic. You can directly use `npm` commands to deploy your API extension. - -```bash -npm run deploy -``` - -After successful deployment, you will get a public internet address, which you can add in Dify as an API Endpoint. Please note not to miss the `endpoint` path. - -
- - -
- -Additionally, you can use the `npm run dev` command to deploy locally for testing. - -```bash -npm install -npm run dev -``` - -Related output: - -```bash -$ npm run dev -> dev -> wrangler dev src/index.ts - - ⛅️ wrangler 3.99.0 -------------------- - -Your worker has access to the following bindings: -- Vars: - - TOKEN: "ban****ool" -⎔ Starting local server... -[wrangler:inf] Ready on http://localhost:58445 -``` - -After this, you can use tools like Postman to debug the local interface. - -## Other Logic TL;DR - -### About Bearer Auth - -```typescript -import { bearerAuth } from "hono/bearer-auth"; - -(c, next) => { - const auth = bearerAuth({ token: c.env.TOKEN }); - return auth(c, next); -}, -``` - -Our Bearer authentication logic is as shown above. We use the `hono/bearer-auth` package for Bearer authentication. You can use `c.env.TOKEN` in `src/index.ts` to get the Token. - -### About Parameter Validation - -```typescript -import { z } from "zod"; -import { zValidator } from "@hono/zod-validator"; - -const schema = z.object({ - point: z.union([ - z.literal("ping"), - z.literal("app.external_data_tool.query"), - ]), // Restricts 'point' to two specific values - params: z - .object({ - app_id: z.string().optional(), - tool_variable: z.string().optional(), - inputs: z.record(z.any()).optional(), - query: z.any().optional(), // string or null - }) - .optional(), -}); -``` - -We use `zod` to define the types of parameters. You can use `zValidator` in `src/index.ts` for parameter validation. Get validated parameters through `const { point, params } = c.req.valid("json");`. Our point has only two values, so we use `z.union` for definition. `params` is an optional parameter, defined with `z.optional`. It includes a `inputs` parameter, a `Record` type representing an object with string keys and any values. This type can represent any object. You can get the `count` parameter in `src/index.ts` using `params?.inputs?.count`. - -### Accessing Logs of Cloudflare Workers - -```bash -wrangler tail -``` - -## Reference Content - -* [Cloudflare Workers](https://workers.cloudflare.com/) -* [Cloudflare Workers CLI](https://developers.cloudflare.com/workers/cli-wrangler/install-update) -* [Example GitHub Repository](https://github.com/crazywoola/dify-extension-workers) - -{/* -Contributing Section -DO NOT edit this section! -It will be automatically generated by the script. -*/} - ---- - -[Edit this page](https://github.com/langgenius/dify-docs/edit/main/en/guides/extension/api-based-extension/cloudflare-workers.mdx) | [Report an issue](https://github.com/langgenius/dify-docs/issues/new?title=Documentation%20Issue%3A%20flare-work&body=%23%23%20Issue%20Description%0A%3C%21--%20Please%20briefly%20describe%20the%20issue%20you%20found%20--%3E%0A%0A%23%23%20Page%20Link%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fen/guides/extension/api-based-extension%2Fcloudflare-workers.mdx%0A%0A%23%23%20Suggested%20Changes%0A%3C%21--%20If%20you%20have%20specific%20suggestions%20for%20changes%2C%20please%20describe%20them%20here%20--%3E%0A%0A%3C%21--%20Thank%20you%20for%20helping%20improve%20our%20documentation%21%20--%3E) - diff --git a/en/guides/extension/api-based-extension/external-data-tool.mdx b/en/guides/extension/api-based-extension/external-data-tool.mdx deleted file mode 100644 index ec3bb7ef..00000000 --- a/en/guides/extension/api-based-extension/external-data-tool.mdx +++ /dev/null @@ -1,201 +0,0 @@ ---- -title: External Data Tools ---- - -External data tools are used to fetch additional data from external sources after the end user submits data, and then assemble this data into prompts as additional context information for the LLM. Dify provides a default tool for external API calls, check [External Data Tool](https://docs.dify.ai/guides/knowledge-base/external-data-tool) for details. - -For developers deploying Dify locally, to meet more customized needs or to avoid developing an additional API Server, you can directly insert custom external data tool logic in the form of a plugin based on the Dify service. After extending custom tools, your custom tool options will be added to the dropdown list of tool types, and team members can use these custom tools to fetch external data. - -## Quick Start - -Here is an example of extending an external data tool for `Weather Search`, with the following steps: - -1. Initialize the directory -2. Add frontend form specifications -3. Add implementation class -4. Preview the frontend interface -5. Debug the extension - -### 1. Initialize the Directory - -To add a custom type `Weather Search`, you need to create the relevant directory and files under `api/core/external_data_tool`. - -```python -. -└── api - └── core - └── external_data_tool - └── weather_search - ├── __init__.py - ├── weather_search.py - └── schema.json -``` - -### 2. Add Frontend Component Specifications - -* `schema.json`, which defines the frontend component specifications, detailed in [.](./ "mention") - -```json -{ - "label": { - "en-US": "Weather Search", - "zh-Hans": "天气查询" - }, - "form_schema": [ - { - "type": "select", - "label": { - "en-US": "Temperature Unit", - "zh-Hans": "温度单位" - }, - "variable": "temperature_unit", - "required": true, - "options": [ - { - "label": { - "en-US": "Fahrenheit", - "zh-Hans": "华氏度" - }, - "value": "fahrenheit" - }, - { - "label": { - "en-US": "Centigrade", - "zh-Hans": "摄氏度" - }, - "value": "centigrade" - } - ], - "default": "centigrade", - "placeholder": "Please select temperature unit" - } - ] -} -``` - -### 3. Add Implementation Class - -`weather_search.py` code template, where you can implement the specific business logic. - - - The class variable `name` must be the custom type name, consistent with the directory and file name, and must be unique. - - -```python -from typing import Optional - -from core.external_data_tool.base import ExternalDataTool - - -class WeatherSearch(ExternalDataTool): - """ - The name of custom type must be unique, keep the same with directory and file name. - """ - name: str = "weather_search" - - @classmethod - def validate_config(cls, tenant_id: str, config: dict) -> None: - """ - schema.json validation. It will be called when user save the config. - - Example: - .. code-block:: python - config = { - "temperature_unit": "centigrade" - } - - :param tenant_id: the id of workspace - :param config: the variables of form config - :return: - """ - - if not config.get('temperature_unit'): - raise ValueError('temperature unit is required') - - def query(self, inputs: dict, query: Optional[str] = None) -> str: - """ - Query the external data tool. - - :param inputs: user inputs - :param query: the query of chat app - :return: the tool query result - """ - city = inputs.get('city') - temperature_unit = self.config.get('temperature_unit') - - if temperature_unit == 'fahrenheit': - return f'Weather in {city} is 32°F' - else: - return f'Weather in {city} is 0°C' -``` - - -### 4. Debug the Extension - -Now, you can select the custom `Weather Search` external data tool extension type in the Dify application orchestration interface for debugging. - -#### Implementation Class Template - -```python -from typing import Optional - -from core.external_data_tool.base import ExternalDataTool - - -class WeatherSearch(ExternalDataTool): - """ - The name of custom type must be unique, keep the same with directory and file name. - """ - name: str = "weather_search" - - @classmethod - def validate_config(cls, tenant_id: str, config: dict) -> None: - """ - schema.json validation. It will be called when user save the config. - - :param tenant_id: the id of workspace - :param config: the variables of form config - :return: - """ - - # implement your own logic here - - def query(self, inputs: dict, query: Optional[str] = None) -> str: - """ - Query the external data tool. - - :param inputs: user inputs - :param query: the query of chat app - :return: the tool query result - """ - - # implement your own logic here - return "your own data." -``` - -### Detailed Introduction to Implementation Class Development - -#### def validate_config - -`schema.json` form validation method, called when the user clicks "Publish" to save the configuration. - -* `config` form parameters - * `{{variable}}` custom form variables - -### def query - -User-defined data query implementation, the returned result will be replaced into the specified variable. - -* `inputs`: Variables passed by the end user -* `query`: Current conversation input content from the end user, a fixed parameter for conversational applications. - -{/* -Contributing Section -DO NOT edit this section! -It will be automatically generated by the script. -*/} - ---- - -[Edit this page](https://github.com/langgenius/dify-docs/edit/main/en/guides/extension/api-based-extension/external-data-tool.mdx) | [Report an issue](https://github.com/langgenius/dify-docs/issues/new?title=Documentation%20Issue%3A%20nal-data-t&body=%23%23%20Issue%20Description%0A%3C%21--%20Please%20briefly%20describe%20the%20issue%20you%20found%20--%3E%0A%0A%23%23%20Page%20Link%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fen/guides/extension/api-based-extension%2Fexternal-data-tool.mdx%0A%0A%23%23%20Suggested%20Changes%0A%3C%21--%20If%20you%20have%20specific%20suggestions%20for%20changes%2C%20please%20describe%20them%20here%20--%3E%0A%0A%3C%21--%20Thank%20you%20for%20helping%20improve%20our%20documentation%21%20--%3E) - diff --git a/en/guides/extension/api-based-extension/moderation-extension.mdx b/en/guides/extension/api-based-extension/moderation-extension.mdx deleted file mode 100644 index 32f943b4..00000000 --- a/en/guides/extension/api-based-extension/moderation-extension.mdx +++ /dev/null @@ -1,160 +0,0 @@ ---- -title: Moderation ---- - -This module is used to review the content input by end-users and the output from LLMs within the application, divided into two types of extension points. - -Please read [.](./ "mention") to complete the development and integration of basic API service capabilities. - -## Extension Point - -`app.moderation.input`: End-user input content review extension point. It is used to review the content of variables passed in by end-users and the input content of dialogues in conversational applications. - -`app.moderation.output`: LLM output content review extension point. It is used to review the content output by LLM. When the LLM output is streaming, the content will be requested by the API in chunks of 100 characters to avoid delays in review when the output content is lengthy. - -### `app.moderation.input` - -#### Request Body - -```json -{ - "point": "app.moderation.input", - "app_id": string, - "inputs": { - "var_1": "value_1", - "var_2": "value_2", - ... - }, - "query": string | null - } -} -``` - -* Example - -```json -{ - "point": "app.moderation.input", - "params": { - "app_id": "61248ab4-1125-45be-ae32-0ce91334d021", - "inputs": { - "var_1": "I will kill you.", - "var_2": "I will fuck you." - }, - "query": "Happy everydays." - } -} -``` - -#### API Response - -```json -{ - "flagged": bool, - "action": string, - "preset_response": string, - "inputs": { - "var_1": "value_1", - "var_2": "value_2", - ... - }, - "query": string | null -} -``` - -* Example - -`action=direct_output` - -```json -{ - "flagged": true, - "action": "direct_output", - "preset_response": "Your content violates our usage policy." -} -``` - -`action=overridden` - -``` -{ - "flagged": true, - "action": "overridden", - "inputs": { - "var_1": "I will *** you.", - "var_2": "I will *** you." - }, - "query": "Happy everydays." -} -``` - -### `app.moderation.output` - -#### Request Body - -```JSON -{ - "point": "app.moderation.output", - "params": { - "app_id": string, - "text": string - } -} -``` - -* Example - - - - ```JSON - { - "point": "app.moderation.output", - "params": { - "app_id": "61248ab4-1125-45be-ae32-0ce91334d021", - "text": "I will kill you." - } - } - ``` - -#### API Response - -```JSON -{ - "flagged": bool, - "action": string, - "preset_response": string, - "text": string -``` - -* Example - -`action=direct_output` - -* ```JSON - { - "flagged": true, - "action": "direct_output", - "preset_response": "Your content violates our usage policy." - } - ``` - -`action=overridden` - -* ```JSON - { - "flagged": true, - "action": "overridden", - "text": "I will *** you." - } - ``` - -{/* -Contributing Section -DO NOT edit this section! -It will be automatically generated by the script. -*/} - ---- - -[Edit this page](https://github.com/langgenius/dify-docs/edit/main/en/guides/extension/api-based-extension/moderation-extension.mdx) | [Report an issue](https://github.com/langgenius/dify-docs/issues/new?title=Documentation%20Issue%3A%20ation-extens&body=%23%23%20Issue%20Description%0A%3C%21--%20Please%20briefly%20describe%20the%20issue%20you%20found%20--%3E%0A%0A%23%23%20Page%20Link%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fen/guides/extension/api-based-extension%2Fmoderation-extension.mdx%0A%0A%23%23%20Suggested%20Changes%0A%3C%21--%20If%20you%20have%20specific%20suggestions%20for%20changes%2C%20please%20describe%20them%20here%20--%3E%0A%0A%3C%21--%20Thank%20you%20for%20helping%20improve%20our%20documentation%21%20--%3E) - diff --git a/en/guides/extension/api-based-extension/moderation.mdx b/en/guides/extension/api-based-extension/moderation.mdx deleted file mode 100644 index 8c9a9783..00000000 --- a/en/guides/extension/api-based-extension/moderation.mdx +++ /dev/null @@ -1,150 +0,0 @@ ---- -title: Sensitive Content Moderation ---- - -This module is used to review the content input by end-users and the output content of the LLM within the application. It is divided into two types of extension points. - -### Extension Points - -* `app.moderation.input` - Extension point for reviewing end-user input content - * Used to review the variable content passed in by end-users and the input content of conversational applications. -* `app.moderation.output` - Extension point for reviewing LLM output content - * Used to review the content output by the LLM. - * When the LLM output is streamed, the content will be segmented into 100-character blocks for API requests to avoid delays in reviewing longer outputs. - -### app.moderation.input Extension Point - -#### Request Body - -```json -{ - "point": "app.moderation.input", // Extension point type, fixed as app.moderation.input here - "params": { - "app_id": string, // Application ID - "inputs": { // Variable values passed in by end-users, key is the variable name, value is the variable value - "var_1": "value_1", - "var_2": "value_2", - ... - }, - "query": string | null // Current dialogue input content from the end-user, fixed parameter for conversational applications. - } -} -``` - -* Example - * ``` - { - "point": "app.moderation.input", - "params": { - "app_id": "61248ab4-1125-45be-ae32-0ce91334d021", - "inputs": { - "var_1": "I will kill you.", - "var_2": "I will fuck you." - }, - "query": "Happy everydays." - } - } - ``` - -#### API Response - -``` -{ - "flagged": bool, // Whether it violates the moderation rules - "action": string, // Action to take, direct_output for directly outputting a preset response; overridden for overriding the input variable values - "preset_response": string, // Preset response (returned only when action=direct_output) - "inputs": { // Variable values passed in by end-users, key is the variable name, value is the variable value (returned only when action=overridden) - "var_1": "value_1", - "var_2": "value_2", - ... - }, - "query": string | null // Overridden current dialogue input content from the end-user, fixed parameter for conversational applications. (returned only when action=overridden) -} -``` - -* Example - * `action=direct_output` - * ``` - { - "flagged": true, - "action": "direct_output", - "preset_response": "Your content violates our usage policy." - } - ``` - * `action=overridden` - * ``` - { - "flagged": true, - "action": "overridden", - "inputs": { - "var_1": "I will *** you.", - "var_2": "I will *** you." - }, - "query": "Happy everydays." - } - ``` - -### app.moderation.output Extension Point - -#### Request Body - -``` -{ - "point": "app.moderation.output", // Extension point type, fixed as app.moderation.output here - "params": { - "app_id": string, // Application ID - "text": string // LLM response content. When the LLM output is streamed, this will be content segmented into 100-character blocks. - } -} -``` - -* Example - * ``` - { - "point": "app.moderation.output", - "params": { - "app_id": "61248ab4-1125-45be-ae32-0ce91334d021", - "text": "I will kill you." - } - } - ``` - -#### API Response - -``` -{ - "flagged": bool, // Whether it violates the moderation rules - "action": string, // Action to take, direct_output for directly outputting a preset response; overridden for overriding the input variable values - "preset_response": string, // Preset response (returned only when action=direct_output) - "text": string // Overridden LLM response content (returned only when action=overridden) -} -``` - -* Example - * `action=direct_output` - * ``` - { - "flagged": true, - "action": "direct_output", - "preset_response": "Your content violates our usage policy." - } - ``` - * `action=overridden` - * ``` - { - "flagged": true, - "action": "overridden", - "text": "I will *** you." - } - ``` - -{/* -Contributing Section -DO NOT edit this section! -It will be automatically generated by the script. -*/} - ---- - -[Edit this page](https://github.com/langgenius/dify-docs/edit/main/en/guides/extension/api-based-extension/moderation.mdx) | [Report an issue](https://github.com/langgenius/dify-docs/issues/new?title=Documentation%20Issue%3A%20at&body=%23%23%20Issue%20Description%0A%3C%21--%20Please%20briefly%20describe%20the%20issue%20you%20found%20--%3E%0A%0A%23%23%20Page%20Link%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fen/guides/extension/api-based-extension%2Fmoderation.mdx%0A%0A%23%23%20Suggested%20Changes%0A%3C%21--%20If%20you%20have%20specific%20suggestions%20for%20changes%2C%20please%20describe%20them%20here%20--%3E%0A%0A%3C%21--%20Thank%20you%20for%20helping%20improve%20our%20documentation%21%20--%3E) - diff --git a/en/guides/extension/code-based-extension/README.mdx b/en/guides/extension/code-based-extension/README.mdx deleted file mode 100644 index d6c0e324..00000000 --- a/en/guides/extension/code-based-extension/README.mdx +++ /dev/null @@ -1,112 +0,0 @@ ---- -title: Code Based Extensions ---- - - -For developers deploying Dify locally, if you want to implement extension capabilities without rewriting an API service, you can use code extensions. This allows you to extend or enhance the functionality of the program in code form (i.e., plugin capability) without disrupting the original code logic of Dify. It follows certain interfaces or specifications to achieve compatibility and plug-and-play capability with the main program. Currently, Dify offers two types of code extensions: - -* Adding a new type of external data tool [External Data Tool](/en/guides/extension/api-based-extension/external-data-tool) -* Extending sensitive content moderation strategies [Moderation](/en/guides/extension/api-based-extension/moderation) - -Based on the above functionalities, you can achieve horizontal expansion by following the code-level interface specifications. If you are willing to contribute your extensions to us, we warmly welcome you to submit a PR to Dify. - -## Frontend Component Specification Definition - -The frontend styles of code extensions are defined through `schema.json`: - -* label: Custom type name, supporting system language switching -* form_schema: List of form contents - * type: Component type - * select: Dropdown options - * text-input: Text - * paragraph: Paragraph - * label: Component name, supporting system language switching - * variable: Variable name - * required: Whether it is required - * default: Default value - * placeholder: Component hint content - * options: Exclusive property for the "select" component, defining the dropdown contents - * label: Dropdown name, supporting system language switching - * value: Dropdown option value - * max_length: Exclusive property for the "text-input" component, maximum length - -### Template Example - -```json -{ - "label": { - "en-US": "Cloud Service", - "zh-Hans": "云服务" - }, - "form_schema": [ - { - "type": "select", - "label": { - "en-US": "Cloud Provider", - "zh-Hans": "云厂商" - }, - "variable": "cloud_provider", - "required": true, - "options": [ - { - "label": { - "en-US": "AWS", - "zh-Hans": "亚马逊" - }, - "value": "AWS" - }, - { - "label": { - "en-US": "Google Cloud", - "zh-Hans": "谷歌云" - }, - "value": "GoogleCloud" - }, - { - "label": { - "en-US": "Azure Cloud", - "zh-Hans": "微软云" - }, - "value": "Azure" - } - ], - "default": "GoogleCloud", - "placeholder": "" - }, - { - "type": "text-input", - "label": { - "en-US": "API Endpoint", - "zh-Hans": "API Endpoint" - }, - "variable": "api_endpoint", - "required": true, - "max_length": 100, - "default": "", - "placeholder": "https://api.example.com" - }, - { - "type": "paragraph", - "label": { - "en-US": "API Key", - "zh-Hans": "API Key" - }, - "variable": "api_keys", - "required": true, - "default": "", - "placeholder": "Paste your API key here" - } - ] -} -``` - -{/* -Contributing Section -DO NOT edit this section! -It will be automatically generated by the script. -*/} - ---- - -[Edit this page](https://github.com/langgenius/dify-docs/edit/main/en/guides/extension/code-based-extension/README.mdx) | [Report an issue](https://github.com/langgenius/dify-docs/issues/new?title=Documentation%20Issue%3A%20&body=%23%23%20Issue%20Description%0A%3C%21--%20Please%20briefly%20describe%20the%20issue%20you%20found%20--%3E%0A%0A%23%23%20Page%20Link%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fen/guides/extension/code-based-extension%2FREADME.mdx%0A%0A%23%23%20Suggested%20Changes%0A%3C%21--%20If%20you%20have%20specific%20suggestions%20for%20changes%2C%20please%20describe%20them%20here%20--%3E%0A%0A%3C%21--%20Thank%20you%20for%20helping%20improve%20our%20documentation%21%20--%3E) - diff --git a/en/guides/extension/code-based-extension/external-data-tool.mdx b/en/guides/extension/code-based-extension/external-data-tool.mdx deleted file mode 100644 index 2bf96fec..00000000 --- a/en/guides/extension/code-based-extension/external-data-tool.mdx +++ /dev/null @@ -1,200 +0,0 @@ ---- -title: External Data Tools ---- - -External data tools are used to fetch additional data from external sources after the end user submits data, and then assemble this data into prompts as additional context information for the LLM. Dify provides a default tool for external API calls, check [api-based-extension](/en/guides/extension/api-based-extension) for details. - -For developers deploying Dify locally, to meet more customized needs or to avoid developing an additional API Server, you can directly insert custom external data tool logic in the form of a plugin based on the Dify service. After extending custom tools, your custom tool options will be added to the dropdown list of tool types, and team members can use these custom tools to fetch external data. - -## Quick Start - -Here is an example of extending an external data tool for `Weather Search`, with the following steps: - -1. Initialize the directory -2. Add frontend form specifications -3. Add implementation class -4. Preview the frontend interface -5. Debug the extension - -### 1. **Initialize the Directory** - -To add a custom type `Weather Search`, you need to create the relevant directory and files under `api/core/external_data_tool`. - -```python -. -└── api - └── core - └── external_data_tool - └── weather_search - ├── __init__.py - ├── weather_search.py - └── schema.json -``` - -### 2. **Add Frontend Component Specifications** - -* `schema.json`, which defines the frontend component specifications, detailed in [.](./ "mention") - -```json -{ - "label": { - "en-US": "Weather Search", - "zh-Hans": "天气查询" - }, - "form_schema": [ - { - "type": "select", - "label": { - "en-US": "Temperature Unit", - "zh-Hans": "温度单位" - }, - "variable": "temperature_unit", - "required": true, - "options": [ - { - "label": { - "en-US": "Fahrenheit", - "zh-Hans": "华氏度" - }, - "value": "fahrenheit" - }, - { - "label": { - "en-US": "Centigrade", - "zh-Hans": "摄氏度" - }, - "value": "centigrade" - } - ], - "default": "centigrade", - "placeholder": "Please select temperature unit" - } - ] -} -``` - -### 3. Add Implementation Class - -`weather_search.py` code template, where you can implement the specific business logic. - - -Note: The class variable `name` must be the custom type name, consistent with the directory and file name, and must be unique. - - -```python -from typing import Optional - -from core.external_data_tool.base import ExternalDataTool - - -class WeatherSearch(ExternalDataTool): - """ - The name of custom type must be unique, keep the same with directory and file name. - """ - name: str = "weather_search" - - @classmethod - def validate_config(cls, tenant_id: str, config: dict) -> None: - """ - schema.json validation. It will be called when user save the config. - - Example: - .. code-block:: python - config = { - "temperature_unit": "centigrade" - } - - :param tenant_id: the id of workspace - :param config: the variables of form config - :return: - """ - - if not config.get('temperature_unit'): - raise ValueError('temperature unit is required') - - def query(self, inputs: dict, query: Optional[str] = None) -> str: - """ - Query the external data tool. - - :param inputs: user inputs - :param query: the query of chat app - :return: the tool query result - """ - city = inputs.get('city') - temperature_unit = self.config.get('temperature_unit') - - if temperature_unit == 'fahrenheit': - return f'Weather in {city} is 32°F' - else: - return f'Weather in {city} is 0°C' -``` - -### 4. **Debug the Extension** - -Now, you can select the custom `Weather Search` external data tool extension type in the Dify application orchestration interface for debugging. - -## Implementation Class Template - -```python -from typing import Optional - -from core.external_data_tool.base import ExternalDataTool - - -class WeatherSearch(ExternalDataTool): - """ - The name of custom type must be unique, keep the same with directory and file name. - """ - name: str = "weather_search" - - @classmethod - def validate_config(cls, tenant_id: str, config: dict) -> None: - """ - schema.json validation. It will be called when user save the config. - - :param tenant_id: the id of workspace - :param config: the variables of form config - :return: - """ - - # implement your own logic here - - def query(self, inputs: dict, query: Optional[str] = None) -> str: - """ - Query the external data tool. - - :param inputs: user inputs - :param query: the query of chat app - :return: the tool query result - """ - - # implement your own logic here - return "your own data." -``` - -### Detailed Introduction to Implementation Class Development - -### def validate_config - -`schema.json` form validation method, called when the user clicks "Publish" to save the configuration. - -* `config` form parameters - * `{{variable}}` custom form variables - -### def query - -User-defined data query implementation, the returned result will be replaced into the specified variable. - -* `inputs`: Variables passed by the end user -* `query`: Current conversation input content from the end user, a fixed parameter for conversational applications. - -{/* -Contributing Section -DO NOT edit this section! -It will be automatically generated by the script. -*/} - ---- - -[Edit this page](https://github.com/langgenius/dify-docs/edit/main/en/guides/extension/code-based-extension/external-data-tool.mdx) | [Report an issue](https://github.com/langgenius/dify-docs/issues/new?title=Documentation%20Issue%3A%20nal-data-t&body=%23%23%20Issue%20Description%0A%3C%21--%20Please%20briefly%20describe%20the%20issue%20you%20found%20--%3E%0A%0A%23%23%20Page%20Link%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fen/guides/extension/code-based-extension%2Fexternal-data-tool.mdx%0A%0A%23%23%20Suggested%20Changes%0A%3C%21--%20If%20you%20have%20specific%20suggestions%20for%20changes%2C%20please%20describe%20them%20here%20--%3E%0A%0A%3C%21--%20Thank%20you%20for%20helping%20improve%20our%20documentation%21%20--%3E) - diff --git a/en/guides/extension/code-based-extension/moderation.mdx b/en/guides/extension/code-based-extension/moderation.mdx deleted file mode 100644 index d2796c5c..00000000 --- a/en/guides/extension/code-based-extension/moderation.mdx +++ /dev/null @@ -1,321 +0,0 @@ ---- -title: Sensitive Content Moderation ---- - -In addition to the system's built-in content moderation types, Dify also supports user-defined content moderation rules. This method is suitable for developers customizing their own private deployments. For instance, in an enterprise internal customer service setup, it may be required that users, while querying or customer service agents while responding, not only avoid entering words related to violence, sex, and illegal activities but also avoid specific terms forbidden by the enterprise or violating internally established moderation logic. Developers can extend custom content moderation rules at the code level in a private deployment of Dify. - -## Quick Start - -Here is an example of extending a `Cloud Service` content moderation type, with the steps as follows: - -1. Initialize the directory -2. Add the frontend component definition file -3. Add the implementation class -4. Preview the frontend interface -5. Debug the extension - -### 1. Initialize the Directory - -To add a custom type `Cloud Service`, create the relevant directories and files under the `api/core/moderation` directory. - -```plaintext -. -└── api - └── core - └── moderation - └── cloud_service - ├── __init__.py - ├── cloud_service.py - └── schema.json -``` - -### 2. Add Frontend Component Specifications - -* `schema.json`: This file defines the frontend component specifications. - -```json -{ - "label": { - "en-US": "Cloud Service", - "zh-Hans": "云服务" - }, - "form_schema": [ - { - "type": "select", - "label": { - "en-US": "Cloud Provider", - "zh-Hans": "云厂商" - }, - "variable": "cloud_provider", - "required": true, - "options": [ - { - "label": { - "en-US": "AWS", - "zh-Hans": "亚马逊" - }, - "value": "AWS" - }, - { - "label": { - "en-US": "Google Cloud", - "zh-Hans": "谷歌云" - }, - "value": "GoogleCloud" - }, - { - "label": { - "en-US": "Azure Cloud", - "zh-Hans": "微软云" - }, - "value": "Azure" - } - ], - "default": "GoogleCloud", - "placeholder": "" - }, - { - "type": "text-input", - "label": { - "en-US": "API Endpoint", - "zh-Hans": "API Endpoint" - }, - "variable": "api_endpoint", - "required": true, - "max_length": 100, - "default": "", - "placeholder": "https://api.example.com" - }, - { - "type": "paragraph", - "label": { - "en-US": "API Key", - "zh-Hans": "API Key" - }, - "variable": "api_keys", - "required": true, - "default": "", - "placeholder": "Paste your API key here" - } - ] -} -``` - -### 3. Add Implementation Class - -`cloud_service.py` code template where you can implement specific business logic. - - -Note: The class variable name must be the same as the custom type name, matching the directory and file names, and must be unique. - - -```python -from core.moderation.base import Moderation, ModerationAction, ModerationInputsResult, ModerationOutputsResult - -class CloudServiceModeration(Moderation): - """ - The name of custom type must be unique, keep the same with directory and file name. - """ - name: str = "cloud_service" - - @classmethod - def validate_config(cls, tenant_id: str, config: dict) -> None: - """ - schema.json validation. It will be called when user saves the config. - - Example: - .. code-block:: python - config = { - "cloud_provider": "GoogleCloud", - "api_endpoint": "https://api.example.com", - "api_keys": "123456", - "inputs_config": { - "enabled": True, - "preset_response": "Your content violates our usage policy. Please revise and try again." - }, - "outputs_config": { - "enabled": True, - "preset_response": "Your content violates our usage policy. Please revise and try again." - } - } - - :param tenant_id: the id of workspace - :param config: the variables of form config - :return: - """ - - cls._validate_inputs_and_outputs_config(config, True) - - if not config.get("cloud_provider"): - raise ValueError("cloud_provider is required") - - if not config.get("api_endpoint"): - raise ValueError("api_endpoint is required") - - if not config.get("api_keys"): - raise ValueError("api_keys is required") - - def moderation_for_inputs(self, inputs: dict, query: str = "") -> ModerationInputsResult: - """ - Moderation for inputs. - - :param inputs: user inputs - :param query: the query of chat app, there is empty if is completion app - :return: the moderation result - """ - flagged = False - preset_response = "" - - if self.config['inputs_config']['enabled']: - preset_response = self.config['inputs_config']['preset_response'] - - if query: - inputs['query__'] = query - flagged = self._is_violated(inputs) - - # return ModerationInputsResult(flagged=flagged, action=ModerationAction.overridden, inputs=inputs, query=query) - return ModerationInputsResult(flagged=flagged, action=ModerationAction.DIRECT_OUTPUT, preset_response=preset_response) - - def moderation_for_outputs(self, text: str) -> ModerationOutputsResult: - """ - Moderation for outputs. - - :param text: the text of LLM response - :return: the moderation result - """ - flagged = False - preset_response = "" - - if self.config['outputs_config']['enabled']: - preset_response = self.config['outputs_config']['preset_response'] - - flagged = self._is_violated({'text': text}) - - # return ModerationOutputsResult(flagged=flagged, action=ModerationAction.overridden, text=text) - return ModerationOutputsResult(flagged=flagged, action=ModerationAction.DIRECT_OUTPUT, preset_response=preset_response) - - def _is_violated(self, inputs: dict): - """ - The main logic of moderation. - - :param inputs: - :return: the moderation result - """ - return False -``` - -### 4. Debug the Extension - -At this point, you can select the custom `Cloud Service` content moderation extension type for debugging in the Dify application orchestration interface. - -## Implementation Class Template - -```python -from core.moderation.base import Moderation, ModerationAction, ModerationInputsResult, ModerationOutputsResult - -class CloudServiceModeration(Moderation): - """ - The name of custom type must be unique, keep the same with directory and file name. - """ - name: str = "cloud_service" - - @classmethod - def validate_config(cls, tenant_id: str, config: dict) -> None: - """ - schema.json validation. It will be called when user saves the config. - - :param tenant_id: the id of workspace - :param config: the variables of form config - :return: - """ - cls._validate_inputs_and_outputs_config(config, True) - - # implement your own logic here - - def moderation_for_inputs(self, inputs: dict, query: str = "") -> ModerationInputsResult: - """ - Moderation for inputs. - - :param inputs: user inputs - :param query: the query of chat app, there is empty if is completion app - :return: the moderation result - """ - flagged = False - preset_response = "" - - # implement your own logic here - - # return ModerationInputsResult(flagged=flagged, action=ModerationAction.overridden, inputs=inputs, query=query) - return ModerationInputsResult(flagged=flagged, action=ModerationAction.DIRECT_OUTPUT, preset_response=preset_response) - - def moderation_for_outputs(self, text: str) -> ModerationOutputsResult: - """ - Moderation for outputs. - - :param text: the text of LLM response - :return: the moderation result - """ - flagged = False - preset_response = "" - - # implement your own logic here - - # return ModerationOutputsResult(flagged=flagged, action=ModerationAction.overridden, text=text) - return ModerationOutputsResult(flagged=flagged, action=ModerationAction.DIRECT_OUTPUT, preset_response=preset_response) -``` - -## Detailed Introduction to Implementation Class Development - -### def validate\_config - -The `schema.json` form validation method is called when the user clicks "Publish" to save the configuration. - -* `config` form parameters - * `{variable}` custom variable of the form - * `inputs_config` input moderation preset response - * `enabled` whether it is enabled - * `preset_response` input preset response - * `outputs_config` output moderation preset response - * `enabled` whether it is enabled - * `preset_response` output preset response - -### def moderation\_for\_inputs - -Input validation function - -* `inputs`: values passed by the end user -* `query`: the current input content of the end user in a conversation, a fixed parameter for conversational applications. -* `ModerationInputsResult` - * `flagged`: whether it violates the moderation rules - * `action`: action to be taken - * `direct_output`: directly output the preset response - * `overridden`: override the passed variable values - * `preset_response`: preset response (returned only when action=direct_output) - * `inputs`: values passed by the end user, with key as the variable name and value as the variable value (returned only when action=overridden) - * `query`: overridden current input content of the end user in a conversation, a fixed parameter for conversational applications (returned only when action=overridden) - -### def moderation\_for\_outputs - -Output validation function - -* `text`: content output by the model -* `moderation_for_outputs`: output validation function - * `text`: content of the LLM response. When the LLM output is streamed, this is the content in segments of 100 characters. - * `ModerationOutputsResult` - * `flagged`: whether it violates the moderation rules - * `action`: action to be taken - * `direct_output`: directly output the preset response - * `overridden`: override the passed variable values - * `preset_response`: preset response (returned only when action=direct_output) - * `text`: overridden content of the LLM response (returned only when action=overridden). - -{/* -Contributing Section -DO NOT edit this section! -It will be automatically generated by the script. -*/} - ---- - -[Edit this page](https://github.com/langgenius/dify-docs/edit/main/en/guides/extension/code-based-extension/moderation.mdx) | [Report an issue](https://github.com/langgenius/dify-docs/issues/new?title=Documentation%20Issue%3A%20at&body=%23%23%20Issue%20Description%0A%3C%21--%20Please%20briefly%20describe%20the%20issue%20you%20found%20--%3E%0A%0A%23%23%20Page%20Link%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fen/guides/extension/code-based-extension%2Fmoderation.mdx%0A%0A%23%23%20Suggested%20Changes%0A%3C%21--%20If%20you%20have%20specific%20suggestions%20for%20changes%2C%20please%20describe%20them%20here%20--%3E%0A%0A%3C%21--%20Thank%20you%20for%20helping%20improve%20our%20documentation%21%20--%3E) - diff --git a/en/guides/monitoring/integrate-external-ops-tools/integrate-arize.mdx b/en/guides/monitoring/integrate-external-ops-tools/integrate-arize.mdx index 9852e45b..c02b0b74 100644 --- a/en/guides/monitoring/integrate-external-ops-tools/integrate-arize.mdx +++ b/en/guides/monitoring/integrate-external-ops-tools/integrate-arize.mdx @@ -568,5 +568,5 @@ It will be automatically generated by the script. --- -[Edit this page](https://github.com/langgenius/dify-docs/edit/main/en/guides/monitoring/integrate-external-ops-tools/integrate-arize.mdx) | [Report an issue](https://github.com/langgenius/dify-docs/issues/new?title=Documentation%20Issue%3A%20rate-o&body=%23%23%20Issue%20Description%0A%3C%21--%20Please%20briefly%20describe%20the%20issue%20you%20found%20--%3E%0A%0A%23%23%20Page%20Link%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fen/guides/monitoring/integrate-external-ops-tools%2Fintegrate-arize.mdx%0A%0A%23%23%20Suggested%20Changes%0A%3C%21--%20If%20you%20have%20specific%20suggestions%20for%20changes%2C%20please%20describe%20them%20here%20--%3E%0A%0A%3C%21--%20Thank%20you%20for%20helping%20improve%20our%20documentation%21%20--%3E) +[Edit this page](https://github.com/langgenius/dify-docs/edit/main/en/guides/monitoring/integrate-external-ops-tools/integrate-arize.mdx) | [Report an issue](https://github.com/langgenius/dify-docs/issues/new?title=Documentation%20Issue%3A%20rate-ar&body=%23%23%20Issue%20Description%0A%3C%21--%20Please%20briefly%20describe%20the%20issue%20you%20found%20--%3E%0A%0A%23%23%20Page%20Link%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fen/guides/monitoring/integrate-external-ops-tools%2Fintegrate-arize.mdx%0A%0A%23%23%20Suggested%20Changes%0A%3C%21--%20If%20you%20have%20specific%20suggestions%20for%20changes%2C%20please%20describe%20them%20here%20--%3E%0A%0A%3C%21--%20Thank%20you%20for%20helping%20improve%20our%20documentation%21%20--%3E) diff --git a/en/guides/monitoring/integrate-external-ops-tools/integrate-phoenix.mdx b/en/guides/monitoring/integrate-external-ops-tools/integrate-phoenix.mdx index 412b5aae..23c29d5a 100644 --- a/en/guides/monitoring/integrate-external-ops-tools/integrate-phoenix.mdx +++ b/en/guides/monitoring/integrate-external-ops-tools/integrate-phoenix.mdx @@ -568,5 +568,5 @@ It will be automatically generated by the script. --- -[Edit this page](https://github.com/langgenius/dify-docs/edit/main/en/guides/monitoring/integrate-external-ops-tools/integrate-phoenix.mdx) | [Report an issue](https://github.com/langgenius/dify-docs/issues/new?title=Documentation%20Issue%3A%20rate-o&body=%23%23%20Issue%20Description%0A%3C%21--%20Please%20briefly%20describe%20the%20issue%20you%20found%20--%3E%0A%0A%23%23%20Page%20Link%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fen/guides/monitoring/integrate-external-ops-tools%2Fintegrate-phoenix.mdx%0A%0A%23%23%20Suggested%20Changes%0A%3C%21--%20If%20you%20have%20specific%20suggestions%20for%20changes%2C%20please%20describe%20them%20here%20--%3E%0A%0A%3C%21--%20Thank%20you%20for%20helping%20improve%20our%20documentation%21%20--%3E) +[Edit this page](https://github.com/langgenius/dify-docs/edit/main/en/guides/monitoring/integrate-external-ops-tools/integrate-phoenix.mdx) | [Report an issue](https://github.com/langgenius/dify-docs/issues/new?title=Documentation%20Issue%3A%20rate-phoe&body=%23%23%20Issue%20Description%0A%3C%21--%20Please%20briefly%20describe%20the%20issue%20you%20found%20--%3E%0A%0A%23%23%20Page%20Link%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fen/guides/monitoring/integrate-external-ops-tools%2Fintegrate-phoenix.mdx%0A%0A%23%23%20Suggested%20Changes%0A%3C%21--%20If%20you%20have%20specific%20suggestions%20for%20changes%2C%20please%20describe%20them%20here%20--%3E%0A%0A%3C%21--%20Thank%20you%20for%20helping%20improve%20our%20documentation%21%20--%3E) diff --git a/en/guides/tools/mcp.mdx b/en/guides/tools/mcp.mdx new file mode 100644 index 00000000..e88f8b6e --- /dev/null +++ b/en/guides/tools/mcp.mdx @@ -0,0 +1,185 @@ +--- +title: "Using MCP Tools" +--- + +Use [tools](https://modelcontextprotocol.io/docs/concepts/tools) provided by external [MCP](https://modelcontextprotocol.io/introduction) servers directly in your Dify agents and workflow applications. Instead of being limited to existing Dify plugins, you can tap into a growing [ecosystem](https://mcpservers.org/) of MCP servers that provide specialized capabilities. + + + This article shows how to use MCP tools within Dify. If you're looking to publish an Dify application as an MCP server, check [here](/en/guides/application-publishing/publish-mcp). + + + + Currently, only MCP servers supporting [HTTP transport](https://modelcontextprotocol.io/docs/concepts/architecture#transport-layer) can be used. + + +## Accessing MCP Server Management + +Navigate to **Tools** → **MCP** in your Dify workspace. This is where you manage all external MCP servers that provide tools for your applications. + +![6cef1436fcc13a65ccedb54bcf5ab77eb87b8faba1098a85951839fb1907f2d2.png](/images/6cef1436fcc13a65ccedb54bcf5ab77eb87b8faba1098a85951839fb1907f2d2.png) + +## Adding an MCP Server + +b5429131836c1caae84f4ce8b3b806221e39636723644961ce2f2a97d5421f16.png + +Click **Add MCP Server (HTTP)** to connect a new external tool provider: + +**Server URL**: The HTTP endpoint of the MCP server (e.g., `https://api.notion.com/mcp` for a Notion integration). + +**Name & Icon**: Give it a name that describes what tools it provides. Dify auto-fetches icons when ever it can from the server domain, or you can choose your own. + +**Server Identifier**: A unique ID (lowercase, numbers, underscores, hyphens, max 24 characters) that Dify uses to track this server. + + + The server ID is permanent by design. If you change it, any existing agents or workflows using tools from this server will break. This is critical for [application portability](##application-portability). + + +## Authorization and Tool Discovery + +After adding a server, Dify automatically: + +1. **Discovers Available Tools**: Checks what capabilities the server provides +2. **Handles Authorization**: Initiates OAuth flows if the server requires authentication +3. **Fetches Tool Definitions**: Downloads tool schemas so they can be used in your applications +4. **Updates Tool Inventory**: Makes the tools available in agent and workflow builders + +A server card is added once Dify successfully retrieves at least one usable tool: + +![fcef5ecad1deca82a1d8988c4bcb7cec745a0cd47945ff05fca588502cfaafbc.png](/images/fcef5ecad1deca82a1d8988c4bcb7cec745a0cd47945ff05fca588502cfaafbc.png) + +## Managing Connected Servers + +Click any server card to: + +**Update Tools**: Refresh available tools from the server. Use this when the external service adds new capabilities. + +7b526a64ff34b10a357511b2cd3e42f251a6786210eac71c58ca7bfccdf63f0c.png + +**Re-authorize**: Click on the authorization status to renew permissions. + +**Edit Configuration**: Change server details. + + + Note: URL changes trigger re-authorization, server ID changes break existing applications. + + +CleanShot 2025-07-07 at 07.28.04@2x.png + +**Remove Server**: Disconnects the server. Applications using its tools will show errors until you reconnect or remove those tools. + +## Using MCP Tools in Your Applications + +Once a server is configured, its tools appear in the tool selection interface when building: + +### Agent Applications + +- MCP tools appear alongside built-in tools in the agent configuration +- Tools are organized by server: "Notion MCP » Create Page", "Linear MCP » Create Issue" +- "Add All" option lets you quickly enable all tools from a server + +### Workflow Applications + +- MCP tools appear as available node types when building workflows +- Each tool node shows which server it comes from (helpful for troubleshooting) +- Complex tool parameters get JSON input interfaces for structured data + +### Agent Nodes in Workflows + +- MCP tools can be selected within agent nodes, just like in standalone agents + +## Customizing MCP Tools for Your Use Case + +When you add an MCP tool to an agent node or agent, you can customize how it behaves: + +CleanShot 2025-07-07 at 07.41.33@2x.png + +### Tool Description + +You can override the default description that comes from the MCP server. This is useful for making the description more specific to your use case. + +### Parameter Configuration (Reasoning Config) + +For each tool parameter, you can choose between: + +**Auto**: Let the AI model determine the parameter value based on context (default behavior) + +**Fixed Value**: Set a specific value (can be a static value or a variable) that will always be used, removing the parameter from AI inference + +This is powerful for: + +- Setting consistent configuration values (like `numResults: 10` for search tools) +- Pre-filling parameters that shouldn't change (like specific API endpoints or format preferences) +- Simplifying tool usage by reducing the number of parameters the AI needs to handle + +For example, with a web search tool, you might: + +- Keep `query` on "Auto" so the AI determines what to search for +- Set `numResults` to a fixed value like "5" to limit response size +- Set other parameters like search filters to fixed values for consistent behavior + +## Application Portability + +When you export Dify applications that use MCP tools: + +**DSL Export**: The exported DSL includes references to MCP servers by their IDs. + +**Environment Migration**: To use the application elsewhere, add the same MCP servers with identical IDs in the target environment. + +**Sharing Applications**: Document which MCP servers your application depends on, including URLs and required server IDs. + +## Troubleshooting Integration Issues + +**"Unconfigured Server"**: Authorization failed or no tools found. Check server URL and re-authorize. + +**Missing Tools in Applications**: Hit "Update Tools" - the external service may have changed its offerings. + +**Broken Applications After Server Changes**: If you modified server IDs or removed servers, applications will show tool errors. Re-add servers with original IDs to restore functionality. + +## Best Practices + +**Consistent Server IDs**: Use descriptive, permanent IDs like `github-mcp` or `salesforce-api`. Never change them once applications depend on them. + +**Environment Consistency**: Keep the same MCP server configurations across development, staging, and production environments. + +**Tool Customization**: Take advantage of parameter configuration to make tools behave consistently in your applications. Set fixed values for configuration parameters and let the AI handle dynamic inputs. + +**Tool Documentation**: Document which external tools your applications use, what customizations you've made, and what they do. This helps team members understand application dependencies. + +**Gradual Updates**: When external services update their MCP servers, test tool changes in development before updating production integrations. + +**Backup Plans**: Consider how your applications will behave if an external MCP server becomes unavailable. + +{/* +Contributing Section +DO NOT edit this section! +It will be automatically generated by the script. +*/} + +--- + +[Edit this page](https://github.com/langgenius/dify-docs/edit/main/en/guides/tools/mcp.mdx) | [Report an issue](https://github.com/langgenius/dify-docs/issues/new?title=Documentation%20Issue%3A%20&body=%23%23%20Issue%20Description%0A%3C%21--%20Please%20briefly%20describe%20the%20issue%20you%20found%20--%3E%0A%0A%23%23%20Page%20Link%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fen/guides/tools%2Fmcp.mdx%0A%0A%23%23%20Suggested%20Changes%0A%3C%21--%20If%20you%20have%20specific%20suggestions%20for%20changes%2C%20please%20describe%20them%20here%20--%3E%0A%0A%3C%21--%20Thank%20you%20for%20helping%20improve%20our%20documentation%21%20--%3E) + diff --git a/en/guides/tools/types-of-tools.mdx b/en/guides/tools/types-of-tools.mdx new file mode 100644 index 00000000..43643f2f --- /dev/null +++ b/en/guides/tools/types-of-tools.mdx @@ -0,0 +1,33 @@ +--- +title: "Types of tools" +description: "Tools are defined services that can be used within workflows and by agents alike." +--- + + + + Explore hundreds of third-party tools native to Dify on Dify's [Marketplace](https://marketplace.dify.ai/?category=tool_) + + + Connect with an evergrowing ecosystem of tools based on the [Model Context Protocol](https://modelcontextprotocol.io/introduction). + + + + + + Transform any OpenAPI/Swagger standard formatted API service into a tool. + + + Call another Dify workflow as a tool + + + +{/* +Contributing Section +DO NOT edit this section! +It will be automatically generated by the script. +*/} + +--- + +[Edit this page](https://github.com/langgenius/dify-docs/edit/main/en/guides/tools/types-of-tools.mdx) | [Report an issue](https://github.com/langgenius/dify-docs/issues/new?title=Documentation%20Issue%3A%20-of-to&body=%23%23%20Issue%20Description%0A%3C%21--%20Please%20briefly%20describe%20the%20issue%20you%20found%20--%3E%0A%0A%23%23%20Page%20Link%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fen/guides/tools%2Ftypes-of-tools.mdx%0A%0A%23%23%20Suggested%20Changes%0A%3C%21--%20If%20you%20have%20specific%20suggestions%20for%20changes%2C%20please%20describe%20them%20here%20--%3E%0A%0A%3C%21--%20Thank%20you%20for%20helping%20improve%20our%20documentation%21%20--%3E) + diff --git a/en/guides/workflow/README.mdx b/en/guides/workflow/README.mdx deleted file mode 100644 index 267e8e06..00000000 --- a/en/guides/workflow/README.mdx +++ /dev/null @@ -1,58 +0,0 @@ ---- -title: Introduction ---- - -### Basic Introduction - -Workflows reduce system complexity by breaking down complex tasks into smaller steps (nodes), reducing reliance on prompt engineering and model inference capabilities, and enhancing the performance of LLM applications for complex tasks. This also improves the system's interpretability, stability, and fault tolerance. - -Dify workflows are divided into two types: - -* **Chatflow**: Designed for conversational scenarios, including customer service, semantic search, and other conversational applications that require multi-step logic in response construction. -* **Workflow**: Geared towards automation and batch processing scenarios, suitable for high-quality translation, data analysis, content generation, email automation, and more. - -![](https://assets-docs.dify.ai/dify-enterprise-mintlify/en/guides/workflow/65e9ed3fb88e03f631b3862acc2479e4.png) - -To address the complexity of user intent recognition in natural language input, Chatflow provides question understanding nodes. Compared to Workflow, it adds support for Chatbot features such as conversation history (Memory), annotated replies, and Answer nodes. - -To handle complex business logic in automation and batch processing scenarios, Workflow offers a variety of logic nodes, such as code nodes, IF/ELSE nodes, template transformation, iteration nodes, and more. Additionally, it provides capabilities for timed and event-triggered actions, facilitating the construction of automated processes. - -### Common Use Cases - -* Customer Service - -By integrating LLM into your customer service system, you can automate responses to common questions, reducing the workload of your support team. LLM can understand the context and intent of customer queries and generate helpful and accurate answers in real-time. - -* Content Generation - -Whether you need to create blog posts, product descriptions, or marketing materials, LLM can assist by generating high-quality content. Simply provide an outline or topic, and LLM will use its extensive knowledge base to produce engaging, informative, and well-structured content. - -* Task Automation - -LLM can be integrated with various task management systems like Trello, Slack, and Lark to automate project and task management. Using natural language processing, LLM can understand and interpret user input, create tasks, update statuses, and assign priorities without manual intervention. - -* Data Analysis and Reporting - -LLM can analyze large datasets and generate reports or summaries. By providing relevant information to LLM, it can identify trends, patterns, and insights, transforming raw data into actionable intelligence. This is particularly valuable for businesses looking to make data-driven decisions. - -* Email Automation - -LLM can be used to draft emails, social media updates, and other forms of communication. By providing a brief outline or key points, LLM can generate well-structured, coherent, and contextually relevant messages. This saves significant time and ensures your responses are clear and professional. - -### How to Get Started - -* Start by building a workflow from scratch or use system templates to help you get started. -* Get familiar with basic operations, including creating nodes on the canvas, connecting and configuring nodes, debugging workflows, and viewing run history. -* Save and publish a workflow. -* Run the published application or call the workflow through an API. - -{/* -Contributing Section -DO NOT edit this section! -It will be automatically generated by the script. -*/} - ---- - -[Edit this page](https://github.com/langgenius/dify-docs/edit/main/en/guides/workflow/README.mdx) | [Report an issue](https://github.com/langgenius/dify-docs/issues/new?title=Documentation%20Issue%3A%20&body=%23%23%20Issue%20Description%0A%3C%21--%20Please%20briefly%20describe%20the%20issue%20you%20found%20--%3E%0A%0A%23%23%20Page%20Link%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fen/guides/workflow%2FREADME.mdx%0A%0A%23%23%20Suggested%20Changes%0A%3C%21--%20If%20you%20have%20specific%20suggestions%20for%20changes%2C%20please%20describe%20them%20here%20--%3E%0A%0A%3C%21--%20Thank%20you%20for%20helping%20improve%20our%20documentation%21%20--%3E) - diff --git a/en/introduction.mdx b/en/introduction.mdx index 60a81978..6ee45808 100644 --- a/en/introduction.mdx +++ b/en/introduction.mdx @@ -30,7 +30,7 @@ With Dify, you can: ### Dify -The name Dify comes from "Define + Modify", referring to defining and continuously improving your AI applications. It's made for you. +The name Dify comes from **D**o **I**t **F**or **Y**ou. Here's how various groups are leveraging Dify: diff --git a/en/workshop/README.mdx b/en/workshop/README.mdx deleted file mode 100644 index 012a1a40..00000000 --- a/en/workshop/README.mdx +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: Introduction ---- - -Welcome to the Dify Workshop! These tutorials are designed for beginners who want to start learning Dify from scratch. Whether you have programming or AI-related background knowledge or not, we will guide you step by step to master the core concepts and usage of Dify without skipping any details. - -We will help you understand Dify through a series of experiments. Each experiment will include detailed steps and explanations to ensure you can easily follow and grasp the content. We will interweave knowledge teaching in the experiments, allowing you to learn in practice and gradually build a comprehensive understanding of Dify. - -No need to worry about any prerequisites! We will start from the most basic concepts and gradually guide you into more advanced topics. Whether you are a complete beginner or have some programming experience but want to learn AI technology, this tutorial will provide you with everything you need. - -Let's embark on this learning journey together and explore the endless possibilities of Dify! - -{/* -Contributing Section -DO NOT edit this section! -It will be automatically generated by the script. -*/} - ---- - -[Edit this page](https://github.com/langgenius/dify-docs/edit/main/en/workshop/README.mdx) | [Report an issue](https://github.com/langgenius/dify-docs/issues/new?title=Documentation%20Issue%3A%20&body=%23%23%20Issue%20Description%0A%3C%21--%20Please%20briefly%20describe%20the%20issue%20you%20found%20--%3E%0A%0A%23%23%20Page%20Link%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fen/workshop%2FREADME.mdx%0A%0A%23%23%20Suggested%20Changes%0A%3C%21--%20If%20you%20have%20specific%20suggestions%20for%20changes%2C%20please%20describe%20them%20here%20--%3E%0A%0A%3C%21--%20Thank%20you%20for%20helping%20improve%20our%20documentation%21%20--%3E) - diff --git a/images/6cef1436fcc13a65ccedb54bcf5ab77eb87b8faba1098a85951839fb1907f2d2.png b/images/6cef1436fcc13a65ccedb54bcf5ab77eb87b8faba1098a85951839fb1907f2d2.png new file mode 100644 index 00000000..458d1b36 Binary files /dev/null and b/images/6cef1436fcc13a65ccedb54bcf5ab77eb87b8faba1098a85951839fb1907f2d2.png differ diff --git a/images/7b526a64ff34b10a357511b2cd3e42f251a6786210eac71c58ca7bfccdf63f0c.png b/images/7b526a64ff34b10a357511b2cd3e42f251a6786210eac71c58ca7bfccdf63f0c.png new file mode 100644 index 00000000..7139a8b6 Binary files /dev/null and b/images/7b526a64ff34b10a357511b2cd3e42f251a6786210eac71c58ca7bfccdf63f0c.png differ diff --git a/images/CleanShot2025-07-07at07.09.17@2x.png b/images/CleanShot2025-07-07at07.09.17@2x.png new file mode 100644 index 00000000..a81428c9 Binary files /dev/null and b/images/CleanShot2025-07-07at07.09.17@2x.png differ diff --git a/images/CleanShot2025-07-07at07.16.24@2x.png b/images/CleanShot2025-07-07at07.16.24@2x.png new file mode 100644 index 00000000..8dcff775 Binary files /dev/null and b/images/CleanShot2025-07-07at07.16.24@2x.png differ diff --git a/images/CleanShot2025-07-07at07.28.04@2x.png b/images/CleanShot2025-07-07at07.28.04@2x.png new file mode 100644 index 00000000..627d7edf Binary files /dev/null and b/images/CleanShot2025-07-07at07.28.04@2x.png differ diff --git a/images/CleanShot2025-07-07at07.41.33@2x.png b/images/CleanShot2025-07-07at07.41.33@2x.png new file mode 100644 index 00000000..b978ad72 Binary files /dev/null and b/images/CleanShot2025-07-07at07.41.33@2x.png differ diff --git a/images/CleanShot2025-07-07at08.18.02.png b/images/CleanShot2025-07-07at08.18.02.png new file mode 100644 index 00000000..26c0eadb Binary files /dev/null and b/images/CleanShot2025-07-07at08.18.02.png differ diff --git a/images/b5429131836c1caae84f4ce8b3b806221e39636723644961ce2f2a97d5421f16.png b/images/b5429131836c1caae84f4ce8b3b806221e39636723644961ce2f2a97d5421f16.png new file mode 100644 index 00000000..e6032b76 Binary files /dev/null and b/images/b5429131836c1caae84f4ce8b3b806221e39636723644961ce2f2a97d5421f16.png differ diff --git a/images/db464aa6a197173d5e696ae263bf5e09819b815d9965349139f5376c053ac067.png b/images/db464aa6a197173d5e696ae263bf5e09819b815d9965349139f5376c053ac067.png new file mode 100644 index 00000000..bc550dab Binary files /dev/null and b/images/db464aa6a197173d5e696ae263bf5e09819b815d9965349139f5376c053ac067.png differ diff --git a/images/f43fe9da6ddbe9613aea03fa794a7b3d0043a8b517df69b54c69200d3bd19ad2.png b/images/f43fe9da6ddbe9613aea03fa794a7b3d0043a8b517df69b54c69200d3bd19ad2.png new file mode 100644 index 00000000..a6e9b084 Binary files /dev/null and b/images/f43fe9da6ddbe9613aea03fa794a7b3d0043a8b517df69b54c69200d3bd19ad2.png differ diff --git a/images/fcef5ecad1deca82a1d8988c4bcb7cec745a0cd47945ff05fca588502cfaafbc.png b/images/fcef5ecad1deca82a1d8988c4bcb7cec745a0cd47945ff05fca588502cfaafbc.png new file mode 100644 index 00000000..bf43c0fb Binary files /dev/null and b/images/fcef5ecad1deca82a1d8988c4bcb7cec745a0cd47945ff05fca588502cfaafbc.png differ diff --git a/images/image.png b/images/image.png new file mode 100644 index 00000000..a6e9b084 Binary files /dev/null and b/images/image.png differ diff --git a/ja-jp/getting-started/install-self-hosted/environments.mdx b/ja-jp/getting-started/install-self-hosted/environments.mdx index 70f7a625..27ff3064 100644 --- a/ja-jp/getting-started/install-self-hosted/environments.mdx +++ b/ja-jp/getting-started/install-self-hosted/environments.mdx @@ -482,6 +482,26 @@ dockerイメージまたはdocker-composeによる起動時にのみ有効です openGaussベクトルデータベースのPQ加速を有効にします。 +- MATRIXONE_HOST + + Matrixoneのhost設定。デフォルトはmatrixone。 + +- MATRIXONE_PORT + + Matrixoneのport設定。デフォルトは6001。 + +- MATRIXONE_USER + + Matrixoneのuser設定。デフォルトはdump。 + +- MATRIXONE_PASSWORD + + Matrixoneのpassword設定。デフォルトは111。 + +- MATRIXONE_DATABASE + + Matrixoneのdatabase設定。デフォルトはdify。 + ### ナレッジベース設定 - UPLOAD_FILE_SIZE_LIMIT: アップロードファイルのサイズ制限。デフォルトは15M。 diff --git a/ja-jp/getting-started/readme/features-and-specifications.mdx b/ja-jp/getting-started/readme/features-and-specifications.mdx index efbd7d41..64f52d31 100644 --- a/ja-jp/getting-started/readme/features-and-specifications.mdx +++ b/ja-jp/getting-started/readme/features-and-specifications.mdx @@ -168,7 +168,7 @@ Difyでは、製品の仕様に関する透明性の高いポリシーを採用 ベクトルデータベース対応 - Qdrant(推奨)、Weaviate、Zilliz/Milvus、Pgvector、Pgvector-rs、Chroma、OpenSearch、TiDB、Tencent Cloud VectorDB、Oracle、Relyt、Analyticdb、Couchbase、OceanBase、Tablestore、Lindorm、OpenGauss + Qdrant(推奨)、Weaviate、Zilliz/Milvus、Pgvector、Pgvector-rs、Chroma、OpenSearch、TiDB、Tencent Cloud VectorDB、Oracle、Relyt、Analyticdb、Couchbase、OceanBase、Tablestore、Lindorm、OpenGauss、Matrixone エージェント技術 diff --git a/ja-jp/guides/application-publishing/publish-mcp.mdx b/ja-jp/guides/application-publishing/publish-mcp.mdx new file mode 100644 index 00000000..be90cca4 --- /dev/null +++ b/ja-jp/guides/application-publishing/publish-mcp.mdx @@ -0,0 +1,66 @@ +--- +title: "DifyのアプリをMCPサーバーとして公開" +--- + +Difyがアプリケーションを[MCP](https://modelcontextprotocol.io/introduction)(モデルコンテキストプロトコル)サーバーとして公開できるようになりました。これにより、Claude Desktop のような AI アシスタントや Cursor のような開発環境とのシームレスな統合が可能になります。これらのツールは、まるでネイティブな拡張機能のように、Difyアプリと直接やり取りすることができます。 + + + Difyのワークフローやエージェント内でMCPツールを使用する方法については、[こちら](/ja-jp/guides/tools/mcp)を参照してください。 + + +## DifyアプリをMCPサーバーとして設定 + +Difyのアプリケーション設定ページに移動すると、MCPサーバー設定モジュールが表示されます。デフォルトで無効化されていますが、有効化するとDifyがアプリケーション用のユニークなMCPサーバーアドレスを生成します。このアドレスは、外部ツールが接続するための接続点として機能します。 + + + 生成されたMCPサーバーURLには認証情報が含まれているため、APIキーのように扱ってください。もし漏洩の恐れがある場合は、「regenerate」ボタンを使用して新しいURLを作成してください。古いURLはすぐに無効になります。 + + +CleanShot 2025-07-07 at 08.18.02.png + +## Claude Desktop との統合 + +DifyアプリをClaude Desktopに接続するには、Claudeとの統合を追加する必要があります。Claude Profile > Settings > Integrations > Add integration に移動してください。統合URLをDifyアプリのサーバーURLに置き換えてください。 + +## Cursor との統合 + +Cursorに対しては、プロジェクトのルートにある `.cursor/mcp.json` ファイルを作成または編集します: + +```json +{ + "mcpServers": { + "your-server-name": { + "url": "your-server-url" + } + } +} +``` + +指定された URL を Dify アプリの MCP サーバーアドレスに置き換えてください。Cursor はこの設定を自動的に検出し、あなたの Dify アプリをツールとして利用可能にします。`mcpServers` オブジェクトに追加のエントリーを含めることで、複数の Dify アプリを追加することもできます。 + +## 実用的な考慮事項 + +- 説明 + + ツールとその入力パラメータの説明を編成する際、AIがそれをどのように解釈するかを考慮することをお勧めします。明確で具体的な記述を心がけることで、より良い呼び出しを引き出します。「入力データ」とするのではなく、「必須フィールド(名前、メールアドレス、好み)を含むユーザープロファイルのJSONオブジェクト」と具体的に記述してください。 + +- レイテンシ + + MCPプロトコルは通信層を扱いますが、Difyアプリのパフォーマンスも重要です。アプリの処理に通常30秒かかる場合、その遅延がクライアントアプリケーションにも影響します。進捗状況を表示したり、複雑なワークフローをより小さく迅速な操作に分割したりすることを検討してください。 + +{/* +Contributing Section +DO NOT edit this section! +It will be automatically generated by the script. +*/} + +--- + +[このページを編集する](https://github.com/langgenius/dify-docs/edit/main/ja-jp/guides/application-publishing/publish-mcp.mdx) | [問題を報告する](https://github.com/langgenius/dify-docs/issues/new?title=ドキュメントの問題%3A%20sh-&body=%23%23%20問題の説明%0A%3C%21--%20発見した問題について簡単に説明してください%20--%3E%0A%0A%23%23%20ページリンク%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fja-jp/guides/application-publishing%2Fpublish-mcp.mdx%0A%0A%23%23%20提案される変更%0A%3C%21--%20特定の変更案がある場合は、ここで説明してください%20--%3E%0A%0A%3C%21--%20ドキュメントの品質向上にご協力いただきありがとうございます!%20--%3E) + diff --git a/ja-jp/guides/monitoring/integrate-external-ops-tools/integrate-arize.mdx b/ja-jp/guides/monitoring/integrate-external-ops-tools/integrate-arize.mdx index c52a9044..5a77f532 100644 --- a/ja-jp/guides/monitoring/integrate-external-ops-tools/integrate-arize.mdx +++ b/ja-jp/guides/monitoring/integrate-external-ops-tools/integrate-arize.mdx @@ -518,5 +518,5 @@ It will be automatically generated by the script. --- -[このページを編集する](https://github.com/langgenius/dify-docs/edit/main/ja-jp/guides/monitoring/integrate-external-ops-tools/integrate-arize.mdx) | [問題を報告する](https://github.com/langgenius/dify-docs/issues/new?title=ドキュメントの問題%3A%20rate-o&body=%23%23%20問題の説明%0A%3C%21--%20発見した問題について簡単に説明してください%20--%3E%0A%0A%23%23%20ページリンク%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fja-jp/guides/monitoring/integrate-external-ops-tools%2Fintegrate-arize.mdx%0A%0A%23%23%20提案される変更%0A%3C%21--%20特定の変更案がある場合は、ここで説明してください%20--%3E%0A%0A%3C%21--%20ドキュメントの品質向上にご協力いただきありがとうございます!%20--%3E) +[このページを編集する](https://github.com/langgenius/dify-docs/edit/main/ja-jp/guides/monitoring/integrate-external-ops-tools/integrate-arize.mdx) | [問題を報告する](https://github.com/langgenius/dify-docs/issues/new?title=ドキュメントの問題%3A%20rate-ar&body=%23%23%20問題の説明%0A%3C%21--%20発見した問題について簡単に説明してください%20--%3E%0A%0A%23%23%20ページリンク%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fja-jp/guides/monitoring/integrate-external-ops-tools%2Fintegrate-arize.mdx%0A%0A%23%23%20提案される変更%0A%3C%21--%20特定の変更案がある場合は、ここで説明してください%20--%3E%0A%0A%3C%21--%20ドキュメントの品質向上にご協力いただきありがとうございます!%20--%3E) diff --git a/ja-jp/guides/monitoring/integrate-external-ops-tools/integrate-phoenix.mdx b/ja-jp/guides/monitoring/integrate-external-ops-tools/integrate-phoenix.mdx index 6d05b81b..ea4d6546 100644 --- a/ja-jp/guides/monitoring/integrate-external-ops-tools/integrate-phoenix.mdx +++ b/ja-jp/guides/monitoring/integrate-external-ops-tools/integrate-phoenix.mdx @@ -518,5 +518,5 @@ It will be automatically generated by the script. --- -[このページを編集する](https://github.com/langgenius/dify-docs/edit/main/ja-jp/guides/monitoring/integrate-external-ops-tools/integrate-phoenix.mdx) | [問題を報告する](https://github.com/langgenius/dify-docs/issues/new?title=ドキュメントの問題%3A%20rate-o&body=%23%23%20問題の説明%0A%3C%21--%20発見した問題について簡単に説明してください%20--%3E%0A%0A%23%23%20ページリンク%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fja-jp/guides/monitoring/integrate-external-ops-tools%2Fintegrate-phoenix.mdx%0A%0A%23%23%20提案される変更%0A%3C%21--%20特定の変更案がある場合は、ここで説明してください%20--%3E%0A%0A%3C%21--%20ドキュメントの品質向上にご協力いただきありがとうございます!%20--%3E) +[このページを編集する](https://github.com/langgenius/dify-docs/edit/main/ja-jp/guides/monitoring/integrate-external-ops-tools/integrate-phoenix.mdx) | [問題を報告する](https://github.com/langgenius/dify-docs/issues/new?title=ドキュメントの問題%3A%20rate-phoe&body=%23%23%20問題の説明%0A%3C%21--%20発見した問題について簡単に説明してください%20--%3E%0A%0A%23%23%20ページリンク%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fja-jp/guides/monitoring/integrate-external-ops-tools%2Fintegrate-phoenix.mdx%0A%0A%23%23%20提案される変更%0A%3C%21--%20特定の変更案がある場合は、ここで説明してください%20--%3E%0A%0A%3C%21--%20ドキュメントの品質向上にご協力いただきありがとうございます!%20--%3E) diff --git a/ja-jp/guides/tools/mcp.mdx b/ja-jp/guides/tools/mcp.mdx new file mode 100644 index 00000000..24730b29 --- /dev/null +++ b/ja-jp/guides/tools/mcp.mdx @@ -0,0 +1,182 @@ +--- +title: "MCPツールの活用" +--- + +外部の[MCP](https://modelcontextprotocol.io/introduction)サーバーが提供する[ツール](https://modelcontextprotocol.io/docs/concepts/tools)を直接 Dify Agent やワークフローで利用できます。既存のDifyプラグインに制限される代わりに、特定の機能を提供する成長している MCP サーバーの[エコシステム](https://mcpservers.org/)を活用できます。 + + + この記事では、Dify内でMCPツールを使用する方法を解説します。Difyアプリケーションを MCP サーバーとして公開する方法については、[こちら](https://mcpservers.org/en/guides/application-publishing/publish-mcp)をご覧ください。 + + + + 現在、[HTTPトランスポート](https://modelcontextprotocol.io/docs/concepts/architecture#transport-layer)をサポートしている MCP サーバーのみが利用可能です。 + + +## MCPサーバー管理へのアクセス + +Difyワークスペースの**ツール** → **MCP**に移動します。ここでは、アプリケーション用にツールを提供する全ての外部MCPサーバーを管理します。 + +![6cef1436fcc13a65ccedb54bcf5ab77eb87b8faba1098a85951839fb1907f2d2.png](/images/6cef1436fcc13a65ccedb54bcf5ab77eb87b8faba1098a85951839fb1907f2d2.png) + +## MCPサーバーの追加 + +b5429131836c1caae84f4ce8b3b806221e39636723644961ce2f2a97d5421f16.png + +**MCP Server (HTTP)を追加** をクリックして、新しい外部ツールプロバイダーに接続します: + +* **サーバーURL**: MCPサーバーのHTTPエンドポイント(例: `https://api.notion.com/mcp` はNotionとの統合に用いるためのHTTPエンドポイントです)。 + +* **名前とアイコン**: 提供されるツールを説明する名前を付けます。Difyは可能な限りサーバーのドメインからアイコンを自動で取得し、自分で選ぶこともできます。 + +* **サーバーの識別**: Difyがこのサーバーを管理するために使用するユニークなID(小文字、数字、アンダースコア、ハイフン、最大24文字)。 + + + サーバーIDは設計上永久的です。これを変更すると、このサーバーのツールを使用している既存の Agent やワークフローが機能しなくなります。これは[アプリケーションのポータビリティ](##application-portability)にとって重要です。 + + +## 認証とツールの発見 + +サーバーを追加した後、Difyは自動的に以下を行います: + +1. **利用可能なツールの検出**: サーバーが提供する機能をチェックします。 +2. **認証処理**: サーバーが認証を必要とする場合、OAuthフローを開始します。 +3. **ツール定義の取得**: アプリケーションで使用できるようツールのスキーマをダウンロードします。 +4. **ツールのインベントリを更新**: Agent やワークフロービルダーでツールを使用できるようにします。 + +Difyが少なくとも1つの使用可能なツールを正常に取得するとサーバーカードが追加されます: + +![fcef5ecad1deca82a1d8988c4bcb7cec745a0cd47945ff05fca588502cfaafbc.png](/images/fcef5ecad1deca82a1d8988c4bcb7cec745a0cd47945ff05fca588502cfaafbc.png) + +## 接続されたサーバーの管理 + +サーバーカードをクリックすると、以下ができます: + +* **ツールの更新**: サーバーから入手可能なツールを更新します。外部サービスが新しい機能を追加した場合に使用します。 + + 7b526a64ff34b10a357511b2cd3e42f251a6786210eac71c58ca7bfccdf63f0c.png + +* **再認証**: 認証ステータスをクリックして権限を更新します。 + +* **設定の変更**: サーバーの詳細を変更します。 + + + 注意: URLの変更は再認証を引き起こし、サーバーIDの変更は既存のアプリケーションを破損させます。 + + + CleanShot 2025-07-07 at 07.28.04@2x.png + +* **サーバーの削除**: サーバーを切断します。そのツールを使用しているアプリケーションは、再接続またはツールを削除するまでエラーが表示されます。 + +## アプリケーションでのMCPツールの使用 + +サーバーが設定されると、そのツールは作成時のツール選択インターフェースに表示されます: + +### Agent アプリケーション + +- MCP ツールは Agent 設定の組み込みツールと一緒に表示されます。 +- ツールはサーバー別に整理されます: "Notion MCP » ページ作成", "Linear MCP » 課題作成"。 +- "すべて追加"オプションを使用すると、サーバーの全ツールを迅速に有効にできます。 + +### Workflow アプリケーション +- MCP ツールは Workflow ビルダーの利用可能なノードタイプとして表示されます。 +- 各ツールノードはどのサーバーから来ているかを示します(トラブルシューティングに役立ちます)。 +- 複雑なツールパラメーターは構造化データ用のJSON入力インターフェースを持ちます。 + +### Workflow 内の Agent ノード + +- MCPツールはスタンドアロン Agent と同様に Agent ノード内でも選択できます。 + +### MCP ツールをユースケースにカスタマイズする + +Agent ノードや Agent に MCP ツールを追加すると、その動作をカスタマイズできます: + +CleanShot 2025-07-07 at 07.41.33@2x.png + +### ツールの説明 + +MCPサーバーからのデフォルトの説明をオーバーライドできます。これにより、ユースケースに特化した説明が可能です。 + +### パラメーター設定(推論設定) + +各ツールパラメーターについて、次の選択ができます: + +**自動**: コンテキストに基づいてAIモデルがパラメーター値を決定します(デフォルトの動作)。 + +**固定値**: 常に使用される特定の値(静的な値または変数)を設定し、AIの推論からパラメーターを取り除きます。 + +これは次のような状況で便利です: + +- 一貫した設定値を設定するため(検索ツールに対して `numResults: 10` のように)。 +- 変更すべきでないパラメーターを事前に設定するため(特定のAPIエンドポイントやフォーマット設定)。 +- AIが処理する必要のあるパラメーターを減らしてツールの使用を簡素化します。 + +例えば、Web 検索ツールを使う場合、以下のように設定できます: + +* `query`を「自動」に保ち、AIが何を検索するかを決定します。 +* `numResults`を「5」として固定値に設定し、応答サイズを制限します。 +* 検索フィルターなど他のパラメーターを固定値として設定し、一貫した動作を実現します。 + +## アプリケーションのポータビリティ + +MCPツールを使用するDifyアプリケーションをエクスポートすると: + +* **DSLエクスポート**: エクスポートされたDSLは、MCPサーバーをそのIDで参照します。 + +* **環境移行**: 他の場所でアプリケーションを使用するには、ターゲット環境に同じMCPサーバーを同一のIDで追加します。 + +* **アプリの共有**: アプリケーションに依存するMCPサーバーを、URLや必要なサーバーIDを含めて文書化します。 + +## 統合問題のトラブルシューティング + +* **"未設定サーバー"**: 認証に失敗したか、ツールが見つかりません。サーバーURLを確認し、再認証してください。 +* **アプリ内のツールが欠如**: "ツールを更新"をクリックして — 外部サービスが提供を変更したかもしれません。 +* **サーバー変更後のアプリの破損**: サーバーIDを変更したりサーバーを削除した場合、アプリケーションはツールエラーを表示します。元のIDでサーバーを再追加して機能を回復させてください。 + +## ベストプラクティス + +**一貫したサーバーID**: github-mcpやsalesforce-apiのような説明的で永久的なIDを使用します。一度、アプリケーションが依存し始めたら変更しないでください。 + +**環境の一貫性**: 開発、ステージング、プロダクション環境間で同じMCPサーバー構成を維持します。 + +**ツールのカスタマイズ**: パラメーター設定を活用し、アプリケーションでツールが一貫して機能するようにします。固定値を設定し、動的な入力をAIに処理させます。 + +**ツールの文書化**: アプリケーションで使用している外部ツール、行ったカスタマイズ、及びその機能を文書化します。これにより、チームメンバーがアプリケーションの依存関係を理解しやすくなります。 + +**段階的な更新**: 外部サービスがMCPサーバーを更新する際、プロダクション環境での統合を更新する前に開発環境でツールの変更をテストします。 + +**バックアッププラン**: 外部MCPサーバーが利用できなくなった場合、アプリケーションがどのように動作するかを考慮します。 + +{/* +Contributing Section +DO NOT edit this section! +It will be automatically generated by the script. +*/} + +--- + +[このページを編集する](https://github.com/langgenius/dify-docs/edit/main/ja-jp/guides/tools/mcp.mdx) | [問題を報告する](https://github.com/langgenius/dify-docs/issues/new?title=ドキュメントの問題%3A%20&body=%23%23%20問題の説明%0A%3C%21--%20発見した問題について簡単に説明してください%20--%3E%0A%0A%23%23%20ページリンク%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fja-jp/guides/tools%2Fmcp.mdx%0A%0A%23%23%20提案される変更%0A%3C%21--%20特定の変更案がある場合は、ここで説明してください%20--%3E%0A%0A%3C%21--%20ドキュメントの品質向上にご協力いただきありがとうございます!%20--%3E) + diff --git a/ja-jp/guides/tools/types-of-tools.mdx b/ja-jp/guides/tools/types-of-tools.mdx new file mode 100644 index 00000000..2ae71283 --- /dev/null +++ b/ja-jp/guides/tools/types-of-tools.mdx @@ -0,0 +1,33 @@ +--- +title: "ツールの種類" +description: "ツールは、ワークフローやエージェントが同様に使用できる定義済みのサービスです。" +--- + + + + Difyの[マーケットプレイス](https://marketplace.dify.ai/?category=tool_)で、Difyネイティブの数百ものツールを探索しましょう + + + [Model Context Protocol](https://modelcontextprotocol.io/introduction)に基づいた、常に成長し続けるツールのエコシステムに接続しましょう。 + + + + + + OpenAPI / Swagger標準フォーマットのAPIサービスを、ツールに変換します。 + + + 別のDifyワークフローをツールとして呼び出します + + + +{/* +Contributing Section +DO NOT edit this section! +It will be automatically generated by the script. +*/} + +--- + +[このページを編集する](https://github.com/langgenius/dify-docs/edit/main/ja-jp/guides/tools/types-of-tools.mdx) | [問題を報告する](https://github.com/langgenius/dify-docs/issues/new?title=ドキュメントの問題%3A%20-of-to&body=%23%23%20問題の説明%0A%3C%21--%20発見した問題について簡単に説明してください%20--%3E%0A%0A%23%23%20ページリンク%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fja-jp/guides/tools%2Ftypes-of-tools.mdx%0A%0A%23%23%20提案される変更%0A%3C%21--%20特定の変更案がある場合は、ここで説明してください%20--%3E%0A%0A%3C%21--%20ドキュメントの品質向上にご協力いただきありがとうございます!%20--%3E) + diff --git a/plugin-dev-zh/0412-doc-understanding-the-dimensions.mdx b/plugin-dev-zh/0412-doc-understanding-the-dimensions.mdx index 608da2d4..951368f0 100644 --- a/plugin-dev-zh/0412-doc-understanding-the-dimensions.mdx +++ b/plugin-dev-zh/0412-doc-understanding-the-dimensions.mdx @@ -17,7 +17,7 @@ Dify 最初的成功很大程度上源于其产品的直观易用性。对于核 然而,随着 **Dify Plugin 插件生态的上线和蓬勃发展**,情况发生了显著变化: -1. 受众扩大化: 我们的开发者社区不再局限于能够深入源码的核心贡献者。大量拥有一定技术背景但可能不熟悉 Dify 底层或特定编程范式的**“半专业开发者” (Citizen Developers)** 或集成开发者涌现,他们需要清晰、循序渐进的指导来构建和贡献插件。 +1. 受众扩大化: 我们的开发者社区不再局限于能够深入源码的核心贡献者。大量拥有一定技术背景但可能不熟悉 Dify 底层或特定编程范式的 **“半专业开发者” (Citizen Developers)** 或集成开发者涌现,他们需要清晰、循序渐进的指导来构建和贡献插件。 2. 内容交织与目标模糊: 现有的文档往往将面向最终用户的**帮助内容**(如何使用插件)与面向开发者的**技术内容**(如何开发插件)混合在一起,导致两类受众都感到困惑,增加了信息查找成本。 3. 结构缺失与导航困难: 文档缺乏统一的组织结构和逻辑顺序,使得开发者(尤其是新加入者)难以找到所需信息,也无法形成对插件开发生命周期的完整认知。现有导航难以承载日益增长的内容。 4. 构建开发者关系 (DevRel) 的基石: 一个清晰、有效、结构优异的开发者文档体系,是构建成功开发者关系、繁荣插件生态不可或缺的一环。它直接影响开发者的体验、贡献意愿和成功率。 diff --git a/zh-hans/getting-started/install-self-hosted/environments.mdx b/zh-hans/getting-started/install-self-hosted/environments.mdx index 97389e61..c7361894 100644 --- a/zh-hans/getting-started/install-self-hosted/environments.mdx +++ b/zh-hans/getting-started/install-self-hosted/environments.mdx @@ -253,6 +253,7 @@ Flask 调试模式,开启可在接口输出 trace 信息,方便调试。 * `tablestore` * `lindorm` * `tencent` + * `matrixone` * WEAVIATE_ENDPOINT @@ -487,6 +488,26 @@ Flask 调试模式,开启可在接口输出 trace 信息,方便调试。 指定是否开启HybridSearch。[稀疏向量文档](https://cloud.tencent.com/document/product/1709/110110)。 +* MATRIXONE_HOST + + Matrxone 数据库 host 配置,默认为 matrixone。 + +* MATRIXONE_PORT + + Matrxone 数据库 port 配置,默认为 6001。 + +* MATRIXONE_USER + + Matrxone 数据库 user 配置,默认为 dump。 + +* MATRIXONE_PASSWORD + + Matrxone 数据库 password 配置,默认为 111。 + +* MATRIXONE_DATABASE + + Matrxone 数据库 database 配置,默认为 dify。 + ### 知识库配置 * UPLOAD_FILE_SIZE_LIMIT diff --git a/zh-hans/getting-started/readme/features-and-specifications.mdx b/zh-hans/getting-started/readme/features-and-specifications.mdx index 319d0550..01fe4f7b 100644 --- a/zh-hans/getting-started/readme/features-and-specifications.mdx +++ b/zh-hans/getting-started/readme/features-and-specifications.mdx @@ -168,7 +168,7 @@ description: 对于已经熟悉 LLM 应用技术栈的技术人士来说,这 向量数据库支持 - Qdrant(推荐),Weaviate,Zilliz/Milvus,Pgvector,Pgvector-rs,Chroma,OpenSearch,TiDB,Tencent Cloud VectorDB,Oracle,Relyt,Analyticdb,Couchbase,OceanBase,Tablestore,Lindorm,OpenGauss + Qdrant(推荐),Weaviate,Zilliz/Milvus,Pgvector,Pgvector-rs,Chroma,OpenSearch,TiDB,Tencent Cloud VectorDB,Oracle,Relyt,Analyticdb,Couchbase,OceanBase,Tablestore,Lindorm,OpenGauss,Matrixone Agent 技术 diff --git a/zh-hans/guides/application-publishing/publish-mcp.mdx b/zh-hans/guides/application-publishing/publish-mcp.mdx new file mode 100644 index 00000000..dd69df6c --- /dev/null +++ b/zh-hans/guides/application-publishing/publish-mcp.mdx @@ -0,0 +1,66 @@ +--- +title: "将 Dify 应用部署为 MCP 服务器" +--- + +Dify 现已支持将你的应用部署为 [MCP](https://modelcontextprotocol.io/introduction)(模型上下文协议,一种让 AI 工具之间相互通信的标准协议)服务器。通过这一功能,你可以轻松将 Dify 应用集成到如 Claude Desktop 这样的 AI 助手,或像 Cursor 这样的开发环境中,让这些工具能够直接调用你的 Dify 应用,实现无缝扩展。 + + + 如果你希望在 Dify 工作流或智能体中使用 MCP 工具,请参考[相关指南](/zh-hans/guides/tools/mcp)。 + + +## 配置 Dify 应用为 MCP 服务器 + +在 Dify 应用的配置页面中,你可以找到 MCP 服务器的相关配置选项。该功能默认关闭,开启后,Dify 将为当前应用自动生成唯一的 MCP 服务器地址。此地址将作为外部工具访问你应用的专用接口。 + + + MCP 服务器地址包含了敏感的身份验证信息,应等同于 API Key 妥善保管。如怀疑信息泄露,可点击"重新生成",获取新的服务器地址,原有地址将立即失效。 + + +CleanShot 2025-07-07 at 08.18.02.png + +## 与 Claude Desktop 集成 + +要将 Dify 应用集成到 Claude Desktop,请依次选择:个人资料 > 设置 > 集成 > 添加集成。在"集成 URL"一栏,填写你 Dify 应用的 MCP 服务器地址即可。 + +## 与 Cursor 集成 + +在 Cursor 中集成 Dify 应用,只需在项目根目录下创建或编辑 `.cursor/mcp.json` 文件,内容如下: + +```json +{ + "mcpServers": { + "your-server-name": { + "url": "your-server-url" + } + } +} +``` + +请将 `url` 部分替换为你的 Dify 应用的 MCP 服务器地址。保存文件后,重启 Cursor 即可自动识别这一配置,并将 Dify 应用作为工具集成。该配置支持添加多个应用,只需在 `mcpServers` 对象下增加新的条目即可。 + +## 实用建议 + +- **描述信息的清晰性** + + 在编写工具描述和参数说明时,应从 AI 处理数据的角度出发。说明越明确、具体,AI 的调用效果就越好。例如,与其简单写"输入数据",不如详细说明为:"包含用户姓名、邮箱和偏好设置的 JSON 对象"。 + +- **延迟(Latency)管理** + + MCP 协议负责通信层,但 Dify 应用的响应速度依然至关重要。如果你的应用处理时间较长(例如超过 30 秒),用户将在客户端直接感知到延迟。建议增加进度提示,或将复杂流程拆解为多个更快的小步骤,以提升整体体验。 + +{/* +Contributing Section +DO NOT edit this section! +It will be automatically generated by the script. +*/} + +--- + +[编辑此页面](https://github.com/langgenius/dify-docs/edit/main/zh-hans/guides/application-publishing/publish-mcp.mdx) | [提交问题](https://github.com/langgenius/dify-docs/issues/new?title=文档问题%3A%20sh-&body=%23%23%20问题描述%0A%3C%21--%20请简要描述您发现的问题%20--%3E%0A%0A%23%23%20页面链接%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fzh-hans/guides/application-publishing%2Fpublish-mcp.mdx%0A%0A%23%23%20建议修改%0A%3C%21--%20如果有具体的修改建议,请在此说明%20--%3E%0A%0A%3C%21--%20感谢您对文档质量的关注!%20--%3E) + diff --git a/zh-hans/guides/monitoring/integrate-external-ops-tools/integrate-arize.mdx b/zh-hans/guides/monitoring/integrate-external-ops-tools/integrate-arize.mdx index cf98a2c3..4d93b231 100644 --- a/zh-hans/guides/monitoring/integrate-external-ops-tools/integrate-arize.mdx +++ b/zh-hans/guides/monitoring/integrate-external-ops-tools/integrate-arize.mdx @@ -344,5 +344,5 @@ It will be automatically generated by the script. --- -[编辑此页面](https://github.com/langgenius/dify-docs/edit/main/zh-hans/guides/monitoring/integrate-external-ops-tools/integrate-arize.mdx) | [提交问题](https://github.com/langgenius/dify-docs/issues/new?title=文档问题%3A%20rate-o&body=%23%23%20问题描述%0A%3C%21--%20请简要描述您发现的问题%20--%3E%0A%0A%23%23%20页面链接%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fzh-hans/guides/monitoring/integrate-external-ops-tools%2Fintegrate-arize.mdx%0A%0A%23%23%20建议修改%0A%3C%21--%20如果有具体的修改建议,请在此说明%20--%3E%0A%0A%3C%21--%20感谢您对文档质量的关注!%20--%3E) +[编辑此页面](https://github.com/langgenius/dify-docs/edit/main/zh-hans/guides/monitoring/integrate-external-ops-tools/integrate-arize.mdx) | [提交问题](https://github.com/langgenius/dify-docs/issues/new?title=文档问题%3A%20rate-ar&body=%23%23%20问题描述%0A%3C%21--%20请简要描述您发现的问题%20--%3E%0A%0A%23%23%20页面链接%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fzh-hans/guides/monitoring/integrate-external-ops-tools%2Fintegrate-arize.mdx%0A%0A%23%23%20建议修改%0A%3C%21--%20如果有具体的修改建议,请在此说明%20--%3E%0A%0A%3C%21--%20感谢您对文档质量的关注!%20--%3E) diff --git a/zh-hans/guides/monitoring/integrate-external-ops-tools/integrate-phoenix.mdx b/zh-hans/guides/monitoring/integrate-external-ops-tools/integrate-phoenix.mdx index c9b5454b..6a69aedb 100644 --- a/zh-hans/guides/monitoring/integrate-external-ops-tools/integrate-phoenix.mdx +++ b/zh-hans/guides/monitoring/integrate-external-ops-tools/integrate-phoenix.mdx @@ -344,5 +344,5 @@ It will be automatically generated by the script. --- -[编辑此页面](https://github.com/langgenius/dify-docs/edit/main/zh-hans/guides/monitoring/integrate-external-ops-tools/integrate-phoenix.mdx) | [提交问题](https://github.com/langgenius/dify-docs/issues/new?title=文档问题%3A%20rate-o&body=%23%23%20问题描述%0A%3C%21--%20请简要描述您发现的问题%20--%3E%0A%0A%23%23%20页面链接%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fzh-hans/guides/monitoring/integrate-external-ops-tools%2Fintegrate-phoenix.mdx%0A%0A%23%23%20建议修改%0A%3C%21--%20如果有具体的修改建议,请在此说明%20--%3E%0A%0A%3C%21--%20感谢您对文档质量的关注!%20--%3E) +[编辑此页面](https://github.com/langgenius/dify-docs/edit/main/zh-hans/guides/monitoring/integrate-external-ops-tools/integrate-phoenix.mdx) | [提交问题](https://github.com/langgenius/dify-docs/issues/new?title=文档问题%3A%20rate-phoe&body=%23%23%20问题描述%0A%3C%21--%20请简要描述您发现的问题%20--%3E%0A%0A%23%23%20页面链接%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fzh-hans/guides/monitoring/integrate-external-ops-tools%2Fintegrate-phoenix.mdx%0A%0A%23%23%20建议修改%0A%3C%21--%20如果有具体的修改建议,请在此说明%20--%3E%0A%0A%3C%21--%20感谢您对文档质量的关注!%20--%3E) diff --git a/zh-hans/guides/tools/mcp.mdx b/zh-hans/guides/tools/mcp.mdx new file mode 100644 index 00000000..9baa5eb8 --- /dev/null +++ b/zh-hans/guides/tools/mcp.mdx @@ -0,0 +1,184 @@ +--- +title: "集成 MCP 工具" +--- + +你可以在 Dify 的 Agent 和 Workflow 应用中,直接集成来自外部 [MCP](https://modelcontextprotocol.io/introduction) 服务器的[工具](https://modelcontextprotocol.io/docs/concepts/tools)。除了使用 Dify 内置插件外,还可以接入 MCP [生态系统](https://mcpservers.org/)中的第三方服务,持续扩展你的应用功能。 + + + 本文介绍了如何在 Dify 内集成和使用 MCP 工具。如果你希望将自己的 Dify 应用发布为 MCP 服务器,请参考此[链接](/zh-hans/guides/application-publishing/publish-mcp)。 + + + + 目前仅支持接入使用 HTTP 传输协议的 [MCP 服务器](https://modelcontextprotocol.io/docs/concepts/architecture#transport-layer) 。 + + +## MCP 服务器管理界面 + +登录 Dify 后,在左侧导航栏中依次点击 **工具** → **MCP**,即可进入外部 MCP 服务器的管理页面。在这里,你可以统一管理所有为自身应用配置的 MCP 服务器。 + +![6cef1436fcc13a65ccedb54bcf5ab77eb87b8faba1098a85951839fb1907f2d2.png](/images/6cef1436fcc13a65ccedb54bcf5ab77eb87b8faba1098a85951839fb1907f2d2.png) + +## 添加 MCP 服务器 + +b5429131836c1caae84f4ce8b3b806221e39636723644961ce2f2a97d5421f16.png + +点击 **添加 MCP 服务器(HTTP)**,即可集成新的外部工具服务。需要填写如下信息: + +* **服务器 URL**:MCP 服务器的 HTTP 接口地址,例如集成 Notion 时为 `https://api.notion.com/mcp`。 + +* **名称与图标**:自定义服务器名称,建议选择能清晰体现工具用途的名字。Dify 会自动尝试获取服务器域名的图标,你也可以手动上传。 + +* **服务器标识符**:Dify 用于区分服务器的唯一 ID。规则:小写字母、数字、下划线或连字符,最多 24 个字符。 + + + 服务器 ID 一旦创建即无法更改。如果更改服务器 ID,所有依赖该服务器工具的 Agent 或 Workflow 都会失效。这一设计对于[应用迁移](##application-portability)尤为重要。 + + +## 授权与工具发现 + +添加服务器后,Dify 会自动执行如下操作: + +1. **检测可用工具**:自动识别该服务器能提供哪些工具功能。 +2. **处理授权流程**:如服务器需要身份验证,则自动发起 OAuth 授权流程。 +3. **获取工具定义**:下载各工具的接口定义(schema)。 +4. **同步工具列表**:将识别到的工具加入 Agent 或Workflow应用的构建页面。 + +当 Dify 成功获取到至少一个可用工具后,会在页面中显示该服务器的信息卡片: + +![fcef5ecad1deca82a1d8988c4bcb7cec745a0cd47945ff05fca588502cfaafbc.png](/images/fcef5ecad1deca82a1d8988c4bcb7cec745a0cd47945ff05fca588502cfaafbc.png) + +## 管理已连接服务器 + +点击对应服务器卡片,可进行以下操作: + +* **更新工具**:重新从服务器获取最新工具信息,适用于服务方新增或调整功能后更新。 + + 7b526a64ff34b10a357511b2cd3e42f251a6786210eac71c58ca7bfccdf63f0c.png + +* **重新授权**:点击授权状态,更新服务器的访问权限(如令牌失效需重新授权)。 + +* **编辑配置**:可修改服务器信息。 + + + 更改服务器 URL 会触发重新授权,修改服务器 ID 会让已有应用失效! + + +CleanShot 2025-07-07 at 07.28.04@2x.png + +* **移除服务器**:断开服务器连接。此后所有依赖该服务器工具的应用都会报错,直到你重新连接或删除相关工具。 + +## 在应用中使用 MCP 工具 + +当服务器配置完成后,其下的工具会出现在应用构建时的工具选择区: + +### Agent 应用 + +- 在 Agent 配置界面,与内置工具并列显示 MCP 工具。 +- 工具按服务器分组,例如:"Notion MCP » 创建页面"、"Linear MCP » 创建任务"等。 +- 可一键"添加全部",快速启用该服务器下的所有工具。 + +### Workflow 应用 + +- 构建 Workflow 时,MCP 工具以可选节点类型出现。 +- 每个工具节点都会指明归属服务器,便于定位和排查问题。 +- 参数较为复杂的工具会自动生成 JSON 格式的结构化输入界面。 + +### Workflows 中的 Agent 节点 + +在 Workflow 的 Agent 节点中,也可灵活选择 MCP 工具进行配置,使用方式与独立 Agent 一致。 + +## 按需定制 MCP 工具 + +将 MCP 工具添加到Agent节点或 Agent 应用中后,你可以根据实际需求灵活定制: + +CleanShot 2025-07-07 at 07.41.33@2x.png + +### 工具说明 + +可自定义工具的显示描述,调整为更贴合业务场景的说明信息,替换原 MCP 服务器自带描述。 + +### 参数配置(Reasoning Config) + +每个工具参数可灵活选择两种模式: + +* **自动(Auto)**:让 AI 根据上下文智能决定该参数值(默认)。 + +* **固定值(Fixed Value)**:设定为某个确定的值(支持静态文本或变量表达式),AI 不再推理此参数。 + +使用示例: + +* 统一配置项,例如将搜索工具的 `numResults` 固定为 10。 +* 预填写不应更改的参数,如特定的 API 地址、返回格式等。 +* 通过减少 AI 需要处理的参数数量,简化工具调用逻辑。 + +例如,配置 Web 搜索工具时: + +* 将 `query` 设置为"自动",由 AI 动态生成搜索内容。 +* 将 `numResults` 固定为 5,控制每次返回结果数量。 +* 其他如过滤条件参数也可固定,以保证结果一致性。 + +## 应用迁移 + +当你导出包含 MCP 工具的 Dify 应用时: + +* **DSL 导出**:导出的 DSL 文件会引用所用 MCP 服务器的唯一标识符(ID)。 +* **环境迁移**:迁移应用到其他环境时,需在目标环境添加相同 ID 的 MCP 服务器。这样可以确保工具引用关系保持不变。 +* **应用共享**:建议在文档中明确标注依赖的 MCP 服务器(包括 URL 和 ID),以便团队协作和环境同步。 + + +## 常见问题排查 + +**"未配置的服务器"**: 授权失败或未获取到工具。请检查服务器 URL 并重新授权。 + +**应用内工具缺失**: 点击"更新工具" - 有可能外部服务更改了工具列表。 + +**服务器变动导致应用失效**: 如果修改服务器 ID 或移除服务器,应用会报错。需用原 ID 重新添加服务器,以恢复功能。 + +## 最佳实践 + +**服务器 ID 保持一致性**: 使用具备描述性的 ID 名,例如 `github-mcp` 或者 `salesforce-api`。ID 一旦被应用引用,请勿更改。 + +**多环境一致性**: 开发、测试、生产等环境的 MCP 服务器配置应保持一致。 + +**工具定制**: 主动设置固定参数值,保证工具行为稳定、简化 AI 推理,仅将动态输入交由 AI 处理。 + +**工具文档**: 明确记录应用中用到的外部工具、定制内容及其用途,方便团队后续运维与协作。 + +**逐步升级**: 外部服务升级或变更 MCP 服务器时,应先在开发环境测试通过后,再同步到生产环境。 + +**应急方案**: 提前规划好关键外部 MCP 服务器不可用时的应用应对策略。 + +{/* +Contributing Section +DO NOT edit this section! +It will be automatically generated by the script. +*/} + +--- + +[编辑此页面](https://github.com/langgenius/dify-docs/edit/main/zh-hans/guides/tools/mcp.mdx) | [提交问题](https://github.com/langgenius/dify-docs/issues/new?title=文档问题%3A%20&body=%23%23%20问题描述%0A%3C%21--%20请简要描述您发现的问题%20--%3E%0A%0A%23%23%20页面链接%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fzh-hans/guides/tools%2Fmcp.mdx%0A%0A%23%23%20建议修改%0A%3C%21--%20如果有具体的修改建议,请在此说明%20--%3E%0A%0A%3C%21--%20感谢您对文档质量的关注!%20--%3E) +