SimpleSallap:SimpleMCP:Body Bytes to Json within mcp_run
Given that there could be other service paths beyond /mcp exposed in future, and given that it is not necessary that their post body contain json data, so move conversion to json to within mcp_run handler. While retaining reading of the body in the generic do_POST ensures that the read size limit is implicitly enforced, whether /mcp now or any other path in future.
This commit is contained in:
parent
fac947f9cd
commit
9d6daaed8c
|
|
@ -122,7 +122,8 @@ class ProxyHandler(http.server.BaseHTTPRequestHandler):
|
|||
tcl = mTC.MCPToolsList(oRPC["id"], mTC.MCPTLResult(gMe.op.toolManager.meta()))
|
||||
self.send_mcp(200, "tools/list follows", tcl)
|
||||
|
||||
def mcp_run(self, oRPC: Any):
|
||||
def mcp_run(self, body: bytes):
|
||||
oRPC = json.loads(body)
|
||||
if oRPC["method"] == "tools/call":
|
||||
self.mcp_toolscall(oRPC)
|
||||
elif oRPC["method"] == "tools/list":
|
||||
|
|
@ -140,14 +141,13 @@ class ProxyHandler(http.server.BaseHTTPRequestHandler):
|
|||
if not acGot.callOk:
|
||||
self.send_error(acGot.statusCode, acGot.statusMsg)
|
||||
pr = urllib.parse.urlparse(self.path)
|
||||
print(f"DBUG:ProxyHandler:GET:{pr}")
|
||||
print(f"DBUG:PH:Post:{pr}")
|
||||
if pr.path != '/mcp':
|
||||
self.send_error(400, f"WARN:UnknownPath:{pr.path}")
|
||||
body = self.rfile.read(gMe.nw.maxReadBytes)
|
||||
if len(body) == gMe.nw.maxReadBytes:
|
||||
self.send_error(400, f"WARN:RequestOverflow:{pr.path}")
|
||||
oRPC = json.loads(body)
|
||||
self.mcp_run(oRPC)
|
||||
self.mcp_run(body)
|
||||
|
||||
def do_POST(self):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Reference in New Issue