Crestapps core mcp

From CrestApps/CrestApps.AgentSkills · View interactive version

Crestapps core mcp is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for CrestApps.Core Model Context Protocol support in any ASP.NET Core host. Covers AddMcpClient and AddCoreAIMcpClient with SSE and StdIO transports, McpConnection stores and custom IMcpClientTransportProvider, AddMcpServer with the MCP C# SDK, WithCrestAppsHandlers and MapMcp, McpServerOption

How to use this skill

Skill file

CrestApps.Core MCP

CrestApps.Core.AI.Mcp provides both sides of MCP: a client that turns remote MCP servers into orchestrator tools, and server handlers that expose CrestApps tools, tool instances, agents, prompts and resources through the official MCP C# SDK. FTP and SFTP resource types are covered in crestapps-core-mcp-file-resources; giving tools to AI agents in the browser through document.modelContext is covered in crestapps-core-webmcp.

Client

builder.Services.AddCrestAppsCore(crestApps => crestApps
    .AddAISuite(ai => ai
        .AddOpenAI()
        .AddMcpClient(mcpClient => mcpClient
            .AddEntityCoreStores()))   // or .AddYesSqlStores(); registers the McpConnection catalog
    .AddEntityCoreSqliteDataStore("Data Source=app.db"));

Server

using CrestApps.Core.AI.Mcp;
using CrestApps.Core.AI.Mcp.Knowledge;
using CrestApps.Core.AI.Mcp.Models;

builder.Services.AddCrestAppsCore(crestApps => crestApps
    .AddAISuite(ai => ai
        .AddOpenAI()
        .AddMcpServer(mcpServer => mcpServer
            .AddYesSqlStores()           // McpPrompt and McpResource catalogs
            .AddKnowledgeResources())));

builder.Services.Configure<McpServerOptions>(options =>
{
    options.AuthenticationType = McpServerAuthenticationType.ApiKey;
    options.ApiKey = builder.Configuration["Mcp:ServerApiKey"];
    options.Tools = ["crestapps-docs", "calculator"];
    options.Agents = ["researcher"];
});

builder.Services.AddMcpServer(options =>
{
    options.ServerInfo = new() { Name = "My MCP Server", Version = "1.0" };
})
.WithHttpTransport()
.WithCrestAppsHandlers();

var app = builder.Build();

app.MapMcp("mcp");

What a Client May Call

Exposure is opt-in. Nothing is listed or callable until allowed.

| Option | Effect |

|---|---|

| Tools | allow-list of tool and tool instance names, case-insensitive |

| ExposeAllTools | every selectable tool and tool instance; system and hidden tools are never exposed |

| Agents | allow-list of agent profile names |

| ExposeAllAgents | every agent profile (AIProfileType.Agent) that has a description, including code-defined system agents |

Tool Results

McpToolResultMapper maps a tool result onto MCP content blocks: a string is one text block, an IMcpToolContentProvider returns its own ContentBlock list, and an IAIToolContentProvider (for example DataSourceRetrievalResult or KnowledgeObjectToolResult) is mapped from its AIContent list, so a search that found a figure returns text plus a resource link. In chat completions the same results reach the model as text.

Custom Resource Types

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

// IProductCatalog is the host's own service.
public sealed class ProductSheetResourceHandler : McpResourceTypeHandlerBase
{
    public const string TypeName = "product-sheet";

    private readonly IProductCatalog _catalog;

    public ProductSheetResourceHandler(IProductCatalog catalog)
        : base(TypeName)
    {
        _catalog = catalog;
    }

    protected override async Task<ReadResourceResult> GetResultAsync(
        McpResource resource,
        IReadOnlyDictionary<string, string> variables,
        CancellationToken cancellationToken)
    {
        if (!variables.TryGetValue("sku", out var sku) || string.IsNullOrWhiteSpace(sku))
        {
            return CreateErrorResult(resource.Resource.Uri, "A product SKU is required.");
        }

        var markdown = await _catalog.GetSheetMarkdownAsync(sku, cancellationToken);

        return new ReadResourceResult
        {
            Contents =
            [
                new TextResourceContents
                {
                    Uri = resource.Resource.Uri,
                    MimeType = "text/markdown",
                    Text = markdown,
                },
            ],
        };
    }
}

builder.Services
    .AddCoreAIMcpServer()
    .AddCoreAIMcpResourceType<ProductSheetResourceHandler>(ProductSheetResourceHandler.TypeName, entry =>
    {
        entry.DisplayName = new LocalizedString("ProductSheet", "Product sheet");
        entry.Description = new LocalizedString("ProductSheet Description", "Reads a product data sheet by SKU.");
        entry.SupportedVariables = [new McpResourceVariable("sku")];
    });

Upgrading from 1.x

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.