A powerful, attribute-driven framework for building Model Context Protocol (MCP) Servers in Delphi.
The Model Context Protocol (MCP) is an open standard for connecting large language models (LLMs) to external tools and data.
It enables AI models to go beyond their training data by accessing new information, performing actions, and interacting with tools and databases.
With MCP servers you can:
- Provide functionality through
Tools(used to execute code or otherwise produce a side effect) - Expose data through
Resources(used to load information into the LLMβs context) - Define interaction through
Prompts(reusable templates for LLM interactions)
Delphi MCP Connect (MCPConnect) is a lightweight yet robust framework designed to drastically simplify the creation of Model Context Protocol (MCP) Servers using Embarcadero Delphi. By leveraging the power of Attributes, the framework allows developers to re-use existing business logic and standard Delphi classes, turning them into protocol-aware server components with minimal boilerplate code. MCPConnect handles the serialization, routing, and context management required for the server-side implementation of the MCP protocol.
- π‘οΈType safety - Define your tool arguments as native delphi class or records, have mcp-connect handle the rest.
- π Transports - Use the built-in transport: HTTP for stateless communication (with stdio already in development).
- β‘ Low boilerplate - mcp-connect generates all the MCP endpoints for you apart from your tools, prompts and resources.
- Attribute-Driven Development: Simply register classes to automatically discover tools, resources, and prompts using the
[McpTool], [McpResource], [McpPrompt]attributes to expose specific methods. - Standard Code Re-use: Easily expose existing business logic classes without heavy modification or complex inheritance hierarchies.
- Automatic Routing: The framework automatically scans and registers methods decorated with the appropriate attributes, handling all request routing.
- Easy-to-use classes for tools, prompts, and resources
- API-Key authentication for http transport (more to be implemented)
- JSON-RPC MCPConnect contains a JSON-RPC library (
JRPC) a comprehensive, high-performance JSON-RPC 2.0 library built specifically for Delphi. - Automatic JSON Schema generation - Using the powerful Neon TSchemaGenaerator, MCPConnect support any Delphi type as parameter or result.
JSON-RPC is a stateless, light-weight remote procedure call (RPC) protocol. Primarily this specification defines several data structures and the rules around their processing. It is transport agnostic in that the concepts can be used within the same process, over sockets, over http, or in many various message passing environments. It uses JSON (RFC 4627) as data format and it is designed to be simple!
Inside MCPConnect you can find a complete implementation of the JSON-RPC v2.0 protocol that can be used independently of MCPConnect for all types of Delphi projects. This library empowers you to focus purely on your application logic, allowing you to define your remote APIs using simple Delphi class methods and attributes. Whether you are creating a client to consume external RPC services or exposing your own high-performance server methods, JRPC makes complex distributed computing simple, declarative, and fast.
The main features of JRPC are:
- Automatic Marshaling: Seamless conversion of Delphi objects into JSON-RPC requests and responses.
- Broad Delphi types support: Using Neon, JRPC supports virtually every Delphi type as Request parameters or result
- Protocol Compliance: Full adherence to the JSON-RPC 2.0 specification.
- Delphi 10 or newer (support for Attributes is essential).
- Neon as Serialization Engine (https://github.com/paolo-rossi/delphi-neon)
- Clone Neon the Repository:
git clone https://github.com/paolo-rossi/delphi-neon
- Clone MCPConnect the Repository:
git clone https://github.com/delphi-blocks/MCPConnect.git
- Add to Project Path: Add the
Sourcedirectory of the cloned repositories to your Delphi Project's search path. - Integrate: Reference the core units, such as
MCPConnect.JRPC.CoreandMCPConnect.MCP.Attributes, in your server project.
Creating an MCP-enabled service is as simple as adding the required attributes to a standard Delphi class and methods.
To get started with your MCP server, you'll need to set up a WebBroker application and configure the JSON-RPC components.
- In Delphi, create a new WebBroker Application project (File β New β Other β Web β Web Server Application).
- Choose your preferred web server type (standalone, ISAPI, Apache, etc.). For development, a standalone application is recommended.
Note: While you can use Indy components directly, WebBroker provides a simpler and more straightforward approach for HTTP-based MCP servers.
In your WebModule's OnCreate event or constructor, create and configure the TJRPCServer and TJRPCDispatcher components:
uses
MCPConnect.JRPC.Server,
MCPConnect.MCP.Server.Api, // This register the standard MCP API
MCPConnect.Transport.WebBroker,
MCPConnect.Configuration.MCP,
Demo.HelpDeskService; // Unit with your MCP classes
// Create the JSON-RPC Server
FJRPCServer := TJRPCServer.Create(Self);
FJRPCServer
.Plugin.Configure<IMCPConfig>
.SetServerName('delphi-mcp-server')
.SetServerVersion('2.0.0')
.SetToolClass(THelpDeskService) // Register your tool class here
.ApplyConfig;
// Create and configure the Dispatcher
FJRPCDispatcher := TJRPCDispatcher.Create(Self); // Self should be the TWebModule
FJRPCDispatcher.PathInfo := '/mcp'; // Set the endpoint path
FJRPCDispatcher.Server := FJRPCServer; // Connect to the serverThe TJRPCDispatcher integrates seamlessly with WebBroker through Delphi's standard component ownership mechanism:
-
Automatic Registration: When you create the dispatcher with
TWebModuleas its owner (via the constructor parameter), it automatically registers itself with the WebBroker framework. -
Request Routing: For each incoming HTTP request, WebBroker checks all registered dispatchers to determine which one should handle it based on the
PathInfoproperty. -
No Manual Wiring Needed: Since the dispatcher was created with
Self(the WebModule) as owner in Step 2, the connection is already established.
// This line (from Step 2) does all the wiring:
FJRPCDispatcher := TJRPCDispatcher.Create(Self); // Self = TWebModule
// β The owner parameter registers the dispatcher automaticallyThat's it! Your MCP server is now ready to accept JSON-RPC requests at the configured endpoint.
Example: If your server runs on port 8080, requests sent to http://localhost:8080/mcp will be automatically routed to your registered MCP tools.
Register the class (the Model) and use the [McpTool] attribute for the methods (the Tools or actions).
unit Demo.HelpDeskService;
interface
uses
System.SysUtils,
MCPConnect.MCP.Attributes;
type
THelpDeskService = class
public
// This method is published as an MCP tool
[McpTool('doclist', 'List all the available documents')]
function ListDocument(
[McpParam('category', 'Document Category')] const ACategory: string
): TContentList;
// This method is NOT exposed because it lacks the [McpTool] attribute
procedure InternalStuff;
end;Once your MCP server is running, you need to configure your LLM client to connect to it. Below are configuration examples for popular clients.
Before configuring any client, ensure:
- Your MCP server is running and accessible (e.g.,
http://localhost:8080/mcp) - You know the authentication token if your server requires one
- The endpoint path matches your
TJRPCDispatcher.PathInfosetting
LM Studio supports HTTP-based MCP servers natively. Add the following configuration to your LM Studio settings:
Configuration file location:
- Windows:
%USERPROFILE%\.lmstudio\mcp.json - macOS/Linux:
~/.lmstudio/mcp.json
Configuration:
{
"mcpServers": {
"delphi-mcp-server": {
"url": "http://localhost:8080/mcp",
"headers": {
"Authorization": "Bearer my-secret-token"
}
}
}
}Configuration Parameters:
delphi-mcp-server: A unique identifier for your server (can be any name)url: The full URL to your MCP server endpointheaders: Optional HTTP headers (e.g., for authentication)
After saving the configuration, restart LM Studio to load the new MCP server.
Claude Desktop currently requires an intermediate tool called mcp-remote to connect to HTTP-based MCP servers, as it doesn't support HTTP transport natively yet.
Before configuring Claude Desktop, verify that mcp-remote can connect to your server:
npx mcp-remote http://localhost:8080/mcp --header "Authorization: Bearer my-secret-token"If the connection is successful, you should see your server's capabilities listed.
Configuration file location:
- Windows:
%APPDATA%\Claude\claude_desktop_config.json - macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
Configuration:
{
"mcpServers": {
"my-demo-server": {
"command": "C:\\Program Files\\nodejs\\npx",
"args": [
"-y",
"mcp-remote",
"http://localhost:8080/mcp",
"--header",
"Authorization: Bearer my-secret-token"
]
}
}
}Configuration Parameters:
my-demo-server: A unique identifier for your servercommand: Path to the Node.jsnpxexecutable- Windows:
C:\\Program Files\\nodejs\\npx(note the double backslashes) - macOS/Linux:
/usr/local/bin/npxornpx(if in PATH)
- Windows:
args: Arguments passed tonpx:-y: Auto-confirm package installationmcp-remote: The bridge tool for HTTP transport- URL to your MCP server
--header: Optional authentication header
After saving the configuration, restart Claude Desktop to load the MCP server connection.
MCPConnect servers can be tested using different approaches, depending on your testing needs and preferences.
For low-level protocol testing, you can use standard HTTP clients like Bruno or Postman to send JSON-RPC requests directly to your MCP server endpoint.
Example test files for Bruno are already available in the demo/api directory of this repository. These files demonstrate how to structure JSON-RPC calls for testing various MCP operations.
For a more specialized testing experience, you can use MCPJam Inspector, a tool specifically designed for testing and debugging MCP servers. MCPJam provides a web-based interface that makes it easy to explore your server's capabilities and test its tools interactively.
To launch MCPJam Inspector, simply run:
npx @mcpjam/inspector@latestThis command will:
- Download the latest version of MCPJam Inspector
- Start the local server
- Open a web interface where you can add and test your MCP server
From the web interface, you can add your Delphi MCP server by providing its endpoint URL (e.g., http://localhost:8080/mcp) and start testing your tools immediately.
We welcome contributions! If you have suggestions, bug reports, or want to contribute code, please:
- Fork the repository.
- Create a new branch (
git checkout -b feature/AmazingFeature). - Commit your changes (
git commit -m 'Add some AmazingFeature'). - Push to the branch (
git push origin feature/AmazingFeature). - Open a Pull Request.
Distributed under the MIT License. See LICENSE for more information.
