Token导航 LogoToken导航TokenDH.com
Drf MCP Docs logo
开发工具stdio官方级别未说明来源级核验

Drf MCP Docs

MCP Server

drf-mcp-docs通过模型上下文协议(MCP)为AI编码代理提供Django REST Framework API文档,帮助开发者编写正确的前端集成代码。

工具数

7

提示词数

0

GitHub Stars

17

资源数

0
API文档代码生成PythonClaude开发工具ClaudeCursor

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

Abdulkhalek-1

提供方

Abdulkhalek-1

最后核验

2026/5/17 20:22

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

pip install drf-mcp-docs

详细介绍

drf-mcp-docs

API documentation via MCP for AI coding agents

______________________________________________________________________

drf mcp文档 公开Django REST框架API 文档 通过 模型上下文协议(MCP) 因此,AI编码代理可以读取、理解并帮助您编写正确的前端集成代码。

这与其他Django+MCP包有什么不同? 套餐如 django-mcp-serverdjango-rest-framework-mcp 暴露DRF 行动 作为MCP工具,AI代理直接调用您的端点。 drf mcp文档 根本不同:它公开了API 文档 因此,AI代理可以帮助开发人员 编写前端代码 (React、Vue、Angular等)。 把它想象成: *drf survival在浏览器中为人类生成文档* → *drf-mcp-docs通过mcp为AI代理生成文档*.

特性

  • MCP资源 -浏览API结构:概述、端点、模式、身份验证方法
  • MCP工具 --搜索端点,获取详细文档,生成请求/响应示例
  • 代码生成 --生成具有实际类型和文档的集成代码(JS/TS:fetch、axios、ky-Python:requests、httpx--cURL)
  • 多适配器 --适用于drf壮观、drf-yasg或drf的内置模式生成
  • 零风险 --只读文档,不可能发生数据突变
  • 两次运输 --stdio用于本地AI工具,可流式传输http用于远程/网络访问

快速开始

1.安装

pip install drf-mcp-docs

使用特定的模式生成器:

pip install drf-mcp-docs[spectacular]   # recommended
pip install drf-mcp-docs[yasg]

2.配置

添加到Django设置中:

INSTALLED_APPS = [
    # ...
    'rest_framework',
    'drf_mcp_docs',
]

这是基本用法。drf-mcp-docs会自动检测您的模式生成器。

3.跑步

stdio传输 (适用于本地AI工具,如Claude Code、Cursor等):

python manage.py runmcpserver --transport stdio

可流式HTTP传输 (用于网络访问):

python manage.py runmcpserver --transport streamable-http --host 0.0.0.0 --port 8100

检查配置 (验证设置、适配器和架构):

python manage.py checkmcpconfig

4.连接您的AI工具

克劳德代码 (~/.claude.json):

{
  "mcpServers": {
    "my-api-docs": {
      "command": "python",
      "args": ["manage.py", "runmcpserver", "--transport", "stdio"],
      "cwd": "/path/to/your/django/project"
    }
  }
}

光标 (.cursor/mcp.json):

{
  "mcpServers": {
    "my-api-docs": {
      "command": "python",
      "args": ["manage.py", "runmcpserver", "--transport", "stdio"],
      "cwd": "/path/to/your/django/project"
    }
  }
}

AI代理可以做什么

一旦连接,您的AI编码代理可以:

You: "Show me all the product endpoints"
Agent: [reads api://endpoints resource, filters by tag]

You: "Generate a React hook to create a new product"
Agent: [calls get_endpoint_detail for POST /api/products/]
       [calls get_request_example for the request body]
       [calls generate_code_snippet with typescript + fetch]
       → Generates a complete, typed React hook with correct fields

可用资源

资源URI描述
api://overviewAPI标题、版本、基本URL、身份验证摘要、标记、终结点计数
api://endpoints所有端点:路径、方法、摘要、标签(紧凑列表)
api://endpoints/{method}/{path}一个端点的完整细节
api://schemas所有模式/模型定义(名称+字段摘要)
api://schemas/{name}具有属性、类型和约束的完整架构
api://auth包含所有身份验证方法的身份验证指南

可用工具

工具参数说明
search_endpointsquery, method?, tag?按关键字搜索端点
get_endpoint_detailpath, method完整的端点文档
get_request_examplepath, method请求正文和参数示例
get_response_examplepath, method, status_code?示例响应
generate_code_snippetpath, method, language?, client?支持分页的集成代码(JS/TS、Python、cURL)
list_schemas--所有数据模型名称和描述
get_schema_detailname包含所有字段和类型的完整架构

配置

所有设置都是可选的。添加一个 DRF_MCP_DOCS dict到你的Django设置:

DRF_MCP_DOCS = {
    # Server
    'SERVER_NAME': 'my-api',                    # MCP server name (default: 'drf-mcp-docs')
    'SERVER_INSTRUCTIONS': 'Custom prompt...',   # Instructions shown to AI agents

    # Schema
    'SCHEMA_ADAPTER': None,                      # Auto-detect, or full dotted path
    'SCHEMA_PATH_PREFIX': '/api/',               # Only include endpoints under this prefix
    'EXCLUDE_PATHS': ['/api/internal/'],          # Paths to exclude
    'CACHE_SCHEMA': not DEBUG,                   # Cache in production, refresh in dev
    'CACHE_TTL': None,                           # Schema cache TTL in seconds (None = no expiry)

    # Transport
    'TRANSPORT': 'streamable-http',              # Default transport: 'streamable-http' or 'stdio'
    'MCP_ENDPOINT': '/mcp/',                     # URL path for HTTP transport

    # Code generation
    'DEFAULT_CODE_LANGUAGE': 'javascript',       # 'javascript', 'typescript', or 'python'
    'DEFAULT_HTTP_CLIENT': 'fetch',              # 'fetch', 'axios', 'ky', 'requests', or 'httpx'
}

架构适配器选择

drf-mcp-docs会按照以下优先级顺序自动检测您的模式生成器:

  1. drf壮观 (推荐)--最完整的OpenAPI 3.x输出
  2. yasg博士 --Swagger 2.0自动转换为OpenAPI 3.0
  3. DRF内置 --具有有限模式细节的基本回退

要强制使用特定适配器,请执行以下操作:

DRF_MCP_DOCS = {
    'SCHEMA_ADAPTER': 'drf_mcp_docs.adapters.spectacular.SpectacularAdapter',
}

ASGI集成

对于使用ASGI的项目,在Django应用程序旁边挂载MCP端点:

# asgi.py
from django.core.asgi import get_asgi_application
from drf_mcp_docs.urls import mount_mcp

django_app = get_asgi_application()
application = mount_mcp(django_app)  # Mounts at /mcp/ by default

使用自定义路径:

application = mount_mcp(django_app, path="/api-docs-mcp/")

发展

git clone https://github.com/Abdulkhalek-1/drf-mcp-docs.git
cd drf-mcp-docs
pip install -e ".[dev]"
pytest

运作原理

┌─────────────┐     ┌──────────────┐     ┌─────────────────┐     ┌───────────┐
│  AI Agent   │────>│  MCP Server  │────>│ Schema Processor │────>│  Adapter  │
│ (Claude,    │<────│  (FastMCP)   │<────│  (OpenAPI dict   │<────│ (spectac- │
│  Cursor...) │     │              │     │   → structured)  │     │  ular,    │
└─────────────┘     └──────────────┘     └─────────────────┘     │  yasg,    │
                    Resources + Tools     Dataclasses + Search    │  DRF)     │
                                                                  └───────────┘
  1. 适配器 从所选生成器中提取OpenAPI模式
  2. 处理器 将原始字典转换为结构化、人工智能友好的数据类
  3. MCP服务器 公开资源(可浏览文档)和工具(搜索、示例、代码生成)
  4. AI 代理 通过stdio或HTTP连接,读取API文档,帮助编写前端代码

许可证

MIT许可证。看 许可证 了解详情。

目录标签

目录标签

API文档代码生成PythonClaude开发工具本地部署AI辅助开发DjangoRESTFramework前端集成

支持客户端

ClaudeCursor

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

none

工具数量(toolCount,工具数)

7

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdionone部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP