
Django里的MCP服务器非常简单。
概览
..图片:: https://img.shields.io/readthedocs/django-mcpz?style=for-the-badge :目标: https://django-mcpz.readthedocs.io/en/latest/ ..图片:: https://img.shields.io/github/actions/workflow/status/adamchainz/django-mcpz/main.yml.svg?branch=main&style=for-the-badge :目标:https://github.com/adamchainz/django-mcpz/actions?workflow=CI ..图片:: https://img.shields.io/badge/Coverage-100%25-success?style=for-the-badge :目标:https://github.com/adamchainz/django-mcpz/actions?workflow=CI ..图片:: https://img.shields.io/pypi/v/django-mcpz.svg?style=for-the-badge :目标:https://pypi.org/project/django-mcpz/ ..图片:: https://img.shields.io/badge/code%20style-black-000000.svg?style=for-the-badge :目标: https://github.com/psf/black ..图片:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=for-the-badge :目标: https://github.
概述(AI 翻译)
=========== Django-MCPZ
…图片:: https://img.shields.io/readthedocs/django-mcpz?style=for-the-badge :目标:https://django-mcpz.readthedocs.io/en/latest/
…图片:: https://img.shields.io/github/actions/workflow/status/adamchainz/django-mcpz/main.yml.svg?branch=main&style=for-the-badge :目标: https://github.com/adamchainz/django-mcpz/actions?workflow=CI
…图片:https://img.shields.io/badge/Coverage-100%25-success?style=for-the-badge :目标: https://github.com/adamchainz/django-mcpz/actions?workflow=CI
…图片:: https://img.shields.io/pypi/v/django-mcpz.svg?style=for-the-badge :目标:https://pypi.org/project/django-mcpz/
…图片:: https://img.shields.io/badge/code style-black-000000.svg?style=for-the-badge :目标:https://github.com/psf/black
…图片:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=for-the-badge :目标:https://github.com/pre-commit/pre-commit :alt:预提交
Django中的MCP服务器非常简单。
django-mcpz 允许你在 Django 项目中构建模型上下文协议(MCP)服务器。
本页由 AI 翻译,技术细节请以原文为准。
README
=========== django-mcpz
… image:: https://img.shields.io/readthedocs/django-mcpz?style=for-the-badge :target: https://django-mcpz.readthedocs.io/en/latest/
… image:: https://img.shields.io/github/actions/workflow/status/adamchainz/django-mcpz/main.yml.svg?branch=main&style=for-the-badge :target: https://github.com/adamchainz/django-mcpz/actions?workflow=CI
… image:: https://img.shields.io/badge/Coverage-100%25-success?style=for-the-badge :target: https://github.com/adamchainz/django-mcpz/actions?workflow=CI
… image:: https://img.shields.io/pypi/v/django-mcpz.svg?style=for-the-badge :target: https://pypi.org/project/django-mcpz/
… image:: https://img.shields.io/badge/code style-black-000000.svg?style=for-the-badge :target: https://github.com/psf/black
… image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=for-the-badge :target: https://github.com/pre-commit/pre-commit :alt: pre-commit
Easy peasy MCP servers in Django.
django-mcpz lets you build a Model Context Protocol (MCP) server in your Django project.
Create an MCP server object with metadata, give it a URL, and attach Python functions to it as tools.
The MCP server acts like a regular synchronous Django view, handling the intricacies of the MCP protocol.
django-mcpz leans on msgspec __ for defining schemas and fast JSON serialization and deserialization.
A quick example:
… code-block:: python
from typing import Literal
import msgspec
from django_mcpz.server import MCPServer
from django_mcpz.bearer_tokens.auth import token_auth
from example.models import Order
server = MCPServer(
name="shop",
version="1.0.0",
instructions="Query the shop’s order database.",
auth=token_auth,
)
class CountOrdersParams(msgspec.Struct):
status: Literal["pending", "shipped", "cancelled"] | None = None
class CountOrdersResult(msgspec.Struct):
count: int
@server.tool(
description="Count Order rows, optionally filtered by status.",
read_only=True,
)
def count_orders(request, params: CountOrdersParams) -> CountOrdersResult:
qs = Order.objects.all()
if params.status is not None:
qs = qs.filter(status=params.status)
return CountOrdersResult(count=qs.count())
Documentation
Please see https://django-mcpz.readthedocs.io/.
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →