Prompts Implement WebMCP in an existing repository

Implement WebMCP in an existing repository

A prompt for analysing an existing repository and implementing WebMCP in a small, realistic and maintainable way. The focus is on identifying the best agent actions, reusing existing frontend and domain logic, avoiding large refactors and delivering concrete code changes, documentation and a test plan.

Giv mig en kaffe

Hvordan det virker

Use this prompt when you want an LLM to implement WebMCP in an existing repository without inventing a loose demo architecture. The prompt is designed to force the model to first analyse the repo, then choose the most valuable and realistic agent actions, and finally make concrete, small and credible code changes.

The prompt is especially useful in codebases with existing UI logic, form flows, services, hooks, stores or actions, where WebMCP should be built on top of existing behaviour instead of duplicating the business logic.

The expected output is:

a short repo analysis
suggestions for suitable WebMCP flows
selection of the best first flows
concrete file changes or a patch/diff
documentation changes
test plan
blockers and assumptions

The prompt prioritises:

small and maintainable integration
reuse of existing code
clear input/output validation
graceful degradation
no large refactors
no pseudocode if a real implementation is possible

Prompt Indhold

You are a senior staff engineer with expertise in frontend architecture, browser APIs, TypeScript/JavaScript, progressive enhancement and agent integrations. Your task is to implement WebMCP in this repository in a way that is correct, minimal, maintainable and true to the existing architecture. Context you must respect: - WebMCP is frontend-oriented and is used to make a live website agent-ready in the browser. - WebMCP must be connected to existing UI and application logic, not duplicated as a separate backend implementation. - Use declarative mechanisms for simple form/standard actions, and imperative registration for dynamic or complex flows. - Implement only what makes sense in this repo. Avoid “demo code” and random tools without real user or product value. - If the repo already has an MCP server, treat WebMCP as a supplement for website interactions, not as a replacement. Way of working: 1. Start by analysing the repository structure. 2. Identify the 3-7 most important user actions that a browser agent should realistically be able to perform. 3. Choose the 1-3 best flows for the first WebMCP implementation based on: - high user/business value - low implementation risk - clear coupling to existing frontend logic - good determinism and verifiability 4. Implement WebMCP with the least invasive change possible to the codebase. 5. Add the necessary documentation, feature flags, fallback behaviour and examples. 6. Return concrete file changes and explain your design choices. Important rules: - First find the existing domain logic, services, actions, hooks, controllers, stores or form handlers, and reuse them. - Do not create new abstractions unless they reduce complexity. - Preserve the repo's existing code style, naming, file structure, state management and test patterns. - Introduce capability detection / graceful degradation so the app works normally without WebMCP. - Do not assume that preview APIs exist in all environments. - Avoid pseudo-implementations. If a real integration cannot be made because of missing API access in the repo's environment, build the best realistic adapter/abstraction and clearly mark what is preview-specific. - Do not make sweeping refactors. - Do not write marketing copy. Technical deliverables: - Implement a small, central WebMCP integration surface, e.g. a module/hook/service that gathers the registration of tools/actions. - Tie tool definitions to existing UI actions or application functions. - Ensure clear input validation, error messages and deterministic outputs. - Ensure that every tool/action has: - a clear name - a precise description - well-defined input fields - an explicit success/error return - a link to real app logic - Where it makes sense, use a declarative approach for forms and an imperative approach for dynamic flows. - Add logs or debug hooks only if they follow the repo's patterns. - Add tests if the repo already has test infrastructure. Otherwise, add at least a verifiable manual test plan. Security and quality requirements: - Do not expose actions that may be dangerous, irreversible or highly privileged without a clear rationale and appropriate guardrails. - Avoid exposing internal helper functions, admin functions or unstable flows. - Protect against invalid input and partial states. - Make sure side effects are clear and preferably idempotent or safely bounded. - If authentication/session/state is relevant, integrate with the existing mechanism instead of bypassing it. How to work step by step: A. Repository analysis - Briefly describe the app's architecture, framework, build system and central domain flows. - Point out exactly which files/modules are relevant to the WebMCP integration. B. Choice of agent actions - Propose the best candidate flows. - Rank them by value and feasibility. - Choose the best first candidates and briefly justify the choice. C. Implementation - Show exactly which files you will change/create. - Then write the concrete code. - Keep the changes small and focused. D. Documentation - Add a README section or docs page with: - what was implemented - where the integration lives - how to extend it with more tools - known limitations - how to test it E. Validation - Provide a short test plan with: - happy path - invalid inputs - unsupported browser / missing WebMCP - auth/state edge cases - regression risks Output format: 1. Short analysis of the repo 2. Selected WebMCP flows 3. Implementation plan 4. Code changes as a patch/diff or complete file blocks 5. Documentation changes 6. Test plan 7. Any blockers or assumptions Very important: - Do not stop after the analysis. Carry out the implementation on a best-effort basis. - If something in the repo is unclear, choose the most conservative, realistic solution and document the assumption. - If WebMCP preview APIs cannot be used directly in this environment, encapsulate the preview dependency behind a small adapter so the rest of the integration remains clean and extensible. - Prioritise a working, small and transparent integration over a “complete” but fragile architecture.

Eksempel på Output

  1. Short analysis of the repo
  • The app is a Next.js frontend with server actions and a search/checkout flow.
  • Relevant files for WebMCP are:
    • app/search/page.tsx
    • components/search/search-form.tsx
    • lib/search/search-service.ts
    • app/cart/actions.ts
    • lib/webmcp/adapter.ts
  1. Selected WebMCP flows
    Prioritised candidate flows:
  2. Product search
  3. Filtering search results
  4. Add to cart

Selected first flows:

  • searchProducts
  • applySearchFilters

Rationale:

  • high user/business value
  • low risk
  • close coupling to existing frontend logic
  • deterministic results
  1. Implementation plan
  • Create a small WebMCP adapter module
  • Register tools centrally
  • Connect tools to the existing search service and filter state
  • Add capability detection and fallback
  • Document setup and testing
  1. Code changes
    Files created:
  • lib/webmcp/adapter.ts
  • lib/webmcp/register-tools.ts

Files changed:

  • app/layout.tsx
  • components/search/search-form.tsx
  • README.md

[then insert concrete code or diff]

  1. Documentation changes
  • New README section: “WebMCP integration”
  • Description of tools, limitations and extension model
  1. Test plan
  • Happy path: agent calls searchProducts with a valid query
  • Invalid input: empty query or invalid filters
  • Browser without WebMCP: normal app behaviour is preserved
  • Auth/state: tool requires an existing session where relevant
  1. Blockers or assumptions
  • Assumes the existing search service is the authoritative source
  • Assumes the preview API does not exist in all environments, so an adapter is used