Delphi MCP Server Prompts (3/4)

With sgcWebSockets 2025.9.0, the Model Context Protocol (MCP) server now supports Prompt Requests, enabling AI clients to query and render dynamic prompt templates. This capability makes it possible to expose reusable AI prompts (like "summarize text" or "review code") directly through WebSockets using the MCP standard.

What Are MCP Prompt Requests?

In MCP, Prompts are structured templates that clients can discover and use to generate model inputs consistently.
Each MCP server exposes:

  1. prompts/list — to enumerate available prompts.
  2. prompts/get — to render a specific prompt with given arguments.
  3. notifications/prompts/list_changed — to notify clients when the prompt catalog changes.

This allows large language models or agents to retrieve available templates and render them dynamically with context.

Listing Prompts

When a client calls prompts/list, your server should return an array of prompt definitions, including each prompt's name, description, and argument schema.

Example code that publishes a code review prompt: 

procedure TMainForm.FormCreate(Sender: TObject);
var
  oPrompt: TsgcAI_MCP_Prompt;
begin
  MCPServer.Prompts.Clear;
  oPrompt := MCPServer.Prompts.AddPrompt('CodeReview',
    'Asks the LLM to analyze code quality and suggest improvements');
  oPrompt.Arguments.AddArgument('code', 'The code to review', True);
end; 

Prompt Request

When a client issues a prompts.call JSON-RPC request, TsgcWSAPIServer_MCP hydrates the strongly-typed request object (including tool name and the provided arguments) before raising the OnMCPRequestPrompt event. Your handler populates the response payload which is then serialized back to the client, alongside a success HTTP status code.

A typical handler looks like this: 

procedure TFRMMCPServer.MCPServerMCPRequestPrompt(Sender: TObject;
  const aSession: TsgcAI_MCP_Session; const aRequest: TsgcAI_MCP_Request_PromptsGet;
  const aResponse: TsgcAI_MCP_Response_PromptsGet);
begin
  if aRequest.Params.Name = 'CodeReview' then
  begin
    aResponse.Result.Description := 'Code review prompt';
    aResponse.Result.Messages.AddText('user',
      'Please review this Delphi code: ShowMessage(''Hello World'' ');
  end;
end; 

With MCP Prompts now integrated into sgcWebSockets 2025.9.0, developers can create AI-aware WebSocket servers that expose structured, discoverable, and dynamic prompts — bridging the gap between LLMs and real-time application data. 

Learn More

For in-depth documentation and component reference, visit:

sgcWebSockets MCP Prompts Server Guide 


Find below a Delphi MCP Server Demo for Windows

sgcMCP_Server
3.9 mb
×
Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

Delphi MCP Server Resources (4/4)
Delphi MCP Server Tools (2/4)