Skip to main content
Glama
parseToolName.test.ts1.96 kB
import { describe, it, expect } from 'vitest'; import { parseToolName } from '../../src/utils/parseToolName'; describe('parseToolName', () => { it('should return actualToolName only for plain tool names', () => { const result = parseToolName('my_tool'); expect(result).toEqual({ actualToolName: 'my_tool' }); expect(result.serverName).toBeUndefined(); }); it('should parse serverName and actualToolName from prefixed format', () => { const result = parseToolName('server__my_tool'); expect(result).toEqual({ serverName: 'server', actualToolName: 'my_tool', }); }); it('should handle tool names with underscores correctly', () => { const result = parseToolName('my_server__my_cool_tool'); expect(result).toEqual({ serverName: 'my_server', actualToolName: 'my_cool_tool', }); }); it('should handle multiple double underscores - use first occurrence', () => { const result = parseToolName('server__tool__extra'); expect(result).toEqual({ serverName: 'server', actualToolName: 'tool__extra', }); }); it('should not parse if separator is at the start', () => { const result = parseToolName('__tool'); expect(result).toEqual({ actualToolName: '__tool' }); expect(result.serverName).toBeUndefined(); }); it('should handle empty string', () => { const result = parseToolName(''); expect(result).toEqual({ actualToolName: '' }); expect(result.serverName).toBeUndefined(); }); it('should handle single underscore (not a separator)', () => { const result = parseToolName('my_tool_name'); expect(result).toEqual({ actualToolName: 'my_tool_name' }); expect(result.serverName).toBeUndefined(); }); it('should handle server name with hyphens', () => { const result = parseToolName('my-server__my_tool'); expect(result).toEqual({ serverName: 'my-server', actualToolName: 'my_tool', }); }); });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/AgiFlow/aicode-toolkit'

If you have feedback or need assistance with the MCP directory API, please join our Discord server