UNPKG

sarvam-mcp-server

Version:

A Model Context Protocol (MCP) server implementation for Sarvam's text processing capabilities, providing language identification, text analytics, translation, and transliteration services for Indian languages.

31 lines (30 loc) 949 B
import envManager from "./env.js"; import { createSarvamError } from "./error.js"; export const SARVAM_BASE_URL = "https://api.sarvam.ai"; const USER_AGENT = "sarvam-mcp/1.0"; export async function sarvamRequest(endpoint, options = {}) { const headers = { "Content-Type": "application/json", "User-Agent": USER_AGENT, ...options.headers, }; if (envManager.getSarvamAPIKey()) { headers["api-subscription-key"] = envManager.getSarvamAPIKey(); } try { const res = await fetch(`${SARVAM_BASE_URL}/${endpoint}`, { method: options.method || "GET", headers, body: options.body ? options.body : undefined, }); if (!res.ok) { throw createSarvamError(res.status, res); } const data = await res.json(); return data; } catch (error) { console.error("Error: ", error); return null; } }