We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/fredriksknese/mcp-cohesity'
If you have feedback or need assistance with the MCP directory API, please join our Discord server
export interface CohesityConfig {
cluster: string;
username: string;
password: string;
domain: string;
allowSelfSigned: boolean;
}
export class CohesityClient {
private baseUrlV2: string;
private baseUrlV1: string;
private accessToken: string | null = null;
private config: CohesityConfig;
constructor(config: CohesityConfig) {
this.config = config;
this.baseUrlV2 = `https://${config.cluster}/v2`;
this.baseUrlV1 = `https://${config.cluster}/irisservices/api/v1/public`;
if (config.allowSelfSigned) {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
}
}
async authenticate(): Promise<void> {
const url = `${this.baseUrlV2}/users/sessions`;
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
username: this.config.username,
password: this.config.password,
domain: this.config.domain,
}),
});
if (!response.ok) {
const errorText = await response.text();
throw new Error(
`Cohesity authentication failed (${response.status}): ${errorText}`,
);
}
const data = (await response.json()) as { accessToken?: string; token?: string };
const token = data.accessToken ?? data.token;
if (!token) {
throw new Error("Cohesity authentication response did not include an access token");
}
this.accessToken = token;
}
private async ensureAuthenticated(): Promise<string> {
if (!this.accessToken) {
await this.authenticate();
}
return this.accessToken!;
}
private async request(
method: string,
url: string,
body?: unknown,
params?: Record<string, string>,
): Promise<unknown> {
const token = await this.ensureAuthenticated();
const fullUrl = new URL(url);
if (params) {
for (const [key, value] of Object.entries(params)) {
fullUrl.searchParams.set(key, value);
}
}
const options: RequestInit = {
method,
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
Accept: "application/json",
},
};
if (body && (method === "POST" || method === "PUT" || method === "PATCH")) {
options.body = JSON.stringify(body);
}
const response = await fetch(fullUrl.toString(), options);
if (response.status === 401) {
// Token may have expired — re-authenticate once and retry
this.accessToken = null;
const newToken = await this.ensureAuthenticated();
(options.headers as Record<string, string>)["Authorization"] = `Bearer ${newToken}`;
const retryResponse = await fetch(fullUrl.toString(), options);
if (!retryResponse.ok) {
const errorText = await retryResponse.text();
throw new Error(
`Cohesity API error (${retryResponse.status}): ${errorText}`,
);
}
const contentType = retryResponse.headers.get("content-type");
if (contentType?.includes("application/json")) {
return retryResponse.json();
}
return retryResponse.text();
}
if (!response.ok) {
const errorText = await response.text();
throw new Error(
`Cohesity API error (${response.status}): ${errorText}`,
);
}
if (response.status === 204) {
return null;
}
const contentType = response.headers.get("content-type");
if (contentType?.includes("application/json")) {
return response.json();
}
return response.text();
}
// V2 API methods
async getV2(
path: string,
params?: Record<string, string>,
): Promise<unknown> {
return this.request("GET", `${this.baseUrlV2}/${path}`, undefined, params);
}
async postV2(
path: string,
body?: unknown,
params?: Record<string, string>,
): Promise<unknown> {
return this.request("POST", `${this.baseUrlV2}/${path}`, body, params);
}
async putV2(
path: string,
body?: unknown,
): Promise<unknown> {
return this.request("PUT", `${this.baseUrlV2}/${path}`, body);
}
async patchV2(
path: string,
body?: unknown,
): Promise<unknown> {
return this.request("PATCH", `${this.baseUrlV2}/${path}`, body);
}
async deleteV2(path: string): Promise<unknown> {
return this.request("DELETE", `${this.baseUrlV2}/${path}`);
}
// V1 API methods
async getV1(
path: string,
params?: Record<string, string>,
): Promise<unknown> {
return this.request("GET", `${this.baseUrlV1}/${path}`, undefined, params);
}
async postV1(
path: string,
body?: unknown,
): Promise<unknown> {
return this.request("POST", `${this.baseUrlV1}/${path}`, body);
}
async putV1(
path: string,
body?: unknown,
): Promise<unknown> {
return this.request("PUT", `${this.baseUrlV1}/${path}`, body);
}
}