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
2 changed files with 1063 additions and 1057 deletions

View file

@ -134,23 +134,23 @@ class ExperimentalHandlers:
if GetTaskRequest not in self._request_handlers:
async def _default_get_task(req: GetTaskRequest) -> ServerResult:
task = await support.store.get_task(req.params.taskId)
task = await support.store.get_task(req.params.task_id)
if task is None:
raise McpError(
ErrorData(
code=INVALID_PARAMS,
message=f"Task not found: {req.params.taskId}",
message=f"Task not found: {req.params.task_id}",
)
)
return ServerResult(
GetTaskResult(
taskId=task.taskId,
task_id=task.task_id,
status=task.status,
statusMessage=task.statusMessage,
createdAt=task.createdAt,
lastUpdatedAt=task.lastUpdatedAt,
status_message=task.status_message,
created_at=task.created_at,
last_updated_at=task.last_updated_at,
ttl=task.ttl,
pollInterval=task.pollInterval,
poll_interval=task.poll_interval,
)
)
@ -172,7 +172,7 @@ class ExperimentalHandlers:
async def _default_list_tasks(req: ListTasksRequest) -> ServerResult:
cursor = req.params.cursor if req.params else None
tasks, next_cursor = await support.store.list_tasks(cursor)
return ServerResult(ListTasksResult(tasks=tasks, nextCursor=next_cursor))
return ServerResult(ListTasksResult(tasks=tasks, next_cursor=next_cursor))
self._request_handlers[ListTasksRequest] = _default_list_tasks
@ -180,7 +180,7 @@ class ExperimentalHandlers:
if CancelTaskRequest not in self._request_handlers:
async def _default_cancel_task(req: CancelTaskRequest) -> ServerResult:
result = await cancel_task(support.store, req.params.taskId)
result = await cancel_task(support.store, req.params.task_id)
return ServerResult(result)
self._request_handlers[CancelTaskRequest] = _default_cancel_task

View file

@ -209,17 +209,17 @@ class Server(Generic[LifespanResultT, RequestT]):
# Set prompt capabilities if handler exists
if types.ListPromptsRequest in self.request_handlers:
prompts_capability = types.PromptsCapability(listChanged=notification_options.prompts_changed)
prompts_capability = types.PromptsCapability(list_changed=notification_options.prompts_changed)
# Set resource capabilities if handler exists
if types.ListResourcesRequest in self.request_handlers:
resources_capability = types.ResourcesCapability(
subscribe=False, listChanged=notification_options.resources_changed
subscribe=False, list_changed=notification_options.resources_changed
)
# Set tool capabilities if handler exists
if types.ListToolsRequest in self.request_handlers:
tools_capability = types.ToolsCapability(listChanged=notification_options.tools_changed)
tools_capability = types.ToolsCapability(list_changed=notification_options.tools_changed)
# Set logging capabilities if handler exists
if types.SetLevelRequest in self.request_handlers: # pragma: no cover
@ -327,7 +327,7 @@ class Server(Generic[LifespanResultT, RequestT]):
async def handler(_: Any):
templates = await func()
return types.ServerResult(types.ListResourceTemplatesResult(resourceTemplates=templates))
return types.ServerResult(types.ListResourceTemplatesResult(resource_templates=templates))
self.request_handlers[types.ListResourceTemplatesRequest] = handler
return func
@ -351,14 +351,14 @@ class Server(Generic[LifespanResultT, RequestT]):
return types.TextResourceContents(
uri=req.params.uri,
text=data,
mimeType=mime_type or "text/plain",
mime_type=mime_type or "text/plain",
**meta_kwargs,
)
case bytes() as data: # pragma: no cover
return types.BlobResourceContents(
uri=req.params.uri,
blob=base64.b64encode(data).decode(),
mimeType=mime_type or "application/octet-stream",
mime_type=mime_type or "application/octet-stream",
**meta_kwargs,
)
@ -474,7 +474,7 @@ class Server(Generic[LifespanResultT, RequestT]):
return types.ServerResult(
types.CallToolResult(
content=[types.TextContent(type="text", text=error_message)],
isError=True,
is_error=True,
)
)
@ -532,7 +532,7 @@ class Server(Generic[LifespanResultT, RequestT]):
# input validation
if validate_input and tool:
try:
jsonschema.validate(instance=arguments, schema=tool.inputSchema)
jsonschema.validate(instance=arguments, schema=tool.input_schema)
except jsonschema.ValidationError as e:
return self._make_error_result(f"Input validation error: {e.message}")
@ -562,14 +562,14 @@ class Server(Generic[LifespanResultT, RequestT]):
return self._make_error_result(f"Unexpected return type from tool: {type(results).__name__}")
# output validation
if tool and tool.outputSchema is not None:
if tool and tool.output_schema is not None:
if maybe_structured_content is None:
return self._make_error_result(
"Output validation error: outputSchema defined but no structured output returned"
)
else:
try:
jsonschema.validate(instance=maybe_structured_content, schema=tool.outputSchema)
jsonschema.validate(instance=maybe_structured_content, schema=tool.output_schema)
except jsonschema.ValidationError as e:
return self._make_error_result(f"Output validation error: {e.message}")
@ -577,8 +577,8 @@ class Server(Generic[LifespanResultT, RequestT]):
return types.ServerResult(
types.CallToolResult(
content=list(unstructured_content),
structuredContent=maybe_structured_content,
isError=False,
structured_content=maybe_structured_content,
is_error=False,
)
)
except UrlElicitationRequiredError:
@ -601,7 +601,7 @@ class Server(Generic[LifespanResultT, RequestT]):
async def handler(req: types.ProgressNotification):
await func(
req.params.progressToken,
req.params.progress_token,
req.params.progress,
req.params.total,
req.params.message,
@ -633,7 +633,7 @@ class Server(Generic[LifespanResultT, RequestT]):
types.CompleteResult(
completion=completion
if completion is not None
else types.Completion(values=[], total=None, hasMore=None),
else types.Completion(values=[], total=None, has_more=None),
)
)