Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 | 20x 20x 20x 20x 20x 20x 20x 20x 20x 51x 51x 51x 51x 51x 51x 51x 51x 4x 1x 3x 8x 8x 8x 40x 8x 8x 8x 8x 8x 6x 6x 6x 1x 1x 1x 1x 1x 3x 3x 1x 2x 2x 2x 1x 2x 3x 3x 3x 1x 2x 2x 2x 1x 1x 2x 2x 2x 2x 2x 2x 2x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 2x 2x 2x 1x 1x 2x 2x 2x 2x 2x 1x 1x 24x 2x 22x 5x 17x 17x 16x 16x 1x 12x 3x 9x 2x 12x 12x 1x 11x 4x 4x 1x 3x 3x 3x 6x 6x 1x 5x 5x 1x 3x 1x 4x 4x 4x 2x 2x 2x 5x 1x 1x 2x 2x 5x 5x 7x 7x 7x 2x 5x 5x 5x 6x 17x 7x 7x 5x | import {
Injectable,
NotFoundException,
Inject,
ForbiddenException,
} from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository, DataSource } from 'typeorm';
import { SystemPrompt } from '../core-entities';
import {
CreateSystemPromptDto,
PreviewSystemPromptDto,
PreviewSystemPromptResponseDto,
UpdateSystemPromptDto,
} from './dto/system-prompt.dto';
import { EventsGateway } from '../events/events.gateway';
import { McpService } from '../mcp/mcp.service';
import { ContextGenerationService } from '../context-generation/context-generation.service';
import { ActionHandler } from '../llm-orchestration/action-handlers/action-handler.interface';
import { CustomVariablesService } from '../custom-variables/custom-variables.service';
@Injectable()
export class SystemPromptsService {
// All available tool names
private readonly ALL_TOOL_NAMES = [
'create_file',
'overwrite_file',
'delete_file',
'patch',
'quick_edit',
'apply_diff',
'execute_code',
'run_command',
'request_context',
'final',
'ask_user',
'new_session',
'write_todo',
'howto',
'invoke_subagent',
'list_sub_agents',
'get_session_history',
'generate_title',
'get_messages',
'discard_messages',
];
constructor(
@InjectRepository(SystemPrompt)
private systemPromptsRepository: Repository<SystemPrompt>,
private dataSource: DataSource,
private readonly eventsGateway: EventsGateway,
private readonly mcpService: McpService,
private readonly contextGenerationService: ContextGenerationService,
@Inject('ACTION_HANDLER_REGISTRY')
private readonly handlerRegistry: Map<string, ActionHandler>,
private readonly customVariablesService: CustomVariablesService,
) {}
/**
* Parse enabledTools from string storage.
* Returns 'all' or string[].
* Automatically filters out deprecated/invalid tool names.
*/
private parseEnabledTools(value: string | null): string[] | 'all' {
Iif (!value) {
return 'all';
}
Iif (value === 'all') {
return 'all';
}
try {
const tools = JSON.parse(value);
Iif (Array.isArray(tools)) {
// Filter out any tools that are no longer valid
const validTools = tools.filter((tool: string) =>
this.ALL_TOOL_NAMES.includes(tool),
);
return validTools;
}
return 'all';
} catch (e) {
return 'all';
}
}
/**
* Serialize enabledTools for storage.
* Converts 'all' or string[] to string.
*/
private serializeEnabledTools(value: string[] | 'all'): string | null {
if (value === 'all') {
return 'all';
}
return JSON.stringify(value);
}
private async _renderPrompt(
content: string,
sessionId?: string,
sessionName?: string,
): Promise<string> {
const mcpToolsDefinition = await this.mcpService.getMcpToolsDefinition();
const toolDefinitions: { [key: string]: string } = {};
for (const handler of this.handlerRegistry.values()) {
toolDefinitions[handler.toolName] = handler.getDefinition();
}
const enabledVariables = await this.customVariablesService.findAllEnabled();
const variablesObject = enabledVariables.reduce((acc, curr) => {
acc[curr.key] = curr.value;
return acc;
}, {});
// Inject session metadata
variablesObject['METADATA'] = {
session_id: sessionId || '',
session_name: sessionName || 'Untitled Session',
instance_name: process.env.REPOBURG_INSTANCE_NAME || 'default',
};
const renderedContent = await this.contextGenerationService.render(
content,
{
mcpServers: mcpToolsDefinition,
tools: toolDefinitions,
VAR: variablesObject,
},
);
return renderedContent;
}
async create(
createSystemPromptDto: CreateSystemPromptDto,
): Promise<SystemPrompt> {
// Serialize enabledTools if provided (convert string[] | 'all' to string)
const { enabledTools, enabledMcpTools, ...dtoData } = createSystemPromptDto;
const prompt = this.systemPromptsRepository.create({
...dtoData,
enabledTools:
enabledTools !== undefined
? this.serializeEnabledTools(enabledTools)
: null,
enabledMcpTools:
enabledMcpTools !== undefined
? this.serializeEnabledMcpTools(enabledMcpTools)
: null,
});
return this.systemPromptsRepository.save(prompt);
}
async findAll(): Promise<SystemPrompt[]> {
const prompts = await this.systemPromptsRepository.find({
order: { prompt_name: 'ASC' },
});
for (const prompt of prompts) {
prompt.prompt_content = await this._renderPrompt(prompt.prompt_content);
}
return prompts;
}
async findOne(id: string): Promise<SystemPrompt> {
const prompt = await this.systemPromptsRepository.findOneBy({ id });
Iif (!prompt) {
throw new NotFoundException(`SystemPrompt with ID "${id}" not found`);
}
prompt.prompt_content = await this._renderPrompt(prompt.prompt_content);
return prompt;
}
async findOneWithSession(
id: string,
sessionId: string,
sessionName: string,
): Promise<SystemPrompt> {
const prompt = await this.systemPromptsRepository.findOneBy({ id });
Iif (!prompt) {
throw new NotFoundException(`SystemPrompt with ID "${id}" not found`);
}
prompt.prompt_content = await this._renderPrompt(
prompt.prompt_content,
sessionId,
sessionName,
);
return prompt;
}
async findByName(name: string): Promise<SystemPrompt | null> {
return this.systemPromptsRepository.findOneBy({ prompt_name: name });
}
async findByBuiltinKey(builtinKey: string): Promise<SystemPrompt | null> {
return this.systemPromptsRepository.findOneBy({ builtin_key: builtinKey });
}
async findOneRaw(id: string): Promise<SystemPrompt> {
const prompt = await this.systemPromptsRepository.findOneBy({ id });
Iif (!prompt) {
throw new NotFoundException(`SystemPrompt with ID "${id}" not found`);
}
return prompt;
}
/**
* Update content of a built-in prompt (for version upgrades).
* Only callable from seeding service.
*/
async updateBuiltinContent(
id: string,
promptContent: string,
enabledTools: string[] | 'all',
enabledMcpTools?: string[] | 'all',
): Promise<SystemPrompt> {
const prompt = await this.systemPromptsRepository.findOneBy({ id });
if (!prompt) {
throw new NotFoundException(`SystemPrompt with ID "${id}" not found`);
}
prompt.prompt_content = promptContent;
prompt.enabledTools = this.serializeEnabledTools(enabledTools);
if (enabledMcpTools !== undefined) {
prompt.enabledMcpTools =
this.serializeEnabledMcpTools(enabledMcpTools);
}
return this.systemPromptsRepository.save(prompt);
}
async findDefault(): Promise<SystemPrompt | null> {
const prompt = await this.systemPromptsRepository.findOneBy({
is_default: true,
});
Iif (prompt) {
prompt.prompt_content = await this._renderPrompt(prompt.prompt_content);
}
return prompt;
}
async findDefaultWithSession(
sessionId: string,
sessionName: string,
): Promise<SystemPrompt | null> {
const prompt = await this.systemPromptsRepository.findOneBy({
is_default: true,
});
Iif (prompt) {
prompt.prompt_content = await this._renderPrompt(
prompt.prompt_content,
sessionId,
sessionName,
);
}
return prompt;
}
async update(
id: string,
updateSystemPromptDto: UpdateSystemPromptDto,
): Promise<SystemPrompt> {
// Fetch raw prompt to avoid injecting tools before writing.
const prompt = await this.systemPromptsRepository.findOneBy({ id });
Iif (!prompt) {
throw new NotFoundException(`SystemPrompt with ID "${id}" not found`);
}
// Check if builtin - forbid modification
if (prompt.is_builtin) {
throw new ForbiddenException(
`Cannot modify built-in system prompt "${prompt.prompt_name}". Duplicate it to create your own version.`,
);
}
// is_default should be handled by setDefault to ensure only one default exists.
const updateData: any = { ...updateSystemPromptDto };
delete updateData.is_default;
// Serialize enabledMcpTools if provided (convert string[] | 'all' to string)
if (updateData.enabledMcpTools !== undefined) {
prompt.enabledMcpTools = this.serializeEnabledMcpTools(
updateData.enabledMcpTools,
);
delete updateData.enabledMcpTools;
}
this.systemPromptsRepository.merge(prompt, updateData);
const updatedPrompt = await this.systemPromptsRepository.save(prompt);
// Inject for the returned value (read operation).
updatedPrompt.prompt_content = await this._renderPrompt(
updatedPrompt.prompt_content,
);
return updatedPrompt;
}
async remove(id: string): Promise<void> {
// Fetch raw prompt to avoid an unnecessary injection.
const prompt = await this.systemPromptsRepository.findOneBy({ id });
Iif (!prompt) {
throw new NotFoundException(`SystemPrompt with ID "${id}" not found`);
}
await this.systemPromptsRepository.remove(prompt);
}
/**
* Duplicate a system prompt (allowed for built-in prompts).
* Creates a user-owned copy with is_builtin=false.
*/
async duplicate(id: string): Promise<SystemPrompt> {
const original = await this.systemPromptsRepository.findOneBy({ id });
Iif (!original) {
throw new NotFoundException(`SystemPrompt with ID "${id}" not found`);
}
// Generate unique name for the duplicate
let newName = `${original.prompt_name} (Copy)`;
let suffix = 2;
while (
await this.systemPromptsRepository.findOneBy({ prompt_name: newName })
) {
newName = `${original.prompt_name} (Copy ${suffix})`;
suffix++;
}
// Create duplicate with user ownership
const duplicate = this.systemPromptsRepository.create({
prompt_name: newName,
prompt_content: original.prompt_content,
url: original.url,
enabledTools: original.enabledTools,
enabledMcpTools: original.enabledMcpTools,
followup_token_limit: original.followup_token_limit,
is_builtin: false,
builtin_key: null,
});
const saved = await this.systemPromptsRepository.save(duplicate);
// Inject tools for the returned value
saved.prompt_content = await this._renderPrompt(saved.prompt_content);
return saved;
}
async setDefault(id: string): Promise<SystemPrompt> {
// Fetch raw prompt to avoid injecting tools before writing.
const newDefaultPrompt = await this.systemPromptsRepository.findOneBy({
id,
});
if (!newDefaultPrompt) {
throw new NotFoundException(`SystemPrompt with ID "${id}" not found`);
}
await this.dataSource.transaction(async (manager) => {
const currentDefault = await manager.findOneBy(SystemPrompt, {
is_default: true,
});
if (currentDefault && currentDefault.id !== newDefaultPrompt.id) {
currentDefault.is_default = false;
await manager.save(currentDefault);
}
if (!newDefaultPrompt.is_default) {
newDefaultPrompt.is_default = true;
await manager.save(newDefaultPrompt);
}
});
// Inject for the returned value (read operation).
newDefaultPrompt.prompt_content = await this._renderPrompt(
newDefaultPrompt.prompt_content,
);
return newDefaultPrompt;
}
async pushToStudio(id: string): Promise<void> {
// findOne already injects tools, no need to do it again.
const prompt = await this.findOne(id);
this.eventsGateway.sendToAll('system-prompt-update', {
systemPrompt: prompt.prompt_content,
});
}
async preview(
previewDto: PreviewSystemPromptDto,
): Promise<PreviewSystemPromptResponseDto> {
const rendered_content = await this._renderPrompt(
previewDto.prompt_content,
);
return { rendered_content };
}
getToolNames(): string[] {
return Array.from(this.handlerRegistry.keys());
}
/**
* Get enabled tools for a system prompt.
* Returns 'all' if all tools are enabled, or list of enabled tool names.
*/
async getEnabledTools(systemPromptId: string): Promise<string[] | 'all'> {
const systemPrompt = await this.systemPromptsRepository.findOneBy({
id: systemPromptId,
});
Iif (!systemPrompt) {
throw new NotFoundException(
`SystemPrompt with ID "${systemPromptId}" not found`,
);
}
return this.parseEnabledTools(systemPrompt.enabledTools);
}
/**
* Update enabled tools for a system prompt.
*/
async setEnabledTools(
systemPromptId: string,
enabledTools: string[] | 'all',
): Promise<{ enabledTools: string[] | 'all' }> {
const systemPrompt = await this.systemPromptsRepository.findOneBy({
id: systemPromptId,
});
Iif (!systemPrompt) {
throw new NotFoundException(
`SystemPrompt with ID "${systemPromptId}" not found`,
);
}
// Filter out any invalid/deprecated tool names (silent cleanup)
let cleanedTools: string[] | 'all';
if (Array.isArray(enabledTools)) {
cleanedTools = enabledTools.filter((tool) =>
this.ALL_TOOL_NAMES.includes(tool),
);
} else {
cleanedTools = enabledTools;
}
systemPrompt.enabledTools = this.serializeEnabledTools(cleanedTools);
await this.systemPromptsRepository.save(systemPrompt);
// Return parsed value
return { enabledTools: this.parseEnabledTools(systemPrompt.enabledTools) };
}
/**
* Get tools that should actually be sent to LLM for a given system prompt.
* Resolves 'all' to full list of tool names.
* Filters out deprecated/invalid tool names.
*/
async getToolsForPrompt(systemPromptId: string): Promise<string[]> {
const enabledTools = await this.getEnabledTools(systemPromptId);
Iif (enabledTools === 'all') {
return this.ALL_TOOL_NAMES;
}
// Filter out any tools that are no longer valid (e.g., deprecated tools)
const validTools = (enabledTools as string[]).filter((tool) =>
this.ALL_TOOL_NAMES.includes(tool),
);
return validTools;
}
/**
* Toggle a specific tool's enabled state for a system prompt.
*/
async toggleTool(
systemPromptId: string,
toolName: string,
): Promise<{ enabledTools: string[] | 'all' }> {
// Validate tool name
Iif (!this.ALL_TOOL_NAMES.includes(toolName)) {
throw new Error(
`Invalid tool name "${toolName}". Valid tools: ${this.ALL_TOOL_NAMES.join(', ')}`,
);
}
const systemPrompt = await this.systemPromptsRepository.findOneBy({
id: systemPromptId,
});
Iif (!systemPrompt) {
throw new NotFoundException(
`SystemPrompt with ID "${systemPromptId}" not found`,
);
}
const currentEnabled = this.parseEnabledTools(systemPrompt.enabledTools);
// If currently 'all', switch to array excluding tool
if (currentEnabled === 'all') {
const enabledArray = this.ALL_TOOL_NAMES.filter((t) => t !== toolName);
systemPrompt.enabledTools = this.serializeEnabledTools(enabledArray);
} else {
// Toggle: if in array, remove; if not, add
const enabled = currentEnabled as string[];
const index = enabled.indexOf(toolName);
if (index === -1) {
enabled.push(toolName);
// If all tools are enabled, switch back to 'all'
if (enabled.length === this.ALL_TOOL_NAMES.length) {
systemPrompt.enabledTools = this.serializeEnabledTools('all');
} else {
systemPrompt.enabledTools = this.serializeEnabledTools(enabled);
}
} else {
enabled.splice(index, 1);
systemPrompt.enabledTools =
enabled.length > 0
? this.serializeEnabledTools(enabled)
: this.serializeEnabledTools([]);
}
}
await this.systemPromptsRepository.save(systemPrompt);
// Return parsed value
return { enabledTools: this.parseEnabledTools(systemPrompt.enabledTools) };
}
/**
* Get all available tool names.
*/
getAllToolNames(): string[] {
return [...this.ALL_TOOL_NAMES];
}
// ==================== MCP Tool Override Methods ====================
/**
* Parse enabledMcpTools from string storage.
* Returns 'all' or string[] of serverName__toolName identifiers.
*/
private parseEnabledMcpTools(value: string | null): string[] | 'all' {
if (!value) {
return 'all';
}
if (value === 'all') {
return 'all';
}
try {
const tools = JSON.parse(value);
if (Array.isArray(tools)) {
return tools;
}
return 'all';
} catch (e) {
return 'all';
}
}
/**
* Serialize enabledMcpTools for storage.
*/
private serializeEnabledMcpTools(value: string[] | 'all'): string | null {
if (value === 'all') {
return 'all';
}
return JSON.stringify(value);
}
/**
* Get all available MCP tool names (from globally active servers/tools).
*/
async getAllMcpToolNames(): Promise<string[]> {
return this.mcpService.getActiveMcpToolNames();
}
/**
* Get enabled MCP tools for a system prompt.
* Returns 'all' if all MCP tools are enabled, or list of enabled tool identifiers.
*/
async getEnabledMcpTools(systemPromptId: string): Promise<string[] | 'all'> {
const systemPrompt = await this.systemPromptsRepository.findOneBy({
id: systemPromptId,
});
if (!systemPrompt) {
throw new NotFoundException(
`SystemPrompt with ID "${systemPromptId}" not found`,
);
}
return this.parseEnabledMcpTools(systemPrompt.enabledMcpTools);
}
/**
* Update enabled MCP tools for a system prompt.
* Supports server-level prefixes (e.g., 'playwright') alongside exact tool names.
* Server prefixes are stored as-is and resolved at query time.
*/
async setEnabledMcpTools(
systemPromptId: string,
enabledMcpTools: string[] | 'all',
): Promise<{ enabledMcpTools: string[] | 'all' }> {
const systemPrompt = await this.systemPromptsRepository.findOneBy({
id: systemPromptId,
});
if (!systemPrompt) {
throw new NotFoundException(
`SystemPrompt with ID "${systemPromptId}" not found`,
);
}
// Store as-is (server prefixes like 'playwright' are preserved)
systemPrompt.enabledMcpTools =
this.serializeEnabledMcpTools(enabledMcpTools);
await this.systemPromptsRepository.save(systemPrompt);
return {
enabledMcpTools: this.parseEnabledMcpTools(systemPrompt.enabledMcpTools),
};
}
/**
* Toggle a specific MCP tool's enabled state for a system prompt.
*/
async toggleMcpTool(
systemPromptId: string,
mcpToolName: string,
): Promise<{ enabledMcpTools: string[] | 'all' }> {
const systemPrompt = await this.systemPromptsRepository.findOneBy({
id: systemPromptId,
});
if (!systemPrompt) {
throw new NotFoundException(
`SystemPrompt with ID "${systemPromptId}" not found`,
);
}
const currentEnabled = this.parseEnabledMcpTools(
systemPrompt.enabledMcpTools,
);
if (currentEnabled === 'all') {
// Switch from 'all' to array excluding the toggled tool
const allActiveMcpTools = await this.mcpService.getActiveMcpToolNames();
const enabledArray = allActiveMcpTools.filter((t) => t !== mcpToolName);
systemPrompt.enabledMcpTools =
this.serializeEnabledMcpTools(enabledArray);
} else {
// Toggle: if in array, remove; if not, add
const enabled = [...(currentEnabled as string[])];
const index = enabled.indexOf(mcpToolName);
if (index === -1) {
enabled.push(mcpToolName);
// Check if all globally active MCP tools are now enabled
const allActiveMcpTools = await this.mcpService.getActiveMcpToolNames();
if (
allActiveMcpTools.length > 0 &&
allActiveMcpTools.every((t) => enabled.includes(t))
) {
systemPrompt.enabledMcpTools = this.serializeEnabledMcpTools('all');
} else {
systemPrompt.enabledMcpTools = this.serializeEnabledMcpTools(enabled);
}
} else {
enabled.splice(index, 1);
systemPrompt.enabledMcpTools =
enabled.length > 0
? this.serializeEnabledMcpTools(enabled)
: this.serializeEnabledMcpTools([]);
}
}
await this.systemPromptsRepository.save(systemPrompt);
return {
enabledMcpTools: this.parseEnabledMcpTools(systemPrompt.enabledMcpTools),
};
}
/**
* Get MCP tools that should actually be sent to LLM for a given system prompt.
* Resolves 'all' to full list of globally active MCP tools.
* Supports server-level prefixes: an entry like 'playwright' matches all
* tools from that server (e.g., 'playwright__browser_navigate').
* Returns array of serverName__toolName identifiers.
*/
async getMcpToolsForPrompt(systemPromptId: string): Promise<string[]> {
const enabledMcpTools = await this.getEnabledMcpTools(systemPromptId);
const allActiveMcpTools = await this.mcpService.getActiveMcpToolNames();
if (enabledMcpTools === 'all') {
return allActiveMcpTools;
}
// Resolve server prefixes and exact matches
return this.resolveMcpToolNames(enabledMcpTools, allActiveMcpTools);
}
/**
* Resolve enabled MCP tool entries against all active tools.
* Each entry can be either:
* - An exact tool name: 'playwright__browser_navigate'
* - A server prefix: 'playwright' (matches all 'playwright__*' tools)
*/
private resolveMcpToolNames(
entries: string[],
allActiveMcpTools: string[],
): string[] {
const result: string[] = [];
for (const entry of entries) {
for (const tool of allActiveMcpTools) {
// Exact match: entry === tool (e.g., 'playwright__browser_navigate')
// Server prefix match: entry === serverName (e.g., 'playwright' matches 'playwright__browser_navigate')
if (tool === entry || tool.startsWith(entry + '__')) {
if (!result.includes(tool)) {
result.push(tool);
}
}
}
}
return result;
}
}
|