Skip to content

[WebModelContext] Consider aligning with MCP's existing API rather than creating a new one #1118

@MiguelsPizza

Description

@MiguelsPizza

Thanks for putting this explainer together. I maintain WebMCP, which is basically what you're proposing but using the existing MCP SDK interface. You can use it today via a script tag:

<script src="https://unpkg.com/@mcp-b/global@latest"></script>
<script>
    window.mcp.registerTool(
      "add-todo",
      {
        title: "Add Todo",
        description: "Add a new todo item",
        inputSchema: {
          type: "object",
          properties: {
            text: { type: "string", description: "The text of the todo item" }
          },
          required: ["text"]
        }
      },
      async ({ text }) => {
        // Add todo item and update UI
        return { content: [{ type: "text", text: `Added: ${text}` }] };
      }
    );
</script>

I think we should stick as close as possible to MCP's existing API. Here's why:

Dynamic tools

The provideContext approach with static tool lists doesn't handle runtime changes well. MCP's registerTool returns a handle you can clean up:

const unregister = window.mcp.registerTool("admin-tool", config, handler);

// Later, when user logs out
unregister.remove();

This is crucial for real apps where tools come and go based on state (empty cart = no checkout tool, logged out = no admin tools). This is also a very effective pattern for context management and tool bloat mitigation (two very pressing issues in the MCP ecosystem at the moment)

Don't fragment the ecosystem

MCP has effectively won with 1000s of servers and adoption from basically every major LLM interface. If browser tabs use the same protocol, they're instantly compatible with everything else. Web devs can reuse backend MCP code in the frontend. Agents can chain tools across sites without special handling. Currently With WebMCP, I can just proxy the Website tools through a web extension and native host which re-exposes the server for Hosts like Claude Desktop to use. No custom translation code is needed since I am basically just relaying MCP JSON-RPC messages.

Creating a web-specific API means every MCP client needs browser-specific code. That's a barrier to adoption and a maintenance burden on those building tooling around this api.

WebMCP can serve as a testing ground for this approach if that helps. We have working implementations and a pretty active ecosystem considering I only open sourced it a few weeks ago. Happy to collaborate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions