Skip to content

Commit 9a497b4

Browse files
committed
refactor(tidb): update get_prompt
Signed-off-by: Xin Liu <sam@secondstate.io>
1 parent 2399b74 commit 9a497b4

File tree

1 file changed

+39
-2
lines changed
  • cardea-tidb/cardea-tidb-mcp-server/src

1 file changed

+39
-2
lines changed

cardea-tidb/cardea-tidb-mcp-server/src/tidb.rs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,42 @@ use rmcp::{
1111
use std::{result::Result, sync::OnceLock};
1212
use tracing::{error, info};
1313

14+
const PROMPT_SEARCH_TOOL: &str = r#"
15+
You are a multilingual AI assistant. Your task is to (1) extract the most relevant and concise keywords or key phrases from the given user query, and (2) return a tool call that invokes the `search` tool with the extracted keywords.
16+
17+
### Requirements for keyword extraction
18+
Follow these requirements strictly:
19+
- Detect the language of the query automatically.
20+
- Return 3 to 7 keywords or keyphrases that best represent the query's core intent.
21+
- Keep the extracted keywords in the **original language** (do not translate).
22+
- Include **multi-word expressions** if they convey meaningful concepts.
23+
- **Avoid all types of stop words, question words, filler words, or overly generic terms**, such as:
24+
- English: what, how, why, is, the, of, and, etc.
25+
- Chinese: 什么、怎么、如何、是、的、了、吗、啊 等。
26+
- Do **not** include punctuation or meaningless words.
27+
- Only return the final keywords, separated by a **single space**.
28+
29+
Examples:
30+
- Input: "What is the impact of artificial intelligence on education?"
31+
Output: artificial intelligence education impact
32+
- Input: "什么是人工智能对教育的影响?"
33+
Output: 人工智能 教育 影响
34+
35+
### Requirements for tool call
36+
- Return a tool call that invokes the `search` tool with the extracted keywords.
37+
- For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
38+
<tool_call>
39+
{"name": <function-name>, "arguments": <args-json-object>}
40+
</tool_call>
41+
42+
Examples:
43+
- Input: "What is the impact of artificial intelligence on education?"
44+
Output:
45+
<tool_call>
46+
{"name": "search", "arguments": {"query": "artificial intelligence education impact"}}
47+
</tool_call>
48+
"#;
49+
1450
static SEARCH_TOOL_PROMPT: OnceLock<String> = OnceLock::new();
1551

1652
pub fn set_search_tool_prompt(prompt: String) {
@@ -197,8 +233,9 @@ impl ServerHandler for TidbServer {
197233
McpError::invalid_params("No query provided to `search` tool", None)
198234
})?;
199235

200-
let prompt = SEARCH_TOOL_PROMPT.get().unwrap();
201-
let prompt = prompt.replace("{query}", &query);
236+
// let prompt = SEARCH_TOOL_PROMPT.get().unwrap();
237+
// let prompt = prompt.replace("{query}", &query);
238+
let prompt = format!("{PROMPT_SEARCH_TOOL}\n\n### Input Query\n{query:#?}");
202239

203240
Ok(GetPromptResult {
204241
description: None,

0 commit comments

Comments
 (0)