SimpleSallap:SimpleMCP:Cleanup initial go by running and seeing
As expected dataclass field member mutable default values needing default_factory. Dont forget returning after sending error response. TypeAlias type hinting flow seems to go beyond TYPE_CHECKING. Also email.message.Message[str,str] not accepted, so keep things simple wrt HttpHeaders for now.
This commit is contained in:
parent
79cfbbfc8a
commit
e9dbe21c67
|
|
@ -101,7 +101,8 @@ class ProxyHandler(http.server.BaseHTTPRequestHandler):
|
||||||
try:
|
try:
|
||||||
if not gMe.op.toolManager:
|
if not gMe.op.toolManager:
|
||||||
raise RuntimeError("DBUG:PH:MCPToolsCall:ToolManager uninitialised")
|
raise RuntimeError("DBUG:PH:MCPToolsCall:ToolManager uninitialised")
|
||||||
resp = gMe.op.toolManager.tc_handle(oRPC["id"], oRPC["params"]["name"], oRPC["params"]["arguments"], self.headers)
|
inHeaders: Any = self.headers
|
||||||
|
resp = gMe.op.toolManager.tc_handle(oRPC["id"], oRPC["params"]["name"], oRPC["params"]["arguments"], inHeaders)
|
||||||
if not resp.response.callOk:
|
if not resp.response.callOk:
|
||||||
self.send_error(resp.response.statusCode, resp.response.statusMsg)
|
self.send_error(resp.response.statusCode, resp.response.statusMsg)
|
||||||
return
|
return
|
||||||
|
|
@ -141,13 +142,16 @@ class ProxyHandler(http.server.BaseHTTPRequestHandler):
|
||||||
acGot = self.auth_check()
|
acGot = self.auth_check()
|
||||||
if not acGot.callOk:
|
if not acGot.callOk:
|
||||||
self.send_error(acGot.statusCode, acGot.statusMsg)
|
self.send_error(acGot.statusCode, acGot.statusMsg)
|
||||||
|
return
|
||||||
pr = urllib.parse.urlparse(self.path)
|
pr = urllib.parse.urlparse(self.path)
|
||||||
print(f"DBUG:PH:Post:{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}")
|
||||||
|
return
|
||||||
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}")
|
||||||
|
return
|
||||||
self.mcp_run(body)
|
self.mcp_run(body)
|
||||||
|
|
||||||
def do_POST(self):
|
def do_POST(self):
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
# Tool Call Base
|
# Tool Call Base
|
||||||
# by Humans for All
|
# by Humans for All
|
||||||
|
|
||||||
from typing import Any, TypeAlias, TYPE_CHECKING
|
from typing import Any, TypeAlias
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass, field
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
import email.message
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
@ -47,8 +45,8 @@ TCInProperties: TypeAlias = dict[str, TCInProperty]
|
||||||
@dataclass
|
@dataclass
|
||||||
class TCInParameters():
|
class TCInParameters():
|
||||||
type: str = "object"
|
type: str = "object"
|
||||||
properties: TCInProperties = {}
|
properties: TCInProperties = field(default_factory=dict)
|
||||||
required: list[str] = []
|
required: list[str] = field(default_factory=list)
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TCFunction():
|
class TCFunction():
|
||||||
|
|
@ -94,7 +92,8 @@ class MCPToolCallResponse:
|
||||||
result: MCPTCRResult
|
result: MCPTCRResult
|
||||||
jsonrpc: str = "2.0"
|
jsonrpc: str = "2.0"
|
||||||
|
|
||||||
HttpHeaders: TypeAlias = dict[str, str] | email.message.Message[str, str]
|
#HttpHeaders: TypeAlias = dict[str, str] | email.message.Message[str, str]
|
||||||
|
HttpHeaders: TypeAlias = dict[str, str]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue