From f2a2b40d2c07172db28cdd685fa8c9098c995acc Mon Sep 17 00:00:00 2001 From: Kadxy <2230318258@qq.com> Date: Thu, 9 Jan 2025 10:20:56 +0800 Subject: [PATCH] feat: carry mcp primitives content as a system prompt --- app/constant.ts | 31 ++++++++++++++++++------------- app/store/chat.ts | 4 +++- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/app/constant.ts b/app/constant.ts index 544e2a24658..9d15b5fa11d 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -260,8 +260,6 @@ export const MCP_PRIMITIVES_TEMPLATE = ` {{ primitives }} `; -// String and scalar parameters should be specified as is, while lists and objects should use JSON format. Note that spaces for string values are not stripped. The output is not expected to be valid XML and is parsed with regular expressions. -// Here are the functions available in JSONSchema format: export const MCP_SYSTEM_TEMPLATE = ` You are an AI assistant with access to system tools. Your role is to help users by combining natural language understanding with tool operations when needed. @@ -269,7 +267,13 @@ You are an AI assistant with access to system tools. Your role is to help users {{ MCP_PRIMITIVES }} 2. WHEN TO USE TOOLS: - - When users ask any questions that can be answered by available tools, you should use the tools to answer the user's question. + - ALWAYS USE TOOLS when they can help answer user questions + - DO NOT just describe what you could do - TAKE ACTION immediately + - If you're not sure whether to use a tool, USE IT + - Common triggers for tool use: + * Questions about files or directories + * Requests to check, list, or manipulate system resources + * Any query that can be answered with available tools 3. HOW TO USE TOOLS: A. Tool Call Format: @@ -287,24 +291,25 @@ You are an AI assistant with access to system tools. Your role is to help users C. Important Rules: - Only ONE tool call per message - - Always use the exact primitive name from available tools + - ALWAYS TAKE ACTION instead of just describing what you could do - Include the correct clientId in code block language tag - Verify arguments match the primitive's requirements 4. INTERACTION FLOW: - A. Understand user's request - B. If tools are needed: - - Explain what you plan to do - - Make the appropriate tool call - - Wait for the response - - Explain the results in user-friendly terms + A. When user makes a request: + - IMMEDIATELY use appropriate tool if available + - DO NOT ask if user wants you to use the tool + - DO NOT just describe what you could do + B. After receiving tool response: + - Explain results clearly + - Take next appropriate action if needed C. If tools fail: - - Explain the error clearly - - Suggest alternatives or ask for clarification + - Explain the error + - Try alternative approach immediately 5. EXAMPLE INTERACTION: User: "What files do I have on my desktop?" - Assistant: "I'll first check which directories I have access to. + Assistant: "I'll check which directories I have access to. \`\`\`json:mcp:filesystem { "method": "tools/call", diff --git a/app/store/chat.ts b/app/store/chat.ts index 80c706ffd9d..93bbde99d64 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -203,6 +203,7 @@ async function getMcpSystemPrompt(): Promise { primitives = primitives.filter((i) => i.primitives.some((p) => p.type === "tool"), ); + let primitivesString = ""; primitives.forEach((i) => { primitivesString += MCP_PRIMITIVES_TEMPLATE.replace( @@ -210,9 +211,10 @@ async function getMcpSystemPrompt(): Promise { i.clientId, ).replace( "{{ primitives }}", - i.primitives.map((p) => JSON.stringify(p)).join("\n"), + i.primitives.map((p) => JSON.stringify(p, null, 2)).join("\n"), ); }); + return MCP_SYSTEM_TEMPLATE.replace("{{ MCP_PRIMITIVES }}", primitivesString); }