ZD

zacharypodbela/django-rest-framework-mcp

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

55 stars 7 forks 质量 71 趋势 0BSD-3-Clause

zacharypodbela/django-rest-framework-mcp 是从 https://github.com/zacharypodbela/django-rest-framework-mcp. 导入的 MCP 服务器候选。

概览

zacharypodbela/django-rest-framework-mcp 是从 https://github.com/zacharypodbela/django-rest-framework-mcp. 导入的 MCP 服务器候选。

概述(AI 翻译)

django-rest-framework-mcp 允许你启动 MCP 服务器,只需几行代码就能将你的 Django Rest Framework API 暴露为 MCP 工具。

强化你的管理流程(让开发管理界面成为过去):

  • “停用 [email protected] 账户” → 实际上是停用账户
  • “延长 [email protected] 免费试用一周” → 更新计划
  • “每周新增用户人数是多少?”→ 返回真实数据→LLM可以快速创建图表_(无需更多复杂的FE图库)_

或者用对话式互动改造你传统、乏味的SaaS用户体验:

  • 旧方式:用户点击“管理”,点击“我的帖子”,点击列表中的帖子,点击“编辑”,更改标题,点击“保存”
  • 关于Django Rest Framework的MCP:“你能把我的帖子从’Django初学者指南’改名为’Django 101’吗?”

快速启动

  1. 安装该软件包:

  2. 在你的INSTALLED_APPS中添加:

  3. 将MCP端点添加到你的urls.py:

  4. 用单个装饰器将任意 DRF 视图集转换为 MCP 工具:

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

Django REST Framework MCP

django-rest-framework-mcp allows you to spin up MCP servers that expose your Django Rest Framework APIs as MCP tools with just a few lines of code.

Supercharge your admin workflows (and make developing Admin interfaces a thing of the past):

  • “Deactivate [email protected]’s account” → Actually deactivates it
  • “Extend [email protected]’s free trial by 1 week” → Updates their plan
  • “How many new users joined week-over-week?” → Returns real data → LLMs can quickly create graphs (no more complex FE graphing libraries needed)

Or transform your traditional, boring SaaS UX with conversational interactions:

  • Old way: User Clicks “Manage”, Clicks “My Posts”, Clicks a post from the list, Clicks “Edit”, changes the title, Clicks “Save”
  • With Django Rest Framework MCP: “Can you rename my post from ‘Beginners Guide to Django’ to ‘Django 101’?”

Quick Start

  1. Install the package:
pip install django-rest-framework-mcp
  1. Add to your INSTALLED_APPS:
INSTALLED_APPS = [
    # ... your other apps
    'djangorestframework_mcp',
]
  1. Add the MCP endpoint to your urls.py:
urlpatterns = [
    # ... your other URL patterns
    path('mcp/', include('djangorestframework_mcp.urls')),
]
  1. Transform any DRF ViewSet into MCP tools with a single decorator:
from djangorestframework_mcp.decorators import mcp_viewset

@mcp_viewset()
class CustomerViewSet(ModelViewSet):
    queryset = Customer.objects.all()
    serializer_class = CustomerSerializer

When @mcp_viewset is applied to a ViewSet class that inherits from GenericViewSet (such as ModelViewSet or ReadOnlyModelViewSet), any of the following methods that are defined will be automatically exposed as MCP tools:

  • list -> List customers with customers_list tool.
  • retrieve -> Retrieve a customer with customers_retrieve tool.
  • create -> Create new customers with customers_create tool.
  • update -> Update customers with customers_update tool. (All fields must be passed in)
  • partial_update -> Update customers with customers_partial_update tool. (A subset of fields can be passed in)
  • destroy -> Delete customers with customers_destroy tool.

For each tool the library automatically:

  • Generates tool schemas from your DRF serializers
  • Preserves your existing permissions, authentication, and filtering
  • Returns context rich error messages to guide LLMs

(See: Custom Actions below for more info on how to expose additional endpoints you created using the @action decorator as tools).

  1. Connect any MCP client to http://localhost:8000/mcp/ and try it out!

Important Differences between MCP Requests and API Requests

在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →

配置

{ "mcpServers": { "my-django-mcp": { "command": "node", "args": [ "path/to/mcp-remote", "http://localhost:8000/mcp/", "--transport", "http-only" ] } } }