pascal-mcp-sdk

mcp
Guvenlik Denetimi
Uyari
Health Uyari
  • License — License: MIT
  • Description — Repository has a description
  • Active repo — Last push 0 days ago
  • Low visibility — Only 5 GitHub stars
Code Uyari
  • network request — Outbound network request in .agents/skills/address-feedback/scripts/review_observation.py
Permissions Gecti
  • Permissions — No dangerous permissions requested

Bu listing icin henuz AI raporu yok.

SUMMARY

FreePascal-native MCP (Model Context Protocol) server library — expose tools, resources, and prompts from Pascal programs to AI agents. Zero third-party dependencies, stdio + Streamable HTTP.

README.md

pascal-mcp-sdk

A FreePascal-native MCP (Model Context Protocol) server library.
Dependency-light, cross-platform (Linux, macOS, Windows), targeting
the current stateless protocol revision (2026-07-28).
Expose tools, resources, and prompts from any Pascal program to AI
agents — no second language runtime, no framework.

  • Zero third-party runtime dependencies — only packages that ship
    inside FPC: the RTL, fpjson and fcl-base (the HTTP transport adds
    fcl-web).
  • Two transports, one core — newline-delimited JSON-RPC over
    stdio (the standard local-subprocess transport) and Streamable
    HTTP
    (single POST endpoint, SSE response streams), both thin
    shells around the same sans-I/O server core.
  • Stateless spec, dual-era by default — native 2026-07-28
    (per-request _meta, mandatory server/discover, no session
    handshake) and, on stdio, the classic initialize handshake
    clients such as Codex still open with: registered over stdio,
    Claude Code, Claude Desktop, and Codex connect whichever
    supported revision they open with.
  • MRTR (input_required) — handlers can ask the client for more
    input mid-call (elicitation, sampling, roots) using the 2026-07-28
    multi-round-trip pattern, without any server-side session state.
  • Server-enforced argument validation — every tool call is
    checked against its registered schema before your handler runs.

📚 Full documentation: guides, API reference, and internals at
https://frostney.github.io/pascal-mcp-sdk/ — rendered from
docs/.

Not these projects

This is a FreePascal library for writing MCP servers. It is not
tina4stack/pascal-mcp
(formerly claude-pascal-mcp; a Python MCP server that compiles and runs
Pascal programs) and not
@pascal-app/mcp
(the MCP server of the Pascal 3D editor).

Install

As an lwpt dependency:

lwpt add frostney/pascal-mcp-sdk@^3.0

Your programs then uses MCP.Server (and friends) directly — lwpt
discovers the library units through the nested manifest, and the
library's own test files stay out of your project's lwpt test
discovery.

By vendoring — copy every library unit from source/units/
(the MCP.*.pas files, leaving out the *.Test.pas suites) and
MCP.inc into your unit path. MCP.Server uses the others, so take
them all even for a text-only server. FPC-shipped packages only (RTL,
fpjson, fcl-base; fcl-web for the HTTP transport unit).

Zero-install from a clone — the repo commits its dependency
modules and the generated FPC response file, so a plain FPC 3.2.2 is
enough to build the demo server with no lwpt binary at all:

mkdir -p build
fpc @lwpt.cfg -FEbuild source/apps/mcpdemo.pas
./build/mcpdemo

Quick start

program myserver;

{$mode delphi} {$H+}

uses
  fpjson,
  MCP.Protocol, MCP.Schema, MCP.Server, MCP.Transport.Stdio;

function Greet(AArguments: TJSONObject;
  const ACtx: TMCPRequestContext): TMCPToolResult;
begin
  Result := MCPTextResult('Hello, ' + AArguments.Get('name', 'world') + '!');
end;

var
  Server: TMCPServer;
begin
  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;
end.

Handlers are synchronous plain functions or methods (of object —
both registration overloads exist). Tool schemas are built with the
fluent MCP.Schema API (ObjectSchema.AddString(...).AddNumber(...);
properties are required unless opted out, and an output schema can be
passed alongside the input schema).

Or skip the schema entirely and let an argument class expand into
it — the handler then receives a populated, validated instance instead
of raw JSON (missing/mistyped arguments are rejected as in-band
isError results before the handler runs):

type
  TAddArgs = class(TMCPArgs)
  private
    FA, FB: Double;
  published
    property a: Double read FA write FA;
    property b: Double read FB write FB;
  end;

function Add(AArgs: TMCPArgs;
  const ACtx: TMCPRequestContext): TMCPToolResult;
begin
  with AArgs as TAddArgs do
    Result := MCPTextResult(FloatToStr(a + b));
end;

// the class IS the schema: {a: number, b: number}, both required
Server.RegisterTool('add', 'Add two numbers', TAddArgs, Add);

Published properties map to JSON Schema types (string kinds →
string, floats → number, integer kinds → integer, Boolean →
boolean, enums → string with the enum names as allowed values;
field-backed dynamic arrays → array, and TMCPArgs properties →
nested objects).
Optionality uses the standard property directives: default 3 makes
an ordinal property optional with that schema default (seeded into
the instance when the argument is omitted), and stored False makes
any property optional without one.
Classes rather than records because FPC 3.2.2 RTTI only exposes field
names for published class properties. Per-property descriptions come
from the fluent builder. For richer schemas ($ref, composition, formats
and other annotations), register the JSON itself through the
JSON-string or definition-object overloads, validated at registration
(schemas beyond the server-enforced subset are marked
.ApplicationValidated, handing argument validation to your handler).

Results are built with MCPTextResult / MCPErrorResult /
MCPStructuredResult / MCPImageResult; handler exceptions become
in-band isError: true tool results automatically, and a handler that
must refuse with a JSON-RPC error raises EMCPProtocolError. MCPImageResult
takes either raw bytes (encoded to base64 for you) or data that is
already base64, plus the image's media type:

Result := MCPImageResult(ScreenshotBytes, 'image/png');

Resources register either as static text (RegisterTextResource) or
with a reader callback (RegisterResource).

Serving the same registrations over Streamable HTTP instead of
stdio is a transport swap (modern-era only; binds 127.0.0.1):

uses
  {$IFDEF UNIX} cthreads, {$ENDIF}   // first in the program uses clause
  ..., MCP.Transport.HTTP;

Transport := TMCPHTTPServer.Create(Server);
Transport.Port := 3000;   // POST http://127.0.0.1:3000/mcp
Transport.Run;            // blocks; Transport.Stop unblocks it

The complete worked example is
source/apps/mcpdemo.pas — including the
MRTR greet_user tool that elicits input mid-call; the protocol-level
walkthrough lives in docs/guides/quick-start.md.

Protocol coverage

Implemented: tools, resources (including RFC 6570 templates),
prompts, argument completion, MRTR, progress/log notifications,
caching hints, extension negotiation with
MCP Apps interactive UIs,
Skills, Events
poll and push delivery and Tasks with task
status notifications over subscriptions/listen, both transports, and
the classic initialize era. Deliberately out: list-changed
notifications and resource subscriptions, since the registries are
static after startup. The authoritative surface-by-surface table,
including verification and interop evidence, lives in
docs/reference/protocol-coverage.md.

Contributing

Building, testing, and formatting the library itself go through the
lwpt toolchain — see CONTRIBUTING.md.

License

MIT — see LICENSE.

Yorumlar (0)

Sonuc bulunamadi