This commit is contained in:
2026-08-20 18:45:39 +07:00
parent 7ffb720f86
commit f62b8f14e7
4 changed files with 216 additions and 105 deletions
+35 -35
View File
@@ -51,8 +51,8 @@ mutable struct yiemAgent <: agent # High-level agent wrapper
llmCall
# Callable struct for MCP server communication.
# Called as: mcpServer("tools/list") → returns parsed JSON dict of available tools
# mcpServer("tools/call", toolName, arguments) → returns tool result as parsed JSON dict
# Called as: mcpServer("tools/list") → returns JSON-RPC 2.0 parsed response
# mcpServer("tools/call", toolName, arguments) → returns JSON-RPC 2.0 parsed response
#
# # Example (weather tool)
# # User provides a callable struct
@@ -64,8 +64,8 @@ mutable struct yiemAgent <: agent # High-level agent wrapper
# end
#
# function (c::MyMCPClient)(method::String)
# payload = Dict("method"=> method)
# payloads = [("method", payload, "dictionary")]
# payload = Dict("jsonrpc" => "2.0", "id" => 1, "method" => method, "params" => Dict{String, Any}())
# payloads = [("payload", payload, "dictionary")]
# _, msg_envelope_json_str = msghandler.smartpack(
# c.topic, payloads; sender_id=c.senderID,
# msg_purpose="mcp_tools_list", fileserver_url=c.fileserver_url)
@@ -75,8 +75,9 @@ mutable struct yiemAgent <: agent # High-level agent wrapper
# end
#
# function (c::MyMCPClient)(method::String, toolName::String, arguments::Dict{String,Any})
# payload = Dict("method"=> method, "toolName"=> toolName, "arguments"=>arguments)
# payloads = [("method", payload, "dictionary"),]
# payload = Dict("jsonrpc" => "2.0", "id" => 2, "method" => method,
# "params" => Dict("name" => toolName, "arguments" => arguments))
# payloads = [("payload", payload, "dictionary"),]
# _, msg_envelope_json_str = msghandler.smartpack(
# c.topic, payloads; sender_id=c.senderID,
# msg_purpose="mcp_tool_call", fileserver_url=c.fileserver_url)
@@ -88,42 +89,41 @@ mutable struct yiemAgent <: agent # High-level agent wrapper
# # "tools/list" input:
# mcpServer("tools/list")
# # sending out payload before smart packed by msghandler:
# Dict("method"=> "tools/list")
# Dict("jsonrpc" => "2.0", "id" => 1, "method" => "tools/list", "params" => Dict{String, Any}())
# # expected return after smart unpacked by msghandler:
# Dict("tools" => [
# Dict(
# "toolName" => "getWeather",
# "title" => "Weather Lookup",
# "description" => "Fetch current weather for a city.",
# "inputSchema" => Dict("type"=>"object",
# "properties" => Dict("city"=>Dict("type"=>"string", "description"=>"City name"),
# "units"=>Dict("type"=>"string", "enum"=>["celsius","fahrenheit"], "default"=>"celsius")),
# "required" => ["city"])
# Dict(
# "jsonrpc" => "2.0", "id" => 1,
# "result" => Dict(
# "tools" => [
# Dict(
# "name" => "getWeather",
# "description" => "Fetch current weather for a city.",
# "inputSchema" => Dict("type"=>"object",
# "properties" => Dict("city"=>Dict("type"=>"string", "description"=>"City name"),
# "units"=>Dict("type"=>"string", "enum"=>["celsius","fahrenheit"], "default"=>"celsius")),
# "required" => ["city"])
# )
# ],
# "nextCursor" => nothing
# )
# ])
# )
#
# # "tools/call" input:
# mcpServer("tools/call", "getWeather", Dict("city"=>"Tokyo", "units"=>"celsius"))
# # sending out payload before smart packed by msghandler:
# Dict(
# "method"=> "tools/call",
# "toolName"=>"getWeather",
# "arguments"=>Dict("city"=>"Tokyo", "units"=>"celsius")
# )
# Dict("jsonrpc" => "2.0", "id" => 2, "method" => "tools/call",
# "params" => Dict("name" => "getWeather", "arguments" => Dict("city"=>"Tokyo", "units"=>"celsius")))
# # expected return after smart unpacked by msghandler (success):
# Dict(
# "toolName"=> "getWeather",
# "content" => [{"type" => "text", "text" => "Weather in Tokyo: Sunny, 22°C"}],
# "error"=> "",
# "isError" => false
# )
# # expected return after smart unpacked by msghandler (error):
# Dict(
# "toolName"=> "getWeather",
# "content" => [],
# "error" => Dict("code"=>1, "message"=>"City not found"),
# "isError" => true
# )
# Dict("jsonrpc" => "2.0", "id" => 2,
# "result" => Dict("content" => [{"type" => "text", "text" => "Weather in Tokyo: Sunny, 22°C"}],
# "isError" => false))
# # expected return after smart unpacked by msghandler (tool error):
# Dict("jsonrpc" => "2.0", "id" => 2,
# "result" => Dict("content" => [{"type" => "text", "text" => "Error: City 'Atlantis' not found."}],
# "isError" => true))
# # expected return after smart unpacked by msghandler (protocol error):
# Dict("jsonrpc" => "2.0", "id" => 2,
# "error" => Dict("code" => -32602, "message" => "Missing required argument 'city'"))
mcpServer
# Callback invoked before executing a tool call (ask for user permission/confirmation/abort, etc..)