diff --git a/.env.example b/.env.example index 0c75293..3056b88 100644 --- a/.env.example +++ b/.env.example @@ -1,7 +1,7 @@ # Enable or disable running the MCP server RUN_MCP_SERVER=true -# LLM provider (anthropic, openai, mistral, gemini, ollama) +# LLM provider (anthropic, openai) LM_PROVIDER=anthropic # Default model name for the LLM diff --git a/README.md b/README.md index 01b6418..9e28139 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ This repository bundles the OCL Model Context Protocol (MCP) server together wit - Python 3.10+ (3.12 is used inside the Docker image) with access to the filesystem where the repo lives. - An optional OCL API token when you need access to private or organization-owned repositories. -- Optional LLM provider credentials (for example, Anthropic) if you plan to use the UI’s chat experience. +- Optional LLM provider credentials for Anthropic or OpenAI if you plan to use the UI’s chat experience. ## Configuration @@ -27,7 +27,7 @@ Important variables: |---|---| | `OCL_TOKEN` | OCL API token (40 characters) for authenticated concept/mapping requests. | | `OCL_URL` | Override for the OCL base URL; `chat` defaults to production but allows `staging`, `local`, or any custom URL. | -| `LM_PROVIDER` | Sets a default provider in the UI (defaults to `anthropic`). | +| `LM_PROVIDER` | Sets a default provider in the UI. Supported values are `anthropic` and `openai` (defaults to `anthropic`). | | `LM_MODEL` | Preferred model name for the chat session. | | `LM_TOKEN` | API key for the chosen LLM provider (passed straight to the UI). | | `UI_HOST` / `UI_PORT` | Host and port for the FastAPI app (default `0.0.0.0:8002`). | @@ -82,4 +82,3 @@ Compose loads `.env`, exposes port `8002`, and uses the healthcheck in `docker-c - See `mcp-server/README.md` for detailed MCP server usage, tooling, and available MCP endpoints. - `mcp-server/docs/` contains auxiliary guides (Claude configuration, examples, etc.). -*** End Patch diff --git a/mcp-client/routes/frontend.py b/mcp-client/routes/frontend.py index 6731918..03ea97d 100644 --- a/mcp-client/routes/frontend.py +++ b/mcp-client/routes/frontend.py @@ -1,7 +1,7 @@ import os import json from typing import List, Optional, Dict, Any -from fastapi import APIRouter, Request, Body +from fastapi import APIRouter, Body, HTTPException, Request from fastapi.responses import RedirectResponse, JSONResponse from langchain_anthropic import ChatAnthropic from langchain_openai import ChatOpenAI @@ -9,6 +9,7 @@ from langchain_core.messages import HumanMessage, SystemMessage, AIMessage, ToolMessage from mcp import types as mcp_types +from routes.providers import normalize_provider from web_config import templates from ocl_mcp.server import OCLMCPServer from ocl_mcp.tools import ( @@ -235,13 +236,16 @@ async def chat_message(request: Request, payload: dict = Body(...)): # Initialize LLM config_payload = payload.get("config", {}) - provider = config_payload.get("provider") or os.getenv("LM_PROVIDER", "anthropic") + try: + provider = normalize_provider(config_payload.get("provider") or os.getenv("LM_PROVIDER")) + except ValueError as exc: + raise HTTPException(status_code=400, detail=str(exc)) from exc model_name = config_payload.get("model") or os.getenv("LM_MODEL") api_key = config_payload.get("api_key") or os.getenv("LM_TOKEN") if provider == "openai": llm = ChatOpenAI(model=model_name or "gpt-4o", api_key=api_key) - else: + elif provider == "anthropic": llm = ChatAnthropic(model=model_name or "claude-3-5-sonnet-20241022", api_key=api_key) # Bind tools diff --git a/mcp-client/routes/providers.py b/mcp-client/routes/providers.py new file mode 100644 index 0000000..ff590d4 --- /dev/null +++ b/mcp-client/routes/providers.py @@ -0,0 +1,10 @@ +DEFAULT_PROVIDER = "anthropic" +SUPPORTED_LM_PROVIDERS = ("anthropic", "openai") + + +def normalize_provider(provider): + provider = (provider or DEFAULT_PROVIDER).strip().lower() or DEFAULT_PROVIDER + if provider not in SUPPORTED_LM_PROVIDERS: + supported = ", ".join(SUPPORTED_LM_PROVIDERS) + raise ValueError(f"Unsupported LLM provider '{provider}'. Supported providers: {supported}.") + return provider diff --git a/mcp-client/templates/chat.html b/mcp-client/templates/chat.html index 40b0048..a8d8fb6 100644 --- a/mcp-client/templates/chat.html +++ b/mcp-client/templates/chat.html @@ -108,9 +108,6 @@