We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/gergelyszerovay/mcp-id-date'
If you have feedback or need assistance with the MCP directory API, please join our Discord server
getNextOrInitHexId.ts•1.02 kB
import { convertToHex } from './internal/convertToHex';
import { isErrnoException } from './internal/isErrnoException';
import { readCounterFile } from './internal/readCounterFile';
import { writeCounterFile } from './internal/writeCounterFile';
/**
* Gets the next unique 8-digit hexadecimal ID and increments the counter
* Creates the counter file if it doesn't exist
*
* @param counterFilePath - Path to the counter file (defaults to '/workspace/last-tag-id.txt')
* @returns Promise resolving to the next unique hex ID
*/
export async function getNextOrInitHexId(
counterFilePath = '/workspace/last-tag-id.txt',
): Promise<string> {
try {
const current = await readCounterFile(counterFilePath);
const next = current + 1;
await writeCounterFile(counterFilePath, next);
return convertToHex(next);
} catch (error: unknown) {
if (isErrnoException(error) && error.code === 'ENOENT') {
await writeCounterFile(counterFilePath, 0);
return convertToHex(0);
}
throw error;
}
}