Skip to main content
Glama

Netlify MCP Server

Official
by netlify

netlify-coding-rules

Validate coding practices for Netlify serverless functions, edge functions, and SDK usage. Ensure compliance before creating or modifying functions or resources on the Netlify platform.

Instructions

ALWAYS call when writing serverless or Netlify code. required step before creating or editing any type of functions, Netlify sdk/library usage, etc.

Input Schema

NameRequiredDescriptionDefault
creationTypeYes

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "creationType": { "enum": [ "serverless", "edge-functions", "blobs", "image-cdn", "forms", "db" ], "type": "string" } }, "required": [ "creationType" ], "type": "object" }

Implementation Reference

  • netlify-mcp.ts:82-104 (registration)
    Registration of the 'netlify-coding-rules' tool, including input schema (creationType enum derived from context consumers), annotations, and inline handler function that fetches and returns the relevant Netlify coding context.
    server.registerTool( "netlify-coding-rules", { description: "ALWAYS call when writing serverless or Netlify code. required step before creating or editing any type of functions, Netlify sdk/library usage, etc.", inputSchema:{ creationType: creationTypeEnum }, annotations: { readOnlyHint: true } }, async ({creationType}: {creationType: z.infer<typeof creationTypeEnum>}) => { checkCompatibility(); const context = await getNetlifyCodingContext(creationType); const text = context?.content || ''; return ({ content: [{type: "text", text}] }); } );
  • Handler function for the tool: validates input, checks compatibility, retrieves Netlify coding context for the specified creationType, and returns it as text content.
    async ({creationType}: {creationType: z.infer<typeof creationTypeEnum>}) => { checkCompatibility(); const context = await getNetlifyCodingContext(creationType); const text = context?.content || ''; return ({ content: [{type: "text", text}] }); }
  • Core helper function implementing the logic to fetch, cache (10 min TTL), and return Netlify coding context for a given contextKey from the dynamic endpoint defined in consumer config.
    export async function getNetlifyCodingContext(contextKey: string): Promise<ContextFile | undefined> { const now = Date.now(); // Check if we have a cached version that's less than 10 minutes old // If so, return the cached version otherwise fetch fresh data if (contextCache[contextKey] && (now - contextCache[contextKey].timestamp) < TEN_MINUTES_MS) { return contextCache[contextKey]?.data; } const consumer = await getContextConsumerConfig(); if(!consumer || !consumer.contextScopes[contextKey]?.endpoint){ console.error('unable to find the context you are looking for. Check docs.netlify.com for more information.'); return; } const endpoint = new URL(consumer.contextScopes[contextKey].endpoint); endpoint.searchParams.set('consumer', getConsumer()); let data = ''; try { const response = await unauthenticatedFetch(endpoint.toString()) data = await response.text() as string; if(!data){ console.error('unable to find the context you are looking for. Check docs.netlify.com for more information.'); return; } const contextFile: ContextFile = { key: contextKey, config: consumer.contextScopes[contextKey], content: data }; contextCache[contextKey] = { data: contextFile, timestamp: Date.now() }; } catch (error) { console.error('Error fetching context:', error); } return contextCache[contextKey]?.data; }
  • Input schema for the tool: requires 'creationType' parameter as Zod enum of available context types from Netlify consumers; includes description and read-only annotation.
    description: "ALWAYS call when writing serverless or Netlify code. required step before creating or editing any type of functions, Netlify sdk/library usage, etc.", inputSchema:{ creationType: creationTypeEnum },

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/netlify/netlify-mcp'

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