Orchardcore ai mcp server

From CrestApps/CrestApps.AgentSkills · View interactive version

Orchardcore ai mcp server is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for the CrestApps Orchard Core MCP Server feature (CrestApps.OrchardCore.AI.Mcp.Server). Covers the Streamable HTTP endpoint at /mcp, OpenId, ApiKey and None authentication, opt-in tool exposure on the MCP Server settings card (McpServerSettings loaded into McpServerOptions with ExposeAllTools

How to use this skill

Skill file

Orchard Core MCP Server

The MCP Server feature exposes Orchard Core AI tools, tool instances, prompts, and resources to external MCP clients (IDEs, desktop agents, other AI apps) over the MCP Streamable HTTP transport.

Guidelines

Enable the feature

{
  "steps": [
    {
      "name": "Feature",
      "enable": [
        "CrestApps.OrchardCore.AI",
        "CrestApps.OrchardCore.AI.Mcp.Server"
      ],
      "disable": []
    }
  ]
}

Enable CrestApps.OrchardCore.AI.Agent and other tool-providing features only when you intend to expose their tools, and enable CrestApps.OrchardCore.AI.ToolInstances to expose tool instances.

Endpoint

routes.MapMcp("mcp") maps one Streamable HTTP endpoint, relative to the tenant URL prefix, protected by the McpServerPolicy authorization policy (schemes McpApiKey and Api).

| Method | Purpose |

|---|---|

| POST /mcp | Send a JSON-RPC message. The reply is a JSON payload or a text/event-stream. |

| GET /mcp | Open the server-to-client event stream for an established session. |

| DELETE /mcp | End the session. |

The deprecated HTTP+SSE transport (GET /mcp/sse plus POST /mcp/message) is not mapped. Clients that only speak that transport cannot connect.

Tool exposure

Configure exposure under Settings → Artificial Intelligence, on the MCP Server card (permission ManageMcpServerSettings, granted to Administrator by default):

The allow-list is enforced by both the list and the call handlers, so a tool that is not exposed can neither be discovered nor invoked. Each Tools entry matches a code-registered tool name, a tool instance's function name, or a tool instance's technical name (case-insensitive).

Configuration override

The card is stored as McpServerSettings site settings and projected into McpServerOptions. The shell configuration section OrchardCore:CrestApps:AI:McpServer is bound afterwards and overrides the stored values (the older OrchardCore:CrestApps:McpServer section is still read first for backward compatibility).

{
  "OrchardCore": {
    "CrestApps": {
      "AI": {
        "McpServer": {
          "AuthenticationType": "OpenId",
          "RequireAccessPermission": true,
          "ExposeAllTools": false,
          "Tools": [ "searchForContentItems", "orchardcore-docs" ],
          "ExposeAllAgents": false,
          "Agents": [ "research-agent" ]
        }
      }
    }
  }
}

| Option | Default | Description |

|---|---|---|

| AuthenticationType | OpenId | OpenId, ApiKey, or None. |

| ApiKey | null | Key required in ApiKey mode. |

| RequireAccessPermission | true | In OpenId mode, also require the AccessMcpServer permission. |

| ExposeAllTools | false | Expose every selectable tool and tool instance; Tools is ignored. |

| Tools | [] | Allow-list of tool and tool instance names. |

| ExposeAllAgents | false | Expose every Agent profile as a callable tool. Not on the admin card. |

| Agents | [] | Allow-list of Agent profile Names. Not on the admin card. |

An exposed agent runs its whole profile (system message, tools, data sources) for any client that passes authentication. Its internal tools are neither filtered by nor exposed through Tools.

Example - expose documentation search only

  1. Enable CrestApps.OrchardCore.AI.ToolInstances.
  2. Under Artificial Intelligence → Tool Instances, add one Documentation search (sitemap) instance per public site (for example orchardcore-docs with base URL https://docs.orchardcore.net). See orchardcore-ai-tool-instances.
  3. Enable the MCP Server and configure authentication.
  4. On the MCP Server card, leave Expose all tools off and tick only those instances under Tool instances.

MCP clients now discover exactly those search tools while every content or management tool stays private.

Authentication

| Mode | How clients authenticate |

|---|---|

| OpenId | Bearer token from the Orchard Core OpenID server (Api scheme). Requires AccessMcpServer when RequireAccessPermission is true. |

| ApiKey | Authorization: Bearer <key>, Authorization: ApiKey <key>, or the raw key. |

| None | No credentials. Development only. |

Prefer setting ApiKey through user secrets or environment variables (OrchardCore__CrestApps__AI__McpServer__ApiKey) rather than the admin card in production.

Client configuration

{
  "mcpServers": {
    "orchard-core": {
      "transport": {
        "type": "http",
        "url": "https://your-orchard-site.com/mcp",
        "headers": {
          "Authorization": "Bearer <token-or-api-key>"
        }
      }
    }
  }
}

Send Accept: application/json, text/event-stream on POST /mcp.

MCP prompts

Managed under Artificial Intelligence → Model Context Protocol → Prompts (permission ManageMcpPrompts). A prompt has a Title, unique Name, optional Description, optional Arguments (name, title, description, required) referenced in content as {{argName}}, and one or more Messages with role user or assistant. Clients call ListPrompts and GetPrompt.

{
  "steps": [
    {
      "name": "McpPrompt",
      "Prompts": [
        {
          "Prompt": {
            "Name": "summarize",
            "Title": "Summarize",
            "Description": "Summarizes supplied text.",
            "Arguments": [
              { "Name": "text", "Description": "The text to summarize.", "Required": true }
            ]
          },
          "Messages": [
            { "Role": "user", "Content": "Summarize the following text in three bullet points: {{text}}" }
          ]
        }
      ]
    }
  ]
}

MCP resources

Managed under Artificial Intelligence → Model Context Protocol → Resources (permission ManageMcpResources). Add Resource lists the registered resource types. The editor takes Display Text, Name, Path, Description, MIME Type, and type-specific fields. The URI is built as {source}://{itemId}/{path}, and a path with {variable} placeholders becomes a templated resource listed by ListResourceTemplates.

| Type | Variables | Registered when |

|---|---|---|

| file | {fileName}, optional {providerName} | Always; reads only the tenant's McpFiles folder or a registered provider (see below) |

| media | {path} | OrchardCore.Media is enabled |

| content-item | {contentItemId}, {contentItemVersionId} | OrchardCore.ContentManagement is enabled |

| content-type | {contentType} | OrchardCore.ContentManagement is enabled |

| recipe-schema | none | CrestApps.OrchardCore.Recipes is enabled |

| recipe-step-schema | {stepName} | CrestApps.OrchardCore.Recipes is enabled |

| recipe | {recipeName} | CrestApps.OrchardCore.Recipes is enabled |

| ftp, sftp | {path} | See orchardcore-ai-mcp-resources |

Where file resources read from. Without {providerName}, a file resource reads only from the tenant's App_Data/Sites/{tenant}/McpFiles folder. Create the folder and put in it only the files to share; until it exists nothing is found. Paths that leave the folder and dot-prefixed, hidden or system files are refused. A {providerName} template variable (the client supplies the value) selects a provider registered in code with McpFileProviderOptions (CrestApps.OrchardCore.AI.Mcp.Services); an unknown name is not found. A literal name in the template, such as handbook/{fileName}, does not select a provider: it is only part of the path. Earlier versions read from the web host's content root, so move the shared files into McpFiles when upgrading.

services.Configure<McpFileProviderOptions>(options =>
{
    options.AddProvider("handbook", sp => new PhysicalFileProvider("/srv/handbook"));
});

The MCP client picks the file name, so every file a provider can reach is readable by every client allowed to read resources. Never register the content root or the application data folder (they hold appsettings.json, connection strings, keys and every tenant's database).

{
  "steps": [
    {
      "name": "McpResource",
      "Resources": [
        {
          "Source": "recipe-step-schema",
          "DisplayText": "Recipe step schema",
          "Resource": {
            "Uri": "{stepName}",
            "Name": "recipe-step-schema",
            "Description": "JSON schema for one recipe step.",
            "MimeType": "application/json"
          }
        }
      ]
    }
  ]
}

Resource.Uri accepts either the path portion (expanded to {source}://{itemId}/{path} on import) or a full URI that already uses the source scheme. The resource title is always taken from DisplayText.

Custom resource type

using CrestApps.Core.AI.Mcp;
using CrestApps.Core.AI.Mcp.Models;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using ModelContextProtocol.Protocol;
using OrchardCore.Modules;

[RequireFeatures("CrestApps.OrchardCore.AI.Mcp.Server")]
public sealed class Startup : StartupBase
{
    internal readonly IStringLocalizer S;

    public Startup(IStringLocalizer<Startup> stringLocalizer)
    {
        S = stringLocalizer;
    }

    public override void ConfigureServices(IServiceCollection services)
    {
        services.AddCoreAIMcpResourceType<DatabaseResourceTypeHandler>("database", entry =>
        {
            entry.DisplayName = S["Database"];
            entry.Description = S["Query data from databases."];
            entry.SupportedVariables =
            [
                new McpResourceVariable("table") { Description = S["The database table name."] },
                new McpResourceVariable("id") { Description = S["The row ID to fetch."] },
            ];
        });
    }
}

public sealed class DatabaseResourceTypeHandler : McpResourceTypeHandlerBase
{
    public DatabaseResourceTypeHandler()
        : base("database")
    {
    }

    protected override Task<ReadResourceResult> GetResultAsync(
        McpResource resource,
        IReadOnlyDictionary<string, string> variables,
        CancellationToken cancellationToken)
    {
        variables.TryGetValue("table", out var table);
        variables.TryGetValue("id", out var id);

        // Query your data source here and return its contents.
        return Task.FromResult(CreateErrorResult(resource.Resource.Uri, "Not implemented."));
    }
}

The base class also offers SanitizePath (rejects traversal sequences) and IsTextMimeType. Add an McpResource display driver gated on entry.Source when the type needs its own fields.

Deployment

With OrchardCore.Deployment enabled, the MCP Prompts and MCP Resources export steps appear under the Artificial Intelligence category of the deployment-plan editor. With CrestApps Recipes (CrestApps.OrchardCore.Recipes) enabled, the McpPrompt and McpResource recipe steps have JSON schemas.

Related features

Admin lists

The Prompts and Resources pages use Orchard Core's AdminList shape (list names McpPrompts and McpResources), so they follow the site's List or Grid layout. See orchardcore-admin-lists to add columns with IAdminListColumnsProvider.

Upgrading from 2.x

Troubleshooting

| Symptom | Check |

|---|---|

| Client connects but lists no tools | Tools are opt-in. Select them on the MCP Server card or set ExposeAllTools. |

| A tool is missing even with ExposeAllTools | It is a system or hidden tool, or its providing feature is disabled. |

| Tool listed but the call fails or is skipped | The calling identity lacks AccessAITool_{name} or AccessAnyAITool. |

| 401 or 403 | Authentication type and credentials do not match, or AccessMcpServer is missing in OpenId mode. |

| Legacy SSE client cannot connect | Point it at /mcp with a Streamable HTTP transport. |

| appsettings.json value ignored | Use OrchardCore:CrestApps:AI:McpServer; configuration changes need an app restart. |

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.