FastMCP client SSL error with self-signed cert: how to point it at a CA bundle or disable verify?
FastMCP's Client fails with
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificatewhen connecting to an HTTPS MCP server using a self-signed or internal CA certificate. There is no top-levelverify=parameter onClientin this thread. How can I make the client trust my CA bundle, or disable TLS verification for a test server, without monkey-patching Python's ssl module?Originally asked on GitHub: https://github.com/PrefectHQ/fastmcp/issues/717
6 answers
Status: the issue is closed as completed, but this thread does not show a maintainer-supplied
verifyparameter onClient. Commenters confirmed several workarounds using a custom HTTPX client factory or environment variables.- With langchain-mcp-adapters 0.1.9, inject an
httpx_client_factorythat uses your CA bundle (confirmed working):
pythonimport ssl import httpx from langchain_mcp_adapters.client import MultiServerMCPClient CA_BUNDLE = "/path/to/rootCA.cert" def make_httpx_factory(ca_path: str): def httpx_client_factory(**kwargs) -> httpx.AsyncClient: ctx = ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH) ctx.load_verify_locations(cafile=ca_path) ctx.check_hostname = True ctx.verify_mode = ssl.CERT_REQUIRED return httpx.AsyncClient(verify=ctx, follow_redirects=True, **kwargs) return httpx_client_factory client = MultiServerMCPClient({ "secure_server": { "transport": "streamable_http", "url": "https://your-mcp.example.com/mcp/", "headers": {"Authorization": "Bearer <TOKEN>"}, "httpx_client_factory": make_httpx_factory(CA_BUNDLE), } }) tools = asyncio.run(client.get_tools())- With FastMCP directly, one commenter shared an example using
StreamableHttpTransportwith anhttpx_client_factory, specifically to use system certificates on Windows (not confirmed to have run):
pythonfrom fastmcp.client.transports.http import StreamableHttpTransport from fastmcp import Client _URL = "my URL" _TOKEN = "if you have one..." def create_mcp_http_client(): .... # used the code from mcp/shared/_httpx_utils.py but added: kwargs['verify'] = ssl.create_default_context() async def test_connection(): transport = StreamableHttpTransport(_URL, httpx_client_factory=create_mcp_http_client) async with Client(transport, auth=_TOKEN) as client: await client.ping()- For the FastMCP CLI, a commenter reported this works with a self-signed cert:
bashexport REQUESTS_CA_BUNDLE=cert.crt export SSL_CERT_FILE=cert.crt uv run fastmcp list --transport http https://testvm1.kvm:3000/mcp-
To disable verification entirely for a test server, return
httpx.AsyncClient(verify=False, **kwargs)from a factory; a commenter confirmed this worked. -
One commenter said they “sorted this issue” with a monkey-patch or a patch to the library and asked whether the owner takes PRs (screenshots only).
As general advice, prefer a CA bundle over
verify=False; disabling certificate verification leaves connections exposed to man-in-the-middle attacks.Did this work for you?- With langchain-mcp-adapters 0.1.9, inject an
What @Ankit1919 tried on GitHub (Worked)
Used
MultiServerMCPClientfrom langchain-mcp-adapters 0.1.9 with anhttpx_client_factorythat builds an SSLContext from a CA bundle while keeping verification enabled.Source: https://github.com/PrefectHQ/fastmcp/issues/717#issuecomment-3287757096 (opens external site)
Did this work for you?What @djoreilly tried on GitHub (Worked)
Set
REQUESTS_CA_BUNDLEandSSL_CERT_FILEto the self-signed certificate, then ranuv run fastmcp list --transport http https://testvm1.kvm:3000/mcp.Source: https://github.com/PrefectHQ/fastmcp/issues/717#issuecomment-4011891599 (opens external site)
Did this work for you?What @Ankit1919 tried on GitHub (Worked)
Suggested passing a custom HTTPX client factory that returns
httpx.AsyncClient(verify=False, **kwargs); a later commenter confirmed this worked.Source: https://github.com/PrefectHQ/fastmcp/issues/717#issuecomment-3628150789 (opens external site)
Did this work for you?What @krpatter-intc tried on GitHub (Outcome unclear)
Shared an example using
StreamableHttpTransportwith anhttpx_client_factoryto use system certificates on Windows, but did not report that it ran successfully.Source: https://github.com/PrefectHQ/fastmcp/issues/717#issuecomment-4011649468 (opens external site)
Did this work for you?What @strunker tried on GitHub (Outcome unclear)
Reported they had sorted the issue with a monkey-patch or a patch to the library, showing screenshots and asking if the owner accepts PRs.
Source: https://github.com/PrefectHQ/fastmcp/issues/717#issuecomment-4016963551 (opens external site)
Did this work for you?
Related questions
- How do I expose existing FastAPI endpoints as MCP tools with FastMCP 2?
- How to access HTTP headers from SSE requests in a fastmcp MCP server?
- FastMCP: how to get auto-reload / hot reload for the server during development?
- Does FastMCP OAuthProxy support multiple tenant authorization servers?
- FastMCP KeycloakAuthProvider: Keycloak 26.6.x requirement and MCP Inspector OAuth fix