mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-18 09:45:23 +00:00
Merge ec13e2821f into e16d79d635
This commit is contained in:
commit
933c1ba486
7 changed files with 198 additions and 12 deletions
|
|
@ -7741,7 +7741,7 @@
|
|||
"paths": {
|
||||
"/claude-code/marketplace.json": {
|
||||
"get": {
|
||||
"description": "Serve marketplace.json for Claude Code plugin discovery.\n\nThis endpoint is accessed by Claude Code CLI when users run:\n- claude plugin marketplace add <url>\n- claude plugin install <name>@<marketplace>\n\nWithout `key` the catalog holds the enabled (public) plugins. With `?key=sk-...`\nthe key is authenticated and the catalog also holds the disabled plugins granted\nto it through `object_permission.skills` or an access group on the key or its team.\n\nReturns:\n Marketplace catalog with list of available plugins and their git sources.\n\nExample:\n ```bash\n claude plugin marketplace add http://localhost:4000/claude-code/marketplace.json\n claude plugin marketplace add \"http://localhost:4000/claude-code/marketplace.json?key=sk-...\"\n claude plugin install my-plugin@litellm\n ```",
|
||||
"description": "Serve marketplace.json for Claude Code plugin discovery.\n\nThis endpoint is accessed by Claude Code CLI when users run:\n- claude plugin marketplace add <url>\n- claude plugin install <name>@<marketplace>\n\nWithout a key the catalog holds the enabled (public) plugins. With `?key=sk-...`\nthe key is authenticated and the catalog also holds the disabled plugins granted\nto it through `object_permission.skills` or an access group on the key or its team.\n\nWith `general_settings.claude_code_marketplace_auth_required: true` a caller with\nno key gets a 401, and the key may also come in the `Authorization` or\n`x-litellm-api-key` header (Claude Code sends them from the marketplace's `headers`).\n\nReturns:\n Marketplace catalog with list of available plugins and their git sources.\n\nExample:\n ```bash\n claude plugin marketplace add http://localhost:4000/claude-code/marketplace.json\n claude plugin marketplace add \"http://localhost:4000/claude-code/marketplace.json?key=sk-...\"\n claude plugin install my-plugin@litellm\n ```",
|
||||
"operationId": "get_marketplace_claude_code_marketplace_json_get",
|
||||
"parameters": [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2833,6 +2833,10 @@ class ConfigGeneralSettings(LiteLLMPydanticObjectBase):
|
|||
None,
|
||||
description="If True, stores request messages and responses in spend logs. Default is False.",
|
||||
)
|
||||
claude_code_marketplace_auth_required: bool = Field(
|
||||
False,
|
||||
description="If True, GET /claude-code/marketplace.json requires a LiteLLM key (Authorization or x-litellm-api-key header, the litellm_key_header_name header, or ?key=) and answers 401 without one, and GET /public/skill_hub returns an empty list. Default is False, which serves the enabled plugins to anyone.",
|
||||
)
|
||||
disable_requester_ip_address_logging: bool | None = Field(
|
||||
None,
|
||||
description="If True, new spend log rows store requester_ip_address as null in the column, the metadata and the stored request. The stored request also drops client-IP forwarding headers such as x-forwarded-for, and IP addresses in its other header values and in stored error messages are masked. Guardrails, metrics and callbacks that read the standard logging payload still receive the IP. Default is False.",
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ Actual plugin files are hosted on GitHub/GitLab/Bitbucket or as a zip archive on
|
|||
any HTTPS host (S3, Artifactory, a static file server).
|
||||
|
||||
Endpoints:
|
||||
/claude-code/marketplace.json - GET - List plugins for Claude Code discovery (unauthenticated; `?key=` adds the key's granted skills)
|
||||
/claude-code/marketplace.json - GET - List plugins for Claude Code discovery (anonymous unless
|
||||
general_settings.claude_code_marketplace_auth_required; a key adds its granted skills)
|
||||
/claude-code/plugins - POST - Register a new plugin (create-only, proxy admin only)
|
||||
/claude-code/plugins - GET - List plugins visible to the key (enabled, plus granted disabled ones)
|
||||
/claude-code/plugins/{name} - GET - Get plugin details (403 on a disabled plugin the key is not granted)
|
||||
|
|
@ -39,6 +40,7 @@ from litellm.proxy.anthropic_endpoints.claude_code_endpoints.claude_code_skill_a
|
|||
from litellm.proxy.auth.user_api_key_auth import user_api_key_auth
|
||||
from litellm.proxy.common_utils.resource_ownership import is_proxy_admin
|
||||
from litellm.repositories.table_repositories import ClaudeCodePluginRepository
|
||||
from litellm.types.proxy.auth.special_headers import SpecialHeaders
|
||||
from litellm.types.proxy.claude_code_endpoints import (
|
||||
InstallationPreference,
|
||||
ListPluginsResponse,
|
||||
|
|
@ -109,6 +111,24 @@ async def get_prisma_client() -> object:
|
|||
_get_prisma_client: Final = get_prisma_client
|
||||
|
||||
|
||||
def marketplace_auth_required() -> bool:
|
||||
from litellm.proxy.proxy_server import general_settings_view
|
||||
|
||||
return general_settings_view().get("claude_code_marketplace_auth_required") is True
|
||||
|
||||
|
||||
async def _marketplace_caller(request: Request, key: str | None) -> UserAPIKeyAuth | None:
|
||||
if key:
|
||||
return await user_api_key_auth(request=request, api_key=f"Bearer {key}")
|
||||
if not marketplace_auth_required():
|
||||
return None
|
||||
return await user_api_key_auth(
|
||||
request=request,
|
||||
api_key=request.headers.get(SpecialHeaders.openai_authorization.value) or "",
|
||||
custom_litellm_key_header=request.headers.get(SpecialHeaders.custom_litellm_api_key.value),
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/claude-code/marketplace.json",
|
||||
tags=["Claude Code Marketplace"],
|
||||
|
|
@ -121,10 +141,14 @@ async def get_marketplace(request: Request, key: str | None = None):
|
|||
- claude plugin marketplace add <url>
|
||||
- claude plugin install <name>@<marketplace>
|
||||
|
||||
Without `key` the catalog holds the enabled (public) plugins. With `?key=sk-...`
|
||||
Without a key the catalog holds the enabled (public) plugins. With `?key=sk-...`
|
||||
the key is authenticated and the catalog also holds the disabled plugins granted
|
||||
to it through `object_permission.skills` or an access group on the key or its team.
|
||||
|
||||
With `general_settings.claude_code_marketplace_auth_required: true` a caller with
|
||||
no key gets a 401, and the key may also come in the `Authorization` or
|
||||
`x-litellm-api-key` header (Claude Code sends them from the marketplace's `headers`).
|
||||
|
||||
Returns:
|
||||
Marketplace catalog with list of available plugins and their git sources.
|
||||
|
||||
|
|
@ -136,11 +160,8 @@ async def get_marketplace(request: Request, key: str | None = None):
|
|||
```
|
||||
"""
|
||||
try:
|
||||
caller: Final = await _marketplace_caller(request, key)
|
||||
prisma_client: Final = await get_prisma_client()
|
||||
|
||||
caller: Final[UserAPIKeyAuth | None] = (
|
||||
await user_api_key_auth(request=request, api_key=f"Bearer {key}") if key else None
|
||||
)
|
||||
visibility: Final[SkillVisibility] = await resolve_skill_visibility(caller)
|
||||
plugins: Final[Sequence[_PluginRecord]] = await ClaudeCodePluginRepository(prisma_client).table.find_many(
|
||||
where=visibility.where()
|
||||
|
|
@ -201,7 +222,7 @@ async def get_marketplace(request: Request, key: str | None = None):
|
|||
verbose_proxy_logger.exception("Error generating marketplace: %s", e)
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail={"error": f"Failed to generate marketplace: {e}"},
|
||||
detail={"error": "Failed to generate marketplace"},
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -367,17 +367,20 @@ async def get_mcp_servers():
|
|||
tags=["public", "Claude Code Marketplace"],
|
||||
)
|
||||
async def public_skill_hub():
|
||||
"""Return enabled (public) Claude Code skills — no auth required."""
|
||||
"""Return enabled (public) Claude Code skills, or none when the marketplace requires a key."""
|
||||
from litellm.proxy.anthropic_endpoints.claude_code_endpoints.claude_code_marketplace import (
|
||||
MANIFEST_FIELDS,
|
||||
get_installation_preference,
|
||||
get_prisma_client,
|
||||
marketplace_auth_required,
|
||||
)
|
||||
from litellm.types.proxy.claude_code_endpoints import (
|
||||
ListPluginsResponse,
|
||||
PluginListItem,
|
||||
)
|
||||
|
||||
if marketplace_auth_required():
|
||||
return ListPluginsResponse(plugins=[], count=0)
|
||||
try:
|
||||
prisma_client: Final = await get_prisma_client()
|
||||
plugins: Final = await _plugin_table(prisma_client).find_many(where={"enabled": True})
|
||||
|
|
@ -405,8 +408,11 @@ async def public_skill_hub():
|
|||
)
|
||||
)
|
||||
return ListPluginsResponse(plugins=items, count=len(items))
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
verbose_logger.exception("Error listing public skills: %s", e)
|
||||
raise HTTPException(status_code=500, detail="Failed to list skills")
|
||||
|
||||
|
||||
@router.get(
|
||||
|
|
|
|||
|
|
@ -5,14 +5,18 @@ Covers the git-subdir and archive source types added alongside the existing gith
|
|||
"""
|
||||
|
||||
import json
|
||||
from collections.abc import Mapping
|
||||
from types import MappingProxyType
|
||||
from typing import Final
|
||||
from unittest.mock import AsyncMock, MagicMock
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
from fastapi import HTTPException
|
||||
from pydantic import ValidationError
|
||||
|
||||
import litellm
|
||||
from litellm.caching.caching import DualCache
|
||||
from litellm.proxy._types import LiteLLM_ObjectPermissionTable, ProxyException, UserAPIKeyAuth
|
||||
from litellm.proxy.anthropic_endpoints.claude_code_endpoints import claude_code_marketplace
|
||||
from litellm.proxy.anthropic_endpoints.claude_code_endpoints.claude_code_marketplace import (
|
||||
|
|
@ -964,3 +968,87 @@ def test_marketplace_response_rejects_unknown_installation_preference():
|
|||
|
||||
with pytest.raises(ValidationError):
|
||||
MarketplaceResponse.model_validate(catalog)
|
||||
|
||||
|
||||
def _require_marketplace_auth(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(
|
||||
litellm.proxy.proxy_server, "general_settings", {"claude_code_marketplace_auth_required": True}
|
||||
)
|
||||
monkeypatch.setattr(litellm.proxy.proxy_server, "user_api_key_cache", DualCache())
|
||||
|
||||
|
||||
async def _get_marketplace_over_http(
|
||||
headers: Mapping[str, str] = MappingProxyType({}), params: Mapping[str, str] = MappingProxyType({})
|
||||
) -> httpx.Response:
|
||||
async with httpx.AsyncClient(
|
||||
transport=httpx.ASGITransport(app=litellm.proxy.proxy_server.app), base_url="http://test"
|
||||
) as client:
|
||||
return await client.get("/claude-code/marketplace.json", headers=dict(headers), params=dict(params))
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_marketplace_auth_required_refuses_an_anonymous_caller(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
_require_marketplace_auth(monkeypatch)
|
||||
await _register_public_and_private_plugins()
|
||||
|
||||
response: Final = await _get_marketplace_over_http()
|
||||
|
||||
assert response.status_code == 401
|
||||
assert "public-skill" not in response.text
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
"headers, params",
|
||||
[
|
||||
({"Authorization": f"Bearer {MASTER_KEY}"}, {}),
|
||||
({"x-litellm-api-key": f"Bearer {MASTER_KEY}"}, {}),
|
||||
({}, {"key": MASTER_KEY}),
|
||||
],
|
||||
)
|
||||
async def test_marketplace_auth_required_serves_a_caller_with_a_valid_key(
|
||||
monkeypatch: pytest.MonkeyPatch, headers: Mapping[str, str], params: Mapping[str, str]
|
||||
) -> None:
|
||||
_require_marketplace_auth(monkeypatch)
|
||||
await _register_public_and_private_plugins()
|
||||
|
||||
response: Final = await _get_marketplace_over_http(headers, params)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert sorted(plugin["name"] for plugin in response.json()["plugins"]) == ["private-skill", "public-skill"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_marketplace_auth_required_refuses_an_unknown_bearer_key(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
_require_marketplace_auth(monkeypatch)
|
||||
litellm.proxy.proxy_server.prisma_client.get_data = AsyncMock(return_value=None)
|
||||
await _register_public_and_private_plugins()
|
||||
|
||||
response: Final = await _get_marketplace_over_http({"Authorization": "Bearer sk-not-a-litellm-key"})
|
||||
|
||||
assert response.status_code == 401
|
||||
assert "public-skill" not in response.text
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_marketplace_without_auth_required_ignores_an_unrelated_authorization_header(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(litellm.proxy.proxy_server, "general_settings", {})
|
||||
await _register_public_and_private_plugins()
|
||||
|
||||
response: Final = await _get_marketplace_over_http({"Authorization": "Bearer an-identity-aware-proxy-token"})
|
||||
|
||||
assert response.status_code == 200
|
||||
assert [plugin["name"] for plugin in response.json()["plugins"]] == ["public-skill"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_marketplace_500_body_carries_no_exception_text(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(litellm.proxy.proxy_server, "general_settings", {})
|
||||
table: Final = litellm.proxy.proxy_server.prisma_client.db.litellm_claudecodeplugintable
|
||||
table.find_many = AsyncMock(side_effect=RuntimeError("could not reach postgres://admin:hunter2@db.internal"))
|
||||
|
||||
response: Final = await _get_marketplace_over_http()
|
||||
|
||||
assert response.status_code == 500
|
||||
assert "hunter2" not in response.text
|
||||
assert "db.internal" not in response.text
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import asyncio
|
||||
import json
|
||||
import re
|
||||
from collections.abc import Mapping
|
||||
from datetime import datetime, timezone
|
||||
from importlib.resources import files
|
||||
from itertools import chain
|
||||
|
|
@ -8,6 +9,7 @@ from types import SimpleNamespace
|
|||
from typing import Final
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
|
@ -1723,3 +1725,58 @@ def test_public_skill_hub_echoes_registered_installation_preference(preference):
|
|||
assert [(p["name"], p["installation_preference"]) for p in response.json()["plugins"]] == [
|
||||
("security-review", preference)
|
||||
]
|
||||
|
||||
|
||||
_INTERNAL_PLUGIN: Final = SimpleNamespace(
|
||||
id="plugin-id",
|
||||
name="deploy-helper",
|
||||
enabled=True,
|
||||
created_at=None,
|
||||
updated_at=None,
|
||||
manifest_json=json.dumps(
|
||||
{
|
||||
"source": {
|
||||
"source": "git-subdir",
|
||||
"url": "https://gitlab.internal.example.com/platform/claude-skills.git",
|
||||
"path": "plugins/deploy-helper",
|
||||
}
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def _skill_hub_response(find_many: AsyncMock, general_settings: Mapping[str, object]) -> httpx.Response:
|
||||
table: Final = MagicMock()
|
||||
table.find_many = find_many
|
||||
prisma: Final = MagicMock()
|
||||
prisma.db.litellm_claudecodeplugintable = table
|
||||
app: Final = FastAPI()
|
||||
app.include_router(router)
|
||||
|
||||
with (
|
||||
patch("litellm.proxy.proxy_server.prisma_client", prisma),
|
||||
patch("litellm.proxy.proxy_server.general_settings", dict(general_settings)),
|
||||
):
|
||||
return TestClient(app).get("/public/skill_hub")
|
||||
|
||||
|
||||
def test_public_skill_hub_is_empty_when_marketplace_auth_is_required() -> None:
|
||||
find_many: Final = AsyncMock(return_value=[_INTERNAL_PLUGIN])
|
||||
|
||||
public: Final = _skill_hub_response(find_many, {})
|
||||
gated: Final = _skill_hub_response(find_many, {"claude_code_marketplace_auth_required": True})
|
||||
|
||||
assert [plugin["name"] for plugin in public.json()["plugins"]] == ["deploy-helper"]
|
||||
assert gated.status_code == 200
|
||||
assert gated.json()["plugins"] == []
|
||||
assert "gitlab.internal.example.com" not in gated.text
|
||||
|
||||
|
||||
def test_public_skill_hub_500_body_carries_no_exception_text() -> None:
|
||||
response: Final = _skill_hub_response(
|
||||
AsyncMock(side_effect=RuntimeError("could not reach postgres://admin:hunter2@db.internal")), {}
|
||||
)
|
||||
|
||||
assert response.status_code == 500
|
||||
assert "hunter2" not in response.text
|
||||
assert "db.internal" not in response.text
|
||||
|
|
|
|||
14
ui/litellm-dashboard/src/lib/http/schema.d.ts
generated
vendored
14
ui/litellm-dashboard/src/lib/http/schema.d.ts
generated
vendored
|
|
@ -2408,10 +2408,14 @@ export interface paths {
|
|||
* - claude plugin marketplace add <url>
|
||||
* - claude plugin install <name>@<marketplace>
|
||||
*
|
||||
* Without `key` the catalog holds the enabled (public) plugins. With `?key=sk-...`
|
||||
* Without a key the catalog holds the enabled (public) plugins. With `?key=sk-...`
|
||||
* the key is authenticated and the catalog also holds the disabled plugins granted
|
||||
* to it through `object_permission.skills` or an access group on the key or its team.
|
||||
*
|
||||
* With `general_settings.claude_code_marketplace_auth_required: true` a caller with
|
||||
* no key gets a 401, and the key may also come in the `Authorization` or
|
||||
* `x-litellm-api-key` header (Claude Code sends them from the marketplace's `headers`).
|
||||
*
|
||||
* Returns:
|
||||
* Marketplace catalog with list of available plugins and their git sources.
|
||||
*
|
||||
|
|
@ -13783,7 +13787,7 @@ export interface paths {
|
|||
};
|
||||
/**
|
||||
* Public Skill Hub
|
||||
* @description Return enabled (public) Claude Code skills — no auth required.
|
||||
* @description Return enabled (public) Claude Code skills, or none when the marketplace requires a key.
|
||||
*/
|
||||
get: operations["public_skill_hub_public_skill_hub_get"];
|
||||
put?: never;
|
||||
|
|
@ -29863,6 +29867,12 @@ export interface components {
|
|||
claude_code_gateway_managed_settings?: {
|
||||
[key: string]: unknown;
|
||||
} | null;
|
||||
/**
|
||||
* Claude Code Marketplace Auth Required
|
||||
* @description If True, GET /claude-code/marketplace.json requires a LiteLLM key (Authorization or x-litellm-api-key header, the litellm_key_header_name header, or ?key=) and answers 401 without one, and GET /public/skill_hub returns an empty list. Default is False, which serves the enabled plugins to anyone.
|
||||
* @default false
|
||||
*/
|
||||
claude_code_marketplace_auth_required: boolean;
|
||||
/**
|
||||
* Completion Model
|
||||
* @description proxy level default model for all chat completion calls
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue