Skip to content

Integrate spatie/laravel-markdown-response for AI agent markdown responses #133

@ManukMinasyan

Description

@ManukMinasyan

Summary

Integrate spatie/laravel-markdown-response to serve markdown-formatted responses to AI agents and bots.

When an AI agent requests a page (detected via Accept: text/markdown header, recognized AI user agent patterns, or .md URL suffix), the response should be automatically converted from HTML to clean markdown.

Why

As AI agents increasingly interact with web applications, serving structured markdown instead of raw HTML improves:

  • AI comprehension — markdown is a more natural format for LLMs to parse
  • Token efficiency — markdown is significantly smaller than HTML, reducing token usage
  • Interoperability — complements our MCP Server support (MCP Server Support - Expose CRM data to AI assistants #89) by making the web-facing side AI-friendly too

Implementation Details

Package Features

  • Driver-based HTML-to-markdown conversion (local PHP, Cloudflare Workers AI, or markdown.new)
  • Built-in caching for converted responses
  • HTML preprocessing before conversion
  • Markdown::fake() and Markdown::assertConverted() for testing

Tasks

  • Install spatie/laravel-markdown-response
  • Configure the conversion driver and caching strategy
  • Apply ProvideMarkdownResponse middleware to relevant route groups
  • Evaluate which routes/pages should be AI-accessible
  • Add tests for markdown response behavior
  • Document the integration

Related

Metadata

Metadata

Assignees

Labels

area:apiAPI and integrationsarea:integrationsThird-party integrations and external servicesenhancementNew feature or request

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions