Community Example
Full-stack Nuxt 3 with SSR support by Mike Chao
Client-Only Plugin
Create a plugin that initializes WebMCP on the client:Basic Usage
Useimport.meta.client to guard registration:
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Integrate WebMCP tools with Nuxt 3, handling SSR safely.
import '@mcp-b/global';
export default defineNuxtPlugin(() => {
// .client.ts suffix ensures this only runs in browser
});
import.meta.client to guard registration:
<script setup lang="ts">
import { onMounted, onUnmounted } from 'vue';
let reg: { unregister: () => void } | null = null;
if (import.meta.client) {
onMounted(() => {
reg = navigator.modelContext.registerTool({
name: 'get_page',
description: 'Get current page info',
inputSchema: { type: 'object', properties: {} },
async execute() {
return { content: [{ type: 'text', text: window.location.pathname }] };
}
});
});
onUnmounted(() => reg?.unregister());
}
</script>
<script setup lang="ts">
const route = useRoute();
const { data: product } = await useFetch(`/api/products/${route.params.id}`);
let reg: { unregister: () => void } | null = null;
if (import.meta.client) {
onMounted(() => {
reg = navigator.modelContext.registerTool({
name: 'get_product',
description: 'Get current product details',
inputSchema: { type: 'object', properties: {} },
async execute() {
if (!product.value) return { content: [{ type: 'text', text: 'No product' }] };
return { content: [{ type: 'text', text: JSON.stringify(product.value) }] };
}
});
});
onUnmounted(() => reg?.unregister());
}
</script>
<template>
<ClientOnly>
<ToolRegistrationComponent />
</ClientOnly>
<NuxtPage />
</template>
'navigator is not defined' error
import.meta.client check.client.ts suffix for plugins<ClientOnly> componentonMounted hook (runs client-side only)Tools disappear after navigation
app.vue or a layout so they persist across routes.Was this page helpful?
