Blog
All Blog Posts | Next Post | Previous Post
Windows Service Deployment Guide for the HTTP.SYS-Ready MCP Server Built with TMS AI Studio
Monday, December 22, 2025
Creating the Windows Service Project
The first step is to let Delphi generate a service application for us. This is done by selecting File → New → Other → Delphi Projects → Service Application. Delphi will generate a class descending from TService along with the standard service registration glue code. This project will compile into an executable that Windows can install and run as a real service.
The key moment is understanding that your entire MCP server lifecycle should be contained inside the ServiceStart and ServiceStop methods. Whatever you start in ServiceStart should be stopped cleanly in ServiceStop. This balance ensures that Windows can start and stop the service repeatedly without leaving sockets open or threads hanging around.
When Delphi generates the service, most of the scaffolding is already in place. What matters is adding our MCP server object so that it lives as long as the service is running.
Embedding TTMSMCPServer into the Service
TMS AI Studios TTMSMCPServer is the main class that exposes the MCP protocol and allows clients to communicate with your application. The component is designed to be lightweight, self-contained, and easy to configure through both constructor parameters and a builder pattern.
Inside ServiceStart, we typically create the MCP server instance, configure it, and call its Start method. A basic example looks like this:
However, TTMSMCPServer also provides a fluent builder API, which makes the configuration phase cleaner, especially when enabling optional MCP capabilities. Through the builder, you can turn on tool notifications, resource notifications, prompt notifications, sampling support, adjust pagination settings, and more. For example:
Once created, calling Start activates the server and binds it to its HTTP endpoint.
One of the nicest design choices in the MCP server is that you do not need to configure HTTP.SYS or any other networking layer manually. On Windows, the server automatically uses HTTP.SYS, which means Windows itself handles the HTTP listener, manages kernel-mode request queues, and provides robust throughput without requiring IIS. You simply start the server and Windows does the rest.
Adding Tools and Streamable Handlers
An MCP server is not very useful until you define tools and handlers that clients can call. Tools are the MCP equivalent of JSON-RPC methods. They can return data immediately or even provide streamed results if your tool supports it.
Inside your service class, you assign event handlers such as OnListTools. This event is where you describe all the tools your server exposes. A simple example is a tool that returns the current time:
The actual method (DoTime) does not receive any arguments and returns the current machine time as a TValue, which TTMSMCPServer will serialize back to the MCP client.
If you want to support streaming responses such as sending incremental output, chunked data, or long-running progress the MCP framework inside TMS AI Studio has built-in support for that as well. Streamable responses are especially useful when interacting with AI models, long computations, or processes that produce staged output.
You can also assign logging handlers, resource providers, prompt handlers, and other features described in the TTMSMCPServer documentation. The server is fully extensible and supports the entire MCP specification through its events and builder configuration.
Starting and Stopping the Server
In the ServiceStart method, after configuring the server, you call:
This triggers the creation of the HTTP listener and readies the MCP environment. When the Windows service is stopped, the ServiceStop method executes, and you simply shut the server down and free it:
This pattern ensures that:
-
The HTTP endpoint is released correctly
-
All ongoing MCP sessions are shut down properly
-
Windows can restart the service without errors
A well-behaved service is predictable and easy to deploy and this pattern ensures exactly that.
Installing and Running the Service
Once compiled, the service executable can be installed through standard Windows mechanisms. You can either implement installer logic in the service itself or install it using the command line via sc create. After installation, start the service either through the Services manager or through:
At that moment, Windows launches your executable, triggers ServiceStart, and your MCP server becomes available through its HTTP endpoint immediately. Since HTTP.SYS is doing the heavy lifting, you inherit all of its benefits: efficient request queuing, kernel-level performance, and stability even under load.
Final Thoughts
By combining Delphis Windows service framework with TMS AI Studios TTMSMCPServer, you get a clean and robust foundation for running an MCP server in production. The service runs invisibly in the background, accepts MCP/JSON-RPC clients, handles tools, resources, and prompts, and can stream output all while relying on the built-in HTTP.SYS infrastructure.
This makes the deployment extremely lightweight, removes the need for external process managers, and offers a predictable service lifecycle. Whether youre integrating AI processing, providing automation tools, or building internal development utilities, running TTMSMCPServer inside a Windows service is one of the most reliable ways to host MCP capabilities on a Windows machine.
If you want a ready-to-compile example project or a downloadable template, just let me know I can generate a full skeleton service project with all the code pre-wired.
Start Building the Future Today
The AI revolution is here, and with TMS AI Studio, Delphi developers are perfectly positioned to be at the forefront. Whether you're building intelligent business applications, creating AI-powered tools, or exploring the possibilities of the Model Context Protocol, TMS AI Studio gives you everything you need to succeed.
Ready to transform your development process?
Starting at 225 EUR for a single developer license, TMS AI Studio offers exceptional value for the comprehensive AI development toolkit it provides.
Join the growing community of developers who are already building tomorrow's AI applications with TMS AI Studio. The future of intelligent software development starts here.

TMS AI Studio requires Delphi 11.0 or higher.
Bradley Velghe
Related Blog Posts
-
Add AI superpower to your Delphi & C++Builder apps part 1
-
Add AI superpower to your Delphi & C++Builder apps part 2: function calling
-
Add AI superpower to your Delphi & C++Builder apps part 3: multimodal LLM use
-
Add AI superpower to your Delphi & C++Builder apps part 4: create MCP servers
-
Add AI superpower to your Delphi & C++Builder apps part 5: create your MCP client
-
Add AI superpower to your Delphi & C++Builder apps part 6: RAG
-
Introducing TMS AI Studio: Your Complete AI Development Toolkit for Delphi
-
Automatic invoice data extraction in Delphi apps via AI
-
AI based scheduling in classic Delphi desktop apps
-
Voice-Controlled Maps in Delphi with TMS AI Studio + OpenAI TTS/STT
-
Creating an n8n Workflow to use a Logging MCP Server
-
Supercharging Delphi Apps with TMS AI Studio v1.2 Toolsets: Fine-Grained AI Function Control
-
AI-powered HTML Reports with Embedded Browser Visualization
-
Additional audio transcribing support in TMS AI Studio v1.2.3.0 and more ...
-
Introducing Attributes Support for MCP Servers in Delphi
-
Using AI Services securely in TMS AI Studio
-
Automate StellarDS database operations with AI via MCP
-
TMS AI Studio v1.4 is bringing HTTP.sys to MCP
-
Windows Service Deployment Guide for the HTTP.SYS-Ready MCP Server Built with TMS AI Studio
-
Extending AI Image Capabilities in TMS AI Studio v1.5.0.0
-
Try the Free TMS AI Studio RAG App
This blog post has not received any comments yet.
All Blog Posts | Next Post | Previous Post
