Setting Up the MCP Server
This page adds the Code Effects MCP server to an ASP.NET Core application: the packages, the registration, the endpoint and every option. Signing callers in is on the next page, Authentication and the Caller; the two together make a working server.
Why it is set up this way. The server is one endpoint in your own application, behind your own authentication, reading the same database as your Rule Repository. There is nothing to install or run separately, no second database and no credential of its own, and each library you own (Repository, Audit, or both) adds its own tools.
Before You Start
- An ASP.NET Core application on .NET 8 or later. It can be the application that already hosts RR, or a new one; see Rule Repository for creating and securing a host application.
- The Rule Repository's database, created and current (see The Database), and the Rule Repository library, Audit, or both.
- HTTPS, and an identity provider that issues tokens for the server.
Step 1: Add the Packages
| Package |
Why |
CodeEffects.Rule.Mcp |
The MCP server |
CodeEffects.Rule.Repository |
The Rule Repository's tools (skip for Audit alone) |
CodeEffects.Rule.Audit |
Audit's evaluation tools (skip for the Repository alone) |
CodeEffects.Rule.Connection.SqlServer or CodeEffects.Rule.Connection.Postgres |
The database provider |
Microsoft.AspNetCore.Authentication.JwtBearer |
Validating your identity provider's tokens |
The MCP server brings Microsoft's MCP SDK for .NET (ModelContextProtocol.AspNetCore) with it.
Step 2: Register the Server
In Program.cs, after your authentication (next page), add the server and the libraries you own:
using CodeEffects.Rule.Mcp;
using CodeEffects.Rule.Repository;
var connectionString = builder.Configuration.GetConnectionString("Rules")!;
var dbProvider = new CodeEffects.Rule.Connection.SqlServer.DbProvider(connectionString);
builder.Services
.AddCodeEffectsMcp(options =>
{
options.MapCaller = (user, http) => Callers.Map(user);
options.ServerName = "rules";
options.Instructions = "Our rules decide order discounts and shipping holds. Answer in the user's language.";
})
.WithRepository(repository =>
{
repository.DbProvider = dbProvider;
repository.Configure = (caller, config) =>
{
config.Notify = Approvals.Notify;
config.Agents = new AgentSettings { AgentDataSourceItems = false };
};
})
.WithAudit(audit => audit.DbProvider = dbProvider);
Callers.Map is your own method that turns the signed-in user into an McpCaller; it is described on Authentication and the Caller. For PostgreSQL, use CodeEffects.Rule.Connection.Postgres.DbProvider.
- Repository only: leave out
WithAudit.
- Audit only: leave out
WithRepository. Agents can then find, read and summarize recorded evaluations, nothing else.
- Both: the Repository's evaluation tools serve, with explanations, in place of Audit's.
Step 3: Map the Endpoint
var app = builder.Build();
app.UseAuthentication();
app.UseAuthorization();
app.MapCodeEffectsMcp("/mcp").RequireAuthorization();
Always require authorization on it. The server never signs anyone in; without .RequireAuthorization(), anonymous calls reach the server and only your MapCaller stands between them and your rules. The address your users add to their AI clients is your application's address plus this path, such as https://rules.example.com/mcp.
The server uses MCP's stateless HTTP transport: every call stands alone, so several instances behind a load balancer need no session affinity.
The Options
CodeEffectsMcpOptions, in AddCodeEffectsMcp:
| Option |
Default |
What it decides |
MapCaller |
(required) |
Turns the caller your authentication verified into an McpCaller: the user, the agent acting for them, their permissions. Called on every request. Return null for a caller you do not recognize, and the request is refused. The application does not start without it |
ServerName |
"codeeffects" |
The server's name, as AI clients show it |
Instructions |
null |
Your own instructions for every agent, added after the server's: what your rules are for, your terms, what to avoid |
SkillsFolder |
null |
The full path of a folder of your own skills, served beside Code Effects' (see below) |
RepositoryMcpOptions, in WithRepository:
| Option |
Default |
What it decides |
DbProvider |
(required) |
The Rule Repository's database, the same one your RR endpoint uses |
Configure |
null |
Completes the Configuration each call is answered with, after the caller's identity and permissions are set on it |
AuditMcpOptions, in WithAudit:
| Option |
Default |
What it decides |
DbProvider |
(required) |
The database Audit records evaluations to |
Customizing
- Keep the MCP server and RR's screens consistent. In
Configure, set what your RR endpoint sets on its configuration: Notify (so approvers hear about versions agents saved), TypeResolver (if your RR endpoint needs one to load your source types), UiXml (translated texts) and Agents (the agent settings, shared with the in-app AI). Do not change the user or the permissions there: those come from MapCaller.
- Your own instructions.
Instructions reaches every agent that connects, with every client. Use it for your vocabulary ("a hold is ..."), for which sources matter, or for what agents must not propose.
- Your own skills. Skills are short guides an agent reads before a task. Code Effects ships six (see Tools and Skills); add your own with
SkillsFolder: every folder in it is one skill, named by the folder, with a SKILL.md in the Agent Skills format. Your skills are served beside Code Effects', never in place of one. The folder is read when the application starts, and the application refuses to start if a skill breaks the format, its name starts with codeeffects- or is already taken, it contains a symbolic link, or a file name uses characters other than letters, digits, ., _ and -.
- The agents' limits (test runs, data source items): set
config.Agents in Configure.
A Separate Application for the MCP Server
If RR is hosted on .NET Framework, or you prefer to keep AI traffic apart, create a small ASP.NET Core application for the MCP server alone, pointed at the same database. It needs the same source types (or a TypeResolver that finds them) when your sources are .NET classes, and the same database account rights as the RR application. Users then connect to that application's address.
Checking It
- Call the endpoint without a token: it must answer 401, never a list of tools.
- Connect a client as a test user (see Connecting Users to Your MCP Server) and ask it which source objects there are.
- Ask it to save a small rule, then open RR: the version must be waiting for approval, and the user activity must name the test user and the AI client.