Skip to content

AI Integration

Stratal can expose your API routes as Model Context Protocol (MCP) tools, letting AI agents interact with your application directly. It also provides skills that teach AI agents the framework’s conventions and patterns.

The Model Context Protocol (MCP) is an open standard for connecting AI agents to external tools and data sources. Stratal’s MCP integration automatically converts your routes into MCP tools that AI agents can discover and call. Since Stratal generates an OpenAPI spec from your routes out of the box, the MCP server works with no additional setup.

Use mcp:tools to preview which routes will be exposed as MCP tools:

Terminal window
npx quarry mcp:tools

This outputs a table with all discovered tools:

ColumnDescription
NameTool name (from operationId or generated from method + path)
MethodHTTP method (GET, POST, etc.)
PathRoute path
DescriptionFrom the route’s summary and description
Terminal window
# Only show tools tagged "Users" in OpenAPI
npx quarry mcp:tools --tag Users
# Only show tools under /api/admin
npx quarry mcp:tools --path /api/admin
# Combine filters
npx quarry mcp:tools --tag Users --tag Admin --path /api/v1
OptionDescription
--tagFilter by OpenAPI tag (repeatable)
--pathFilter by path prefix
Terminal window
npx quarry mcp:serve

This starts an MCP server using the stdio transport. The server registers each API route as an MCP tool and exposes the full OpenAPI spec as a resource at openapi://spec.

OptionDescription
--urlBase URL for dispatching to a remote API (e.g., https://api.example.com)
--headerHeaders as Key:Value (repeatable)
--tagOnly expose routes with these OpenAPI tags (repeatable)
--pathOnly expose routes matching this path prefix

Each OpenAPI operation is converted into an MCP tool:

  • Tool name — uses the route’s operationId if set, otherwise generates one from the method and path (e.g., get_api_users)
  • Description — combines the route’s summary and description
  • Input schema — built from path parameters, query parameters, and request body:
SourceInput key formatExample
Path parameter :idpath_id{ "path_id": "abc-123" }
Query parameter pagequery_page{ "query_page": "2" }
Request bodybody{ "body": { "name": "Alice" } }

When a tool is called, path parameters are interpolated, query strings are assembled, and the request is dispatched to your application.

By default, mcp:serve dispatches requests to your local application. Use --url to send requests to a deployed API instead:

Terminal window
# Point at a deployed staging API
npx quarry mcp:serve --url https://staging.example.com --header "Authorization:Bearer token123"

This is useful for letting AI agents interact with a live environment while using your local OpenAPI spec for tool definitions.

The MCP server exposes the full OpenAPI specification as a resource at openapi://spec. AI agents can read this resource to understand your API structure without calling individual tools.

Configure your AI agent to connect to the Stratal MCP server. Each example assumes your project is at /path/to/your/project — replace this with the actual path to your Stratal application.

Add to your project’s .claude/settings.local.json:

{
"mcpServers": {
"stratal": {
"type": "stdio",
"command": "npx",
"args": ["quarry", "mcp:serve"],
"cwd": "/path/to/your/project"
}
}
}

Or with filters and remote dispatch:

{
"mcpServers": {
"stratal": {
"type": "stdio",
"command": "npx",
"args": [
"quarry", "mcp:serve",
"--tag", "Users",
"--url", "https://api.example.com",
"--header", "Authorization:Bearer token123"
],
"cwd": "/path/to/your/project"
}
}
}

Stratal provides AI skills that teach your AI agent the framework’s conventions, patterns, and APIs. When installed, your AI agent automatically applies Stratal best practices — correct decorators, import paths, module structure, and more.

  • Framework rules — patterns that prevent runtime failures (DI decorators, import paths, ESM requirements)
  • Reference guides — modules, routing, DI, events, queues, cron, database, auth, RBAC, testing, and more
  • Project scaffold — templates for bootstrapping new Stratal projects
  • Gotchas — Cloudflare Workers constraints and common pitfalls

Use the skills CLI to install the Stratal skill into your project:

Terminal window
npx skills add strataljs/stratal

This installs the Stratal skill into your project’s .agents/ directory. Your AI agent automatically discovers and uses the skill when working with Stratal code.