Call Desearch web search through LiteLLM

    Call Desearch web search through LiteLLM

    Tested 17 November 2026.

    For developers who want a local LiteLLM MCP gateway to route a search tool call. This example lists Desearch tools and calls web-search through LiteLLM's direct REST endpoints. It does not call an LLM or register Desearch as a model provider.

    Tested versions: LiteLLM 1.109.1 with MCP SDK 2.3.0; Desearch MCP server 0.3.3.

    Before you begin

    Use Node.js 24.16.0, Python 3.12.13 and uv 0.12.1. These examples were tested on macOS with Apple Silicon on 17 November 2026. You need a Desearch API key with available credits, and network access to the npm and Python package registries and Desearch. Set DESEARCH_API_KEY in your shell using your secret manager before running the example. Keep it out of source files.

    Desearch API requests use your account credits. Check Desearch pricing for current rates. This example calls the web-search tool once. Search titles and links can change between runs.

    Keep the accompanying assets folder beside this guide. Run the commands in that directory. The package lock fixes Desearch MCP server 0.3.3 and its npm dependencies. The Python lock fixes the tested dependency set.

    Download the assets

    Save these files in an assets folder in your working directory, keeping the paths shown:

    Install the pinned dependencies

    bash
    mkdir -p server configs cp assets/desearch-mcp-server/package.json server/package.json cp assets/desearch-mcp-server/package-lock.json server/package-lock.json cp assets/litellm.yaml configs/litellm.yaml npm ci --prefix server uv venv --python 3.12.13 litellm-venv uv pip sync --python litellm-venv/bin/python assets/litellm.lock

    The accompanying configuration uses os.environ/DESEARCH_API_KEY for upstream bearer authentication and os.environ/LITELLM_MASTER_KEY for the local gateway. These are environment references. The example generates a temporary local gateway key in memory and supplies it to the child process; it never writes either key into the configuration file. It starts no database.

    Run a search

    Save this as litellm_search.py in the same directory:

    python
    import json,os,subprocess,time,secrets from pathlib import Path import httpx root=Path.cwd() key=os.environ['DESEARCH_API_KEY'] master='sk-'+secrets.token_urlsafe(32) server_env=dict(os.environ,HOST='127.0.0.1',PORT='19966') server_env.pop('DESEARCH_API_KEY',None) server=subprocess.Popen(['node',str(root/'server/node_modules/desearch-mcp-server/build/index.js'),'--http'],env=server_env,stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL) gateway_env=dict(os.environ,LITELLM_MASTER_KEY=master,LITELLM_LOG='ERROR') gateway=subprocess.Popen([str(root/'litellm-venv/bin/litellm'),'--config',str(root/'configs/litellm.yaml'),'--host','127.0.0.1','--port','19968'],env=gateway_env,stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL) try: with httpx.Client(timeout=60,headers={'Authorization':'Bearer '+master}) as client: for _ in range(200): if server.poll() is not None or gateway.poll() is not None:raise RuntimeError('Local process exited before readiness') try: r=client.get('http://127.0.0.1:19968/health/liveliness') if r.status_code==200:break except httpx.ConnectError:pass time.sleep(.1) else:raise RuntimeError('Gateway did not become ready') listed=client.get('http://127.0.0.1:19968/mcp-rest/tools/list',params={'server_id':'desearch'}) listed.raise_for_status() assert any(t['name']=='web-search' for t in listed.json()['tools']) result=client.post('http://127.0.0.1:19968/mcp-rest/tools/call',json={'server_id':'desearch','name':'web-search','arguments':{'query':'Python official documentation'}}) result.raise_for_status() body=result.json() assert not body.get('isError'), body payload=json.loads(next(c['text'] for c in body['content'] if c['type']=='text')) first=payload['data'][0] assert first['title'] and first['link'] print(json.dumps({'title':first['title'],'link':first['link']},indent=2)) finally: gateway.terminate();server.terminate();gateway.wait(timeout=10);server.wait(timeout=10)

    Run with DESEARCH_API_KEY already set by your secret manager:

    bash
    litellm-venv/bin/python litellm_search.py

    Success prints JSON with a nonempty title and link. The test returned Our Documentation | Python.org and a Desearch redirect path beginning /go/v1/. Result order and redirect tokens can change. The example terminates both child processes after the call.

    Troubleshooting

    Use unused loopback ports 19966 and 19968. The sample binds both services to 127.0.0.1 and is a local evaluation. If readiness fails, confirm these ports are free and install the exact provided dependency lock.

    HTTP discovery at the upstream Desearch server is public. An unauthenticated tools/call returned HTTP 401 with isError: true. Successful discovery alone does not prove search access. The local LiteLLM key admits requests to the gateway; DESEARCH_API_KEY authorizes the upstream search. For a rejected Desearch key or insufficient credits, check the key and account balance before retrying.

    Use server_id: desearch with the unprefixed web-search name, as in the example. The REST endpoints here are /mcp-rest/tools/list and /mcp-rest/tools/call. They are separate from the MCP JSON-RPC endpoint.

    Official references