TTMSMCPCustomServer Class
Base implementation of a Model Context Protocol server: it hosts tools, resources and prompts, negotiates the protocol version with each client, dispatches inbound JSON-RPC requests, and drives the server-initiated round trips for sampling, elicitation and roots.
API unit family: TMS.MCP.Server
Inherits from: TTMSMCPCustomComponent
Syntax
TTMSMCPCustomServer = class(TTMSMCPCustomComponent)
Remarks
The class publishes nothing itself so that a descendant can choose which settings to surface at design time; TTMSMCPServer is the ready-to-use published descendant. Message exchange is delegated to the assigned transport, and a standard input/output transport is created automatically by Start when none was assigned.
Properties
| Name | Description |
|---|---|
| ProtocolVersion | Protocol version this server offers to clients, for example 2025-06-18. It is the version reported when a client asks for one the server cannot serve, and the fallback for transports that have no sessions. |
| ProtocolVersionEnum | The same setting as ProtocolVersion expressed as an enumerated value, for code that prefers a compile-time-checked constant over a version string. |
| TaskRegistry | Registry holding every task this server created, with their status, result and expiry. It backs the task-related protocol methods and is owned by the server. |
Methods
| Name | Description |
|---|---|
| ActiveSessionIds | Returns the identifiers of the sessions the transport currently holds open. |
| BroadcastNotification | Sends a ready-made JSON-RPC notification to every connected session. Does nothing when no transport is assigned. |
| ClientSupportsExtension | Indicates whether the client whose request is being handled on the calling thread declared support for an extension. Use it to offer extension behavior only to clients that understand it. |
| CreateBuilder | Starts a fluent configuration chain and returns the builder class to continue it on. Finish the chain with Build to obtain the configured server. |
| CurrentSessionId | Returns the identifier of the session whose request is being handled on the calling thread, which is how a tool implementation learns which client it is serving. |
| CurrentSessionState | Returns the state object of the session whose request is being handled on the calling thread. |
| EffectiveProtocolVersion | Returns the protocol version that governs the request currently being handled on the calling thread: the version carried by the request when one is present, otherwise the version negotiated for the current session, and finally the server-wide setting. |
| FlagToolCallError | Marks the tool call running on the calling thread as failed, so the response carries an error flag while still returning the content the tool produced. |
| GetSessionProtocolVersion | Returns the protocol version negotiated for a specific session, regardless of which request is currently being handled. |
| GetTask | Looks up a task by identifier. |
| IsExtensionRegistered | Indicates whether this server declares an extension. |
| IsInitializedForRequest | Indicates whether the request currently being handled may proceed, which is the case once a client has completed initialization or when the request itself carries the capability information that makes a prior handshake unnecessary. |
| ProcessRequest | Processes one inbound JSON-RPC message and returns the response text. This is the entry point a transport calls for every message it receives. |
| RegisterExtension | Declares a protocol extension this server supports, so it is advertised to clients during initialization. Registering the same identifier again replaces the earlier configuration. |
| RegisteredExtensions | Returns the identifiers of every extension this server declares. |
| RemoveSessionValue | Discards a string value stored against the session whose request is being handled on the calling thread. Does nothing outside a request or on a transport without sessions. |
| RequestElicitation | Asks the connected client to collect input from its user and blocks until the client answers. |
| RequestRootsList | Asks the connected client for the roots it exposes, typically the workspace folders the user has opened. |
| RequestSampling | Asks the connected client to run a model completion on the server's behalf and blocks until the client answers. |
| RequestTaskElicitation | Collects user input in the middle of a running task, tagging the request with the task so the client can relate the two. |
| Run | Runs the assigned transport's message loop, blocking the calling thread until the transport stops. This is the usual entry point for a console host. |
| SendLogMessage | Sends a log record to connected clients as a notifications/message notification. This is the log channel the client actually sees, as opposed to the local OnLog trace, which never leaves the process. |
| SendNotificationToSession | Sends a ready-made JSON-RPC notification to one session. Use it for notifications the server does not build itself. Does nothing when no transport is assigned. |
| SendProgressNotification | Broadcasts a progress update for a long-running operation the client is tracking through a progress token. |
| SendPromptsChangedNotification | Broadcasts a notifications/prompts/list_changed message to every connected client. |
| SendResourceUpdatedForSession | Sends a resource-updated notification to one session, but only when that session subscribed to the URI. A session that did not subscribe receives nothing. |
| SendResourceUpdatedNotification | Broadcasts a notifications/resources/updated message for one resource to every connected client, without testing subscriptions. |
| SendResourcesChangedNotification | Broadcasts a notifications/resources/list_changed message to every connected client. |
| SendToolsChangedNotification | Broadcasts a notifications/tools/list_changed message to every connected client. Call it after changing the tool collection from code that bypasses the collection's own change tracking. |
| SessionCount | Returns how many client sessions the transport currently holds open. |
| SetSessionValue | Stores a string value against the session whose request is being handled on the calling thread, so state can be carried between calls from the same client. |
| SetTaskError | Completes a task with a failure and notifies the client that owns it. |
| SetTaskResult | Completes a task successfully with the payload a later tasks/result request will return, and notifies the client that owns it. |
| Start | Starts serving: creates a standard input/output transport when none was assigned, then starts the transport so it begins accepting messages. |
| Stop | Stops the transport and with it the serving of requests. Safe to call when the server is not running or has no transport. |
| TryGetSessionValue | Reads a string value stored against the session whose request is being handled on the calling thread. |
| UnregisterExtension | Withdraws a previously declared extension so it is no longer advertised. Nothing happens when the identifier was not registered. |
| UpdateTaskStatus | Moves a task to a new status and notifies the client that owns it. Use it to report progress from long-running work. |