How sarvamai/sarvam-mcp works
Purpose and Invocation
sarvam-mcp is a Python 3.11+ MCP server that makes Sarvam AI APIs callable as MCP tools by desktop/editor clients. The package is launched through its console/module entry point, then communicates over the MCP transport used by the host client.
Paths: src/sarvam_mcp/__main__.py, src/sarvam_mcp/server.py, pyproject.toml.
Server Composition and Tool Registration
The server builds the MCP application and registers two tool namespaces: runtime API tools and builder/code-assistance tools. The registry centralizes discovery/registration rather than exposing service modules directly.
Paths: src/sarvam_mcp/server.py, src/sarvam_mcp/_registry.py, src/sarvam_mcp/tools/__init__.py.
Authentication and Runtime Configuration
Configuration establishes the Sarvam API base URL, output base path, and audio output mode. Authentication resolves an API key from SARVAM_API_KEY first, with credential-file fallback; context/elicit modules support carrying or requesting credentials at MCP boundaries.
Paths: src/sarvam_mcp/config.py, src/sarvam_mcp/auth/api_key.py, src/sarvam_mcp/auth/context.py.
Sarvam API Boundary
Runtime tools translate MCP inputs into Sarvam REST calls through a shared HTTP client. The HTTP layer owns request behavior, error normalization, and retry policy, isolating upstream API failures and transport details from individual tools.
Paths: src/sarvam_mcp/http/client.py, src/sarvam_mcp/http/errors.py, src/sarvam_mcp/http/retry.py.
Runtime AI Capability Tools
Service-specific MCP tools cover speech-to-text, text-to-speech, translation/transliteration/language ID, LLM completions, text analytics, vision job submission/status, and pronunciation dictionaries. Tool modules are the primary contract boundary presented to MCP clients.
Paths: src/sarvam_mcp/tools/stt.py, src/sarvam_mcp/tools/tts.py, src/sarvam_mcp/tools/llm.py.
File and Audio Handling
Audio-oriented tools resolve input URIs and write generated media through configurable sinks. This separates remote API payloads from local file/resource delivery and honors the configured MCP base path/output mode.
Paths: src/sarvam_mcp/audio/uris.py, src/sarvam_mcp/audio/sinks.py, src/sarvam_mcp/tools/vision.py.
Higher-Level Workflows and Builder Tools
Workflows compose lower-level runtime calls into voice, dubbing, localization, and recall operations. Separately, code tools expose Sarvam documentation, snippets, and curated data for agents generating API-integrated applications.
Paths: src/sarvam_mcp/workflows/dub.py, src/sarvam_mcp/workflows/localize.py, src/sarvam_mcp/code/docs.py.
Observability and Deployment Surfaces
The Python server emits analytics/observability signals. A separate Next.js website supplies health/ready endpoints and usage tracking, packaged for Kubernetes via Helm; it appears operationally separate from the MCP process.
Paths: src/sarvam_mcp/analytics.py, src/sarvam_mcp/observability.py, web/app/api/track/route.ts, helmchart/sarvam-mcp-website/templates/sarvam-mcp-website.yaml.
Main entry points: server.py MCP application · __init__.py Tool namespaces · stt.py Runtime AI tools · client.py Shared HTTP client
Components 20
MCP Server
- Package entry point
src/sarvam_mcp/__main__.py - MCP application
src/sarvam_mcp/server.py - Tool registry · Centralizes runtime and builder tool discovery.
src/sarvam_mcp/_registry.py - Tool namespaces
src/sarvam_mcp/tools/__init__.py - Runtime configuration · Sets API URL, output path, and audio mode.
src/sarvam_mcp/config.py - API key resolution · Uses environment credentials before credential-file fallback.
src/sarvam_mcp/auth/api_key.py - Credential context · Carries or elicits credentials at MCP boundaries.
src/sarvam_mcp/auth/context.py - Analytics and observability
src/sarvam_mcp/observability.py
Runtime Services
- Runtime AI tools · Speech, LLM, translation, analytics, vision, and dictionary capabilities.
src/sarvam_mcp/tools/stt.py - Speech synthesis tools
src/sarvam_mcp/tools/tts.py - LLM completion tools
src/sarvam_mcp/tools/llm.py - Dubbing workflows · Composes lower-level calls into voice workflows.
src/sarvam_mcp/workflows/dub.py - Localization workflows
src/sarvam_mcp/workflows/localize.py - Builder documentation tools · Exposes documentation, snippets, and curated agent data.
src/sarvam_mcp/code/docs.py - Audio URI resolver
src/sarvam_mcp/audio/uris.py - Audio output sinks · Writes generated media according to configured output mode.
src/sarvam_mcp/audio/sinks.py
Sarvam Boundary
- Shared HTTP client · Owns requests, retries, and normalized upstream failures.
src/sarvam_mcp/http/client.py - Sarvam AI APIs
Operations Website
- Usage tracking endpoint
web/app/api/track/route.ts - Website Helm deployment
helmchart/sarvam-mcp-website/templates/sarvam-mcp-website.yaml
Connections 24
- Package entry point → MCP application: launches
- MCP application → Tool registry: initializes
- Tool registry → Tool namespaces: registers
- Tool namespaces → Runtime AI tools: exposes
- Tool namespaces → Speech synthesis tools: exposes
- Tool namespaces → LLM completion tools: exposes
- Tool namespaces → Builder documentation tools: exposes
- MCP application → Runtime configuration: loads
- MCP application → Credential context: uses
- Credential context → API key resolution: supplies or requests
- Runtime AI tools → API key resolution: authenticates with
- Runtime AI tools → Shared HTTP client: calls through
- Speech synthesis tools → Audio URI resolver: resolves input
- Speech synthesis tools → Audio output sinks: writes output
- Speech synthesis tools → Shared HTTP client: calls through
- LLM completion tools → Shared HTTP client: calls through
- Dubbing workflows → Runtime AI tools: composes
- Localization workflows → Runtime AI tools: composes
- Runtime configuration → Audio output sinks: configures
- API key resolution → Shared HTTP client: authorizes
- Shared HTTP client → Sarvam AI APIs: REST requests
- MCP application → Analytics and observability: emits signals
- Analytics and observability → Usage tracking endpoint: reports usage
- Website Helm deployment → Usage tracking endpoint: deploys