MCPcopy Create free account
hub / github.com/plotly/dash / _handle_mcp_request

Function _handle_mcp_request

dash/mcp/_server.py:125–168  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

123 return _handle_mcp_request(await adapter.get_json())
124
125 def _handle_mcp_request(data) -> Any:
126 adapter = app.backend.request_adapter()
127 content_type = adapter.headers.get("Content-Type", "")
128 if "application/json" not in content_type:
129 return app.backend.make_response(
130 json.dumps({"error": "Content-Type must be application/json"}),
131 content_type="application/json",
132 status=415,
133 )
134
135 if data is None:
136 return app.backend.make_response(
137 json.dumps({"error": "Invalid JSON"}),
138 content_type="application/json",
139 status=400,
140 )
141
142 method = data.get("method", "")
143
144 try:
145 is_stale_session = _check_session(method)
146 except ValueError as err:
147 return app.backend.make_response(
148 json.dumps({"error": str(err)}),
149 content_type="application/json",
150 status=400,
151 )
152
153 response_data = _process_mcp_message(data)
154
155 if response_data is None:
156 return app.backend.make_response("", status=202)
157
158 if is_stale_session:
159 return _json_response(
160 {"jsonrpc": "2.0", "method": "notifications/tools/list_changed"},
161 {
162 "jsonrpc": "2.0",
163 "method": "notifications/resources/list_changed",
164 },
165 response_data,
166 )
167
168 return _json_response(response_data)
169
170 def _handle_get():
171 """

Callers 2

_handle_postFunction · 0.85
_handle_post_asyncFunction · 0.85

Calls 5

_check_sessionFunction · 0.85
_process_mcp_messageFunction · 0.85
_json_responseFunction · 0.85
getMethod · 0.45
make_responseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…