E1 · Both branches
5 minRun the "os dois ramos" block and read deteccao.js line by line.
Done when: node detectar.mjs depois → line sem API · WebMCP ausente, line com stub · WebMCP presente, both with botão Agendar: sim, and saída: 0.
Lesson 4 · 15 min
The two names look like the same thing, but they are not. MCP connects an agent to a server of yours, outside the browser, and it is stable. WebMCP lets the page itself declare tools for the agent running in the browser, and it is a draft. In this lesson you separate the two in one picture and run the feature detection that keeps the site working without the API.
Start the lesson
Goal: place MCP (server) and WebMCP (page) in one picture and see feature detection with fallback running.
Click each block.
MCP: the agent goes to your server. WebMCP: the open page offers tools to the browser's agent. The HTML holds up both.
What changes between the two, in four questions.
MCP: in a process of yours (on the agent's machine over stdio, or at an HTTP address). WebMCP: inside the open tab, in the page's JavaScript.
MCP: the client (the agent) calls the server. WebMCP: the browser's agent reads the list with getTools and runs the tool; the function that runs is the page's.
MCP: stable, revision 2026-07-28 (tutorials with SSE and initialize are from old revisions). WebMCP: a draft that has already been renamed once (from navigator to document, accepted on 05/19/2026). Lesson 5.
WebMCP: experimental as of 10/19/2026 (origin trial Chrome 149–156, Edge 150).
HTML that the agent reads (lesson 3) works for both. If you have a service with an API, the MCP server is the stable step. The page with WebMCP comes in as a lab, always with detection and fallback.
The only WebMCP JavaScript in this course: check whether the API exists and, without it, leave the form as it is. Registering real tools is course 2. The detectar.mjs opens the page without the API and with an empty stub (it is not the API or the polyfill), just to show the two branches.
// deteccao.js — WebMCP feature detection with fallback (course 0 kit, WebMCP Program).
// Spec used: WebMCP, Draft Community Group Report from 2026-10-16 (document.modelContext).
// It is a Community Group draft, not a standard: in Chrome only with an origin trial (149–156) or a local flag.
// Without the API, nothing changes: the form above is still the path for people and agents.
(function () {
const caminho = "modelContext" in document
? "WebMCP presente: aqui a página registraria as ferramentas (curso 2 da formação)"
: "WebMCP ausente: o site segue pelo formulário, igual para todos";
document.documentElement.dataset.webmcp = "modelContext" in document ? "sim" : "nao";
console.log(caminho);
})();cd ~/projetos/formacao-webmcp-base-v72/kit node detectar.mjs depois; echo "saída: $?"
sem API · WebMCP ausente: o site segue pelo formulário, igual para todos · botão Agendar: sim com stub · WebMCP presente: aqui a página registraria as ferramentas (curso 2 da formação) · botão Agendar: sim saída: 0
In both branches the "Agendar" button is still there: the fallback doesn't depend on the API. With the API present, the page would register the tools; without it, the page works the same for everyone.
sem API · (a página não faz detecção) · botão Agendar: não com stub · (a página não faz detecção) · botão Agendar: não saída: 1
Running the same test on antes.html: the page does no detection at all and has no named button. WebMCP code without "modelContext" in document breaks in a browser that doesn't have the API, which today is almost every browser.
Both branches and detection in your copy.
Run the "os dois ramos" block and read deteccao.js line by line.
Done when: node detectar.mjs depois → line sem API · WebMCP ausente, line com stub · WebMCP presente, both with botão Agendar: sim, and saída: 0.
Copy kit/site/deteccao.js to /tmp/oficina/ and add <script src="deteccao.js"></script> at the end of the body of the copy you fixed in lesson 3.
Done when: node detectar.mjs /tmp/oficina/antes.html → both lines with botão Agendar: sim and saída: 0.
Write three lines: which action on your site an agent would ask for; whether it lives in a service with an API (a candidate for MCP, course 1) or only on the page (a candidate for WebMCP, course 2); and which form is the fallback.
Done when: the file with the three lines exists and each action has a named fallback form.
Question 1 of 4
Where does the tool run in an MCP server?skill
Question 2 of 4
What is the WebMCP surface in the October 16, 2026 draft?skill
Question 3 of 4
What is the "modelContext" in document detection for?
Question 4 of 4
Is the detectar.mjs stub the WebMCP polyfill?
Pick an answer. The explanation shows up after you try.