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()))
|
tcl = mTC.MCPToolsList(oRPC["id"], mTC.MCPTLResult(gMe.op.toolManager.meta()))
|
||||||
self.send_mcp(200, "tools/list follows", tcl)
|
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":
|
if oRPC["method"] == "tools/call":
|
||||||
self.mcp_toolscall(oRPC)
|
self.mcp_toolscall(oRPC)
|
||||||
elif oRPC["method"] == "tools/list":
|
elif oRPC["method"] == "tools/list":
|
||||||
|
|
@ -140,14 +141,13 @@ class ProxyHandler(http.server.BaseHTTPRequestHandler):
|
||||||
if not acGot.callOk:
|
if not acGot.callOk:
|
||||||
self.send_error(acGot.statusCode, acGot.statusMsg)
|
self.send_error(acGot.statusCode, acGot.statusMsg)
|
||||||
pr = urllib.parse.urlparse(self.path)
|
pr = urllib.parse.urlparse(self.path)
|
||||||
print(f"DBUG:ProxyHandler:GET:{pr}")
|
print(f"DBUG:PH:Post:{pr}")
|
||||||
if pr.path != '/mcp':
|
if pr.path != '/mcp':
|
||||||
self.send_error(400, f"WARN:UnknownPath:{pr.path}")
|
self.send_error(400, f"WARN:UnknownPath:{pr.path}")
|
||||||
body = self.rfile.read(gMe.nw.maxReadBytes)
|
body = self.rfile.read(gMe.nw.maxReadBytes)
|
||||||
if len(body) == gMe.nw.maxReadBytes:
|
if len(body) == gMe.nw.maxReadBytes:
|
||||||
self.send_error(400, f"WARN:RequestOverflow:{pr.path}")
|
self.send_error(400, f"WARN:RequestOverflow:{pr.path}")
|
||||||
oRPC = json.loads(body)
|
self.mcp_run(body)
|
||||||
self.mcp_run(oRPC)
|
|
||||||
|
|
||||||
def do_POST(self):
|
def do_POST(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue