agentleFS
aks129aks129/HealthClawGuardrails/skills/fhir-upstream-proxy/SKILL.md

fhir-upstream-proxy

Skill33 starsChanged 4 months agoMITView on GitHub

Connect to real FHIR servers through the MCP guardrail proxy. Use when: (1) Connecting to HAPI FHIR, SMART Health IT, or Epic sandbox servers, (2) Proxying AI agent requests to production EHR systems with guardrails, (3) Ensuring upstream server URLs never leak to clients, (4) Understanding how redaction, audit, and step-up auth apply to upstream data.

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    All query parameters forwarded to upstream.

    line 66
  2. Distinctive:

    All upstream server URLs in responses are replaced with local proxy URLs.

    line 74

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

FHIR Upstream Server Proxy

Connect to real FHIR servers while keeping the full MCP guardrail stack active.

Client -> MCP Server -> Flask (guardrails) -> Upstream FHIR Server
                             |
               redaction, audit, step-up,
               tenant isolation, disclaimers,
               URL rewriting

When to Use This Skill

  • You need to connect an AI agent to a real FHIR server (HAPI, SMART, Epic)
  • You want automatic PHI redaction on upstream server responses
  • You need audit trails for agent access to production clinical data
  • You want URL rewriting so upstream server details never leak to clients

Configuration

Set the FHIR_UPSTREAM_URL environment variable to enable proxy mode:

# HAPI FHIR R4 (open, no auth)
FHIR_UPSTREAM_URL=https://hapi.fhir.org/baseR4 python main.py

# SMART Health IT (open, no auth)
FHIR_UPSTREAM_URL=https://r4.smarthealthit.org python main.py

# HAPI FHIR R5 (open, no auth)
FHIR_UPSTREAM_URL=https://hapi.fhir.org/baseR5 python main.py

# Local HAPI instance
FHIR_UPSTREAM_URL=http://localhost:8080/fhir python main.py

# Docker Compose with upstream
FHIR_UPSTREAM_URL=https://hapi.fhir.org/baseR4 docker-compose up -d --build

Environment Variables

VariableDefaultDescription
FHIR_UPSTREAM_URL(empty)Upstream FHIR server base URL. Enables proxy when set.
FHIR_UPSTREAM_TIMEOUT15HTTP timeout for upstream requests (seconds)
FHIR_LOCAL_BASE_URL(empty)Local server URL for URL rewriting in responses

What the Proxy Does

Reads

Fetched from upstream, then redacted + audited + disclaimers added. The agent never sees unredacted upstream data.

Searches

All query parameters forwarded to upstream. Results redacted per entry. Upstream's full search capabilities are available (chaining, _include, etc.).

Writes

Validated locally first (structural checks), then forwarded to upstream with step-up auth verification. Both local and upstream audit records created.

URL Rewriting

All upstream server URLs in responses are replaced with local proxy URLs. The agent and client never see the upstream server's hostname or paths.

Health Check

/r6/fhir/health reports upstream connection status including FHIR version and server software name.

Graceful Fallback

Network errors return proper FHIR OperationOutcome responses, not stack traces.

What the Proxy Does NOT Do

  • No caching — every request hits the upstream server
  • No SMART-on-FHIR auth forwarding — uses upstream's native auth model
  • No cross-version translation — R4 responses stay R4
  • No tenant isolation on upstream — enforced locally only
  • No response transformation — upstream resources pass through as-is (after redaction)

Tested Upstream Servers

ServerURLAuthStatus
HAPI FHIR R4https://hapi.fhir.org/baseR4NoneTested
SMART Health IThttps://r4.smarthealthit.orgNoneTested
HAPI FHIR R5https://hapi.fhir.org/baseR5NoneTested
Local HAPIhttp://localhost:8080/fhirNoneTested
Epic Sandboxhttps://open.epic.com/Interface/FHIROAuth 2.0Limited

Proxy Implementation

The proxy uses httpx for HTTP client operations with:

  • Configurable timeout (default 15 seconds)
  • Automatic redirect following
  • application/fhir+json accept header
  • User-Agent identification: HealthClaw-Guardrails/1.0.0

URL rewriting is recursive — it traverses the entire response JSON tree and replaces all occurrences of the upstream URL with the local proxy URL.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.