mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 23:27:37 +00:00
Fix DeprecationWarnings in mcp_server (#135927)
* Fix DeprecationWarnings in mcp_server * Spelling
This commit is contained in:
parent
dedcef7230
commit
0c9fd7c482
@ -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
|
This registers HTTP endpoints that supports SSE as a transport layer
|
||||||
for the Model Context Protocol. There are two HTTP endpoints:
|
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 config_entry.state == ConfigEntryState.LOADED
|
||||||
]
|
]
|
||||||
if not config_entries:
|
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:
|
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]
|
return config_entries[0]
|
||||||
|
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ class ModelContextProtocolMessagesView(HomeAssistantView):
|
|||||||
"""Process incoming messages for the Model Context Protocol.
|
"""Process incoming messages for the Model Context Protocol.
|
||||||
|
|
||||||
The request passes a session ID which is used to identify the original
|
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.
|
layer then writes them to the MCP server stream for the session.
|
||||||
"""
|
"""
|
||||||
hass = request.app[KEY_HASS]
|
hass = request.app[KEY_HASS]
|
||||||
@ -156,14 +156,14 @@ class ModelContextProtocolMessagesView(HomeAssistantView):
|
|||||||
session_manager = config_entry.runtime_data
|
session_manager = config_entry.runtime_data
|
||||||
if (session := session_manager.get(session_id)) is None:
|
if (session := session_manager.get(session_id)) is None:
|
||||||
_LOGGER.info("Could not find session ID: '%s'", session_id)
|
_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()
|
json_data = await request.json()
|
||||||
try:
|
try:
|
||||||
message = types.JSONRPCMessage.model_validate(json_data)
|
message = types.JSONRPCMessage.model_validate(json_data)
|
||||||
except ValueError as err:
|
except ValueError as err:
|
||||||
_LOGGER.info("Failed to parse message: %s", 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)
|
_LOGGER.debug("Received client message: %s", message)
|
||||||
await session.read_stream_writer.send(message)
|
await session.read_stream_writer.send(message)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user