Skip to content

feat: add mcp server#246

Merged
Antoni-Czaplicki merged 20 commits into
devfrom
mcp
Jun 5, 2026
Merged

feat: add mcp server#246
Antoni-Czaplicki merged 20 commits into
devfrom
mcp

Conversation

@Antoni-Czaplicki

Copy link
Copy Markdown
Member

What changed

  • Adds OAuth/CIMD plumbing and MCP endpoint documentation.
  • Adds MCP toolsets for user profile/settings and quiz, study, progress, and folder workflows.
  • Rewrites quiz MCP serialization to reuse existing DRF serializers instead of bespoke response shaping.
  • Routes MCP question creation and edits through existing question serializers, with MCP-specific closed-question normalization for agent-friendly errors.

Why

The quiz MCP implementation had started to duplicate serializer behavior and validation. Reusing serializers keeps the REST and MCP contracts closer together, avoids partial update bugs, and prevents malformed closed questions with no correct answer.

Validation

  • python3 -m ruff check
  • python3 manage.py check
  • python3 manage.py test quizzes.tests.test_question_crud quizzes.tests.test_quiz_crud users.tests.test_oauth
  • python3 manage.py test

@Antoni-Czaplicki Antoni-Czaplicki marked this pull request as ready for review June 2, 2026 18:33
Copilot AI review requested due to automatic review settings June 2, 2026 18:33
Comment thread oauth_integrations/oauth_cimd.py Fixed
Comment thread quizzes/mcp.py Fixed
Comment thread oauth_integrations/oauth_cimd.py Fixed
@Antoni-Czaplicki Antoni-Czaplicki changed the title [codex] add oauth mcp integration feat: add oauth mcp integration Jun 2, 2026
Comment thread oauth_integrations/oauth_cimd.py Fixed
Comment thread oauth_integrations/oauth_cimd.py Fixed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces OAuth 2.0/CIMD-backed authentication for the new MCP server endpoint and adds MCP toolsets that let authenticated agents read/write quiz content, run study flows, and fetch user profile/settings. It also refactors settings/admin wiring to include the new OAuth + MCP apps and adds documentation for connecting MCP clients.

Changes:

  • Adds OAuth2 authorization server enhancements (CIMD client bootstrap + per-scope consent UI) and exposes discovery metadata endpoints.
  • Adds MCP server endpoint (/api/mcp) and tool implementations for user + quizzes/study/progress/folders, reusing existing DRF serializers.
  • Extends the quiz domain with Quiz.is_ai_generated and surfaces it via serializers/admin for labeling AI-created content.

Reviewed changes

Copilot reviewed 22 out of 26 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
users/mcp.py Adds MCP tools for user profile/settings guarded by OAuth scopes.
users/admin.py Re-registers oauth-toolkit + JWT blacklist models with Unfold styling.
testownik_core/urls.py Adds MCP endpoint route and OAuth discovery/management routes.
testownik_core/settings.py Enables oauth2_provider + mcp_server apps and configures OAuth/MCP settings.
testownik_core/settings_configs/init.py Introduces grouped settings module package.
testownik_core/settings_configs/unfold.py Extracts UNFOLD configuration into a helper.
testownik_core/settings_configs/spectacular.py Extracts drf-spectacular settings into a helper.
testownik_core/settings_configs/mcp.py Adds MCP global server config and auth class settings.
testownik_core/mcp_auth.py Adds shared require_scope() helper for MCP tool scope enforcement.
templates/oauth2_provider/authorize.html Adds a custom per-scope consent screen template.
requirements.txt Adds django-mcp-server and django-oauth-toolkit dependencies.
quizzes/models.py Adds Quiz.is_ai_generated field.
quizzes/migrations/0031_quiz_is_ai_generated.py Migrates the new is_ai_generated quiz field.
quizzes/serializers.py Exposes is_ai_generated on quiz serializers (read-only in metadata serializer).
quizzes/admin.py Adds is_ai_generated to quiz admin list display/filter.
quizzes/mcp.py Implements MCP toolsets for quizzes/study/progress/folders with serializer reuse.
oauth_integrations/apps.py Adds the oauth_integrations Django app config.
oauth_integrations/models.py Adds persisted CIMD metadata model linked to OAuth Application.
oauth_integrations/migrations/0001_initial.py Creates the CIMD metadata table.
oauth_integrations/migrations/init.py Migration package init.
oauth_integrations/admin.py Adds admin registration for CIMD metadata (Unfold styling).
oauth_integrations/oauth_cimd.py Implements CIMD metadata fetching/validation and custom OAuth2 validator.
oauth_integrations/views.py Adds scoped consent view and OAuth metadata + authorized-apps endpoints.
oauth_integrations/tests/init.py Test package init for oauth_integrations.
oauth_integrations/init.py Package init for oauth_integrations.
docs/MCP.md Adds documentation for MCP endpoint, OAuth/CIMD flow, and tool catalog.

Comment thread docs/MCP.md Outdated
Comment thread docs/MCP.md Outdated
Comment thread docs/MCP.md Outdated
Comment thread quizzes/mcp.py
Comment thread quizzes/mcp.py Outdated
Comment thread quizzes/mcp.py Outdated
Comment thread templates/oauth2_provider/authorize.html Outdated
Comment thread oauth_integrations/oauth_cimd.py Outdated
Comment thread testownik_core/settings.py
Comment thread docs/MCP.md Outdated
Comment thread oauth_integrations/oauth_cimd.py Fixed
Avoid DNS lookups for caller-supplied hostnames that are not on the
allowlist by moving the allowlist gate ahead of getaddrinfo. The
private-address resolution check is kept as defense-in-depth for
allowlisted hosts.
Copilot AI review requested due to automatic review settings June 2, 2026 18:47
Comment thread oauth_integrations/oauth_cimd.py Fixed
Comment thread oauth_integrations/oauth_cimd.py Fixed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 26 changed files in this pull request and generated 12 comments.

Comment thread quizzes/mcp.py Outdated
Comment thread quizzes/mcp.py Outdated
Comment thread quizzes/mcp.py Outdated
Comment thread quizzes/mcp.py
Comment thread docs/MCP.md Outdated
Comment thread docs/MCP.md Outdated
Comment thread docs/MCP.md Outdated
Comment thread oauth_integrations/models.py
Comment thread templates/oauth2_provider/authorize.html Outdated
Comment thread oauth_integrations/oauth_cimd.py Outdated
Comment thread oauth_integrations/oauth_cimd.py Fixed
Copilot AI review requested due to automatic review settings June 2, 2026 19:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings June 3, 2026 20:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Comment thread oauth_integrations/views.py Fixed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

3 participants