Skip to main content
Glama

Core Content Services MCP Server

Official
by ibm-ecm
ssl_adapter.py3.93 kB
# Licensed Materials - Property of IBM (c) Copyright IBM Corp. 2025 All Rights Reserved. # US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with # IBM Corp. # DISCLAIMER OF WARRANTIES : # Permission is granted to copy and modify this Sample code, and to distribute modified versions provided that both the # copyright notice, and this permission notice and warranty disclaimer appear in all copies and modified versions. # THIS SAMPLE CODE IS LICENSED TO YOU AS-IS. IBM AND ITS SUPPLIERS AND LICENSORS DISCLAIM ALL WARRANTIES, EITHER # EXPRESS OR IMPLIED, IN SUCH SAMPLE CODE, INCLUDING THE WARRANTY OF NON-INFRINGEMENT AND THE IMPLIED WARRANTIES OF # MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL IBM OR ITS LICENSORS OR SUPPLIERS BE LIABLE FOR # ANY DAMAGES ARISING OUT OF THE USE OF OR INABILITY TO USE THE SAMPLE CODE, DISTRIBUTION OF THE SAMPLE CODE, OR # COMBINATION OF THE SAMPLE CODE WITH ANY OTHER CODE. IN NO EVENT SHALL IBM OR ITS LICENSORS AND SUPPLIERS BE LIABLE # FOR ANY LOST REVENUE, LOST PROFITS OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE # DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, EVEN IF IBM OR ITS LICENSORS OR SUPPLIERS HAVE # BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. """ Custom SSL Adapter for requests library This module provides a custom HTTPAdapter that uses a provided SSL context for all HTTPS connections. This ensures consistent SSL behavior across all requests made through the adapter. The SSLAdapter is designed to work with the GraphQLClient class to provide a unified SSL handling approach for both synchronous and asynchronous requests. """ import logging from requests.adapters import HTTPAdapter # Set up logging logger = logging.getLogger("SSLAdapter") __all__ = ["SSLAdapter"] class SSLAdapter(HTTPAdapter): """ A custom HTTP adapter that uses a provided SSL context for requests library. This adapter uses a single SSL context for all HTTPS connections, ensuring consistent SSL behavior across all requests. It's designed to be used with the GraphQLClient class, which creates and manages the SSL context. The adapter is mounted to the 'https://' prefix in a requests.Session object, so it will be used for all HTTPS requests made through that session. Example usage: ssl_context = create_ssl_context() session = requests.Session() adapter = SSLAdapter(ssl_context=ssl_context) session.mount('https://', adapter) """ def __init__(self, ssl_context, **kwargs): """ Initialize the SSL adapter with the given SSL context. Args: ssl_context: The SSL context to use for all HTTPS connections. This should be a properly configured ssl.SSLContext object. **kwargs: Additional arguments to pass to HTTPAdapter, such as pool_connections, pool_maxsize, etc. """ self.ssl_context = ssl_context super().__init__(**kwargs) logger.debug("SSLAdapter initialized with custom SSL context") def init_poolmanager(self, *args, **kwargs): """ Initialize the connection pool manager with the provided SSL context. This method is called by requests when creating a new connection pool. By providing our SSL context here, we ensure all connections made through this adapter use the same SSL configuration. Args: *args: Positional arguments to pass to the parent init_poolmanager **kwargs: Keyword arguments to pass to the parent init_poolmanager """ kwargs["ssl_context"] = self.ssl_context logger.debug("Connection pool manager initialized with custom SSL context") return super().init_poolmanager(*args, **kwargs)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ibm-ecm/cs-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server