Skip to content

feat: WebMCP polyfill — register skills tools with navigator.modelContext#150

Open
dfinityianblenke wants to merge 1 commit intomainfrom
ianblenke/webmcp-polyfill
Open

feat: WebMCP polyfill — register skills tools with navigator.modelContext#150
dfinityianblenke wants to merge 1 commit intomainfrom
ianblenke/webmcp-polyfill

Conversation

@dfinityianblenke
Copy link
Copy Markdown

@dfinityianblenke dfinityianblenke commented Apr 2, 2026

Summary

Registers list_skills, get_skill, and search_skills with navigator.modelContext so AI agents can call them as tools from any browser — Chrome 146+ natively, all others via the inline polyfill.

Two changes:

public/webmcp-setup.js — self-contained polyfill + tool registration

  • Installs a navigator.modelContext shim if the native API is absent (non-Chrome-146+)
  • Registers the three tools using the site's existing /.well-known/skills/ static endpoints — zero new dependencies, works right now
  • execute() implementations use plain fetch(): no @dfinity/agent, no bundler, no CDN
  • When PR feat: skills canister — list_skills, get_skill, search_skills #148 is deployed and @dfinity/webmcp is published to npm, the execute() bodies can be upgraded to full ICWebMCP canister calls with certified responses

src/layouts/BaseLayout.astro — two additions

How the three tools work today (static API):

Tool Implementation
list_skills GET /.well-known/skills/index.json
get_skill(name) GET /.well-known/skills/{name}/SKILL.md
search_skills(query) filter on index.json by name + description

Upgrade path (post PR #148 + npm publish):

const { installPolyfill, ICWebMCP } = await import('@dfinity/webmcp');
installPolyfill();
const webmcp = new ICWebMCP({ manifestUrl: '/.well-known/webmcp.json' });
await webmcp.registerAll(); // uses Candid query calls with certified responses

Test plan

  • npm run build passes (verified locally)
  • <link rel="modelcontext"> and <script src="/webmcp-setup.js"> present in built HTML
  • In Chrome 146+ DevTools: navigator.modelContext is the native object; webmcp-setup.js still runs but polyfill install is skipped
  • In Firefox/Safari: navigator.modelContext._registry has three tools registered after page load
  • navigator.modelContext._registry.get('list_skills').execute() returns the skills index
  • navigator.modelContext._registry.get('get_skill').execute({name:'motoko'}) returns SKILL.md content

This optionally (but ideally) extends PR #149, and that should be merged first, which also depends on PR #148

Registers list_skills, get_skill, and search_skills with
navigator.modelContext so AI agents can call them as tools regardless of
browser: Chrome 146+ uses the native WebMCP API, all others pick up the
inline polyfill installed by this script.

- public/webmcp-setup.js — self-contained polyfill + tool registration
  Uses the existing /.well-known/skills/ static API endpoints (no canister
  or @dfinity/webmcp dependency required). When PR #148 is deployed and
  @dfinity/webmcp is published, the execute() functions can be upgraded to
  use ICWebMCP for full Candid canister calls with certified responses.

- src/layouts/BaseLayout.astro
  <link rel="modelcontext" href="/.well-known/webmcp.json"> — signals
  Chrome 146+ to load the manifest automatically.
  <script src="/webmcp-setup.js" defer> — loads the polyfill on every page.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dfinityianblenke dfinityianblenke requested review from a team and JoshDFN as code owners April 2, 2026 14:44
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

Skill Validation Report

No skill files were changed in this PR — validation skipped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant