GD

gts360/django-mcp-server

开发工具

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

383 stars 59 forks 质量 70 趋势 19MIT

Django MCP 服务器是 Django 的一个扩展,旨在通过模型上下文协议轻松使 AI 代理与 Django 应用交互,它在 WSGI 和 ASGI 上同样出色地运行。

概览

是Django扩展的一个实现。该模块允许并实现无缝交互。 🚀 Django 风格声明式工具,允许 AI 代理和 MCP 客户端工具与 Django 交互。🚀以安全的方式,以两行代码形式公开 Django 模型,并支持 MCP 工具查询。🚀只需一个注释,即可将 Django Rest Framework API 转换为 MCP 工具。✅在不更改基础设施的情况下同时开发 WSGI 和 ASGI。✅已验证为与 Claude AI 的远程集成。🤖任何支持 MCP 的 MCP 客户端或 AI 代理(Google Agent 开发套件、Claude AI、Claude Desktop 等)都可以与你的应用程序交互。 非常感谢🙏所有贡献者社区的朋友们 由Smart GTS软件工程部门精心维护✨。 - 将 Django 模型和逻辑暴露为 。- 在您的 Django 应用内提供 MCP 端点。- 轻松集成 AI 代理、MCP 客户端或 Google ADK 等工具。

概述(AI 翻译)

Django MCP 服务器是 Django 的 Model Context Protocol (MCP) 扩展的实现。该模块允许 MCP 客户端和 AI 代理与任何 Django 应用无缝交互。

🚀 Django 风格的声明式工具,允许 AI 代理和 MCP 客户端工具与 Django 交互。 🚀 为AI代理和MCP工具提供Django模型,以安全的方式在两行代码内进行查询。 🚀 只需一个注释,即可将Django Rest Framework API转换为MCP工具。 ✅ 我同时在WSGI和ASGI上工作,基础设施没有变动。 ✅ 已验证为与Claude AI的远程集成。 🤖 任何支持 MCP 的 MCP 客户端或 AI 代理(如 Google 代理开发套件、Claude AI、Claude Desktop 等)都可以与你的应用交互。

非常感谢🙏所有贡献者社区的朋友们

由Smart GTS软件工程部门精心维护✨。

采用MIT许可证许可。


特色

  • 将Django模型和逻辑作为MCP工具公开展示。
  • 在您的 Django 应用中提供一个 MCP 端点。
  • 轻松集成 AI 代理、MCP 客户端或 Google ADK 等工具。

快速启动

1️# 安装

或者直接访问GitHub:


2️¶ 配置Django

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

README

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

Django MCP Server

Django MCP Server is an implementation of the Model Context Protocol (MCP) extension for Django. This module allows MCP Clients and AI agents to interact with any Django application seamlessly.

🚀 Django-Style declarative style tools to allow AI Agents and MCP clients tool to interact with Django. 🚀 Expose Django models for AI Agents and MCP Tools to query in 2 lines of code in a safe way. 🚀 Convert Django Rest Framework APIs to MCP tools with one annotation. ✅ Working on both WSGI and ASGI without infrastructure change. ✅ Validated as a Remote Integration with Claude AI. 🤖 Any MCP Client or AI Agent supporting MCP , (Google Agent Developement Kit, Claude AI, Claude Desktop …) can interact with your application.

Many thanks 🙏 to all the contributor community

Maintained ✨ with care by Smart GTS software engineering.

Licensed under the MIT License.


Features

  • Expose Django models and logic as MCP tools.
  • Serve an MCP endpoint inside your Django app.
  • Easily integrate with AI agents, MCP Clients, or tools like Google ADK.

Quick Start

1️⃣ Install

pip install django-mcp-server

Or directly from GitHub:

pip install git+https://github.com/omarbenhamid/django-mcp-server.git

2️⃣ Configure Django

✅ Add mcp_server to your INSTALLED_APPS:

INSTALLED_APPS = [
    # your apps...
    'mcp_server',
]

✅ Add the MCP endpoint to your urls.py:

from django.urls import path, include

urlpatterns = [
    # your urls...
    path("", include('mcp_server.urls')),
]

By default, the MCP endpoint will be available at /mcp.


3️⃣ Define MCP Tools

In mcp.py create a subclass of ModelQueryToolset to give access to a model :

from mcp_server import ModelQueryToolset
from .models import *

class BirdQueryTool(ModelQueryToolset):
    model = Bird

    def get_queryset(self):
        """self.request can be used to filter the queryset"""
        return super().get_queryset().filter(location__isnull=False)

class LocationTool(ModelQueryToolset):
    model = Location

class CityTool(ModelQueryToolset):
    model = City

Or create a sub class of MCPToolset to publish generic methods (private _ methods are not published)

在 GitHub 查看完整 README

安装

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

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

配置

{ "mcpServers": { "test_django_mcp": { "command": "/path/to/interpreter/python", "args": [ "/path/to/your/project/manage.py", "stdio_server" ] } }