flary v0.2.12
Flary
A versatile toolkit for building and managing Cloudflare Workers applications, including AI integrations, project scaffolding, and component management.
Table of Contents
Prerequisites
Before you begin, ensure you have:
- Node.js 18.x or later installed
- A Cloudflare account
- Wrangler CLI installed and configured:
npm install -g wrangler wrangler login
Installation
npm install flary
Features
- 🚀 Project Scaffolding: Quickly set up modern Cloudflare Workers projects.
- 🎨 Component Management: Import and organize components from v0.dev.
- 🤖 AI Integration: Tools and utilities for AI applications.
- 🔒 Secure MCP Integration: Model Context Protocol integration with robust authentication.
CLI Usage
Project Initialization
Create a new Flary project interactively:
flary init
This command will:
- Prompt for your project name.
- Allow template selection (e.g., Full-Stack React App).
- Set up a complete project structure.
- Configure dependencies and Wrangler automatically.
Follow the provided steps after creation:
Navigate to your project:
cd your-project-name
Install dependencies:
npm install
Start development server:
npm run dev
v0.dev Component Import
Import and organize components from v0.dev:
# Default directory (src/components)
flary v0 "https://v0.dev/chat/your-component-url"
# Custom directory
flary v0 --dir game-components "https://v0.dev/chat/your-component-url"
Options:
-d, --dir <directory>
: Specify target subdirectory (relative tosrc/
).-h, --help
: Display help information.
Deployment
Deploy your Flary application to Cloudflare Workers:
Build your application:
npm run build
Deploy to Cloudflare Workers:
npm run deploy # or directly with wrangler wrangler deploy
Your application will be deployed to https://<project-name>.<your-subdomain>.workers.dev
Environment Variables
Set environment variables for production:
# Set a secret
wrangler secret put MY_SECRET
# Set a variable in wrangler.toml
wrangler deploy --var MY_VAR=value
MCP Integration
Basic Usage
Initialize MCP instance and register tools:
import { z } from "zod";
import { MCP } from "flary";
const app = new MCP({
name: "test-mcp",
description: "A test MCP",
version: "1.0.0",
});
const sumSchema = z
.object({
a: z.number().describe("The first number to add"),
b: z.number().describe("The second number to add"),
})
.describe("Calculate the sum of two numbers");
async function calculateSum({ a, b }: z.input<typeof sumSchema>) {
return a + b;
}
calculateSum.schema = sumSchema;
app.tool("calculate_sum", calculateSum);
export default app;
export const { McpObject } = app;
Authentication
Supports Bearer token authentication:
const app = new MCP({
auth: {
type: "bearer",
token: "your-secret-token",
validate: async (token) => token === (await getValidToken()),
},
});
Connection Types
- SSE (Server-Sent Events): Connect via
/
or/sse
. - WebSockets: Connect via
/
or/ws
.
Cursor Integration
Cursor uses SSE exclusively:
https://your-worker.workers.dev/?key=your-secret-token
No Authentication
Publicly accessible MCP server:
const app = new MCP({
name: "test-mcp",
description: "A test MCP",
version: "1.0.0",
});
Durable Objects Setup
MCP requires Durable Objects for state management. Configure them in your wrangler.json
:
{
"durable_objects": {
"bindings": [{ "name": "McpObject", "class_name": "McpObject" }]
},
"migrations": [{ "tag": "v1", "new_classes": ["McpObject"] }]
}
Make sure to export the McpObject
from your worker entry point as shown in the Basic Usage example.
License
MIT © flary