Skip to content

Commit

Permalink
feat: carry mcp primitives content as a system prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
Kadxy committed Jan 9, 2025
1 parent 77be190 commit f2a2b40
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
31 changes: 18 additions & 13 deletions app/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,20 @@ 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.
1. TOOLS AVAILABLE:
{{ 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:
Expand All @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion app/store/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,18 @@ async function getMcpSystemPrompt(): Promise<string> {
primitives = primitives.filter((i) =>
i.primitives.some((p) => p.type === "tool"),
);

let primitivesString = "";
primitives.forEach((i) => {
primitivesString += MCP_PRIMITIVES_TEMPLATE.replace(
"{{ clientId }}",
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);
}

Expand Down

0 comments on commit f2a2b40

Please sign in to comment.