Skip to main content
Glama

wpnav_context

Retrieve WordPress site context for AI agent initialization, including focus mode, available tools, active role, and safety settings.

Instructions

Get a compact context dump of the WordPress site including focus mode, available tools, active role, cookbooks, site info, and safety settings. Designed for AI agent initialization.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
compactNoIf true, returns minimal context (~200-300 tokens). If false, includes full tool list and role context.
include_snapshotNoIf true, includes a summary of pages and posts. Increases token usage.

Implementation Reference

  • Handler for the wpnav_context tool. Calls buildContextOutput to generate site context and returns it as JSON, with error handling.
    /**
     * Handler for wpnav_context
     *
     * Returns context dump for AI agent initialization.
     */
    export async function contextToolHandler(
      args: { compact?: boolean; include_snapshot?: boolean },
      context: ToolExecutionContext
    ): Promise<ToolResult> {
      const { compact = true, include_snapshot = false } = args;
    
      try {
        const contextOutput = await buildContextOutput(context, {
          compact,
          includeSnapshot: include_snapshot,
        });
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(contextOutput, null, 2),
            },
          ],
        };
      } catch (error) {
        const errorMessage = error instanceof Error ? error.message : String(error);
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(
                {
                  error: 'CONTEXT_FAILED',
                  message: `Failed to gather context: ${errorMessage}`,
                  hint: 'Ensure WordPress site is reachable and WP Navigator plugin is active',
                },
                null,
                2
              ),
            },
          ],
        };
      }
    }
  • Tool definition object for wpnav_context, including name, description, and inputSchema with optional compact and include_snapshot parameters.
    /**
     * Tool definition for wpnav_context
     */
    export const contextToolDefinition = {
      name: 'wpnav_context',
      description:
        'Get a compact context dump of the WordPress site including focus mode, available tools, active role, cookbooks, site info, and safety settings. Designed for AI agent initialization.',
      inputSchema: {
        type: 'object' as const,
        properties: {
          compact: {
            type: 'boolean',
            description:
              'If true, returns minimal context (~200-300 tokens). If false, includes full tool list and role context.',
            default: true,
          },
          include_snapshot: {
            type: 'boolean',
            description: 'If true, includes a summary of pages and posts. Increases token usage.',
            default: false,
          },
        },
      },
    };
  • Registers the wpnav_context tool definition and handler with the central toolRegistry.
    /**
     * Register the context tool
     */
    export function registerContextTool(): void {
      toolRegistry.register({
        definition: contextToolDefinition,
        handler: contextToolHandler,
        category: ToolCategory.CORE,
      });
    }
  • Core helper function that orchestrates gathering of all context data: introspect WP site, load manifest, get focus mode/tools/role/cookbooks/safety/AI settings, and builds the ContextOutput object.
    export async function buildContextOutput(
      context: ToolExecutionContext,
      options: { compact?: boolean; includeSnapshot?: boolean } = {}
    ): Promise<ContextOutput> {
      // 1. Fetch introspect data from WordPress
      const introspect = (await context.wpRequest('/wpnav/v1/introspect')) as Record<string, unknown>;
    
      // 2. Load manifest
      const manifestResult = loadManifest();
      const manifest =
        manifestResult.found && manifestResult.manifest && isManifestV2(manifestResult.manifest)
          ? manifestResult.manifest
          : null;
    
      // 3. Get focus mode
      const focusMode = manifest ? getFocusMode(manifest) : 'content-editing';
      const focusModePreset = getFocusModePreset(focusMode);
    
      // 4. Get enabled tools
      const allTools = toolRegistry.getAllDefinitions();
      const enabledTools = allTools.filter((t) => toolRegistry.isEnabled(t.name));
      const toolsByCategory = groupToolsByCategory(enabledTools);
    
      // 5. Get active role
      const activeRoleSlug = runtimeRoleState.getRole();
      let activeRole: LoadedRole | null = null;
      if (activeRoleSlug) {
        activeRole = getRole(activeRoleSlug) || null;
      }
    
      // 6. Get cookbooks
      const { cookbooks: availableCookbooks } = discoverCookbooks();
      const loadedCookbooks: string[] = [];
      const recommendedCookbooks: string[] = [];
    
      // Check for detected plugins that have matching cookbooks
      const detectedPlugins = detectPlugins(introspect);
      for (const cookbook of availableCookbooks.values()) {
        const cookbookSlug = cookbook.plugin.slug.toLowerCase();
        const cookbookPluginName = cookbook.plugin.name.toLowerCase();
        for (const plugin of detectedPlugins) {
          const pluginLower = plugin.toLowerCase();
          if (
            pluginLower.includes(cookbookSlug) ||
            cookbookSlug.includes(pluginLower) ||
            pluginLower.includes(cookbookPluginName) ||
            cookbookPluginName.includes(pluginLower)
          ) {
            recommendedCookbooks.push(cookbook.plugin.name);
            break;
          }
        }
      }
    
      // 7. Get safety settings
      const safety = manifest ? getManifestSafetyV2(manifest) : null;
      const safetyMode = safety?.mode || 'normal';
      const safetyOps = getSafetyOperations(safetyMode);
    
      // 8. Get AI settings
      const ai = manifest ? getManifestAI(manifest) : null;
    
      // 9. Determine environment
      const environment = 'production';
    
      // Build context output
      const contextOutput: ContextOutput = {
        focus_mode: {
          name: focusMode,
          description: focusModePreset.description,
          token_estimate: focusModePreset.tokenEstimate,
        },
        tools: {
          total_available: allTools.length,
          enabled: enabledTools.length,
          by_category: toolsByCategory,
          // Include tool list only if not compact mode
          ...(!options.compact ? { list: enabledTools.map((t) => t.name) } : {}),
        },
        role: activeRole
          ? {
              active: activeRoleSlug,
              name: activeRole.name,
              context: !options.compact ? activeRole.context : null,
              focus_areas: activeRole.focus_areas || [],
              tools_allowed: activeRole.tools?.allowed || [],
              tools_denied: activeRole.tools?.denied || [],
            }
          : null,
        cookbooks: {
          loaded: loadedCookbooks,
          available: Array.from(availableCookbooks.keys()),
          recommended: recommendedCookbooks,
        },
        site: {
          name: (introspect.site_name as string) || null,
          url: context.config.baseUrl,
          plugin_version:
            (introspect.plugin_version as string) || (introspect.version as string) || null,
          plugin_edition: (introspect.edition as string) || null,
          detected_plugins: detectedPlugins,
          page_builder: (introspect.page_builder as string) || null,
        },
        safety: {
          mode: safetyMode,
          enable_writes: context.config.toggles.enableWrites,
          allowed_operations: safetyOps.allowed,
          blocked_operations: safetyOps.blocked,
        },
        ai: {
          instructions: ai?.instructions || null,
          prompts_path: ai?.prompts_path || null,
        },
        environment,
      };
    
      return contextOutput;
    }
  • wpnav_context is listed in META_TOOLS, enabling direct execution via the MCP server's CallTool handler (bypassing the general wpnav_execute requirement).
    const META_TOOLS = new Set([
      'wpnav_introspect',
      'wpnav_search_tools',
      'wpnav_describe_tools',
      'wpnav_execute',
      'wpnav_context',
    ]);
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It discloses that the tool returns a 'compact context dump' and mentions token usage implications ('~200-300 tokens,' 'Increases token usage'), which adds useful behavioral context. However, it does not detail aspects like rate limits, error handling, or authentication needs, leaving some gaps for a tool with no annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded, with the first sentence covering the core purpose and components, and the second sentence adding key usage context. Every sentence earns its place by providing essential information without redundancy or fluff.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (initialization-focused with parameters controlling output detail), no annotations, and no output schema, the description is fairly complete. It covers the purpose, components, usage context, and hints at behavioral aspects like token usage. However, it could be more complete by specifying the exact format of the returned context or error scenarios, but it's adequate for a read-only tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the input schema already fully documents the two parameters (compact and include_snapshot) with clear descriptions. The description does not add any meaning beyond what the schema provides, such as explaining why these parameters matter or their impact on initialization. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'Get' and specifies the resource 'compact context dump of the WordPress site' with detailed components listed (focus mode, available tools, active role, etc.). It explicitly distinguishes this tool from siblings by noting it's 'Designed for AI agent initialization,' suggesting it's for setup rather than ongoing operations like wpnav_execute or wpnav_search_tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use this tool ('Designed for AI agent initialization'), indicating it's for initial setup. However, it does not explicitly state when not to use it or name specific alternatives among the sibling tools (e.g., wpnav_describe_tools might overlap), so it lacks full exclusion guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/littlebearapps/wp-navigator-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server