Installation
Why This Package Exists
The official MCP TypeScript SDK has a restriction that prevents registering server capabilities (like tools) after a transport connection is established. This is enforced by this check in theServer class:
- Tools arrive dynamically - Web pages call
window.navigator.modelContext.provideContext({ tools: [...] })at any time - Transport must be ready immediately - The MCP server/transport needs to be connected when the page loads
- Asynchronous registration - Tools are registered as the page’s JavaScript executes, potentially long after initialization
Modifications from Official SDK
BrowserMcpServer Class
TheBrowserMcpServer extends McpServer with these changes:
What’s Re-Exported
This package re-exports almost everything from the official SDK:Types
- All MCP protocol types (
Tool,Resource,Prompt, etc.) - Request/response schemas
- Client and server capabilities
- Error codes and constants
Classes
Server- Base server class (unchanged)McpServer- Aliased toBrowserMcpServerwith our modifications
Utilities
TransportinterfacemergeCapabilitieshelper- Protocol version constants
Usage
Use it exactly like the official SDK:Architecture
Maintenance Strategy
This package is designed for minimal maintenance:- ✅ ~50 lines of custom code
- ✅ Automatic updates for types, protocol, validation via official SDK dependency
- ✅ Single modification point - only capability registration behavior
- ✅ Type-safe - no prototype hacks or unsafe casts
Syncing with Upstream
When the official SDK updates:- Update the catalog version in
pnpm-workspace.yaml - Run
pnpm installto get latest SDK - Test that capability registration still works
- Update this README if SDK behavior changes
Use Cases
Web Model Context API
This package is primarily used by@mcp-b/global to implement the W3C Web Model Context API:
Single-Page Applications
Perfect for SPAs where tools are registered as components mount:Differences from Official SDK
| Feature | Official SDK | @mcp-b/webmcp-ts-sdk |
|---|---|---|
| Tool registration before connect | ✅ Yes | ✅ Yes |
| Tool registration after connect | ❌ No | ✅ Yes |
| Static server capabilities | ✅ Yes | ✅ Yes |
| Dynamic capability announcements | ❌ No | ✅ Yes (tools) |
listChanged capability | Manual | ✅ Pre-registered |
Related Packages
@mcp-b/global- W3C Web Model Context API implementation (uses this package)@mcp-b/transports- Browser-specific MCP transports@modelcontextprotocol/sdk- Official MCP SDK
