KristofferStrube.Blazor.WebMCP 0.1.0-alpha.1

Prefix Reserved
This is a prerelease version of KristofferStrube.Blazor.WebMCP.
dotnet add package KristofferStrube.Blazor.WebMCP --version 0.1.0-alpha.1
                    
NuGet\Install-Package KristofferStrube.Blazor.WebMCP -Version 0.1.0-alpha.1
                    
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="KristofferStrube.Blazor.WebMCP" Version="0.1.0-alpha.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="KristofferStrube.Blazor.WebMCP" Version="0.1.0-alpha.1" />
                    
Directory.Packages.props
<PackageReference Include="KristofferStrube.Blazor.WebMCP" />
                    
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 KristofferStrube.Blazor.WebMCP --version 0.1.0-alpha.1
                    
#r "nuget: KristofferStrube.Blazor.WebMCP, 0.1.0-alpha.1"
                    
#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 KristofferStrube.Blazor.WebMCP@0.1.0-alpha.1
                    
#: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=KristofferStrube.Blazor.WebMCP&version=0.1.0-alpha.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=KristofferStrube.Blazor.WebMCP&version=0.1.0-alpha.1&prerelease
                    
Install as a Cake Tool

License: MIT GitHub issues GitHub forks GitHub stars

Blazor.WebMCP

A Blazor wrapper for the WebMCP browser API. The Web API enables the browser to provide tools that can be accessed by AI agents and assistive technologies to create collaborative, human-in-the-loop workflows. This project implements a wrapper around the API for Blazor so that we can easily and safely expose our own tools in C# through the WebMCP API.

The browser API is not stable yet, so this project might break in the future if the API changes

Demo

The sample project can be demoed at https://kristofferstrube.github.io/Blazor.WebMCP/

On each page, you can find the corresponding code for the example in the top right corner.

On the API Coverage Status page, you can see how much of the WebIDL specs this wrapper has covered.

Getting started

I don't have a NuGet package out for the library yet, but it is planned. Once it is out you can follow this small guide to add your own tools to your Blazor App.

Using the library you can add your own WebMCP tools to your web page. First you need to register a service in your service collection using the following extension:

builder.Services.AddModelContextService();

Then in some page you can inject the IModelContextService to register your own tool.

@using KristofferStrube.Blazor.DOM
@using KristofferStrube.Blazor.WebMCP
@implements IAsyncDisposable
@inject IModelContextService ModelContextService
@inject IJSRuntime JSRuntime

<PageTitle>Blazor WebMCP</PageTitle>

<h1>@contentFromAI</h1>

@code {
    string contentFromAI = "";
    SupportStatus browserSupport;
    AbortController? toolUnregisterController;

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (!firstRender) return;

        ModelContextTool<ToolArguments, string> tool = new()
        {
            Name = "WriteContent",
            Description = "This tool can write some content to the website.",
            Execute = async (ToolArguments input, ModelContextClient? client) =>
            {
                contentFromAI = input.Message;
                await InvokeAsync(StateHasChanged);
                return "Content was written to the website.";
            }
        };

        toolUnregisterController = await AbortController.CreateAsync(JSRuntime);
        await using AbortSignal toolUnregisterSignal = await toolUnregisterController.GetSignalAsync();

        await ModelContextService.RegisterToolAsync(tool, new ModelContextRegisterToolOptions()
        {
            Signal = toolUnregisterSignal
        });
    }

    public record ToolArguments(string Message);

    public async ValueTask DisposeAsync()
    {
        if (toolUnregisterController is not null)
        {
            await toolUnregisterController.AbortAsync();
            await toolUnregisterController.DisposeAsync();
        }
    }
}

In the above example we also unregister our tool once the user navigated away from the specific page by implementing AsyncDisposable. This is especially important in Blazor WASM where navigation does not reload the page.

The library uses the following other packages to support its features:

This repository was built with help from the following series of articles:

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.

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
0.1.0-alpha.1 23 3/30/2026