mcp-runtime-name.ts 779 B

12345678910111213141516171819202122232425
  1. const MCP_SEGMENT_SEPARATOR = '__';
  2. /**
  3. * Match one canonical `mcp__<server>__<tool>` name to a server-level
  4. * `mcp__<server>` permission rule.
  5. *
  6. * Extra separators make the legacy name ambiguous, so matching fails closed
  7. * instead of treating a shorter prefix as the owning server.
  8. */
  9. export function matchesMcpServerRuntimeName(
  10. toolRuntimeName: string,
  11. serverRuntimeName: string,
  12. ): boolean {
  13. const toolParts = toolRuntimeName.split(MCP_SEGMENT_SEPARATOR);
  14. const serverParts = serverRuntimeName.split(MCP_SEGMENT_SEPARATOR);
  15. return (
  16. toolParts.length === 3 &&
  17. serverParts.length === 2 &&
  18. toolParts[0] === 'mcp' &&
  19. serverParts[0] === 'mcp' &&
  20. Boolean(toolParts[1]) &&
  21. Boolean(toolParts[2]) &&
  22. toolParts[1] === serverParts[1]
  23. );
  24. }