Skip to content

feat: Add C# / .NET Server SDK #188

@tlewers01

Description

@tlewers01

Summary

I'd like to contribute a C# / .NET server SDK (McpUi.Server) for mcp-ui. This aligns with the roadmap item: "Add SDKs for additional programming languages (in progress)".

I'm actively building an MCP server in C# that uses _meta.ui.resourceUri to deliver interactive UI, and I've been manually constructing the UIResource payloads. A proper SDK would formalize this and give the growing .NET MCP ecosystem first-class mcp-ui support.

Scope

Server SDK only — matching the pattern of the existing Python and Ruby SDKs. No client SDK is needed (that's a React/browser concern).

What would be included

Component Description
CreateUIResource() Core factory function — URI validation, rawHtml/externalUrl handling, text/blob encoding
Type definitions UIResource, CreateUIResourceOptions, RawHtmlPayload, ExternalUrlPayload, content payload discriminated unions
UI metadata Metadata prefixing (mcpui.dev/ui-), preferred-frame-size, initial-render-data
External URL fetching Async HTTP fetch with SSRF protections (private IP blocking), <base> tag injection, size limits — matching the TypeScript SDK's behavior
UI Action result helpers Factory methods for tool, prompt, link, intent, notify action types
Custom exceptions McpUiServerException, InvalidUriException, InvalidContentException, EncodingException
Unit tests Full coverage using xUnit — porting the test cases from the Python SDK
README Installation, usage examples, API reference

Proposed file structure

sdks/
└── csharp/
    └── server/
        ├── McpUi.Server.sln
        ├── src/
        │   └── McpUi.Server/
        │       ├── McpUi.Server.csproj
        │       ├── McpUiServer.cs          # Core CreateUIResource
        │       ├── Types.cs                # All type definitions
        │       ├── UIActionResults.cs      # Action result helpers
        │       ├── Utilities.cs            # URL validation, encoding, helpers
        │       └── Exceptions.cs           # Custom exceptions
        └── tests/
            └── McpUi.Server.Tests/
                ├── McpUi.Server.Tests.csproj
                ├── CreateUIResourceTests.cs
                ├── MetadataTests.cs
                └── UIActionResultTests.cs

Dependencies

  • ModelContextProtocol — the official C# MCP SDK, provides EmbeddedResourceBlock, TextResourceContents, BlobResourceContents
  • Target framework: net8.0 (matching the official C# MCP SDK)

Usage example

using McpUi.Server;

var resource = await McpUiServer.CreateUIResourceAsync(new CreateUIResourceOptions
{
    Uri = "ui://my-server/widget",
    Content = new RawHtmlPayload("<h1>Interactive Widget</h1>"),
    Encoding = ContentEncoding.Text,
    UIMetadata = new UIResourceMetadata
    {
        PreferredFrameSize = ("800px", "600px")
    }
});

Questions for maintainers

  1. NuGet package naming: I'm planning McpUi.Server to follow .NET conventions. Any preferences? (MCP.UI.Server, McpUI.Server, etc.)
  2. External URL fetching: The TypeScript SDK does full HTTP fetch + <base> tag injection + SSRF protection. The Python SDK stores the URL string as-is. I'd like to match the TypeScript behavior for feature parity — does that align with your expectations?
  3. CI integration: Should the initial PR include a test:csharp script in the root package.json (similar to test:ruby), or should that be a follow-up?

Happy to discuss further before starting work. Looking forward to contributing!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions