agent-mcps.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {
  2. type AgentName,
  3. getAgentOverride,
  4. McpNameSchema,
  5. type PluginConfig,
  6. } from '.';
  7. /** Default MCPs per agent - "*" means all MCPs, "!item" excludes specific MCPs */
  8. export const DEFAULT_AGENT_MCPS: Record<AgentName, string[]> = {
  9. orchestrator: ['websearch'],
  10. designer: [],
  11. oracle: [],
  12. librarian: ['websearch', 'context7', 'grep_app'],
  13. explorer: [],
  14. fixer: [],
  15. council: [],
  16. councillor: [],
  17. 'council-master': [],
  18. };
  19. /**
  20. * Parse a list with wildcard and exclusion syntax.
  21. */
  22. export function parseList(items: string[], allAvailable: string[]): string[] {
  23. if (!items || items.length === 0) {
  24. return [];
  25. }
  26. const allow = items.filter((i) => !i.startsWith('!'));
  27. const deny = items.filter((i) => i.startsWith('!')).map((i) => i.slice(1));
  28. if (deny.includes('*')) {
  29. return [];
  30. }
  31. if (allow.includes('*')) {
  32. return allAvailable.filter((item) => !deny.includes(item));
  33. }
  34. return allow.filter((item) => !deny.includes(item));
  35. }
  36. /**
  37. * Get available MCP names from schema and config.
  38. */
  39. export function getAvailableMcpNames(config?: PluginConfig): string[] {
  40. const builtinMcps = McpNameSchema.options;
  41. const disabled = new Set(config?.disabled_mcps ?? []);
  42. return builtinMcps.filter((name) => !disabled.has(name));
  43. }
  44. /**
  45. * Get the MCP list for an agent (from config or defaults).
  46. */
  47. export function getAgentMcpList(
  48. agentName: string,
  49. config?: PluginConfig,
  50. ): string[] {
  51. const agentConfig = getAgentOverride(config, agentName);
  52. if (agentConfig?.mcps !== undefined) {
  53. return agentConfig.mcps;
  54. }
  55. const defaultMcps = DEFAULT_AGENT_MCPS[agentName as AgentName];
  56. return defaultMcps ?? [];
  57. }