McpSseServer 1.0.5

dotnet add package McpSseServer --version 1.0.5
                    
NuGet\Install-Package McpSseServer -Version 1.0.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="McpSseServer" Version="1.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="McpSseServer" Version="1.0.5" />
                    
Directory.Packages.props
<PackageReference Include="McpSseServer" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add McpSseServer --version 1.0.5
                    
#r "nuget: McpSseServer, 1.0.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package McpSseServer@1.0.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=McpSseServer&version=1.0.5
                    
Install as a Cake Addin
#tool nuget:?package=McpSseServer&version=1.0.5
                    
Install as a Cake Tool

McpSseServer

A lightweight .NET library for building MCP (Model Context Protocol) servers with SSE (Server-Sent Events) transport in ASP.NET Core.

NuGet License: MIT

?? Features

  • Minimal Setup - Get an MCP server running in just 8 lines of code
  • Auto-Discovery - Classes marked with [McpHandler] are automatically registered
  • Strongly-Typed - Write normal C# methods with typed parameters - no JSON parsing!
  • SSE Transport - Full Server-Sent Events support with HTTP/1.1 compatibility
  • Fallback Support - Automatic fallback to direct HTTP responses

?? Installation

dotnet add package McpSseServer

Or via Package Manager:

Install-Package McpSseServer

?? Quick Start

Step 1: Create a new ASP.NET Core Web API project

dotnet new web -n MyMcpServer
cd MyMcpServer
dotnet add package McpSseServer

Step 2: Configure Program.cs

using McpSseServer;

var builder = WebApplication.CreateBuilder(args);

builder.ConfigureKestrelForSse();
builder.Services.AddMcpSseServer(options =>
{
    options.ServerName = "My-MCP-Server";
    options.ServerVersion = "1.0.0";
});

var app = builder.Build();

app.UseMcpSseServer();  // Auto-discovers all [McpHandler] classes!

app.Run();

Step 3: Create your handlers

Create a new file Handlers/MyTools.cs:

using McpSseServer.Attributes;

namespace MyMcpServer.Handlers;

[McpHandler]
public class MyTools
{
    [McpTool("greet", "Greets a person by name")]
    public string Greet(string name)
    {
        return $"Hello, {name}!";
    }

    [McpTool("add", "Adds two numbers")]
    public string Add(double a, double b)
    {
        return $"Result: {a + b}";
    }
}

Step 4: Run and connect

dotnet run

Your MCP server is now running at http://localhost:5000/sse ??


?? Creating Tools

Tools are functions that the AI can call to perform actions.

Basic Tool

using McpSseServer.Attributes;

[McpHandler]
public class BasicTools
{
    [McpTool("generate_uuid", "Generates a new random UUID")]
    public string GenerateUuid()
    {
        return Guid.NewGuid().ToString();
    }
}

Tool with Parameters

[McpHandler]
public class MathTools
{
    [McpTool("calculate", "Performs arithmetic calculations")]
    public string Calculate(
        [McpParameter("Operation to perform", EnumValues = ["add", "subtract", "multiply", "divide"])] string operation,
        [McpParameter("First operand")] double a,
        [McpParameter("Second operand")] double b)
    {
        var result = operation switch
        {
            "add" => a + b,
            "subtract" => a - b,
            "multiply" => a * b,
            "divide" when b != 0 => a / b,
            "divide" => double.NaN,
            _ => throw new ArgumentException($"Unknown operation: {operation}")
        };

        return double.IsNaN(result) ? "Error: Division by zero" : $"{a} {operation} {b} = {result}";
    }
}

Tool with Optional Parameters

[McpHandler]
public class SearchTools
{
    [McpTool("search", "Searches for items")]
    public string Search(
        [McpParameter("Search query")] string query,
        [McpParameter("Maximum results")] int limit = 10,      // Optional with default
        [McpParameter("Sort order")] string? order = null)     // Nullable = optional
    {
        return $"Searching '{query}' with limit {limit}, order {order ?? "default"}";
    }
}

Parameter Type Mapping

C# Type JSON Schema Type Required
string string Yes
int, long integer Yes
double, float number Yes
bool boolean Yes
enum string (with values) Yes
string?, int? Same as base No
param = value Same as base No

?? Creating Resources

Resources provide read-only data that the AI can access.

using System.Text.Json;
using McpSseServer.Attributes;

[McpHandler]
public class MyResources
{
    [McpResource("config://app/settings", "App Settings", "Application configuration", "application/json")]
    public string GetAppSettings()
    {
        return JsonSerializer.Serialize(new
        {
            theme = "dark",
            language = "en",
            version = "1.0.0"
        });
    }

    [McpResource("docs://readme", "README", "Application documentation", "text/plain")]
    public string GetReadme()
    {
        return "# My Application\n\nWelcome to the documentation!";
    }

    [McpResource("info://server/status", "Server Status", "Current server status", "application/json")]
    public string GetServerStatus()
    {
        return JsonSerializer.Serialize(new
        {
            status = "running",
            timestamp = DateTime.UtcNow,
            uptime = TimeSpan.FromMinutes(42)
        });
    }
}

Resource Attribute Parameters

[McpResource(
    uri: "scheme://path/to/resource",  // Unique identifier
    name: "Display Name",               // Human-readable name
    description: "Description",         // What the resource contains
    mimeType: "application/json"        // Content type (default: text/plain)
)]

?? Creating Prompts

Prompts are reusable templates that help guide AI interactions.

using McpSseServer.Attributes;

[McpHandler]
public class MyPrompts
{
    [McpPrompt("greeting", "Generates a personalized greeting")]
    public string Greeting(
        [McpArgument("Name to greet")] string name,
        [McpArgument("Style: formal, casual, enthusiastic")] string style = "casual")
    {
        return style switch
        {
            "formal" => $"Dear {name}, I hope this message finds you well.",
            "enthusiastic" => $"Hey {name}! SO excited to chat with you!",
            _ => $"Hi {name}! How can I help you today?"
        };
    }

    [McpPrompt("code_review", "Creates a code review prompt")]
    public string CodeReview(
        [McpArgument("Programming language")] string language,
        [McpArgument("Focus area")] string focus = "general")
    {
        return $"Please review the following {language} code with focus on {focus}.";
    }

    [McpPrompt("summarize", "Creates a summarization prompt")]
    public string Summarize(
        [McpArgument("Summary length: brief, medium, detailed")] string length = "medium")
    {
        return length switch
        {
            "brief" => "Provide a 1-2 sentence summary.",
            "detailed" => "Provide a comprehensive summary with all key points.",
            _ => "Provide a balanced summary in 3-5 sentences."
        };
    }
}

?? Configuration Options

builder.Services.AddMcpSseServer(options =>
{
    // Server identity
    options.ServerName = "My-MCP-Server";
    options.ServerVersion = "1.0.0";
    
    // MCP protocol version
    options.ProtocolVersion = "2024-11-05";
    
    // Logging
    options.EnableLogging = true;      // Log MCP requests/responses
    options.EnableHttpLogging = true;  // Log HTTP requests
    
    // Endpoints (customize if needed)
    options.SseEndpoint = "/sse";           // SSE connection endpoint
    options.MessageEndpoint = "/message";   // Message endpoint
    
    // CORS configuration (opt-in)
    options.UseDefaultCors = true;          // Enable permissive CORS for browser clients
});

CORS Configuration

By default, CORS is not enabled. If you need your MCP server to be accessible from browser-based clients, you can enable the built-in permissive CORS policy:

builder.Services.AddMcpSseServer(options =>
{
    options.UseDefaultCors = true;  // Enables AllowAnyOrigin, AllowAnyMethod, AllowAnyHeader
});

Note: For production environments, consider configuring your own CORS policy instead of using the permissive default.


?? Attribute Reference

Attribute Target Purpose
[McpHandler] Class Marks class for auto-discovery
[McpTool(name, description)] Method Defines a callable tool
[McpResource(uri, name, desc, mime)] Method Defines a readable resource
[McpPrompt(name, description)] Method Defines a prompt template
[McpParameter(description)] Parameter Adds metadata to tool parameters
[McpArgument(description)] Parameter Adds metadata to prompt arguments

?? Connecting Clients

MCP Inspector

npx @anthropic/mcp-inspector http://localhost:5000/sse

Claude Desktop

Add to your Claude Desktop config (claude_desktop_config.json):

{
  "mcpServers": {
    "my-server": {
      "url": "http://localhost:5000/sse"
    }
  }
}

Custom Client

Connect to the SSE endpoint at /sse. The server will send an endpoint event with the message URL:

event: endpoint
data: http://localhost:5000/message?sessionId=<guid>

?? Example Project Structure

MyMcpServer/
??? Program.cs
??? Handlers/
?   ??? ToolHandlers.cs      # [McpHandler] with [McpTool] methods
?   ??? ResourceHandlers.cs  # [McpHandler] with [McpResource] methods
?   ??? PromptHandlers.cs    # [McpHandler] with [McpPrompt] methods
??? Properties/
?   ??? launchSettings.json
??? MyMcpServer.csproj

?? Complete Example

Program.cs

using McpSseServer;

var builder = WebApplication.CreateBuilder(args);

builder.ConfigureKestrelForSse();
builder.Services.AddMcpSseServer(options =>
{
    options.ServerName = "Demo-MCP-Server";
    options.ServerVersion = "1.0.0";
});

var app = builder.Build();
app.UseMcpSseServer();
app.Run();

Handlers/DemoHandlers.cs

using System.Text.Json;
using McpSseServer.Attributes;

namespace MyMcpServer.Handlers;

[McpHandler]
public class DemoHandlers
{
    // === TOOLS ===
    
    [McpTool("get_time", "Gets the current time")]
    public string GetTime(string timezone = "UTC")
    {
        var tz = TimeZoneInfo.FindSystemTimeZoneById(timezone);
        var time = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, tz);
        return $"Current time in {timezone}: {time:yyyy-MM-dd HH:mm:ss}";
    }

    [McpTool("calculate", "Basic calculator")]
    public string Calculate(string operation, double a, double b)
    {
        var result = operation switch
        {
            "add" => a + b,
            "subtract" => a - b,
            "multiply" => a * b,
            "divide" => a / b,
            _ => throw new ArgumentException($"Unknown: {operation}")
        };
        return $"{a} {operation} {b} = {result}";
    }

    // === RESOURCES ===
    
    [McpResource("info://status", "Status", "Server status", "application/json")]
    public string GetStatus()
    {
        return JsonSerializer.Serialize(new { status = "ok", time = DateTime.UtcNow });
    }

    // === PROMPTS ===
    
    [McpPrompt("hello", "Greeting prompt")]
    public string Hello(string name) => $"Hello {name}! How can I help?";
}

?? Source Code

GitHub Repository: https://github.com/keerukee/MCPServer_Sse.git


?? License

MIT License - feel free to use in your projects!


?? Recent Changes

Latest Update

  • CORS Configuration (Opt-in): CORS is now optional and disabled by default. Use UseDefaultCors = true to enable a permissive CORS policy for browser-based clients. This gives you full control over CORS configuration in your application.

?? Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.5 146 1/18/2026
1.0.4 117 1/18/2026
1.0.3 131 1/13/2026
1.0.0 119 1/13/2026