🔒 You must be logged in as an Administrator or Editor to listen to this audio.
In the CrestApps Orchard Core project, the integration of Prompts and Resources via the Model Context Protocol (MCP) depends on whether Orchard Core is acting as the Client (consuming external prompts/resources) or the Server (exposing its internal data as prompts/resources).
Here is the sequence and flow for both scenarios.
Scenario A: Orchard Core as an MCP Client
(Flow: An Orchard Core AI Agent uses an external MCP server's prompts and resources)
When you chat with an AI Agent in Orchard Core that is connected to an external MCP Server (e.g., a local Python script or a remote database server), the system orchestrates the context building before sending the request to the LLM.
Sequence Flow:
- User Input: The user sends a chat message to the Orchard Core AI Agent.
- Context Building Initiation: The Orchard Core
DefaultOrchestratortriggers the context-building phase (IAICompletionContextBuilder). - Capability Resolution: The
IMcpCapabilityResolverchecks the attached MCP connections (SSE or STDIO) and asks the remote MCP Server for its capabilities (Tools, Prompts, Resources). - Resource Retrieval (Optional):
- If the agent determines it needs a specific remote resource (e.g., a remote file or database row exposed by the MCP server), it invokes the
resources/readprotocol. - The remote MCP server returns the raw resource data.
- The Orchard Core
IMcpResourceHandlercaptures this data and appends it to the LLM's system prompt context.
- If the agent determines it needs a specific remote resource (e.g., a remote file or database row exposed by the MCP server), it invokes the
- Prompt Retrieval (Optional):
- If the agent is instructed to use a remote prompt template, it calls
prompts/getwith required arguments on the remote MCP Server. - The external MCP server renders the prompt and returns the text.
- The
McpAICompletionContextBuilderHandlermerges this returned text into the final prompt instructions.
- If the agent is instructed to use a remote prompt template, it calls
- LLM Execution: Orchard Core sends the fully assembled payload (User Message + MCP Resources Data + MCP Prompt Instructions) to the configured AI Provider (OpenAI, Ollama, etc.).
- Response: The LLM streams the response back to the Orchard Core UI.
Scenario B: Orchard Core as an MCP Server
(Flow: An external client like Claude Desktop queries Orchard Core for prompts and resources)
In this scenario, you use the Orchard Core Admin UI to define McpPrompt (Liquid templates) and McpResource (Content Items, Files, FTP/SFTP locations). An external AI assistant connects to Orchard Core to consume them.
Sequence Flow:
- Connection / Handshake:
- External Client (e.g., Claude) connects to Orchard Core's
/api/mcp/sseendpoint. - Authentication is handled via
McpApiKeyAuthenticationHandleror OAuth2.
- External Client (e.g., Claude) connects to Orchard Core's
- Discovery (
prompts/list&resources/list):- The external client asks Orchard Core what it knows.
- Orchard Core’s
IMcpServerPromptServiceandIMcpServerResourceServicequery the Orchard Core database and return the catalog of defined Prompts and Resources.
- Execution - Taking Prompts (
prompts/get):- Client Request: Claude decides to use a prompt named
summarize_articleand passes required arguments (e.g.,articleId). - Server Routing: The request hits Orchard Core's
McpPromptHandler. - Rendering: Orchard Core evaluates the
McpPromptLiquid template, binds the arguments, accesses internal Orchard Core data if needed, and generates the final text string. - Return: The rendered text is sent back to Claude to be used as system instructions.
- Client Request: Claude decides to use a prompt named
- Execution - Taking Resources (
resources/read):- Client Request: Claude requests a specific URI (e.g.,
content://article/123orftp://server/logs.txt). - Server Routing: Orchard Core's
McpResourceHandlerintercepts the request. - Type Delegation: It delegates the fetch to a specific
IMcpResourceTypeHandler(e.g.,ContentByIdResourceTypeHandler,FtpResourceTypeHandler, orFileResourceTypeHandler). - Data Extraction: The handler fetches the physical file, FTP stream, or Orchard Core Content Item JSON.
- Return: Orchard Core returns the raw data/text to Claude, which Claude then reads to answer the user's question.
- Client Request: Claude requests a specific URI (e.g.,