Skip to main content
Glama
datasourceCredentials.ts1.4 kB
import { z } from 'zod'; import { getConfig } from '../../config.js'; const schema = z.record( z.string().nonempty(), z.array( z .object({ luid: z.string().optional(), u: z.string().nonempty(), p: z.string().nonempty() }) .transform(({ luid, u, p }) => ({ connectionLuid: luid, connectionUsername: u, connectionPassword: p, })), ), ); type Connection = { connectionLuid: string | undefined; connectionUsername: string; connectionPassword: string; }; let credentialMap: Map<string, Array<Connection>> | undefined; let initialized = false; export const getDatasourceCredentials = (datasourceLuid: string): Array<Connection> | undefined => { if (!initialized) { initialized = true; const { datasourceCredentials } = getConfig(); if (!datasourceCredentials) { return; } let obj: any; try { obj = JSON.parse(datasourceCredentials); } catch (e) { throw new Error( `Invalid datasource credentials format. Could not parse JSON string: ${datasourceCredentials}`, { cause: e }, ); } const parsed = schema.parse(obj); credentialMap = new Map(Object.entries(parsed)); } return credentialMap?.get(datasourceLuid); }; export const exportedForTesting = { resetDatasourceCredentials: () => { initialized = false; credentialMap = undefined; }, };

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/datalabs89/tableau-mcp'

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