Commit Graph

678 Commits

Author SHA1 Message Date
hanishkvc 631aa7fb36 SimpleSallap:SimpleMCP/ToolMCP: bring in wrt tools manager
Setup to test initial go of the mcpish server and client logics
2025-12-07 22:46:36 +05:30
hanishkvc 00adebe208 SimpleSallap:ToolMCP:McpishClient:P2:Initial go wrt tools/call
Also fix some minor oversights wrt tools/list
2025-12-07 22:29:00 +05:30
hanishkvc 091262d8cf SimpleSallap:ToolMCP: Initial skeletons at mcpish client
Add logic to fetch tools/list from mcp server and pass it to
tools manager.
2025-12-07 21:49:52 +05:30
hanishkvc 5f895b8abf SimpleSallap:SimpleMCP:duplicate toolweb.mjs for mcpish client 2025-12-07 20:48:57 +05:30
hanishkvc 37651dc7dd SimpleSallap:SimpleMCP:Cleanup, rename; TestMcpCmdline helper
Given toolcall.py maintains ToolCall, ToolManager and MCP related
types and base classes, so rename to toolcalls.py

Also add the bash script with curl used for testing the tools/list
mcp command.

Remove the sample function meta ref, as tools/list is working ok.
2025-12-07 20:09:13 +05:30
hanishkvc f75f93f8d9 SimpleSallap:SimpleMCP:SendMcp expects dataclass and uses asdict 2025-12-07 19:36:07 +05:30
hanishkvc bc9dd580b9 SimpleSallap:SimpleMCP:InitalGoCleanup Limit read to ContentLength
Also enforce need for kind of a sane Content-Length header entry
in our case. NOTE: it does allow for 0 or other small content lengths,
which isnt necessarily valid.
2025-12-07 18:47:22 +05:30
hanishkvc e9dbe21c67 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.
2025-12-07 03:19:22 +05:30
hanishkvc 79cfbbfc8a SimpleSallap:SimpleMCP:Allow auth check to be bypassed, if needed
By default bearer based auth check is done always whether in https
or http mode. However by updating the sec.bAuthAlways config entry
to false, the bearer auth check will be carried out only in https
mode.
2025-12-07 02:34:05 +05:30
hanishkvc 9d6daaed8c 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.
2025-12-07 02:28:49 +05:30
hanishkvc fac947f9cd SimpleSallap:SimpleMCP:tools/list
Fix a oversight wrt ToolManager.meta, where I had created a dict
of name-keyed toolcall metas, instead of a simple list of toolcall
metas. Rather I blindly duplicated structure I used for storing the
tool calls in the tc_switch in the anveshika sallap client side
code.

Add dataclasses to mimic the MCP tools/list response. However wrt
the 2 odd differences between the MCP structure and OpenAi tools
handshake structure, for now I have retained the OpenAi tools hs
structure.

Add a common helper send_mcp to ProxyHandler given that both
mcp_toolscall and mcp_toolslist and even others like mcp_initialise
in future require a common response mechanism.

With above and bit more implement initial go at tools/list response.
2025-12-07 00:29:37 +05:30
hanishkvc 69be7f2029 SimpleSallap:SimpleMCP: Use ToolManager for some of needed logics
Build the list of tool calls

Trap some of the MCP post json based requests and map to related
handlers. Inturn implement the tool call execution handler.

Add some helper dataclasses wrt expected MCP response structure

TOTHINK: For now maintain id has a string and not int, with idea
to map it directly to callid wrt tool call handshake by ai model.

TOCHECK: For now suffle the order of fields wrt jsonrpc and type
wrt MCP response related structures, assuming the order shouldnt
matter. Need to cross check.
2025-12-06 23:48:58 +05:30
hanishkvc 8700d522a5 SimpleSallap:SimpleMCP:ToolCalls beyond initial go
Define a typealias for HttpHeaders and use it where ever needed.
Inturn map this to email.message.Message and dict for now.
If and when python evolves Http Headers type into better one,
need to replace in only one place.

Add a ToolManager class which
* maintains the list of tool calls and inturn allows any given
  tool call to be executed and response returned along with needed
  meta data
* generate the overall tool calls meta data
* add ToolCallResponseEx which maintains full TCOutResponse for
  use by tc_handle callers

Avoid duplicating handling of some of the basic needed http header
entries.

Move checking for any dependencies before enabling a tool call into
respective tc??? module.
* for now this also demotes the logic from the previous fine grained
  per tool call based dependency check to a more global dep check at
  the respective module level
2025-12-06 22:38:10 +05:30
hanishkvc 0a445c875b SimpleSallap:SimpleMCP:Move towards post json based flow 2025-12-06 19:46:48 +05:30
hanishkvc 1db3a80f40 SimpleSallap:SimpleMCP:Duplicate simpleproxy for mcpish handshake
Will be looking at changing the handshake between AnveshikaSallap
web tech based client logic and this tool calls server to follow
the emerging interoperable MCP standard
2025-12-06 18:29:39 +05:30
hanishkvc cb1d91999d SimpleSallap:SimpleMCP:FileMagic switch to TCOutResponse 2025-12-06 18:21:52 +05:30
hanishkvc 4ce55eb0af SimpleSallap:SimpleMCP:TCPdf: update
Implement pdftext around toolcall class++ flow
2025-12-06 18:00:48 +05:30
hanishkvc 01a7800f51 SimpleSallap:SimpleMCP:TCPdf: Duplicate pdfmagic 2025-12-06 17:57:26 +05:30
hanishkvc 66038f99cf SimpleSallap:SimpleMCP:TCWeb:XMLFiltered initial go wrt new flow
Also remember to picks the tagDropREs from passed args object and
not from got http header.

Even TCHtmlText updated to get the tags to drop from passed args
object and not got http header. And inturn allow ai to pass this
optional arg, as it sees fit in co-ordination with user.
2025-12-06 17:49:08 +05:30
hanishkvc 5bf608dedd SimpleSallap:SimpleMCP:TCWeb:HtmlText updated for new flow
Rather initial go at the new flow, things require to be tweaked
later wrt final valid runnable flow
2025-12-06 17:47:07 +05:30
hanishkvc b17cd18bc5 SimpleSallap:SimpleMCP:TCWeb:Update TCUrlRaw + Helper
Now generic handle_urlreq and handle_urlraw updated to work with the
new ToolCall flow
2025-12-06 17:45:52 +05:30
hanishkvc cbb632eec0 SimpleSallap:SimpleMCP:TCWeb: Duplicate webmagic starting point
To help with switching to tool call class++ based flow
2025-12-06 17:31:23 +05:30
hanishkvc 47bd2bbc90 SimpleSallap:SimpleMCP:Update toolcall to suite calls needed 2025-12-06 01:47:38 +05:30
hanishkvc 452e610095 SimpleSallap:SimpleMCP:Skeletons for a toolcall class 2025-12-06 00:48:48 +05:30
hanishkvc a52ac5ddde SimpleSallap:SimpleProxy:use RequestHandler's setup after ssl hs
Instead of manually setting up rfile and wfile after switching to
ssl mode wrt a client request, now use the builtin setup provided
by the RequestHandler logic, so that these and any other needed
things will be setup as needed after the ssl hs based new socket,
just in case new things are needed in future.
2025-12-05 22:28:55 +05:30
hanishkvc d470d7e47d SimpleSallap:SimpleProxy:DataClass Config simpleproxy updated 2025-12-05 21:42:41 +05:30
hanishkvc 277225dddd SimpleSallap:SimpleProxy:DataClass Config - p4
Minimal skeleton to allow dict [] style access to dataclass based
class's attributes/fields. Also get member function similar to dict.

This simplifies the flow and avoids duplicating data between
attribute and dict data related name and data spaces.
2025-12-05 21:10:01 +05:30
hanishkvc 4f790cb646 SimpleSallap:SimpleProxy:DataClass Config - P3
Add a helper base class to try map data class's attributes into
underlying dict.

TODO: this potentially duplicates data in both normal attribute
space as well as dict items space. And will require additional
standard helper logics to be overridden to ensure sync between
both space etal. Rather given distance from python internals for
a long time now, on pausing and thinking a bit, better to move
into a simpler arch where attributes are directly worked on for
dict [] style access.
2025-12-05 20:47:33 +05:30
hanishkvc 5560840099 SimpleSallap:SimpleProxy:DataclassDict driven Config - p2
Assigning defaut values wrt compound type class members
2025-12-05 18:36:43 +05:30
hanishkvc 4e7c7374d7 SimpleSallap:SimpleProxy:Make Config dataclass driven - p1
Instead of maintaining the config and some of the runtime states
identified as gMe as a generic literal dictionary which grows at
runtime with fields as required, try create it as a class of classes.

Inturn use dataclass annotation to let biolerplate code get auto
generated.

A config module created with above, however remaining part of the
code not yet updated to work with this new structure.

process_args and load_config moved into the new Config class.
2025-12-05 17:59:20 +05:30
hanishkvc 05697afc15 SimpleSallap:SimpleProxy:Trap all GET request handling
otherwise aum path was not handled immidiately wrt exceptions.

this also ensures any future changes wrt get request handling
also get handled immidiately wrt exceptions, that may be missed
by any targetted exception handling.
2025-12-05 03:04:52 +05:30
hanishkvc e52a7aa304 SimpleSallap:SimpleProxy: MultiThreading
Given that default HTTPServer handles only one connection and inturn
request at any given time, so if a client opens connection and then
doesnt do anything with it, it will block other clients by putting their
requests into network queue for long.

So to overcome the above issue switch to ThreadingHTTPServer, which
starts a new thread for each request.

Given that previously ssl wrapping was done wrt the main server socket,
even with switching to ThreadingHTTPServer, the handshake for ssl/tls
still occurs in the main thread before a child thread is started for
parallel request handling, thus the ssl handshake phase blocking other
client requests.

So now avoid wrapping ssl wrt the main server socket, instead wait for
ThreadingHttpServer to start the new thread for a client request ie
after a connection is accepted for the client, before trying to wrap
the connection in ssl. This ensures that the ssl handshake occurs in
this child (ie client request related) thread. So some rogue entity
opening a http connection and not doing ssl handshake wont block.

Inturn in this case the rfile and wfile instances within the proxy
handler need to be remapped to the new ssl wrapped socket.
2025-12-05 01:53:12 +05:30
hanishkvc c4e0c03107 SimpleSallap:SimpleProxy: Enable https mode 2025-12-04 20:51:00 +05:30
hanishkvc 593e831175 SimpleSallap:Cleanup notes 2025-12-04 19:42:10 +05:30
hanishkvc 2981033fac SimpleChatTCRV:UICleanup:Ai Reasoning/Live response
Implement todo noted in last commit, and bit more.

This brings in clearing of the external ai tool call special chat
session divStream during chat show, which ensures that it gets
hidden by default wrt other chat sessions and inturn only get
enabled if user triggers a new tool call involving external ai
tool call.

This patch also ensures that if ext ai tool call takes too much
time and so logic gives you back control with a timed out response
as a possible response back to ai wrt the tool call, then the
external ai tool call's ai live response is no longer visible in
the current chat session ui. So user can go ahead with the timed
out response or some other user decided response as the response
to the tool call. And take the chat in a different direction of
their and ai's choosing.

Or else, if they want to they can switch to the External Ai
specific special chat session and continue to monitor the response
from the tool call there, to understand what the final response
would have been wrt that tool call.

Rather this should keep the ui flow clean.

ALERT: If the user triggers a new ext ai tool call, when the
old one is still alive in the background, then response from
both will be in a race for user visibility, so beware of it.
2025-12-04 19:41:40 +05:30
hanishkvc 29f9abede9 SimpleChatTCRV:UICleanup: Show own divstream mostly, ShowInfo all
Always show all the info wihen show_info is called, inturn avoid
the corresponding all info enable flag wrt show_info as well as
chat_show.

Now chat_show gives the option to its caller to enable showing of
its own chat session divStream. This is in addition to the handle
multipart response also calling corresponding divStream show.

Previously chat_show would have not only cleared corresponding chat
session's divStream contents but would have also hidden divStream.

Now except for the clearChat case, in all other cases own divStream
is unhidden, when chat_show is called.

Without this, when a tool call takes too much time and inturn
a chat session times out the tool call and inturn user switches
between chat sessions, if the tool call was external_ai, then its
related live ai response would no longer be visible in any of the
chat sessions, including the external_ai special chat session, if
the user had switched to this external_ai special chat session.
But now in the external_ai special chat session, the live response
will be visible.

TODO: With this new semantic wrt chat_show, where a end user can
always peek into a chat session's ai live stream response if any,
as long as that chat session's ai server handshake is still active,
So now After tool call timeout, which allows users to switch between
sessions, it is better to disable the external ai live divStream
in other chat sessions, when user switches into them. This ensures
that

1. if user doesnt switch out of the chat session which triggered
external_ai, for now the user can continue to see the ext ai live
response stream.

2. Switching out of the chat session which triggered ext ai, will
automatically disable viewing of external ai live response from
all chat sessions except for the external ai's special chat session.

IE I need to explicitly clear not just the own divStream, but also
the external ai related divStream, which is appened to end of all
chat session's UI.

This will tidy up the usage flow and ui and avoid forcefully showing
external ai tool call's ai live response in other chat sessions,
which didnt trigger the ext ai tool call. And also in the chat
session which triggered ext ai, it will stop showing if user exits
out of that chat session. Same time user can always look at the
ext ai live response stream in the special chat session corresponding
to ext ai.
2025-12-04 19:41:40 +05:30
hanishkvc afd6365ecc SimpleChatTCRV:CMTextFormat: Common flow accounting User and Auto
If user explicitly makes a content text format selection, the
same will be used.

Else based on session settings, a format will be used.

Now when the popover menu is shown, the current message's format
type is reflected in the popover menu.
2025-12-04 19:41:40 +05:30
hanishkvc c68316bf07 SimpleChatTCRV:CMTextFormat: PopOver & Message UI adjust
Add format selection box to the popover.

Update show_message logic to allow refreshing a existing message
ui element, rather than creating a new one.

Trigger refresh of the message ui element, when format selection
changes.
2025-12-04 19:41:40 +05:30
hanishkvc 701ebca477 SimpleChatTCRV:CMContentTextFormat: towards user fine adjustable
Add a textFormat field wrt ChatMessageEx.

User can be allowed to change how to interpret the text content
at a individual message level.
2025-12-04 19:41:40 +05:30
hanishkvc d97147568f SimpleChatTCRV:Markdown: Usage flow cleanup
Move all markdown configs into a single object field.

Add always flag, which if set, all roles' message contents will be
treated as markdown, else only ai assistant's messages will be
treated as markdown.
2025-12-04 19:41:40 +05:30
hanishkvc e9546168ae SimpleChatTCRV:Markdown:OrderedLists - allow only number markers 2025-12-04 19:41:40 +05:30
hanishkvc 6358a2083d SimpleChatTCRV:Markdown:List items without list marker cleanup
If lines immidately follows a list item, without the list marker
at their begining, but with a offset matching the list item, then
these lines will be appended to that list item.

If a empty line is there between a list item and a new line with
some content, but without a list marker

* if the content offset is less than the last list item, then
  unwind the lists before such a line.

* if the content offset is larger than the last list item, then
  the line will be added as a new list item at the same level
  as the last list item.

* if the content offset is same as the last list tiem, then
  unwind the list by one level and then insert this line as a
  new list item at this new unwound level.
2025-12-04 19:41:40 +05:30
hanishkvc 82d436b537 SimpleChatTCRV:Markdown: flexible unwind list 2025-12-04 19:41:40 +05:30
hanishkvc 11eab92d08 SimpleChatTCRV:TC:FetchUrlRaw: Rename to avoid confusion
Given that now fetch_web_url_raw can also fetch local files, if local
file access scheme is enabled in simpleproxy.py, so rename this
tool call by dropping web from its name, given that some ai models
were getting confused because of the same.
2025-12-04 19:41:40 +05:30
hanishkvc 67f971527d SimpleChatTCRV:Markdown:Process headline and horizline
Also update readme a bit, better satisfying md file format.
2025-12-04 19:41:40 +05:30
hanishkvc 707b719f67 SimpleChatTCRV:Markdown:ReEnable Sanitize, lineRaw
Maintain raw and sanitized versions of line.

Make blockquote work with raw line and not the sanitized line.
So irrespective of whether sanitize is enabled or not, the logic
will still work. Inturn re-enable HtmlSanitize.
2025-12-04 19:41:40 +05:30
hanishkvc 0f5be059cf SimpleChatTCRV:Markdown: Move Pre Fenced handling into func 2025-12-04 19:41:40 +05:30
hanishkvc edba012d80 SimpleChatTCRV:Markdown:BlockQuote support 2025-12-04 19:41:40 +05:30
hanishkvc 1d26453b52 SimpleChatTCRV:Markdown: CommonLogic listitem & para extend/append
Similar to listitem before, now also allow a para to have its long
lines split into adjacent lines. Inturn the logic will take care of
merging them into single para.

The common logic wrt both flows moved into its own helper function.
2025-12-04 19:41:40 +05:30
hanishkvc b3645a1164 SimpleChatTCRV:ToolCall:ExtAi: Task decomposition/planning
Had forgotten to include this in the examples before.
2025-12-04 19:41:40 +05:30