Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works

Random project

MCPFramework4D

MCP Server/Client framework for Delphi and Lazarus

View on GitHub

Anyone may press Interesting, signed in or not. It helps others find this project.

Member rating

No ratings yet.

Sign in to rate this project.

README

MCPFramework4D

Model Context Protocol for Pascal developers.

MCPFramework4D helps you build MCP servers and clients in Delphi 11+ and Lazarus/FPC on Windows, with IDE components, project templates, and sample apps ready for Claude Desktop testing.

Why this project

  • Build MCP servers over stdio
  • Call local MCP servers from Delphi or Lazarus apps
  • Add MCP support to legacy desktop applications through non-visual components
  • Start faster with Delphi and Lazarus project wizards

First-glance feature summary

Area Delphi 11+ Lazarus / FPC
Runtime package Yes Yes
Design-time package Yes Yes
Components in IDE TMCPServerComponent, TMCPServerHostComponent, TMCPClientComponent TMCPServerComponent, TMCPServerHostComponent, TMCPClientComponent
Project wizards Yes Yes
stdio server hosting Yes Yes
stdio client transport Yes Yes
HTTP client transport Yes Not yet
HTTP host transport Yes Not yet

Supported MCP surface

Currently implemented and tested around the local Windows workflow:

  • initialize
  • notifications/initialized
  • ping
  • tools/list
  • tools/call
  • protocol version negotiation

Supported protocol versions:

  • 2025-11-25
  • 2025-06-18
  • 2025-03-26
  • 2024-11-05

Packages and IDE integration

Delphi

  • Runtime package: package\MCPFramework4D.dproj
  • Design-time package: package\MCPFramework4DDesign.dproj
  • Workspace: MCPFramework4D_GroupProject.groupproj

After installing the design-time package, RAD Studio adds:

  • Tool Palette page: MCPFramework4D

  • Components: TMCPServerComponent, TMCPServerHostComponent, TMCPClientComponent

    image

  • New Project entries:

    • MCP Server Project
    • MCP Client Project

image

Lazarus

  • Runtime package: lazarus\MCPFramework4DRuntime.lpk
  • Design-time package: lazarus\MCPFramework4DDesign.lpk

After installing the design-time package, Lazarus adds:

  • Component palette page: MCPFramework4D
  • Components: TMCPServerComponent, TMCPServerHostComponent, TMCPClientComponent

image

  • New Project category: MCPFramework4D

image

Programming model

Delphi 11+

Delphi uses attribute-based tool registration.

pascal
[MCPTool('sample', 'Sample tools')]
TSampleTools = class
public
  [MCPToolMethod('echo', 'Echo a message back')]
  function Echo([MCPToolParam('Message to echo back')] const Text: string): string;
end;

Lazarus / FPC

Lazarus uses explicit descriptor registration.

pascal
procedure RegisterMyTool;
var
  LDescriptor: TMCPToolDescriptor;
begin
  LDescriptor := TMCPToolDescriptor.Create('sample', 'Sample tools', TSampleTools);
  with LDescriptor.AddMethod('Echo', 'echo', 'Echo a message back', @InvokeEcho) do
    AddParameter('Text', 'Message to echo back', 'string');
  TMCPToolRegistry.GetInstance.RegisterToolDescriptor(LDescriptor);
end;

Main components

TMCPServerComponent

Use this to expose tools and server metadata from an existing application.

Main capabilities:

  • register tools
  • handle messages
  • run a server over stdio

TMCPServerHostComponent

Use this to host a TMCPServerComponent over a selected transport.

Main capabilities:

  • start and stop hosting
  • stdio hosting in Delphi and Lazarus
  • HTTP/HTTPS hosting in Delphi

Note: in Lazarus/FPC, mtHttp currently raises a clear runtime error and is intentionally not enabled yet.

TMCPClientComponent

Use this to connect to and call another MCP server.

Main capabilities:

  • connect and disconnect
  • list tools
  • call tools
  • ping

Note: in Lazarus/FPC, TMCPClientComponent currently supports mtStdio. HTTP transport is still Delphi-only.

Samples

The repo includes practical samples instead of toy-only demos:

  • src\Samples\SimpleServer
  • src\Samples\SimpleClient
  • src\Samples\VclServerDemo

The sample server exposes system-style tools such as:

  • machine overview
  • memory information
  • drive information
  • OS information

The VCL demo can run as a normal visible app or be launched by Claude Desktop as an MCP server.

Claude Desktop quick start

Example config:

json
{
  "mcpServers": {
    "mcpframework4d-sample": {
      "command": "D:\\path\\to\\YourServer.exe",
      "args": []
    }
  }
}

Suggested test prompt:

text
List the available MCP tools, call one safe sample tool, and summarize whether the server connection is working correctly.

There are also ready-to-edit sample config files in the repository for the included demos.

Build notes

  • Windows-focused
  • stdio first
  • no third-party Delphi dependency required for the core stdio workflow
  • Delphi HTTP/S hosting uses Indy units that ship with RAD Studio
  • package outputs are separated by compiler/platform/config to reduce cross-version conflicts

Compatibility

  • Delphi 11 Alexandria and newer
  • Lazarus with Free Pascal on Windows

Common Delphi package issue

If you see something like:

text
Bad packaged unit format ... Expected version ... Found version ...

you are usually loading package binaries from a different Delphi version.

Typical fix:

  1. Close the IDE.
  2. Delete old generated outputs such as package\build, *.dcp, *.bpl, Win32, Win64, *.identcache, and *.local.
  3. Rebuild the runtime package first.
  4. Rebuild the design-time package second.

Status

This repository is now set up as a dual-purpose Delphi and Lazarus MCP framework with:

  • shared runtime code
  • IDE components in both environments
  • project wizards in both environments
  • sample applications for local Claude Desktop testing

Delphi

Made with :heart: on Delphi