Skip to main content

AuthSec SDK for MCP auth, services, CIBA, and SPIFFE integration

Project description

AuthSec Python SDK (authsec-sdk)

Add OAuth + authorization enforcement to MCP tools.

Install

python3 -m pip install authsec-sdk

Import path:

from authsec_sdk import protected_by_AuthSec, run_mcp_server_with_oauth

Legacy import path is also supported in this release:

from AuthSec_SDK import protected_by_AuthSec, run_mcp_server_with_oauth

Minimal Integration (your MCP server)

from authsec_sdk import mcp_tool, protected_by_AuthSec, run_mcp_server_with_oauth


@mcp_tool(
    name="ping",
    description="Health check",
    inputSchema={"type": "object", "properties": {}, "required": []},
)
async def ping(arguments: dict) -> list:
    return [{"type": "text", "text": "pong"}]


@protected_by_AuthSec(
    tool_name="delete_invoice",
    permissions=["tool:delete_invoice"],  # optional; remove for auth-only
    require_all=True,
    description="Delete invoice",
    inputSchema={
        "type": "object",
        "properties": {
            "invoice_id": {"type": "string"},
            "session_id": {"type": "string"},
        },
        "required": ["invoice_id"],
    },
)
async def delete_invoice(arguments: dict) -> list:
    user = (arguments.get("_user_info") or {}).get("email_id", "unknown")
    return [{"type": "text", "text": f"Deleted {arguments.get('invoice_id')} by {user}"}]


if __name__ == "__main__":
    import __main__

    run_mcp_server_with_oauth(
        user_module=__main__,
        client_id="YOUR_CLIENT_ID",
        app_name="my-mcp-server",
        host="127.0.0.1",
        port=3005,
    )

Run

python3 server.py

Default endpoints (production):

  • Auth API: https://prod.api.authsec.ai/sdkmgr/mcp-auth
  • Services API: https://prod.api.authsec.ai/sdkmgr/services

Optional endpoint overrides (self-hosted gateway):

export AUTHSEC_AUTH_SERVICE_URL="http://localhost:8000/sdkmgr/mcp-auth"
export AUTHSEC_SERVICES_URL="http://localhost:8000/sdkmgr/services"
python3 server.py

Verify

npx @modelcontextprotocol/inspector http://127.0.0.1:3005

Flow:

  • Call oauth_start
  • Complete login in browser
  • Call your protected tool with session_id

For browser auto-open from your local SDK server process:

export AUTHSEC_AUTO_OPEN_BROWSER=1

Troubleshooting

  • ModuleNotFoundError: No module named 'authsec_sdk'
    • You are using a different Python than the one where you installed the package. Use python3 -m pip ... and run with the same python3.
  • ModuleNotFoundError: No module named 'AuthSec_SDK'
    • Upgrade to this release (4.0.2+) or use canonical import authsec_sdk.
  • Server exits with cleanup event-loop error on Ctrl+C
    • Fixed in this release (4.0.2+).
  • oauth_start returns browser_opened: false
    • Set AUTHSEC_AUTO_OPEN_BROWSER=1 or call oauth_start with {"open_browser": true}.
  • OAuth completes in browser but tool calls still unauthorized
    • Check callback_url in oauth_start response.
    • Recommended callback URI is https://prod.api.authsec.ai/sdkmgr/mcp-auth/callback (SDK Manager-hosted callback).
    • Local fallback http://localhost:3005/oauth/callback is also supported by this SDK server.

Publishing (maintainer)

  1. Set credentials:
export TWINE_USERNAME="__token__"
export TWINE_PASSWORD="pypi-..."
  1. Build and upload:
cd /absolute/path/to/sdk-authsec/packages/python-sdk
python3 -m pip install --upgrade build twine
python3 -m build
python3 -m twine check dist/*
# Optional TestPyPI:
# python3 -m twine upload --repository testpypi dist/*
# Publish:
python3 -m twine upload dist/*

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

authsec_sdk-4.0.2.tar.gz (29.4 kB view details)

Uploaded Source

Built Distribution

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

authsec_sdk-4.0.2-py3-none-any.whl (32.5 kB view details)

Uploaded Python 3

File details

Details for the file authsec_sdk-4.0.2.tar.gz.

File metadata

  • Download URL: authsec_sdk-4.0.2.tar.gz
  • Upload date:
  • Size: 29.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.1

File hashes

Hashes for authsec_sdk-4.0.2.tar.gz
Algorithm Hash digest
SHA256 46f14bbc100be81aa69011340596ccc139de10e9a58fa89fb944be057fc62cd4
MD5 7725962f957c2bf894a113f169a7c934
BLAKE2b-256 93aae976686f6d06f6c744d132c368d69f7d6a7591a1a4f82c2cb3c16b69defc

See more details on using hashes here.

File details

Details for the file authsec_sdk-4.0.2-py3-none-any.whl.

File metadata

  • Download URL: authsec_sdk-4.0.2-py3-none-any.whl
  • Upload date:
  • Size: 32.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.1

File hashes

Hashes for authsec_sdk-4.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2f4f12d92144b9a0610c9fc12a150c3bd4c36f6476c42a7874ce9885d4fdf2e3
MD5 911c90d03ef8c662e0ef03193a4ee95c
BLAKE2b-256 bb34e487e36ba7cf09103ff5a723e8058ce514282edd9eaf121074a5d39c409f

See more details on using hashes here.

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