Skip to main content

webmcp-django

Django toolkit for WebMCP — the W3C proposal that lets web pages declare structured tools for AI agents (document.modelContext).

Status: early development. The WebMCP spec is in Chrome origin trial (Chrome 149–156) and its API surface has already changed twice. This package ships the pieces that are stable enough to use today — an Origin-Trial header middleware and declarative template tags — and will grow alongside the spec.

Install

pip install webmcp-django

Setup

Add the middleware to MIDDLEWARE to serve the Origin-Trial token header required by Chrome's origin trial:

# settings.py
MIDDLEWARE = [
    ...
    "webmcp_django.middleware.OriginTrialMiddleware",
]

WEBMCP_ORIGIN_TRIAL_TOKEN = "your-origin-trial-token"

When WEBMCP_ORIGIN_TRIAL_TOKEN is unset, the middleware is a no-op.

Add webmcp_django to INSTALLED_APPS to use the template tags:

INSTALLED_APPS = [
    ...
    "webmcp_django",
]

Usage

{% load webmcp %}

<form {% webmcp_tool "create_task" "Create a new task" autosubmit=True %}>
  <input name="title" {% webmcp_param "The task title" %}>
</form>

renders:

<form toolname="create_task" tooldescription="Create a new task" toolautosubmit>
  <input name="title" toolparamdescription="The task title">
</form>

Values are always HTML-escaped, including values pre-marked as safe with mark_safe — the tags call escape() unconditionally, which ignores Django's "safe" marking, so a caller cannot smuggle unescaped markup into tool metadata.

Security: tool metadata is agent-visible

tooldescription and toolparamdescription aren't just display text — an AI agent reads them as instructions describing what the tool does. Don't build these strings from unvalidated user input (profile fields, query params, uploaded file names, etc.). A user-controlled value rendered into tool metadata is a prompt-injection vector that can hijack the agent's behavior through your own tool declarations. Keep tool names and descriptions as literal strings you write, not values derived at request time from data a visitor controls.

License

MIT

Download files

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

Source Distribution

webmcp_django-0.1.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

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

webmcp_django-0.1.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: webmcp_django-0.1.0.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.5

File hashes

Hashes for webmcp_django-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f0a1759774a91cca75804582469c781e04bbc4b7371d975d3590a98d782a428e
MD5 77ea5c39388a104c32617aaaa29771d4
BLAKE2b-256 d97fec7eac050280660f01b009c0154f168eeae3b4ae13acd33c1b93367e0153

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for webmcp_django-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 772f5720d75f1270e681d9d02aef866dd649ea7b8b9b0c69ecaa5b752bb4e5e4
MD5 a484ba6680fb63fb290d8a1e240ef975
BLAKE2b-256 7d4ae2861d13456179b8a79996fa606b4a7d194ece3de651242991fe885dd581

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