diff --git a/Dockerfile b/Dockerfile index fc2a637..1fe51cd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,8 @@ WORKDIR /app # Enable bytecode compilation ENV UV_COMPILE_BYTECODE=1 +ARG PERPLEXITY_URL_ARG=https://api.perplexity.ai/chat/completions +ENV PERPLEXITY_URL=$PERPLEXITY_URL_ARG # Copy the pyproject.toml to install dependencies COPY pyproject.toml /app/pyproject.toml diff --git a/README.md b/README.md index 6c3f160..6a2f454 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,7 @@ Optional environment variables: - `sonar`: 128k context - Default model - `r1-1776`: 128k context - Alternative architecture +- `PERPLEXITY_URL`: Allows overriding the default Perplexity API URL. If not set, the server will use `https://api.perplexity.ai/chat/completions`. Set this variable if you need to use a different API endpoint. And updated list of models is avaiable (here)[https://docs.perplexity.ai/guides/model-cards] ### Cursor & Claude Desktop Installation diff --git a/smithery.yaml b/smithery.yaml index 0172940..692f231 100644 --- a/smithery.yaml +++ b/smithery.yaml @@ -7,11 +7,15 @@ startCommand: type: object required: - perplexityApiKey + # PERPLEXITY_URL is optional, so not adding to required. properties: perplexityApiKey: type: string description: The API key for the Perplexity AI server. + perplexityUrl: + type: string + description: The URL for the Perplexity AI server. Defaults to https://api.perplexity.ai/chat/completions if not provided. commandFunction: # A function that produces the CLI command to start the MCP on stdio. |- - config => ({ command: 'uv', args: ['run', 'perplexity-mcp'], env: { PERPLEXITY_API_KEY: config.perplexityApiKey } }) + config => ({ command: 'uv', args: ['run', 'perplexity-mcp'], env: { PERPLEXITY_API_KEY: config.perplexityApiKey, PERPLEXITY_URL: config.perplexityUrl } }) diff --git a/src/perplexity_mcp/server.py b/src/perplexity_mcp/server.py index c739188..7234a0d 100644 --- a/src/perplexity_mcp/server.py +++ b/src/perplexity_mcp/server.py @@ -111,7 +111,8 @@ async def call_tool( async def call_perplexity(query: str, recency: str) -> str: - url = "https://api.perplexity.ai/chat/completions" + # Get the PERPLEXITY_URL from environment variable or use default + url = os.getenv("PERPLEXITY_URL", "https://api.perplexity.ai/chat/completions") # Get the model from environment variable or use "sonar" as default model = os.getenv("PERPLEXITY_MODEL", "sonar")