Index of every page on this site: llms.txt
All skills
onmax avatar

/vueuse-functions

@b4e1a3f official
by Maxonmax/nuxt-skills729 stars
38
Run it yourself

Apply VueUse composables where appropriate to build concise, maintainable Vue.js / Nuxt features.

Use this Skill: https://skilld.dev/gh/onmax/nuxt-skills/vueuse-functions

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesuseWebMCP.md

โ‰ˆ2k tokens on demand. Your agent reads this file only when SKILL.md points to it.

useWebMCP

Register a WebMCP tool and tie its lifecycle to the current Vue scope.

WebMCP lets a page expose JavaScript functions as "tools" that an AI agent (browser-built-in, iframe-hosted, or extension) can discover and call, instead of scraping the DOM, the accessibility tree, or screenshots. useWebMCP wraps the imperative, AbortSignal-based registration API in a declarative composable: the tool is registered when the composable runs and unregistered automatically when the scope is disposed, so the set of tools an agent sees stays in lockstep with what is actually on screen.

::: warning Experimental The WebMCP spec is ๐Ÿงช experimental and exposes the imperative API on document.modelContext (registerTool + an AbortSignal for unregistration). This composable feature-detects and degrades to a no-op everywhere the API is absent โ€” check isSupported before relying on it. :::

Usage

import { useWebMCP } from '@vueuse/core'
import { shallowRef } from 'vue'

const todos = shallowRef<string[]>([])

const { isSupported, isRegistered, error } = useWebMCP({
  name: 'add-todo',
  description: 'Add a new item to the user\'s active todo list',
  inputSchema: {
    type: 'object',
    properties: {
      text: { type: 'string', description: 'The text content of the todo item' },
    },
    required: ['text'],
  },
  async execute({ text }) {
    todos.value = [...todos.value, text]
    return `Added todo item: "${text}" successfully.`
  },
})

The raw imperative API this wraps looks like:

const controller = new AbortController()

document.modelContext.registerTool({
  name: 'add-todo',
  description: 'Add a new item to the user\'s active todo list',
  inputSchema: { /* โ€ฆ */ },
  async execute({ text }) {
    return { content: [{ type: 'text', text: `Added todo item: "${text}".` }] }
  },
}, { signal: controller.signal })

// Unregister later:
controller.abort()

Result normalization

Whatever execute returns is normalized into a valid MCP tool result:

  • a string โ†’ { content: [{ type: 'text', text }] }
  • undefined/null (no return) โ†’ { content: [] } (success, no payload)
  • a value that is already { content: [...] } โ†’ passed through untouched
  • a thrown value โ€” Error or not (throw 'not signed in', throw { code: 403 }) โ†’ { content: [{ type: 'text', text }], isError: true }, after onError. A failure must never read as success to the agent.
  • a returned Error โ†’ treated exactly like a throw: onError fires, then an isError result
  • anything else (object/array/number) โ†’ JSON-serialized into a text block

Reactive & conditional registration

name, description, inputSchema, annotations and enabled accept refs or getters. Changing a discoverable field re-registers the tool; toggling enabled unregisters and re-registers it. execute, formatOutput and onError are read live at call time, so a changing closure never churns the registration.

import { useWebMCP } from '@vueuse/core'
import { shallowRef } from 'vue'

const signedIn = shallowRef(false)

useWebMCP({
  name: 'checkout',
  description: 'Complete the checkout for the current cart',
  enabled: signedIn, // only exposed to agents while signed in
  annotations: { readOnlyHint: false },
  execute() {
    // โ€ฆ
  },
  onError(err) {
    console.error('checkout tool failed', err)
  },
})

Registering multiple tools

Call useWebMCP once per tool to register several โ€” each call manages its own registration lifecycle.

import { useWebMCP } from '@vueuse/core'

useWebMCP({
  name: 'add-todo',
  description: 'Add a new item to the todo list',
  execute({ text }) {
    // โ€ฆ
  },
})

useWebMCP({
  name: 'clear-todos',
  description: 'Remove every item from the todo list',
  annotations: { readOnlyHint: false },
  execute() {
    // โ€ฆ
  },
})

References

Type Declarations

/**
 * A single block of a WebMCP tool result.
 *
 * @see https://github.com/webmachinelearning/webmcp
 */
export interface WebMCPToolContent {
  type: string
  text?: string
  [key: string]: unknown
}
/**
 * The normalized result an agent receives after a tool runs.
 */
export interface WebMCPToolResponse {
  content: WebMCPToolContent[]
  isError?: boolean
}
/**
 * Hints an author can attach to a tool to shape how an agent uses it.
 */
export interface WebMCPToolAnnotations {
  /**
   * The tool does not mutate state and is safe to call speculatively.
   */
  readOnlyHint?: boolean
  /**
   * The tool may return content that should be treated as untrusted.
   */
  untrustedContentHint?: boolean
  [key: string]: unknown
}
/**
 * The imperative descriptor passed to `document.modelContext.registerTool`.
 */
export interface WebMCPToolDescriptor {
  name: string
  description: string
  inputSchema?: object
  annotations?: WebMCPToolAnnotations
  execute: (args: any) => Promise<WebMCPToolResponse> | WebMCPToolResponse
}
/**
 * The (experimental) imperative WebMCP API surface exposed on `document`.
 */
export interface ModelContext {
  registerTool: (
    tool: WebMCPToolDescriptor,
    options?: {
      signal?: AbortSignal
    },
  ) => void
}
export interface UseWebMCPOptions<Args, Result> extends ConfigurableDocument {
  /**
   * Tool identifier the agent uses to invoke this tool.
   */
  name: MaybeRefOrGetter<string>
  /**
   * Natural-language description the agent reads to decide when to call it.
   */
  description: MaybeRefOrGetter<string>
  /**
   * JSON Schema describing the tool arguments.
   */
  inputSchema?: MaybeRefOrGetter<object | undefined>
  /**
   * Hints (`readOnlyHint`, `untrustedContentHint`, โ€ฆ) shaping agent behavior.
   */
  annotations?: MaybeRefOrGetter<WebMCPToolAnnotations | undefined>
  /**
   * The function the agent calls. May be async. Its return value is normalized
   * into a WebMCP tool result, and any thrown/returned `Error` becomes an
   * `isError` result.
   */
  execute: (args: Args) => Result | Promise<Result>
  /**
   * Register the tool only while this is `true`.
   *
   * @default true
   */
  enabled?: MaybeRefOrGetter<boolean>
  /**
   * Shape the `execute` result before it is normalized into a tool response.
   */
  formatOutput?: (result: Result, args: Args) => unknown
  /**
   * Side effect invoked when `execute` (or `formatOutput`) throws/returns an error.
   */
  onError?: (error: unknown) => void
}
export interface UseWebMCPReturn extends Supportable {
  /**
   * Whether the tool is currently registered with the browser.
   */
  isRegistered: ShallowRef<boolean>
  /**
   * Registration error, e.g. a `NotAllowedError` from a `tools` permissions policy.
   */
  error: ShallowRef<Error | null>
}
/**
 * Register a [WebMCP](https://github.com/webmachinelearning/webmcp) tool and
 * tie its lifecycle to the current scope.
 *
 * The tool is registered when the composable runs (and whenever a discoverable
 * part โ€” `name`, `description`, `inputSchema`, `annotations` or `enabled` โ€”
 * changes) and unregistered automatically on scope dispose, so the tools an
 * agent sees stay in lockstep with what is on screen. Call it multiple times to
 * register multiple tools.
 *
 * The API is experimental (`document.modelContext`), so this feature-detects
 * and degrades to a no-op wherever it is absent.
 *
 * @see https://vueuse.org/useWebMCP
 * @see https://github.com/webmachinelearning/webmcp
 */
export declare function useWebMCP<Args = Record<string, any>, Result = unknown>(
  options: UseWebMCPOptions<Args, Result>,
): UseWebMCPReturn

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts18d3 checks ยท Risk SAFE
  • Gen Agent Trust Hub18d

    This skill provides a comprehensive guide for using VueUse composables in Vue.js and Nuxt projects. The analysis identified several high-capability tools such as Electron IPC access and external script loading, which are standard for web development but provide significant power to an agent. An indirect prompt injection surface exists through the experimental WebMCP integration, which allows web pages to register tools for AI agents.

  • Socket18d

    No alerts

  • Snyk18d

    Risk: LOW ยท No issues

Signed by skilld at b4e1a3f. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 15 hours ago.

Activeupdated 3 weeks ago
metadata
{
  "author": "SerKo <https://github.com/serkodev>",
  "version": "1.0"
}
compatibility
Requires Vue 3 (or above) or Nuxt 3 (or above) project

README badge

README badge for onmax/nuxt-skills/vueuse-functions