pascal-mcp-sdk

Give AI agents tools written in Pascal. pascal-mcp-sdk turns any FreePascal program into an MCP (Model Context Protocol) server: register tools, resources, and prompts as ordinary Pascal functions, and clients like Claude Code and Claude Desktop connect out of the box. No second language runtime, no framework, zero third-party dependencies — FPC's RTL and fpjson, cross-platform on Linux, macOS, and Windows.

Register a tool, serve it

Server := TMCPServer.Create('my-server', '1.0.0');
try
  Server.RegisterTool('greet', 'Greet someone by name',
    ObjectSchema.AddString('name', 'Who to greet'),
    Greet);
  RunMCPStdioServer(Server);  // serves until the client closes stdin
finally
  Server.Free;
end;

The library validates arguments against your JSON Schema before the handler runs, turns exceptions into errors the model can correct against, and speaks both the newest stateless protocol revision and the classic handshake today's clients use. How tools work →

Install

As an lwpt dependency: lwpt add frostney/pascal-mcp-sdk@^2.0 — then uses MCP.Server in your program.

By vendoring: the library is seven files. Copy them from source/units/ into your unit path — RTL + fpjson only, nothing to fetch.

Just trying it out? Clone the repo and build the demo server with plain FPC — fpc @lwpt.cfg -FEbuild source/apps/mcpdemo.pas — then wire build/mcpdemo into your MCP client.

The 2026-07-28 protocol surface — everything except subscriptions — is implemented and interop-tested against both official MCP TypeScript clients; see protocol coverage.

Frequently asked questions

What is pascal-mcp-sdk?

A FreePascal-native library for building MCP (Model Context Protocol) servers: expose tools, resources, and prompts from any Pascal program to AI agents. It has zero third-party runtime dependencies — just FPC’s RTL and fpjson — and runs on Linux, macOS, and Windows.

Does Claude Code work with a Pascal MCP server?

Yes — and so does Codex. Servers are dual-era by default: they answer the classic initialize handshake current clients still speak alongside the newest stateless protocol revision, and pick per connection. No configuration needed on either side.

How do I build an MCP server in Pascal?

Install FPC 3.2.2, add the library (lwpt add frostney/pascal-mcp-sdk@^2.0, or vendor its seven source files), register your tools with a name, description, and JSON Schema, and call RunMCPStdioServer. The quick start walks through a complete server in a few minutes.

Which parts of the MCP specification are implemented?

Tools, resources with RFC 6570 templates, prompts, multi-round-trip input requests (elicitation, sampling, roots), progress and log notifications, caching hints, stdio and Streamable HTTP transports, plus the classic initialize handshake era that current clients speak. Deliberately out: subscriptions/listen and list-changed notifications, since registries are static after startup.