Skip to main content
Glama
jeffgolden

Cloudflare MCP Server

by jeffgolden

cloudflare-dns-mcp_create_redirect

Create and configure a single URL redirect (Page Rule) for a specified zone, including source and target URLs, redirect type, query string preservation, priority, and status.

Instructions

Create a single URL redirect (Page Rule) for the given zone

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
preserve_query_stringNo
priorityNo
redirect_typeNo
source_urlYes
statusNoactive
target_urlYes
zone_nameYes

Implementation Reference

  • The async handler function that implements the tool logic: parses input, fetches zone ID, constructs page rule payload, posts to Cloudflare API to create redirect, and returns result.
    handler: async (params: unknown) => {
      const { zone_name, source_url, target_url, redirect_type, preserve_query_string, priority, status } = CreateRedirectInputSchema.parse(params);
    
      // Lookup zone id
      const zones = await client.get<Array<{ id: string; name: string }>>('/zones', { name: zone_name });
      if (zones.length === 0) throw new Error(`Zone ${zone_name} not found`);
      const zoneId = zones[0].id;
    
      // Build pagerule payload
      const pageruleBody = {
        targets: [
          {
            target: 'url',
            constraint: { operator: 'matches', value: source_url },
          },
        ],
        actions: [
          {
            id: 'forwarding_url',
            value: {
              url: target_url + (preserve_query_string ? '?$1' : ''),
              status_code: redirect_type,
            },
          },
        ],
        priority: priority ?? 1,
        status,
      };
    
      const created = await client.post(`/zones/${zoneId}/pagerules`, pageruleBody);
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(created, null, 2)
          }
        ]
      };
    },
  • Zod input schema defining parameters for creating a redirect: zone_name, source_url, target_url, redirect_type (301/302), preserve_query_string, priority, status.
    const CreateRedirectInputSchema = z.object({
      zone_name: z.string(),
      source_url: z.string().min(1),
      target_url: z.string().min(1),
      redirect_type: z.number().optional().default(301).refine(v => v === 301 || v === 302, {
        message: 'redirect_type must be 301 or 302',
      }),
      preserve_query_string: z.boolean().optional().default(true),
      priority: z.number().optional(),
      status: z.enum(['active', 'disabled']).optional().default('active'),
    });
  • Registration of the create_redirect tool within the getRedirectTools function's return object.
    return { tools: {
        'cloudflare-dns-mcp/list_page_rules': listPageRulesTool,
        'cloudflare-dns-mcp/create_redirect': createRedirectTool,
        'cloudflare-dns-mcp/delete_page_rule': deletePageRuleTool,
      } };
  • src/index.ts:48-52 (registration)
    Global tool registration in index.ts where tool names are sanitized (slashes replaced with underscores, e.g., 'cloudflare-dns-mcp/create_redirect' becomes 'cloudflare-dns-mcp_create_redirect') and added to toolsMap for the MCP server.
    const toolsMap: Record<string, any> = {};
    for (const tool of Object.values(allTools)) {
      const safeName = tool.name.replace(/[^a-zA-Z0-9_-]/g, '_');
      toolsMap[safeName] = tool;
    }
  • src/index.ts:25-31 (registration)
    Merging of redirectTools (including create_redirect) into the allTools object in main server setup.
    const allTools = {
      ...dnsTools.tools,
      ...securityTools.tools,
      ...sslCertTools.tools,
      ...echoTools.tools,
      ...redirectTools.tools,
      ...zoneTools.tools,
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states this is a creation operation, implying it's a write/mutation tool, but doesn't disclose any behavioral traits like authentication requirements, rate limits, whether the redirect is immediately active, or what happens on duplicate source URLs. This leaves significant gaps for an agent to understand the tool's behavior.

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 a single, efficient sentence that gets straight to the point with zero wasted words. It's appropriately sized for a creation tool and front-loads the essential information without unnecessary elaboration.

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

Completeness2/5

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

Given the complexity (7 parameters, mutation operation, no annotations, no output schema), the description is insufficiently complete. It doesn't explain what a 'Page Rule' is in Cloudflare context, doesn't cover parameter meanings, doesn't describe the return value or success/failure behavior, and provides no usage context. For a mutation tool with rich parameters, this leaves too many unknowns.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate by explaining parameters, but it adds no parameter information beyond what's implied by 'URL redirect'. It doesn't explain what 'zone_name', 'source_url', 'target_url', or any optional parameters mean, their relationships, or format requirements. With 7 parameters (3 required) completely undocumented, this is inadequate.

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

Purpose4/5

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

The description clearly states the action ('Create') and resource ('single URL redirect (Page Rule) for the given zone'), making the purpose unambiguous. It distinguishes this tool from siblings like 'create_dns_record' by specifying it creates redirects rather than DNS records. However, it doesn't explicitly contrast with 'list_page_rules' or 'delete_page_rule', leaving some sibling differentiation incomplete.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (like needing an existing zone), when not to use it, or how it differs from similar tools like 'create_dns_record' (which might handle redirects differently) or 'list_page_rules' (for viewing existing redirects).

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

Related 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/jeffgolden/cloudflare_mcp'

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