refactor: use snake case instead of camel case in types (#1894)
This commit is contained in:
parent
7080fcf1e6
commit
e94b386a13
1 changed files with 1063 additions and 1057 deletions
|
|
@ -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),
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue