set_api_auth
Configure API authentication methods including API keys and bearer tokens, with secure credential handling through environment variables.
Instructions
Configure authentication for an API. Supports API key (header or query param) and bearer token auth. Use env_var to reference a secret from an environment variable — the credential is then resolved at request time and never stored on disk.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| api_id | Yes | The API identifier | |
| auth_type | Yes | Type of authentication | |
| credential | No | The API key or bearer token. Not required when env_var is set. | |
| env_var | No | Environment variable name that holds the credential (e.g., 'GITHUB_TOKEN'). When set, the secret is read from this env var at request time and never written to disk. | |
| header_name | No | Header name for API key (default: X-API-Key) | |
| param_name | No | Query param name for API key auth |
Implementation Reference
- src/jitapi/mcp/tools.py:546-589 (handler)Implementation of the _set_api_auth handler.
async def _set_api_auth(self, args: dict[str, Any]) -> ToolResult: """Configure API authentication.""" api_id = args["api_id"] auth_type = args["auth_type"] credential = args.get("credential", "") env_var = args.get("env_var") # Must provide either credential or env_var if not credential and not env_var: return ToolResult( success=False, data=None, error="Either 'credential' or 'env_var' must be provided.", ) if auth_type == "api_key": header_name = args.get("header_name", "X-API-Key") self.auth_handler.set_api_key( api_id, credential, header_name, env_var=env_var, ) elif auth_type == "api_key_query": param_name = args.get("param_name", "apikey") self.auth_handler.set_api_key_query_param( api_id, credential, param_name, env_var=env_var, ) elif auth_type == "bearer": self.auth_handler.set_bearer_token(api_id, credential, env_var=env_var) else: return ToolResult( success=False, data=None, error=f"Unknown auth type: {auth_type}", ) source = f"env var ${env_var}" if env_var else "provided credential" return ToolResult( success=True, data={ "api_id": api_id, "auth_type": auth_type, "credential_source": "env_var" if env_var else "direct", "message": f"Authentication configured for {api_id} (from {source})", }, ) - src/jitapi/mcp/models.py:128-149 (schema)Pydantic model defining the input schema for the set_api_auth tool.
class SetApiAuthInput(BaseModel): """Input for set_api_auth tool.""" api_id: str = Field( ..., description="The API identifier", min_length=1, ) auth_type: Literal["api_key", "api_key_query", "bearer"] = Field( ..., description="Type of authentication", ) credential: str = Field( "", description="The API key or bearer token. Not required when env_var is set.", ) env_var: str | None = Field( None, description="Environment variable name that holds the credential. " "When set, the secret is read from this env var at request time and never written to disk.", ) header_name: str = Field( - src/jitapi/mcp/tools.py:293-293 (registration)Registration of the set_api_auth tool in the MCP tools dispatcher.
"set_api_auth": self._set_api_auth,