Fix DeprecationWarnings in mcp_server (#135927)

* Fix DeprecationWarnings in mcp_server

* Spelling
This commit is contained in:
Marc Mueller 2025-01-18 17:43:35 +01:00 committed by GitHub
parent dedcef7230
commit 0c9fd7c482
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,4 @@
"""Model Context Protocol transport portocol for Server Sent Events (SSE).
"""Model Context Protocol transport protocol for Server Sent Events (SSE).
This registers HTTP endpoints that supports SSE as a transport layer
for the Model Context Protocol. There are two HTTP endpoints:
@ -62,9 +62,9 @@ def async_get_config_entry(hass: HomeAssistant) -> MCPServerConfigEntry:
if config_entry.state == ConfigEntryState.LOADED
]
if not config_entries:
raise HTTPNotFound(body="Model Context Protocol server is not configured")
raise HTTPNotFound(text="Model Context Protocol server is not configured")
if len(config_entries) > 1:
raise HTTPNotFound(body="Found multiple Model Context Protocol configurations")
raise HTTPNotFound(text="Found multiple Model Context Protocol configurations")
return config_entries[0]
@ -147,7 +147,7 @@ class ModelContextProtocolMessagesView(HomeAssistantView):
"""Process incoming messages for the Model Context Protocol.
The request passes a session ID which is used to identify the original
SSE connection. This view parses incoming messagess from the transport
SSE connection. This view parses incoming messages from the transport
layer then writes them to the MCP server stream for the session.
"""
hass = request.app[KEY_HASS]
@ -156,14 +156,14 @@ class ModelContextProtocolMessagesView(HomeAssistantView):
session_manager = config_entry.runtime_data
if (session := session_manager.get(session_id)) is None:
_LOGGER.info("Could not find session ID: '%s'", session_id)
raise HTTPNotFound(body=f"Could not find session ID '{session_id}'")
raise HTTPNotFound(text=f"Could not find session ID '{session_id}'")
json_data = await request.json()
try:
message = types.JSONRPCMessage.model_validate(json_data)
except ValueError as err:
_LOGGER.info("Failed to parse message: %s", err)
raise HTTPBadRequest(body="Could not parse message") from err
raise HTTPBadRequest(text="Could not parse message") from err
_LOGGER.debug("Received client message: %s", message)
await session.read_stream_writer.send(message)