refactor: use snake case instead of camel case in types (#1894)

This commit is contained in:
Marcelo Trylesinski 2026-01-16 15:51:27 +01:00 • committed by GitHub
commit e94b386a13
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 1063 additions and 1057 deletions

View file

@ -49,7 +49,7 @@ class UrlElicitationRequiredError(McpError):
mode="url",
message="Authorization required for your files",
url="https://example.com/oauth/authorize",
elicitationId="auth-001"
elicitation_id="auth-001"
)
])
"""

View file

@ -48,8 +48,8 @@ def check_tasks_capability(
if required.requests.sampling is not None:
if client.requests.sampling is None:
return False
if required.requests.sampling.createMessage is not None:
if client.requests.sampling.createMessage is None:
if required.requests.sampling.create_message is not None:
if client.requests.sampling.create_message is None:
return False
return True
@ -74,7 +74,7 @@ def has_task_augmented_sampling(caps: ClientCapabilities) -> bool:
return False
if caps.tasks.requests.sampling is None:
return False
return caps.tasks.requests.sampling.createMessage is not None
return caps.tasks.requests.sampling.create_message is not None
def require_task_augmented_elicitation(client_caps: ClientCapabilities | None) -> None:

View file

@ -41,7 +41,7 @@ class TaskContext:
@property
def task_id(self) -> str:
"""The task identifier."""
return self._task.taskId
return self._task.task_id
@property
def task(self) -> Task:

View file

@ -125,12 +125,12 @@ def create_task_state(
"""
now = datetime.now(timezone.utc)
return Task(
taskId=task_id or generate_task_id(),
task_id=task_id or generate_task_id(),
status=TASK_STATUS_WORKING,
createdAt=now,
lastUpdatedAt=now,
created_at=now,
last_updated_at=now,
ttl=metadata.ttl,
pollInterval=500, # Default 500ms poll interval
poll_interval=500, # Default 500ms poll interval
)

View file

@ -79,14 +79,14 @@ class InMemoryTaskStore(TaskStore):
task = create_task_state(metadata, task_id)
if task.taskId in self._tasks:
raise ValueError(f"Task with ID {task.taskId} already exists")
if task.task_id in self._tasks:
raise ValueError(f"Task with ID {task.task_id} already exists")
stored = StoredTask(
task=task,
expires_at=self._calculate_expiry(metadata.ttl),
)
self._tasks[task.taskId] = stored
self._tasks[task.task_id] = stored
# Return a copy to prevent external modification
return Task(**task.model_dump())
@ -124,10 +124,10 @@ class InMemoryTaskStore(TaskStore):
status_changed = True
if status_message is not None:
stored.task.statusMessage = status_message
stored.task.status_message = status_message
# Update lastUpdatedAt on any change
stored.task.lastUpdatedAt = datetime.now(timezone.utc)
# Update last_updated_at on any change
stored.task.last_updated_at = datetime.now(timezone.utc)
# If task is now terminal and has TTL, reset expiry timer
if status is not None and is_terminal(status) and stored.task.ttl is not None:

View file

@ -41,5 +41,5 @@ async def poll_until_terminal(
if is_terminal(status.status):
break
interval_ms = status.pollInterval if status.pollInterval is not None else default_interval_ms
interval_ms = status.poll_interval if status.poll_interval is not None else default_interval_ms
await anyio.sleep(interval_ms / 1000)

View file

@ -48,10 +48,10 @@ def progress(
ProgressContext[SendRequestT, SendNotificationT, SendResultT, ReceiveRequestT, ReceiveNotificationT],
None,
]:
if ctx.meta is None or ctx.meta.progressToken is None: # pragma: no cover
if ctx.meta is None or ctx.meta.progress_token is None: # pragma: no cover
raise ValueError("No progress token provided")
progress_ctx = ProgressContext(ctx.session, ctx.meta.progressToken, total)
progress_ctx = ProgressContext(ctx.session, ctx.meta.progress_token, total)
try:
yield progress_ctx
finally:

View file

@ -301,7 +301,7 @@ class BaseSession(
if isinstance(response_or_error, JSONRPCError):
raise McpError(response_or_error.error)
else:
return result_type.model_validate(response_or_error.result)
return result_type.model_validate(response_or_error.result, by_name=False)
finally:
self._response_streams.pop(request_id, None)
@ -356,7 +356,8 @@ class BaseSession(
elif isinstance(message.message.root, JSONRPCRequest):
try:
validated_request = self._receive_request_type.model_validate(
message.message.root.model_dump(by_alias=True, mode="json", exclude_none=True)
message.message.root.model_dump(by_alias=True, mode="json", exclude_none=True),
by_name=False,
)
responder = RequestResponder(
request_id=message.message.root.id,
@ -393,17 +394,18 @@ class BaseSession(
elif isinstance(message.message.root, JSONRPCNotification):
try:
notification = self._receive_notification_type.model_validate(
message.message.root.model_dump(by_alias=True, mode="json", exclude_none=True)
message.message.root.model_dump(by_alias=True, mode="json", exclude_none=True),
by_name=False,
)
# Handle cancellation notifications
if isinstance(notification.root, CancelledNotification):
cancelled_id = notification.root.params.requestId
cancelled_id = notification.root.params.request_id
if cancelled_id in self._in_flight: # pragma: no branch
await self._in_flight[cancelled_id].cancel()
else:
# Handle progress notifications callback
if isinstance(notification.root, ProgressNotification): # pragma: no cover
progress_token = notification.root.params.progressToken
progress_token = notification.root.params.progress_token
# If there is a progress callback for this token,
# call it with the progress information
if progress_token in self._progress_callbacks: