Skip to main content

fdkey

FDKEY verification middleware for MCP servers (Python). Gate AI-agent access to your tools behind LLM-only puzzles. Drop-in for any Model Context Protocol server built on the official Python SDK's FastMCP.

What it does

  • Injects two MCP tools into your server: fdkey_get_challenge and fdkey_submit_challenge, with stable MCP tool annotations (title, readOnlyHint, destructiveHint, idempotentHint, openWorldHint) for client trust hints. Annotations degrade gracefully on older mcp package versions that lack the keyword.
  • Wraps the tools you want to protect — they return fdkey_verification_required until the connecting agent has solved a challenge.
  • Talks to https://api.fdkey.com for challenge issuance and scoring.
  • Verifies the Ed25519 JWT response offline using the public key from https://api.fdkey.com/.well-known/fdkey.json.

The SDK is puzzle-agnostic. All agent-facing prose (puzzle text, per-type instructions, wire-format examples, timing framing) is rendered server-side by the VPS and passed through verbatim as the fdkey_get_challenge tool result. The VPS supplies the rendered directive in ChallengeResponse.mcp_response_text (sent for client_type='mcp', which the SDK always sets); when present, the SDK returns it verbatim. When absent — e.g. against an older VPS — the SDK falls back to a puzzle-agnostic JSON dict (header + puzzles + example_submission + footer) that the agent can still consume. Adding a new puzzle type or changing an answer format is a VPS-only concern; no SDK release needed.

Install

pip install fdkey

You also need the official MCP Python SDK:

pip install mcp

Get an API key at app.fdkey.com.

Usage

import os
from mcp.server.fastmcp import FastMCP
from fdkey import with_fdkey

server = FastMCP("my-server")

with_fdkey(
    server,
    api_key=os.environ["FDKEY_API_KEY"],
    protect={
        "sensitive_action": {"policy": "each_call"},
        "register": {"policy": "once_per_session"},
    },
)

@server.tool()
def sensitive_action() -> str:
    # Reaches here only after the agent has solved a challenge.
    return "verified"

Policies

Per-tool gating policy — passed as {"policy": ...} in the protect map:

  • "each_call" — verification required for every invocation. Use for irreversible actions (payments, deletes).
  • "once_per_session" — verification required once per connection. Use for account creation, signup-style flows.
  • {"type": "every_minutes", "minutes": N} — verification good for N minutes after the puzzle was solved. Middle ground when "every call" is too aggressive but "once forever" is too loose. The timer does NOT extend on calls — it expires minutes after the solve, regardless of activity.
protect={
    "delete_account":    {"policy": "each_call"},
    "register":          {"policy": "once_per_session"},
    "refresh_dashboard": {"policy": {"type": "every_minutes", "minutes": 15}},
}

Configuration reference

with_fdkey(
    server,
    api_key="fdk_...",          # required
    protect={...},               # tool name -> {"policy": ...}
    vps_url="https://api.fdkey.com",  # override for self-hosted
    difficulty="medium",         # easy | medium | hard
    on_fail="block",             # block | allow (puzzle failed)
    on_vps_error="allow",        # block | allow — see below
    inline_challenge=False,      # embed puzzle in blocked-tool error
    tags={"env": "prod"},        # forwarded to FDKEY for analytics
)

Failure-mode defaults

on_vps_error="allow" is the default — if the FDKEY scoring service is unreachable, the protected tool falls through to your handler instead of blocking. We chose this so an FDKEY outage doesn't brick your workflow (e.g. if we shut down or DNS can't resolve api.fdkey.com). FDKEY is verification, not gating — your service should still serve traffic when ours is down. Set on_vps_error="block" if you'd rather drop traffic than admit unverified callers during an outage.

Reading verification context

from fdkey import get_fdkey_context

@server.tool()
def whoami(ctx) -> str:
    fdkey = get_fdkey_context(server, ctx)
    if fdkey and fdkey.verified:
        # `score` and `tier` are first-class fields on the context.
        # `score` is a 0..1 float — today effectively binary
        # (1.0 passed / 0.0 failed) but reserved for future capability
        # scoring without an API change. `tier` is the VPS-issued
        # capability bucket label.
        return f"verified (score={fdkey.score}, tier={fdkey.tier})"
    return "not verified"

What FDKEY sees

  • The MCP clientInfo your agent reports (when forwarded by your server).
  • Challenge IDs, scores, timestamps.
  • Your integrator-supplied tags.

Security notes

  • JWT aud is not validated by the SDK. The audience claim binds the JWT to the integrator's vps_users.id, which the SDK doesn't know at verify time. The VPS already binds aud to the API key that requested the challenge — defense in depth — but in principle, a JWT issued for one FDKEY-protected service could be replayed against a different one within the JWT lifetime (~5 min default). Keep the JWT lifetime short on the VPS side if your threat model includes cross-integrator replay.

What FDKEY does NOT see

  • Your prompts.
  • Tool inputs or outputs.
  • Your end users' identities or PII.

License

MIT — see LICENSE.

Metadata

Release files for fdkey 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fdkey 0.2.1
File Size Uploaded Provenance Actions
fdkey-0.2.1.tar.gz 34.5 kB With provenance Details for fdkey-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fdkey 0.2.1
File Interpreter ABI Platform Actions
fdkey-0.2.1-py3-none-any.whl Python 3 none any Details for fdkey-0.2.1-py3-none-any.whl

Total release size: 56.8 kB

Release files / fdkey-0.2.1.tar.gz

Download URL fdkey-0.2.1.tar.gz
Size 34.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ed62740516125bad08677a0aa7317d27bb975b6f01f8603030fa6434617b7a1b
BLAKE2b-256 checksum
How to use checksums
d8aa125ca4d8399d611a6331e37501002d8e7b6561fa007c98d26dc15d04f21f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 11, 2026.

Transparency log

Release files / fdkey-0.2.1-py3-none-any.whl

Download URL fdkey-0.2.1-py3-none-any.whl
Size 22.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
baf6bfa58c55cfdbc1cb4293acbee8fc750f0e67a11fd30a653f1f4f8b7888bf
BLAKE2b-256 checksum
How to use checksums
7cfc2bb0911442fe71db3520c241c65dd594c9d854d31df29b083a276adfcf5d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 11, 2026.

Transparency log

Security for fdkey 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for fdkey-0.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 11, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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