Skip to main content

FDKEY verification middleware for MCP servers — gate AI-agent access behind LLM-only puzzles.

Project description

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.
  • 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.

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.

Links

License

MIT — see LICENSE.

Project details


Download files

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

Source Distribution

fdkey-0.1.0.tar.gz (28.1 kB view details)

Uploaded Source

Built Distribution

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

fdkey-0.1.0-py3-none-any.whl (19.7 kB view details)

Uploaded Python 3

File details

Details for the file fdkey-0.1.0.tar.gz.

File metadata

  • Download URL: fdkey-0.1.0.tar.gz
  • Upload date:
  • Size: 28.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fdkey-0.1.0.tar.gz
Algorithm Hash digest
SHA256 417c4b6d6c883f8cbf5248326969c1e74045f63716782ca066b153ecb09122fe
MD5 3954182fbf87811ad9df058f8476e6d9
BLAKE2b-256 96a418dc1d0de94e24e69bb41e60d0ed4f4035a99cb135a29a35a508797e3c16

See more details on using hashes here.

Provenance

The following attestation bundles were made for fdkey-0.1.0.tar.gz:

Publisher: publish-python.yml on fdkey/sdks

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fdkey-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: fdkey-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 19.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fdkey-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 459ab70a30c3dcfb3ee40bd61acad4802dc6f0bebaa24225bbaa5b482a649a9b
MD5 e45aa948a74ff5341e5a9ebfbc875607
BLAKE2b-256 7afbf27e8c9b7ccdcfa37cd62ab6ab171885125e8c7a65086c4667f6120f3724

See more details on using hashes here.

Provenance

The following attestation bundles were made for fdkey-0.1.0-py3-none-any.whl:

Publisher: publish-python.yml on fdkey/sdks

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page