Model Context Protocol (MCP) – Why What How … part 3
July 5, 2025A discussion on Model Context Protocol:
- Part 1 – Why is there a need for MCP
- Part 2 – What MCP is, including its architecture and core components
- Part 3 – A demo of MCP — including how to configure it so anyone can run it
- Part 4 – An example of how to develop an MCP server — a potential starter project for connecting to your own knowledge resources
Part 4 – MCP Development
In this section we shall discuss creating an MCP Server – specifically, the Colour MCP server that was covered in the previous section, and used in the demo.
MCP SDK
To help build MCP servers with minimal effort – there are Software Development Kits (SDKS) for the following languages:
- C#
- Java
- Kotlin
- Python
- Ruby
- Swift
- TypeScript
Links to the different SDKS are at https://modelcontextprotocol.io/
Colors MCP
The source code to the Colors MCP server is at : https://github.com/markharrison/ColorsMCP
It could be used as the basis of your own MCP Server – for knowledge that you want to make available to your AI applications. So take a copy:
git clone https://github.com/markharrison/ColorsMCP
There are several projects in the solution:
- ColorsMCP … this uses the STDIO transport protocol
- ColorsMCP-http … this uses the HTTP Streamable transport protocol
- ColorsCommonMCP … this is common code used by both the ColorMCP and ColorsMCP-http projects
- MCPClient … this is a simple client project to test calling the MCP servers
The code is simple – thanks to the C# SDK, which does the bulk of the work.
ColorsMCP-http
Check program.cs to see how the server application is instantiated with MCP support.
var builder = WebApplication.CreateBuilder(args);
builder.Services
.AddMcpServer()
.WithHttpTransport()
.WithTools();
builder.Services.AddCors(options =>
{
options.AddDefaultPolicy(policy =>
{
policy.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod();
});
});
builder.Services.AddSingleton();
var app = builder.Build();
var colorsService = app.Services.GetRequiredService();
app.UseCors();
app.MapMcp();
app.MapGet(“/health”, () => “Healthy”);
app.Run();
We can see that the startup logic .WithTools refers to a class called ColorsTools – this is what contains our MCP Tools. We shall look at this in detail shortly.
ColorsCommonMCP
The project contains our common code – that is used by the projects to support different transport protocols.
The Colors knowledge is hard coded in a JSON file. But other such servers might access information in databases or call APIs.
[
{
“name”: “ALICEBLUE”,
“hexcode”: “#F0F8FF”,
“rgb”: “RGB(240, 248, 255)”,
“families”: [ “white” ]
},
{
“name”: “ANTIQUEWHITE”,
“hexcode”: “#FAEBD7”,
“rgb”: “RGB(250, 235, 215)”,
“families”: [ “white”, “tan” ]
},
{
“name”: “AQUA”,
“hexcode”: “#00FFFF”,
“rgb”: “RGB(0, 255, 255)”,
“families”: [ “blue”, “aqua” ]
},
etc
]
The three MCP Tools are located in ColorsTools.cs
using ModelContextProtocol.Server;
using System.ComponentModel;
using System.Text.Json;
namespace ColorsCommonMCP;
[McpServerToolType]
public sealed class ColorsTools
{
private readonly ColorsService colorsService;
public ColorsTools(ColorsService colorsService)
{
this.colorsService = colorsService;
}
[McpServerTool, Description(ColorsInfo.GetAllColorsToolDescription)]
public async Task GetAllColors()
{
var colors = await colorsService.GetColors();
return JsonSerializer.Serialize(colors, ColorsContext.Default.ListColors);
}
[McpServerTool, Description(ColorsInfo.GetColorsByFamilyToolDescription)]
public async Task GetColorByFamily(
[Description(ColorsInfo.GetColorsByFamilyParamFamilyDescription)] string family)
{
var colors = await colorsService.GetColorsByFamily(family);
return JsonSerializer.Serialize(colors, ColorsContext.Default.ListColors);
}
[McpServerTool, Description(ColorsInfo.GetColorToolDescription)]
public async Task GetColor([Description(ColorsInfo.GetColorParamNameDescription)] string name)
{
var colors = await colorsService.GetColors(name);
return JsonSerializer.Serialize(colors, ColorsContext.Default.Colors);
}
}
The annotations on the functions are crucial, as they are used by the program logic to identify and link to the appropriate tools.
The description fields within these annotations must be clear and precise, as they are used by the AI logic to determine whether a particular tool should be called to fulfil a given request.
Deployment
The ColorsMCP-http project includes a Docker file to build a container. This makes it simple to deploy e.g. to Azure App Service.
The Command to build the container is in the repo ReadMe file.
Test
A client test utility was included in the solution. This examines the server to see what Tools it exposes, and then it invoked the Tool to get the Red information.
Alternatively use the MCP Inspector utility – instructions to run this are in the ReadMe file.
—
Mark Harrison https://markharrison.io/