Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/server/api/src/app/ai/chat/prompts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ import { ChatFlowContext, CODE_BLOCK_NAME, isNil } from '@openops/shared';
import { ToolSet } from 'ai';
import { readFile } from 'fs/promises';
import { join } from 'path';
import { getAdditionalToolDescriptions } from '../mcp/external-tool-descriptions';
import { hasToolProvider } from '../mcp/tool-utils';
import { QueryClassification } from '../mcp/types';
import { MCPChatContext } from './ai-chat.service';

function buildAdditionalToolNotes(selectedTools: ToolSet | undefined): string {
const descriptions = getAdditionalToolDescriptions(selectedTools);
return descriptions.length > 0 ? descriptions.join('\n\n') : '';
}

export const getMcpSystemPrompt = async ({
queryClassification,
selectedTools,
Expand Down Expand Up @@ -58,7 +64,12 @@ export const getMcpSystemPrompt = async ({

const allPrompts = await Promise.all(promptPromises);

return allPrompts.join('\n\n');
const additionalToolNotes = buildAdditionalToolNotes(selectedTools);
const finalPrompts = additionalToolNotes
? [...allPrompts, additionalToolNotes]
: allPrompts;

return finalPrompts.join('\n\n');
};

export const getBlockSystemPrompt = async (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export type ToolDescription = {
note: string;
mcpServer?: string;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: The mcpServer field is defined but not used anywhere in the codebase. Consider whether this is needed for future functionality or should be removed to keep the interface minimal.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/server/api/src/app/ai/mcp/external-tool-descriptions-data.ts
Line: 3:3

Comment:
**style:** The `mcpServer` field is defined but not used anywhere in the codebase. Consider whether this is needed for future functionality or should be removed to keep the interface minimal.

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added for future functionality in case if we would need it

};

export const MCP_TOOL_ADDITIONAL_DESCRIPTIONS: Record<string, ToolDescription> =
{
'session-sql': {
note: `### Tool Usage Note for 'session-sql'
- The 'session-sql' tool from AWS billing and cost management MCP server does NOT work with OpenOps tables.
- When the user asks about OpenOps tables, table schema, or table operations, DO NOT use 'session-sql'.
- This tool is only for AWS billing and cost management related SQL queries.`,
mcpServer: 'aws-billing-cost-management',
},
};
22 changes: 22 additions & 0 deletions packages/server/api/src/app/ai/mcp/external-tool-descriptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ToolSet } from 'ai';
import { MCP_TOOL_ADDITIONAL_DESCRIPTIONS } from './external-tool-descriptions-data';

export function getAdditionalToolDescriptions(
tools: ToolSet | string[] | undefined,
): string[] {
if (!tools) {
return [];
}

const toolNames = Array.isArray(tools) ? tools : Object.keys(tools);
const descriptions: string[] = [];

for (const toolName of toolNames) {
const description = MCP_TOOL_ADDITIONAL_DESCRIPTIONS[toolName];
if (description?.note) {
descriptions.push(description.note);
}
}

return descriptions;
}
13 changes: 12 additions & 1 deletion packages/server/api/src/app/ai/mcp/llm-query-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { projectService } from '../../project/project-service';
import { getChatTools } from '../chat/ai-chat.service';
import { buildUIContextSection } from '../chat/prompts.service';
import { getAdditionalQueryClassificationDescriptions } from './extensions';
import { getAdditionalToolDescriptions } from './external-tool-descriptions';
import { sanitizeMessages } from './tool-utils';
import { QueryClassification } from './types';

Expand Down Expand Up @@ -202,6 +203,16 @@ const getSystemPrompt = async (
const toolsMessage = toolList
.map((t) => `- ${t.name}: ${t.description}`)
.join('\n');
const additionalToolNotes = getAdditionalToolDescriptions(
Copy link
Copy Markdown
Contributor Author

@ravikiranvm ravikiranvm Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure about this. Since we are sending all tools to LLM for tool selection, this would also send all additional tool descriptions along with the tool selection system prompt.

toolList.map((t) => t.name),
);

const additionalToolNotesSection =
additionalToolNotes.length > 0
? `\n\n### IMPORTANT TOOL USAGE NOTES:\n\n${additionalToolNotes.join(
'\n\n',
)}\n`
: '';
return (
"Given the following conversation history and the list of available tools, select the tools that are most relevant to answer the user's request. " +
`IMPORTANT: Tables tools should always be included in the output if the user asks a question involving those table names: ${openopsTablesNames.join(
Expand All @@ -211,7 +222,7 @@ const getSystemPrompt = async (
'Include ALL relevant categories that apply. ' +
`${
uiContext ? `${await buildUIContextSection(uiContext)}\n` : ''
} Tools: ${toolsMessage}`
} Tools: ${toolsMessage}${additionalToolNotesSection}`
);
};

Expand Down
Loading