![]() |
Qore json Module 1.11.0
|
McpServer class definition; to be registered as a handler in the HttpServer class. More...
#include <McpServerHandler.qc.dox.h>
Inherits JsonRpcHandler, and ServerSentEventHandler.
Public Member Methods | |
| void | constructor (Logger::LoggerInterface logger, HttpServer::AbstractAuthenticator auth) |
| Creates the handler. | |
| void | constructor (HttpServer::AbstractAuthenticator auth) |
| Creates the handler. | |
| void | constructor () |
| Creates the handler. | |
| void | registerTool (soft< AbstractDataProvider > prov, soft< hash< auto > > extra, soft< bool > input_initialized, code tool, soft< AbstractDataProviderType > input, string name, string desc) |
| Registers a tool. | |
| bool | unregisterTool (string name) |
| Unregisters a tool. | |
| list< string > | getToolNames () |
| Returns a list of registered tool names. | |
| bool | hasTools (string name) |
| Checks if a tool is registered. | |
| void | registerResource (soft< code > reader, string mimeType, string desc, string uri, string name) |
| Registers a resource. | |
| bool | unregisterResource (string uri) |
| Unregisters a resource. | |
| void | registerPrompt (soft< code > handler, soft< list< hash< auto > > > arguments, string name, string desc) |
| Registers a prompt. | |
| bool | unregisterPrompt (string name) |
| Unregisters a prompt. | |
| string | getNextRequestId () |
| Returns the next request ID and increments the internal counter. | |
| void | setSessionTimeout (int timeout_secs) |
| Sets the session timeout in seconds. | |
| int | getSessionTimeout () |
| Returns the session timeout in seconds. | |
| int | getSessionCount () |
| Returns the number of active sessions. | |
| list< hash< auto > > | getSessionInfo () |
| Returns information about active sessions (for debugging/monitoring) | |
| string | getHeartbeatMessage (McpServerConnection conn) |
| Use MCP ping as heartbeat message. | |
| void | registerNewConnectionIntern (string cid, ServerSentEventConnection conn) |
| Called while holding the write lock to register the new connection. | |
| hash< auto > | completionComplete (hash< auto > cx, soft< hash< auto > > params) |
| Handle completion/complete requests for autocompletion. | |
| hash< auto > | completionCompleteIntern (hash< auto > cx, soft< hash< auto > > params) |
| Internal completion handler - can be overridden by subclasses. | |
| soft< hash< auto > > | loggingSetLevel (hash< auto > cx, soft< hash< auto > > params) |
| Handle logging/setLevel requests. | |
| string | generateTaskId () |
| Generates a unique task ID. | |
| hash< McpTaskInfo > | createTask (soft< auto > requestId, soft< int > ttl, soft< hash< auto > > params, string sessionId, string method) |
| Creates a new task for background execution. | |
| void | updateTaskStatus (soft< string > message, string status, string sessionId, string taskId) |
| Updates a task's status. | |
| void | setTaskResult (soft< hash< auto > > error, soft< hash< auto > > result, string sessionId, string taskId) |
| Sets the task result (on completion or error) | |
| void | sendTaskStatusNotification (string sessionId, string taskId) |
| Sends a task status notification to the client. | |
| soft< hash< McpTaskInfo > > | getTaskInfo (string sessionId, string taskId) |
| Gets a task's current information. | |
| int | cleanupExpiredTasks (string sessionId) |
| Cleans up expired tasks for a session. | |
| soft< hash< auto > > | tasksGet (hash< auto > cx, soft< hash< auto > > params) |
| Handle tasks/get request - get task status by ID. | |
| soft< hash< auto > > | tasksResult (hash< auto > cx, soft< hash< auto > > params) |
| Handle tasks/result request - block until task completes and return result. | |
| soft< hash< auto > > | tasksCancel (hash< auto > cx, soft< hash< auto > > params) |
| Handle tasks/cancel request - cancel a running task. | |
| hash< auto > | tasksList (hash< auto > cx, soft< hash< auto > > params) |
| Handle tasks/list request - list all tasks for session. | |
| hash< auto > | getTaskResponse (hash< McpTaskInfo > task) |
| Builds a task response hash. | |
| soft< hash< auto > > | resourcesSubscribe (hash< auto > cx, soft< hash< auto > > params) |
| Handle resources/subscribe request. | |
| soft< hash< auto > > | resourcesUnsubscribe (hash< auto > cx, soft< hash< auto > > params) |
| Handle resources/unsubscribe request. | |
| soft< hash< McpResourceTemplateInfo > > | matchResourceTemplate (string uri) |
| Matches a URI against resource templates. | |
| bool | matchUriTemplate (string template, string uri) |
| Simple URI template matching (RFC 6570 basic) | |
| void | registerResourceTemplate (soft< hash< auto > > annotations, soft< code > reader, soft< string > mimeType, soft< string > desc, string uriTemplate, string name) |
| Registers a resource template. | |
| bool | unregisterResourceTemplate (string uriTemplate) |
| Unregisters a resource template. | |
| hash< auto > | resourcesTemplatesList (hash< auto > cx, soft< hash< auto > > params) |
| Handle resources/templates/list request. | |
| void | sendProgress (soft< string > message, soft< int > total, int progress, string sessionId, string progressToken) |
| Sends a progress notification to the client. | |
| soft< string > | getProgressToken (soft< hash< auto > > params) |
| Extracts the progress token from request params. | |
| void | cancelRequest (hash< auto > cx, hash< auto > params) |
| Handles cancellation notification. | |
| bool | isRequestCancelled (string sessionId, auto requestId) |
| Checks if a request has been cancelled. | |
| void | markCancellationProcessed (string sessionId, auto requestId) |
| Marks a cancellation as processed. | |
| hash< auto > | sendClientRequestAndWait (int timeout_ms, hash< auto > params, string method, string sessionId, McpServerConnection conn) |
| Sends a request to the client and waits for a response. | |
| soft< hash< auto > > | toolsCallIntern (hash< auto > cx, soft< hash< auto > > params) |
| Modified toolsCallIntern to support task-based execution. | |
| hash< auto > | toolsCallAsTask (soft< auto > requestId, hash< auto > cx, soft< hash< auto > > params) |
| Executes a tool call as a background task. | |
| void | executeToolInBackground (hash< auto > cx, hash< auto > params, hash< McpToolInfo > info, string sessionId, string taskId) |
| Executes a tool in the background and sets the task result. | |
Private Attributes | |
| hash< string, hash< McpToolInfo > > | tmap |
| Registered tools: name -> tool. | |
| hash< string, hash< McpResourceInfo > > | rmap |
| Registered resources: URI -> resource info. | |
| hash< string, hash< McpPromptInfo > > | pmap |
| Registered prompts: name -> prompt info. | |
| hash< string, hash< McpResourceTemplateInfo > > | rtmap |
| Registered resource templates: uriTemplate -> template info. | |
| hash< string, hash< McpSessionInfo > > | smap |
| Session map; session ID -> session info. | |
| hash< string, int > | sidmap |
| Session ID map. | |
McpServer class definition; to be registered as a handler in the HttpServer class.
| int McpServerHandler::McpServerHandler::cleanupExpiredTasks | ( | string | sessionId | ) |
Cleans up expired tasks for a session.
| sessionId | the session ID |
| hash< auto > McpServerHandler::McpServerHandler::completionComplete | ( | hash< auto > | cx, |
| soft< hash< auto > > | params | ||
| ) |
Handle completion/complete requests for autocompletion.
| cx | the context hash |
| params | the completion parameters including:
|
| hash< McpTaskInfo > McpServerHandler::McpServerHandler::createTask | ( | soft< auto > | requestId, |
| soft< int > | ttl, | ||
| soft< hash< auto > > | params, | ||
| string | sessionId, | ||
| string | method | ||
| ) |
Creates a new task for background execution.
| sessionId | the session ID |
| method | the method that created this task |
| params | the original request parameters |
| ttl | optional TTL in milliseconds (defaults to defaultTaskTtl) |
| soft< hash< McpTaskInfo > > McpServerHandler::McpServerHandler::getTaskInfo | ( | string | sessionId, |
| string | taskId | ||
| ) |
Gets a task's current information.
| sessionId | the session ID |
| taskId | the task ID |
| bool McpServerHandler::McpServerHandler::hasTools | ( | string | name | ) |
Checks if a tool is registered.
| name | the name of the tool |
| bool McpServerHandler::McpServerHandler::isRequestCancelled | ( | string | sessionId, |
| auto | requestId | ||
| ) |
Checks if a request has been cancelled.
| sessionId | the session ID |
| requestId | the request ID |
| void McpServerHandler::McpServerHandler::markCancellationProcessed | ( | string | sessionId, |
| auto | requestId | ||
| ) |
Marks a cancellation as processed.
| sessionId | the session ID |
| requestId | the request ID |
| void McpServerHandler::McpServerHandler::registerPrompt | ( | soft< code > | handler, |
| soft< list< hash< auto > > > | arguments, | ||
| string | name, | ||
| string | desc | ||
| ) |
Registers a prompt.
| name | the name of the prompt |
| desc | the description of the prompt |
| arguments | optional list of argument definitions for the prompt |
| handler | optional code to generate prompt messages; receives (context, arguments) and should return a list of message hashes with "role" and "content" keys |
| void McpServerHandler::McpServerHandler::registerResource | ( | soft< code > | reader, |
| string | mimeType, | ||
| string | desc, | ||
| string | uri, | ||
| string | name | ||
| ) |
Registers a resource.
| uri | the URI of the resource |
| name | the name of the resource |
| desc | the description of the resource |
| mimeType | the MIME type of the resource |
| reader | optional code to read the resource content; if not provided, the resource is not readable |
| void McpServerHandler::McpServerHandler::registerResourceTemplate | ( | soft< hash< auto > > | annotations, |
| soft< code > | reader, | ||
| soft< string > | mimeType, | ||
| soft< string > | desc, | ||
| string | uriTemplate, | ||
| string | name | ||
| ) |
Registers a resource template.
| uriTemplate | the URI template (RFC 6570) |
| name | the name of the template |
| desc | the description of the template |
| mimeType | the MIME type of resources generated by this template |
| reader | optional code to read the resource content |
| annotations | optional annotations |
| hash< auto > McpServerHandler::McpServerHandler::sendClientRequestAndWait | ( | int | timeout_ms, |
| hash< auto > | params, | ||
| string | method, | ||
| string | sessionId, | ||
| McpServerConnection | conn | ||
| ) |
Sends a request to the client and waits for a response.
| sessionId | the session ID |
| conn | the SSE connection to use |
| method | the method name |
| params | the request parameters |
| timeout_ms | the timeout in milliseconds |
| MCP-TIMEOUT | if the request times out |
| MCP-CLIENT-ERROR | if the client returns an error |
| void McpServerHandler::McpServerHandler::sendProgress | ( | soft< string > | message, |
| soft< int > | total, | ||
| int | progress, | ||
| string | sessionId, | ||
| string | progressToken | ||
| ) |
Sends a progress notification to the client.
| sessionId | the session ID |
| progressToken | the progress token |
| progress | the current progress value |
| total | optional total progress value |
| message | optional progress message |
| void McpServerHandler::McpServerHandler::sendTaskStatusNotification | ( | string | sessionId, |
| string | taskId | ||
| ) |
Sends a task status notification to the client.
| sessionId | the session ID |
| taskId | the task ID |
| void McpServerHandler::McpServerHandler::setSessionTimeout | ( | int | timeout_secs | ) |
Sets the session timeout in seconds.
| timeout_secs | the timeout in seconds; 0 disables session timeout |
| void McpServerHandler::McpServerHandler::setTaskResult | ( | soft< hash< auto > > | error, |
| soft< hash< auto > > | result, | ||
| string | sessionId, | ||
| string | taskId | ||
| ) |
Sets the task result (on completion or error)
| sessionId | the session ID |
| taskId | the task ID |
| result | optional result (for successful completion) |
| error | optional error (for failure) |
| bool McpServerHandler::McpServerHandler::unregisterPrompt | ( | string | name | ) |
Unregisters a prompt.
| name | the name of the prompt to unregister |
| bool McpServerHandler::McpServerHandler::unregisterResource | ( | string | uri | ) |
Unregisters a resource.
| uri | the URI of the resource to unregister |
| bool McpServerHandler::McpServerHandler::unregisterResourceTemplate | ( | string | uriTemplate | ) |
Unregisters a resource template.
| uriTemplate | the URI template to unregister |
| bool McpServerHandler::McpServerHandler::unregisterTool | ( | string | name | ) |
Unregisters a tool.
| name | the name of the tool to unregister |
| void McpServerHandler::McpServerHandler::updateTaskStatus | ( | soft< string > | message, |
| string | status, | ||
| string | sessionId, | ||
| string | taskId | ||
| ) |
Updates a task's status.
| sessionId | the session ID |
| taskId | the task ID |
| status | the new status |
| message | optional status message |