Files
doris-mcp-server/examples/dify/dify_demo.md

154 lines
4.9 KiB
Markdown
Raw Normal View History

2025-06-18 12:44:05 +08:00
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# Dify Example: Integrating Doris MCP Server
This document demonstrates how to integrate and use `doris-mcp-server` in Dify to perform Doris SQL calls via MCP.
## Table of Contents
2025-06-19 13:03:17 +08:00
- [Prerequisites](https://www.google.com/search?q=%23prerequisites)
- [Installation & Configuration](https://www.google.com/search?q=%23installation--configuration)
- [Starting the MCP Server](https://www.google.com/search?q=%23starting-the-mcp-server)
- [Ngrok Tunnel (Optional)](https://www.google.com/search?q=%23ngrok-tunnel-optional)
- [Installing & Configuring the Plugin in Dify](https://www.google.com/search?q=%23installing--configuring-the-plugin-in-dify)
- [Creating a Dify App](https://www.google.com/search?q=%23creating-a-dify-app)
- [Adding MCP Tools](https://www.google.com/search?q=%23adding-mcp-tools)
- [Example Calls](https://www.google.com/search?q=%23example-calls)
2025-06-18 12:44:05 +08:00
2025-06-19 13:03:17 +08:00
-----
2025-06-18 12:44:05 +08:00
2025-06-19 13:03:17 +08:00
### Prerequisites
2025-06-18 12:44:05 +08:00
2025-06-19 13:03:17 +08:00
First, install `mcp-doris-server`:
2025-06-18 12:44:05 +08:00
```bash
2025-06-19 13:03:17 +08:00
pip install mcp-doris-server
2025-06-18 12:44:05 +08:00
```
## Starting the MCP Server
Run the startup script:
```bash
2025-06-19 13:03:17 +08:00
# Full configuration with database connection
doris-mcp-server \
--transport http \
--host 0.0.0.0 \
--port 3000 \
--db-host 127.0.0.1 \
--db-port 9030 \
--db-user root \
--db-password your_password
2025-06-18 12:44:05 +08:00
```
2025-06-19 13:03:17 +08:00
If successful, you'll see logs similar to this:
2025-06-18 12:44:05 +08:00
![Server start logs](../images/dify_start_server.png)
2025-06-19 13:03:17 +08:00
-----
2025-06-18 12:44:05 +08:00
## Ngrok Tunnel (Optional)
2025-06-19 13:03:17 +08:00
If your Dify deployment requires a publicly accessible endpoint, you can use the **ngrok** tool. Ngrok is a third-party service that securely exposes local servers to the internet.
2025-06-18 12:44:05 +08:00
2025-06-19 13:03:17 +08:00
-----
2025-06-18 12:44:05 +08:00
2025-06-19 13:03:17 +08:00
## Installing & Configuring the Plugin in Dify
2025-06-18 12:44:05 +08:00
2025-06-19 13:03:17 +08:00
1. In the Dify console, go to **Plugin Marketplace**, search for, and install **MCPSSE / StreamableHTTP**:
![Install plugin](../images/dify_install_plugin.png)
2025-06-18 12:44:05 +08:00
2025-06-19 13:03:17 +08:00
2. After installation, click **Configure** and set the URL to your public or local address. For example, if you're using `ngrok`, this should be the public URL `ngrok` provides, in the format `https://<your-domain>/mcp`. If Dify can directly access your local server, use `http://localhost:3000/mcp`.
2025-06-18 12:44:05 +08:00
2025-06-19 13:03:17 +08:00
```json
{
"doris_mcp_server": {
"transport": "streamable_http",
"url": "https://<your-domain>/mcp"
}
}
```
![Configure plugin](../images/dify_config_mcp.png)
2025-06-18 12:44:05 +08:00
2025-06-19 13:03:17 +08:00
3. Click **Save**. If configured correctly, you'll see a green **Authorized** indicator:
2025-06-18 12:44:05 +08:00
2025-06-19 13:03:17 +08:00
![Authorized](../images/dify_authorized.png)
2025-06-18 12:44:05 +08:00
2025-06-19 13:03:17 +08:00
-----
2025-06-18 12:44:05 +08:00
## Creating a Dify App
2025-06-19 13:03:17 +08:00
1. In the Dify console, click **New App****Blank App**.
2025-06-18 12:44:05 +08:00
![Create app](../images/dify_create_app.png)
2025-06-19 13:03:17 +08:00
2. Select **Agent** as the template and set the **App Name** (e.g., `Doris ChatBI`).
2025-06-18 12:44:05 +08:00
![Agent setup](../images/dify_agent_setup.png)
2025-06-19 13:03:17 +08:00
-----
2025-06-18 12:44:05 +08:00
## Instructions & Tool Configuration
### Instruction Block
Paste the following into the **Instruction** field:
```
<instruction>
Use MCP tools to complete tasks as much as possible. Carefully read the annotations, method names, and parameter descriptions of each tool. Please follow these steps:
1. Analyze the user's question and match the most appropriate tool.
2. Use tool names and parameters exactly as defined; do not invent new ones.
3. Pass parameters in the required JSON format.
4. When calling tools, use:
{"mcp_sse_call_tool": {"tool_name": "<tool_name>", "arguments": "{}"}}
5. Output plain text only—no XML tags.
<input>
User question: user_query
</input>
<output>
Return tool results or a final answer, including analysis.
</output>
</instruction>
```
### Adding MCP Tools
2025-06-19 13:03:17 +08:00
In the **Tools** pane, click **Add** twice to add two entries, both named `mcp_sse` (they will inherit the transport and URL from the plugin):
2025-06-18 12:44:05 +08:00
![Add tools](../images/dify_add_tools.png)
2025-06-19 13:03:17 +08:00
-----
2025-06-18 12:44:05 +08:00
## Example Calls
### List Tables in Database
2025-06-19 13:03:17 +08:00
* **User**: What tables are in the database?
2025-06-18 12:44:05 +08:00
2025-06-19 13:03:17 +08:00
* **Result**: Dify will call the MCP tool to run `SHOW TABLES` and return the list.
![Query tables](../images/dify_query_tabels.png)
2025-06-18 12:44:05 +08:00
### Sales Trend Over Ten Years
2025-06-19 13:03:17 +08:00
* **User**: What has been the sales trend over the past ten years in the ssb database, and which year had the fastest growth?
2025-06-18 12:44:05 +08:00
2025-06-19 13:03:17 +08:00
* **Result**: The tool will execute the SQL, calculate growth rates, and return data.
![Sales trend](../images/dify_sale_trend.png)