Skip to content

refactor: use context var and init whoami sample#8

Merged
gao-sun merged 2 commits intomasterfrom
gao-use-context
May 3, 2025
Merged

refactor: use context var and init whoami sample#8
gao-sun merged 2 commits intomasterfrom
gao-use-context

Conversation

@gao-sun
Copy link
Copy Markdown
Contributor

@gao-sun gao-sun commented May 3, 2025

  • bump python version per MCP SDK latest update
  • use ContextVar to store per-request context
  • init whoami sample to showcase basic usage

@gao-sun gao-sun requested a review from Copilot May 3, 2025 03:19
@codecov
Copy link
Copy Markdown

codecov bot commented May 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 refactors exception naming and handling to use token-based terminology, integrates a context variable for storing authentication info, and updates the whoami sample accordingly. Key changes include replacing "JWT" exception names with "Token" exception names across tests and middleware, injecting a ContextVar for auth info in various functions and tests, and adjusting server sample and configuration to align with the new design.

Reviewed Changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/utils/create_verify_jwt_test.py Updated test assertions and exception names to reflect token verification changes.
tests/middleware/create_bearer_auth_test.py Refactored tests to inject and use a ContextVar for auth info and updated exception names and error messages.
tests/exceptions_test.py Replaced JWT exception tests with token exception tests and updated expected messages.
tests/__init__test.py Adjusted metadata and bearer auth middleware tests to use the new ContextVar parameter.
samples/server/whoami.py Introduced a whoami tool sample that leverages the new context variable-based auth info.
samples/server/starlette.py Removed sample file as part of the refactor.
pyproject.toml Raised the minimum Python version and updated dependency versions.
mcpauth/utils/_create_verify_jwt.py Replaced JwtPayload usage and exception names, omitting expires_at from AuthInfo creation.
mcpauth/types.py Updated AuthInfo fields (e.g., making client_id optional, scopes default empty) and added JwtPayload model.
mcpauth/middleware/create_bearer_auth.py Modified to accept a ContextVar parameter and store auth info via the context variable rather than attaching it to the request state.
mcpauth/exceptions.py Renamed JWT verification exception to token verification exception and updated descriptions accordingly.
mcpauth/config.py Added the userinfo_endpoint field to AuthorizationServerMetadata.
mcpauth/init.py Updated MCPAuth initialization to use the context variable for maintaining auth info.
.github/workflows/main.yml Updated the Python version matrix.
Files not reviewed (1)
  • .python-version: Language not supported

@gao-sun gao-sun force-pushed the gao-use-context branch from 5a00716 to 5937b09 Compare May 3, 2025 03:41
@gao-sun gao-sun marked this pull request as ready for review May 3, 2025 03:43
@gao-sun gao-sun merged commit 43d9b70 into master May 3, 2025
5 checks passed
@gao-sun gao-sun deleted the gao-use-context branch May 3, 2025 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants