Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Disabling SSL verification for testing #415

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/mcp/client/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,17 @@ async def run_session(
logger.info("Initialized")


async def main(command_or_url: str, args: list[str], env: list[tuple[str, str]]):
async def main(
command_or_url: str,
args: list[str],
env: list[tuple[str, str]],
verify_ssl: bool,
):
env_dict = dict(env)

if urlparse(command_or_url).scheme in ("http", "https"):
# Use SSE client for HTTP(S) URLs
async with sse_client(command_or_url) as streams:
async with sse_client(command_or_url, verify_ssl=verify_ssl) as streams:
await run_session(*streams)
else:
# Use stdio client for commands
Expand All @@ -76,9 +81,24 @@ def cli():
help="Environment variables to set. Can be used multiple times.",
default=[],
)
parser.add_argument(
"--disable-ssl-verification",
action='store_true',
default=False,
help="Disable SSL verification on HTTPS. SSL verification by default.",
)

args = parser.parse_args()
anyio.run(partial(main, args.command_or_url, args.args, args.env), backend="trio")
anyio.run(
partial(
main,
args.command_or_url,
args.args,
args.env,
not args.disable_ssl_verification,
),
backend="trio",
)


if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion src/mcp/client/sse.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ async def sse_client(
headers: dict[str, Any] | None = None,
timeout: float = 5,
sse_read_timeout: float = 60 * 5,
verify_ssl: bool = True,
):
"""
Client transport for SSE.
Expand All @@ -43,7 +44,7 @@ async def sse_client(
async with anyio.create_task_group() as tg:
try:
logger.info(f"Connecting to SSE endpoint: {remove_request_params(url)}")
async with httpx.AsyncClient(headers=headers) as client:
async with httpx.AsyncClient(headers=headers, verify=verify_ssl) as client:
async with aconnect_sse(
client,
"GET",
Expand Down