Use Desearch web search with Microsoft Agent Framework

    Use Desearch web search with Microsoft Agent Framework

    Tested 17 November 2026.

    For Python developers integrating tools into Microsoft Agent Framework. This example uses MCPStdioTool directly to validate the connection and search response. It does not require an LLM account or create a complete conversational agent.

    Tested versions: agent-framework-core 1.26.0; MCP SDK 2.3.0; tenacity 9.2.1. 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 cp assets/desearch-mcp-server/package.json server/package.json cp assets/desearch-mcp-server/package-lock.json server/package-lock.json npm ci --prefix server uv venv --python 3.12.13 .venv uv pip sync --python .venv/bin/python assets/agent-framework.lock

    Run a search

    Save this as agent_framework_search.py in the same directory:

    python
    import asyncio import os import json from pathlib import Path from agent_framework import MCPStdioTool async def main(): async with MCPStdioTool( name="desearch", command="node", args=[str(Path("server/node_modules/desearch-mcp-server/build/index.js").resolve())], env={"DESEARCH_API_KEY": os.environ["DESEARCH_API_KEY"]}, allowed_tools=["web-search"], load_prompts=False, request_timeout=60, ) as desearch: result = await desearch.call_tool("web-search", query="Python official documentation") text = result if isinstance(result, str) else next(content.text for content in result if content.text) payload = json.loads(text) first = payload["data"][0] assert first["title"] and first["link"] print(json.dumps({"title": first["title"], "link": first["link"]}, indent=2)) asyncio.run(main())

    Run it with your API key already present in the environment:

    bash
    .venv/bin/python agent_framework_search.py

    A successful run prints JSON containing a nonempty title and link. The test returned Our Documentation | Python.org. The returned link began with /go/v1/; treat it as a Desearch redirect path, rather than a canonical source URL. The response order and redirect token can change. The example stops its child processes on exit.

    Troubleshooting

    A missing DESEARCH_API_KEY environment variable stops the example before a search. Starting the stdio Desearch server directly without it produces DESEARCH_API_KEY environment variable is required and a nonzero exit. HTTP discovery can succeed without credentials: tools/list returned 200, while an unauthenticated tools/call returned HTTP 401 with isError: true and instructions to send a bearer token or x-api-key. Successful discovery alone does not prove search access. For a rejected key or insufficient credits, verify the key and account balance before retrying.

    The core Agent Framework package alone is insufficient here. Missing mcp or tenacity causes a local import or connection failure; install the provided lock. The tested framework emits an MCP ping deprecation warning with SDK 2.3.0; the search completes successfully.

    Official references