Skip to content

[Feature Request] Support Exposing Endpoints as MCP Services (Similar to fastapi_mcp) #1449

@chaofanat

Description

@chaofanat

Background & Use Case

As a long-time user of Django-Ninja, I deeply value the completeness of the Django ecosystem and its clear architecture, as well as the efficient API development experience that Django-Ninja provides. I am currently building a project with Django-Ninja and have a critical need: I want to expose API endpoints as MCP services (similar to how fastapi_mcp does for FastAPI), to integrate with agent-based systems and remote service protocols.

While FastAPI has existing support for such protocols, I prefer to stay within the Django ecosystem to leverage its mature features (middleware, ORM, admin panel, etc.) and avoid fragmenting my tech stack.

Feature Request

I propose adding native support in Django-Ninja to expose endpoints as MCP services.
Key requirements:

  1. Dedicated Router/Decorator: Introduce a @mcp_router decorator or configuration to mark routes/controllers as MCP endpoints, separate from HTTP endpoints if needed.
  2. Protocol Parsing: Support MCP-specific request/response parsing (message format, authentication, streaming, etc.), compatible with Django’s request lifecycle.
  3. Asynchronous & Middleware Compatibility: Work with Django’s async views (if MCP supports async) and integrate seamlessly with existing middleware.

Reasons & Value

  1. Tech Stack Consistency: Keep the project within the Django ecosystem, reducing maintenance costs from adopting additional frameworks.
  2. Future-Proofing: With the rise of agent systems and distributed services, protocols like MCP (e.g., for remote procedure calls, multi-channel communication) are becoming essential. Supporting them will make Django-Ninja more competitive for modern use cases.
  3. Developer Experience: The fastapi_mcp implementation proves this is feasible. Bringing this capability to Django-Ninja will benefit developers who prefer Django’s architecture but need MCP-compatible services.

Desired Outcome

  • Documentation: Clear guides on how to define and configure MCP endpoints in the Django-Ninja docs.
  • Examples: Sample code snippets for basic MCP endpoint definitions, authentication setup, and error handling.
  • Coexistence: MCP services should work alongside existing HTTP endpoints without conflicts.

Thank you for considering this request! I believe it will make Django-Ninja more versatile for emerging service architectures.

Best regards,
chaofan

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions