About LayeredChat.Integrations.Mcp
LayeredChat.Integrations.Mcp is an MCP server in the Commerce category: model Context Protocol (MCP) tools as LayeredChat IToolCatalog and IToolExecutor via the official MCP C# SDK.
Install
git clone https://github.com/OniuUI/LayReXThis server has no ConduID identity, so agent calls to it are not receipted. Pin the version you install and review the source before granting it credentials.
Ask AI
Ask AI about LayeredChat.Integrations.Mcp
Powered by Claude · Grounded in docs
Security checks
- ✓README presentThe repository ships documentation.
5 checks have not been run yet.
README

LayReX LayeredChat
LayReX is the face we put on LayeredChat — a composable, versioned orchestration layer for LLM tool loops in .NET 9+.
Manifest-driven behavior · pluggable connectors · real data planes · stream or finish · ship as version pods.
Architecture · Layers roadmap · Telemetry & billing · Connectors matrix
Why LayReX?
| You need | LayeredChat gives you |
|---|---|
| Versioned “personalities” without copy-pasting prompts | OrchestrationProfileManifest + registry keys (OrchestrationRegistryKeys.Compose) |
| Swap models (OpenAI, Azure, Ollama, MEAI, …) | ILlmChatConnector, OpenAiCompatible, ExtensionsAiChatConnector |
| RAG / SQL / vectors as first-class context | IDataSourceProvider + PostgreSQL, MongoDB, Qdrant packages |
| SSE / buses / gateways | RunTurnStreamingAsync → OrchestrationStreamEnvelope |
| Remote version pods | ExternalForwardUri + HttpOrchestrationForwarder + VersionHost |
| Composed orchestration layers | LayerStackManifest, LayerContribution, ILayerCompositionService; see docs/LAYER_PACKAGE_FORMAT.md |
| Optional layer registry + CLI | LayeredChat.ControlPlane, LayReX.ControlPlane.Client, LayReX-CLI |
Packages (NuGet-ready)
| Package | Purpose |
|---|---|
LayeredChat.Core |
Orchestrator, manifests, layer composition, telemetry, streaming, forward DTOs |
LayReX.ControlPlane.Client |
HTTP client for the optional layer registry (publish from LayReX repo) |
LayReX.CLI |
Global tool layrex — validate/pack/push bundles (LayReX-CLI) |
LayeredChat.Connectors.OpenAiCompatible |
OpenAI-style HTTP (sync + SSE) |
LayeredChat.Connectors.ExtensionsAi |
Microsoft.Extensions.AI.IChatClient |
LayeredChat.Data.PostgreSql |
SQL slices + postgresql_readonly_select tool |
LayeredChat.Data.MongoDb |
Mongo find slice + mongodb_find_json tool |
LayeredChat.Data.Qdrant |
Vector search slice |
LayeredChat.Integrations.Mcp |
Model Context Protocol tools → IToolCatalog / IToolExecutor (official ModelContextProtocol SDK) |
Install from NuGet
Packages are published under the LayeredChat.* IDs on nuget.org. Typical app references:
dotnet add package LayeredChat.Core
dotnet add package LayeredChat.Connectors.OpenAiCompatible
Add connectors, data providers, or MCP as needed (LayeredChat.Connectors.ExtensionsAi, LayeredChat.Data.PostgreSql, LayeredChat.Integrations.Mcp, …).
Publish (maintainers): In the LayReX GitHub repo, add a secret NUGET_API_KEY (API key from nuget.org account API keys, scope Push for LayeredChat.*). Then either push a git tag v0.2.0, or run the Publish NuGet workflow manually and enter the same version string (without v).
Solution: LayeredChat.sln in this folder.
Layout: src/Core/LayeredChat.Core/ is split by feature (Chat/, Llm/, Tools/, Context/, Profiles/, Orchestration/, Forward/, Telemetry/, Agents/ — public namespace remains LayeredChat). Also: src/Connectors/..., src/Data/..., src/Integrations/Mcp, tests/, samples/VersionHost, deploy/version-pod.
Vector mark (SVG, crisp at any size): docs/assets/layeredx-readme-hero.svg
Easiest API: LayeredChatHost
Instead of new LayeredChatOrchestrator(...) with five dependencies, build a single host object:
var host = LayeredChatHost.CreateBuilder()
.UseConnector(myConnector) // ILlmChatConnector (required)
.UseDefinitions(orchestrationDefinition) // or .UseDefinitionRegistry(myRegistry)
.UseTools(myToolCatalog, myToolExecutor) // optional; defaults to no tools
.UseDataSources(myDataSourceRegistry) // optional; defaults to empty
.Build();
var result = await host.RunTurnAsync(new LayeredChatTurnRequest { /* ... */ });
// host.Orchestrator — same instance if you need the raw type
// host.CreateAgent(registryKey) — IChatAgent for fixed-profile turns
For dependency injection, register one factory that returns LayeredChatHost (or register LayeredChatOrchestrator resolved from sp.GetRequiredService<LayeredChatHost>().Orchestrator). Decline-all tools: NoOpToolExecutor.Instance with an empty DictionaryToolCatalog.
Quick start (manual wiring)
- Define a manifest (JSON) or
OrchestrationProfileManifestin code. - Register with
InMemoryOrchestrationDefinitionRegistryor your ownIOrchestrationDefinitionRegistry. - Wire connector,
IToolCatalog,IToolExecutor,IDataSourceRegistry. - Call
RunTurnAsync(finished turn) orRunTurnStreamingAsync(envelopes for SSE / SignalR / Kafka).
var registry = new InMemoryOrchestrationDefinitionRegistry();
registry.Register(new OrchestrationDefinition
{
Manifest = new OrchestrationProfileManifest
{
OrchestrationId = "support",
SemanticVersion = "2.1.0",
DisplayName = "Support bot",
AllowedToolNames = new[] { "kb_search" },
DataSourceIdsInOrder = new[] { "policies_pg" },
Parameters = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
["pgsql.sql"] = "SELECT title, body FROM policies LIMIT 20;"
}
}
});
var http = new HttpClient { Timeout = TimeSpan.FromMinutes(5) };
var connector = new OpenAiCompatibleChatConnector(http, new OpenAiCompatibleOptions
{
BaseUri = new Uri("https://api.openai.com/v1/"),
Model = "gpt-4o-mini",
ApiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY")
});
var dataSources = new DataSourceRegistry(new IDataSourceProvider[]
{
new PostgreSqlParameterDataSource("policies_pg", npgsqlDataSource)
});
var orchestrator = new LayeredChatOrchestrator(
connector,
myToolExecutor,
myToolCatalog,
registry,
dataSources);
var result = await orchestrator.RunTurnAsync(new LayeredChatTurnRequest
{
OrchestrationRegistryKey = OrchestrationRegistryKeys.Compose("support", "2.1.0"),
SystemInstructionText = "You are a concise support agent.",
UserMessageContent = "How do I reset my password?",
PriorMessages = Array.Empty<ChatMessage>(),
Session = new OrchestrationSessionContext { TenantKey = "acme" }
});
Agents (named orchestration profiles)
IChatAgent— fixedOrchestrationRegistryKeywithRunTurnAsync/RunTurnStreamingAsyncoverAgentTurnInput(no key on each call).LayeredChatAgent— thin wrapper overLayeredChatOrchestrator.LayeredChatAgentRegistry— register many agents (e.g.sales,support) on one orchestrator.
Model Context Protocol (MCP)
await McpToolSession.ConnectStdioAsync(...)orConnectAsync(IClientTransport, ...).- Set manifest
AllowedToolNamesto the MCP tool names (useMcpSessionOptions.ToolNamePrefixper server to avoid collisions). - Wire orchestrator:
var mcp = await McpToolSession.ConnectStdioAsync(new StdioClientTransportOptions
{
Name = "tools",
Command = "npx",
Arguments = ["-y", "@modelcontextprotocol/server-filesystem", "."]
}, new McpSessionOptions { ToolNamePrefix = "fs_" });
var catalog = McpOrchestrationWiring.CombineHostCatalogThenMcp(hostCatalog, mcp.Catalog);
var executor = McpOrchestrationWiring.RoutePrefixedMcpThenHost("fs_", mcp.Executor, hostExecutor);
- Use
CompositeToolCatalogandRoutedToolExecutorin Core for other merge / routing patterns.
Multi-tenant hosts can implement IMcpToolSessionFactory (LayeredChat.Integrations.Mcp) to create or pool McpToolSession instances per scope key (tenant, user, etc.).
Connectors & LLM versioning
- OpenAI-compatible HTTP — one client for OpenAI, Azure OpenAI, Ollama, vLLM, LiteLLM gateways, etc. Per-request model:
LlmRequestOptions.ModelNameOverride. See docs/CONNECTORS.md andOpenAiCompatibleWellKnownEndpointsfor common base URLs. - Microsoft.Extensions.AI — reuse your existing
IChatClientregistration; tools use declaration-onlyAIFunctionFactory.CreateDeclaration. - Manifest hints —
LlmAdapterProfileId,PreferredConnectorKind; runtime merge viaLayeredChatTurnRequest.ModelAdapterProfile(LlmModelAdapterProfile).
Data planes
- PostgreSQL —
PostgreSqlParameterDataSource(pgsql.sql,pgsql.maxRows); toolPostgreSqlReadonlySelectToolwithSELECT/WITHguardrails. - MongoDB —
MongoJsonFindDataSource; toolMongoFindTool. - Qdrant —
QdrantVectorSearchDataSource(vector JSON in manifest or sessionqdrant.queryVectorJson). - Composition —
CompositeDataSourceRegistryfor tenant/global providers.
Streaming vs finished turns
- Finished:
RunTurnAsync→LayeredChatTurnResult(messages, tokens,CorrelationId,OrchestrationId,SemanticVersion). - Streamed:
RunTurnStreamingAsync→OrchestrationStreamEnvelope(AssistantTextDelta, tool lifecycle,TurnResultSummary,TurnCompleted).
Observability
IOrchestrationTelemetryonLayeredChatTurnRequest.Hooks— fan out withChainedOrchestrationTelemetry. See docs/TELEMETRY_AND_BILLING.md forUsageUpdate,ModelRoundCompleted, and turn totals.- Propagate
OrchestrationSessionContext.CorrelationIdend-to-end.
Version pods (containers)
Manifest: externalForwardUri, externalForwardTimeoutSeconds.
Host: IHttpOrchestrationForwarder (HttpOrchestrationForwarder).
- Sample:
samples/VersionHost—POST /v1/orchestration/forward - Image build (run from this directory — the folder that contains
LayeredChat.sln):
docker build -f deploy/version-pod/Dockerfile -t layered-chat-version-host:latest . - Compose / Kubernetes:
deploy/version-pod/
Build & test
dotnet build LayeredChat.sln
dotnet test tests/LayeredChat.Core.Tests/LayeredChat.Core.Tests.csproj
Contributing
We love PRs that stay focused and match existing style.
- Open an issue first for larger changes (connectors, manifest schema, breaking API).
- Small fixes (docs, tests, typos) can go straight to a PR.
- Core rule:
LayeredChat.Corestays free of Npgsql, MongoDB, Qdrant, and product domains — put adapters in the named packages. - Tests: extend
LayeredChat.Core.Testsor add a test project next to new packages. - Consumers embedding this tree in a larger repo: keep the same
dotnetcommands with your path prefix (e.g.libs/LayeredChat/).
If you use this library in the wild, a ⭐ on the repo or a short issue with your stack helps us prioritize.
Security
- Treat SQL / Mongo tools as convenience, not authorization — use read-only DB roles and tenant-scoped connections.
- Never put secrets inside manifests; resolve keys in the host and pass via
OrchestrationSessionContext.Propertiesif needed.
License
MIT — see LICENSE. Each package also sets PackageLicenseExpression: MIT in MSBuild.
Repository
Canonical home: github.com/OniuUI/LayReX.
LayReX · LayeredChat is a vendor-neutral LLM orchestration library: the public API lives under the LayeredChat root namespace and carries no host- or domain-specific types. Hero artwork: docs/assets/layeredx-hero.png (replace with your own branding if you fork).
README copy captured when this server was indexed; it may lag the repository. The original is authoritative.