This guide will help you create your first MCP server using SharpMCP.
Install the complete SharpMCP package:
dotnet add package SharpMCP.Server
This automatically includes SharpMCP.Core
and SharpMCP.Tools.Common
.
dotnet new console -n MyMcpServer
cd MyMcpServer
dotnet add package SharpMCP.Server
using SharpMCP.Core.Tools;
using SharpMCP.Core.Schema;
[McpTool("greet", Description = "Greets a person with a custom message")]
public class GreetTool : McpToolBase<GreetArgs>
{
public override string Name => "greet";
public override string? Description => "Greets a person with a custom message";
protected override Task<ToolResponse> ExecuteAsync(GreetArgs args, CancellationToken ct)
{
var message = $"Hello, {args.Name}! {args.Message}";
return Task.FromResult(Success(message));
}
}
public class GreetArgs
{
[JsonRequired]
[JsonDescription("Name of the person to greet")]
public string Name { get; set; } = "";
[JsonDescription("Custom greeting message")]
public string Message { get; set; } = "Nice to meet you!";
}
using SharpMCP.Server;
using SharpMCP.Tools.Common;
class Program
{
static async Task Main(string[] args)
{
var server = new McpServerBuilder()
.WithName("MyMcpServer")
.WithVersion("1.0.0")
.AddTool(new GreetTool())
.AddFileSystemTools() // Optional: add built-in file tools
.Build();
await server.RunAsync();
}
}
dotnet run
Your server will start and communicate via stdin/stdout using the MCP protocol.
SharpMCP includes comprehensive file system tools:
var server = new McpServerBuilder()
.WithName("FileServer")
.WithVersion("1.0.0")
.AddFileSystemTools(allowedDirectories: [
@"C:\MyProject",
@"C:\Data"
])
.Build();
Available tools:
read_file
- Read file contentswrite_file
- Write/create fileslist_directory
- List directory contentssearch_files
- Search with patternsarchive_operations
- ZIP operationsdotnet run
var server = new McpServerBuilder()
.AddTool(new GreetTool())
.Build();
var response = await server.ExecuteToolAsync("greet", new {
name = "Alice",
message = "Welcome!"
});
Console.WriteLine(response.Content[0].Text); // "Hello, Alice! Welcome!"