Call Desearch web search through MetaMCP

    Call Desearch web search through MetaMCP

    Tested 17 November 2026.

    For developers evaluating MetaMCP as a local MCP gateway. This example creates a disposable local gateway, registers the hosted Desearch MCP server, creates an authenticated endpoint and invokes the discovered web-search tool.

    Tested versions: MetaMCP 2.4.22 at commit 32b6e9813acfc13d1013eb2452be1899d6654bb9, PostgreSQL 16 Alpine from a fixed image digest, FastMCP 4.2.0 and MCP SDK 2.3.0. The upstream repository was archived on 12 November 2026 and is read-only. Treat this as a pinned evaluation of that archived release. The hosted Desearch endpoint does not expose a pinned server version in this test; its behavior was verified on the test date.

    Before you begin

    Use Docker Engine 29.5.2, Python 3.12.13 and uv 0.12.1. This example was tested on macOS with Apple Silicon; the MetaMCP image digest below selects Linux ARM64. Keep port 19972 free and allow network access to the image and Python registries and Desearch.

    You need a Desearch API key with available credits. Set DESEARCH_API_KEY through your secret manager. Desearch requests use your account credits; check current pricing. No hosted MetaMCP account or model inference is used. Keep the accompanying assets folder beside the guide and run commands there.

    Download the assets

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

    Install the pinned dependencies

    bash
    docker pull ghcr.io/metatool-ai/metamcp@sha256:eb58c877b93decb88141050b51cfb88f225967bbd1ba4730651c776532d83cda docker pull postgres@sha256:81e77a4833487b8132fe4b00bedd39dc3f74b8641e387f19312a48f7de218c2e uv venv --python 3.12.13 .venv uv pip sync --python .venv/bin/python assets/fastmcp.lock

    The example binds the gateway to loopback. It generates local passwords and signing secrets in memory, creates an account only inside that disposable gateway, and stores the upstream registration in PostgreSQL on tmpfs. It keeps API keys and session cookies in memory. Its finally block stops both containers and removes the private Docker network. No credentials are written into host configuration files. Use MetaMCP's deployment documentation for a persistent service.

    Run a search

    Save this as metamcp_search.py in the same directory:

    python
    import asyncio,json,os,secrets,subprocess,time import httpx from fastmcp import Client from fastmcp.client.transports import StreamableHttpTransport IMAGE='ghcr.io/metatool-ai/metamcp@sha256:eb58c877b93decb88141050b51cfb88f225967bbd1ba4730651c776532d83cda' POSTGRES='postgres@sha256:81e77a4833487b8132fe4b00bedd39dc3f74b8641e387f19312a48f7de218c2e' async def main(): key=os.environ['DESEARCH_API_KEY'];password=secrets.token_urlsafe(32);authsecret=secrets.token_urlsafe(48) suffix=secrets.token_hex(4);network='desearch-meta-'+suffix;db=network+'-db';app=network+'-app' base='http://127.0.0.1:19972';extra=[] def docker(*args,env=None): p=subprocess.run(['docker',*args],env=env,capture_output=True,text=True,timeout=30) if p.returncode:raise RuntimeError(p.stderr) return p.stdout.strip() env=dict(os.environ,POSTGRES_PASSWORD=password,POSTGRES_USER='tester',POSTGRES_DB='testdb',BETTER_AUTH_SECRET=authsecret,DATABASE_URL=f'postgresql://tester:{password}@{db}:5432/testdb',POSTGRES_HOST=db,POSTGRES_PORT='5432',APP_URL=base,NEXT_PUBLIC_APP_URL=base) try: docker('network','create',network) docker('run','--pull=never','-d','--rm','--name',db,'--network',network,'--tmpfs','/var/lib/postgresql/data','-e','POSTGRES_PASSWORD','-e','POSTGRES_USER','-e','POSTGRES_DB',POSTGRES,env=env) for _ in range(100): r=subprocess.run(['docker','exec',db,'pg_isready','-U','tester','-d','testdb'],capture_output=True) if r.returncode==0:break await asyncio.sleep(.2) args=['run','--pull=never','-d','--rm','--name',app,'--network',network,'-p','127.0.0.1:19972:12008'] for n in ('POSTGRES_PASSWORD','POSTGRES_USER','POSTGRES_DB','BETTER_AUTH_SECRET','DATABASE_URL','POSTGRES_HOST','POSTGRES_PORT','APP_URL','NEXT_PUBLIC_APP_URL'):args+=['-e',n] args += [IMAGE];docker(*args,env=env) async with httpx.AsyncClient(timeout=60) as http: for _ in range(800): try: r=await http.get(base+'/api/auth/get-session',timeout=2) if r.status_code==200:break except httpx.HTTPError:pass await asyncio.sleep(.2) else:raise RuntimeError('App readiness timeout: '+docker('logs','--tail','25',app)) signup=await http.post(base+'/api/auth/sign-up/email',headers={'Origin':base},json={'name':'Local test','email':'tester@example.com','password':password}) if signup.status_code!=200:raise RuntimeError('Signup '+str(signup.status_code)+' '+signup.text) async def mutate(method,payload): r=await http.post(base+'/trpc/frontend.'+method,json=payload) if r.status_code!=200:raise RuntimeError(method+' '+str(r.status_code)+' '+r.text) data=r.json()['result']['data'] if isinstance(data,dict) and data.get('success') is False:raise RuntimeError(method+' '+str(data.get('message'))) return data server=await mutate('mcpServers.create',{'name':'desearch','type':'STREAMABLE_HTTP','url':'https://mcp.desearch.ai/mcp','bearerToken':key}) serverid=server['data']['uuid'] namespace=await mutate('namespaces.create',{'name':'desearch-test','mcpServerUuids':[serverid]}) endpoint=await mutate('endpoints.create',{'name':'desearch-test','namespaceUuid':namespace['data']['uuid'],'enableApiKeyAuth':True,'enableOauth':False,'createMcpServer':False}) apikey=await mutate('apiKeys.create',{'name':'local-test'});localkey=apikey['key'];extra.append(localkey) url=base+'/metamcp/desearch-test/mcp' unauth=await http.post(url,json={});assert unauth.status_code in (401,403),unauth.status_code async with Client(StreamableHttpTransport(url,headers={'Authorization':'Bearer '+localkey}),timeout=90,mode='legacy') as client: for _ in range(100): tools=await client.list_tools();names=[t.name for t in tools] matches=[n for n in names if 'web-search' in n or 'web_search' in n] if matches:break await asyncio.sleep(.2) else:raise RuntimeError('web-search unavailable: '+str(names)) tool=matches[0] result=await client.call_tool(tool,{'query':'Python official documentation'}) payload=json.loads(next(c.text for c in result.content if c.type=='text')) first=payload['data'][0];assert first['title'] and first['link'] print(json.dumps({'image':IMAGE,'postgres':POSTGRES,'unauthenticated_status':unauth.status_code,'tool':tool,'tool_count':len(names),'title':first['title'],'link':first['link']},indent=2)) except Exception as exc: message=str(exc) for secret in (key,password,authsecret,*extra):message=message.replace(secret,'[REDACTED]') raise RuntimeError(message) from None finally: for name in (app,db):subprocess.run(['docker','stop','-t','5',name],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL,timeout=15) subprocess.run(['docker','network','rm',network],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL,timeout=15) asyncio.run(main())

    Run with your key already in the environment:

    bash
    .venv/bin/python metamcp_search.py

    Success prints the discovered, prefixed web-search tool name, the local endpoint's unauthenticated status, and a nonempty title and link. The query is Python official documentation. Result titles and links can change; a link beginning /go/v1/ is a Desearch redirect path.

    Troubleshooting

    A missing DESEARCH_API_KEY stops the example before containers are created. An unavailable image digest fails with no such image: run both docker pull commands before the script. Port conflicts and app readiness failures stop the test; check port 19972 and Docker resources. An interrupted Python process can leave containers running: inspect only the containers and network named desearch-meta-<random suffix> created by your run and remove those resources.

    The guide uses the native frontend tRPC procedures from the pinned release for server, namespace, endpoint and local API-key creation. These are version-specific application APIs; do not assume they are a stable public contract across releases. The endpoint requires the locally generated MetaMCP key. The upstream registration separately forwards your Desearch bearer token. Discovery alone does not prove the upstream key works; a titled result verifies the search call. For a rejected Desearch key or insufficient credits, check your key and account balance before retrying.

    Official references