Skip to main content

trialmatch-mcp-bridge

A local stdio↔HTTPS bridge for Claude Desktop (THI-882). Deliberately not the real MCP server — no tool logic here at all. It does PKCE + local-loopback login against Cognito, caches a refresh token, and relays every MCP call from Desktop to the AgentCore Gateway over HTTPS with Authorization: Bearer <token> attached. The actual tools live in ../src/trialmatch_criteria_mcp/, deployed to AgentCore Runtime behind that Gateway.

Setup

Published to PyPI — this is the recommended way to run it, no repo access or git credentials needed at all:

uvx trialmatch-mcp-bridge --login   # one-time interactive sign-in; opens your browser

This matters beyond convenience: some MCP hosts run their server subprocesses in a sandbox that can't reach your normal git credentials — confirmed live, Claude Desktop (an MSIX/Windows-Store packaged app) runs in an AppContainer that can't access the interactive user's gh-configured git credential helper, so a git+https:// dependency against this (private) repo fails there even though it works fine from a plain terminal on the same machine. A public PyPI package has no credential step to fail.

Alternative, if you're already working in a local clone of this repo:

cd bridge
uv sync
uv run trialmatch-mcp-bridge --login

Either way, this caches a refresh token at ~/.trialmatch-mcp/credentials.json (0600). Subsequent runs refresh silently — you shouldn't need --login again unless the refresh token itself expires or is revoked. This refresh happens mid-session too, not just at startup: the bridge process is long-lived (hours), far outliving a single Cognito access token's own ~1hr lifetime, so BearerTokenAuth (auth.py) attaches a freshly-checked token to every request and transparently retries once with a silently-refreshed one if the Gateway ever rejects a request with 401/403 — a live session shouldn't need a manual restart just because the token it started with went stale. If the refresh token itself has expired or been revoked, this retry deliberately gives up rather than popping an interactive browser login mid-session — you'll see the original failure and need to run --login again, same as always.

This covers a stale token specifically, not a stale MCP session: if the deployed Runtime itself gets redeployed to a new version mid-session, the underlying streamable-HTTP session this process already established can stop being honored regardless of how fresh the bearer token is — that still needs a manual restart of this process (or of Claude Desktop's connection to it) today.

Claude Desktop / Claude Code configuration

Add to claude_desktop_config.json (Desktop) or .mcp.json (Code):

{
  "mcpServers": {
    "trialmatch-criteria": {
      "command": "uvx",
      "args": ["trialmatch-mcp-bridge"]
    }
  }
}

Or, from a local clone:

{
  "mcpServers": {
    "trialmatch-criteria": {
      "command": "uv",
      "args": ["run", "--directory", "/absolute/path/to/TrialMatch-Criteria-MCP/bridge", "trialmatch-mcp-bridge"]
    }
  }
}

(Or point command at the installed trialmatch-mcp-bridge console script directly if you've installed this package outside a uv-managed venv.)

Not Claude Code's built-in remote-MCP OAuth support (/mcp add <gateway-url> or .mcp.json's "type": "http" + oauth block) — confirmed live (claude mcp add --transport http ... <gateway-url> against this exact Gateway) that this fails immediately with Incompatible auth server: does not support dynamic client registration, before PKCE or token exchange are even reached. Cognito has no OAuth Dynamic Client Registration endpoint (RFC 7591) at all — a permanent Cognito limitation, not a bug on Cognito's side — and Claude Code's MCP OAuth client currently has no fallback when the auth server doesn't support DCR, even when a pre-configured client id is available (anthropics/claude-code#67258; this project hit the identical symptom against Cognito, adding to that report's existing Box repro). (An earlier version of this note cited anthropics/claude-code#35846 — Cognito's discovery document not advertising code_challenge_methods_supported — as the reason; that condition is real and independently confirmed against this pool too, but it was never actually the failure this bridge exists to route around, since the DCR failure above happens first.) This bridge sidesteps the whole problem by using a real, pre-registered Cognito App Client (created via this repo's own CDK stack) and doing PKCE itself — it never attempts DCR in the first place.

Publishing

Automatic, via .github/workflows/ci.yml's publish-bridge job — no manual version bump, no git tags, no stored PyPI token (uses PyPI's OIDC "Trusted Publishing"). On a merge to main that touches bridge/**: bumps the PATCH version (computed from PyPI's own current "latest", not from anything in this repo) and publishes it.

Gated behind the pypi GitHub Environment (repo Settings → Environments → pypi), which has a deployment-branch policy restricting it to main only — per PyPI's own Trusted Publishing guidance, a dedicated environment for the publishing workflow is "strongly encouraged, especially if your repository has maintainers with commit access who shouldn't have PyPI publishing access." (No pre-release/dev-version channel — deliberately kept to just this one path; testing a specific in-progress change is simpler done straight from a local clone, see Setup above, than by publishing and pinning a throwaway version.)

One-time setup (already done, noted here in case the project is ever re-created):

  1. Create the pypi GitHub Environment with a deployment-branch policy restricting it to main (done via gh api repos/Third-Opinion/TrialMatch-Criteria-MCP/environments/pypi, no UI needed — see git history for the exact call).
  2. A PyPI account with access registers a pending trusted publisher at https://pypi.org/manage/account/publishing/ for project trialmatch-mcp-bridge, owner Third-Opinion, repo TrialMatch-Criteria-MCP, workflow ci.yml, environment name pypi.

Test

uv run pytest
uv run ruff check . && uv run ruff format --check .
uv run mypy src

Unit tests mock the Cognito token endpoint and the loopback callback — no browser or real Cognito pool needed to run them. A real end-to-end test still needs an actual browser login once (--login), since PKCE Authorization Code flow is inherently interactive by design.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trialmatch_mcp_bridge-0.1.5.tar.gz (80.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trialmatch_mcp_bridge-0.1.5-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file trialmatch_mcp_bridge-0.1.5.tar.gz.

File metadata

  • Download URL: trialmatch_mcp_bridge-0.1.5.tar.gz
  • Upload date:
  • Size: 80.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.6 {"installer":{"name":"uv","version":"0.12.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for trialmatch_mcp_bridge-0.1.5.tar.gz
Algorithm Hash digest
SHA256 83866c224b45e82a59fcf26602a35e4123d7c7410b3cf63fa59569c2c617c13c
MD5 0cfec0e39b726a4c27aba4543f181ecb
BLAKE2b-256 2b70f2e785e608f53d040ecc3a31bd87f247564f92e40776d9983353e7feccd1

See more details on using hashes here.

File details

Details for the file trialmatch_mcp_bridge-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: trialmatch_mcp_bridge-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.6 {"installer":{"name":"uv","version":"0.12.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for trialmatch_mcp_bridge-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 f54138229429fa898853a5fbe9f292514693a661ceaf209fd99e93bbd69a2700
MD5 6f6800b0378117a21a5ac6fab2a83f86
BLAKE2b-256 c7c6e2ea3c8081c37029a1d2c4067b510ff810a64736e89b11c335a1fa3b27e6

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

This release

0.1.5 This release

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page