MCP TypeScript SDK (V2)
    Preparing search index...
    • Creates a Fastify application pre-configured for MCP servers.

      When the host is '127.0.0.1', 'localhost', or '::1' (the default is '127.0.0.1'), DNS rebinding protection is automatically applied via an onRequest hook to protect against DNS rebinding attacks on localhost servers.

      Fastify parses JSON request bodies by default, so no additional middleware is required for MCP Streamable HTTP endpoints.

      Parameters

      Returns FastifyInstance

      A configured Fastify application

      const app = createMcpFastifyApp();
      
      const appOpen = createMcpFastifyApp({ host: '0.0.0.0' }); // No automatic DNS rebinding protection
      const appLocal = createMcpFastifyApp({ host: 'localhost' }); // DNS rebinding protection enabled
      const app = createMcpFastifyApp({ host: '0.0.0.0', allowedHosts: ['myapp.local', 'localhost'] });