Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ node_modules/
dist/
build/
lib/
!/**/src/**/lib

# Cloudflare Workers
.wrangler/
Expand Down Expand Up @@ -63,4 +64,4 @@ tmp/
.turbo

data/
*.db
*.db
81 changes: 81 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# AGENTS.md

## Build/Run Commands

- Build: `pnpm run build` (uses tsc)
- Dev mode: `pnpm run dev` (tsx watch)
- Run tests: `pnpm run test` (vitest)
- Run single test: `pnpm run test <test-file-pattern>`
- Test watch mode: `pnpm run test:watch`
- Lint: `pnpm run lint` (eslint)
- Lint fix: `pnpm run lint:fix`
- Typecheck: `pnpm run typecheck` (tsc --noEmit)
- Format: `pnpm run format` (prettier)
- Format check: `pnpm run format:check`

## Code Style Guidelines

- Use double quotes for strings
- No semicolons
- Use tabs for indentation (TSConfig sets this)
- Strict TypeScript with all strict flags enabled
- No unused locals/parameters
- Exact optional property types
- No implicit returns/fallthrough cases
- No unchecked indexed access
- Use ESNext target and modules
- Import paths use `@/*` alias for src/
- Declaration files and source maps generated
- Resolve JSON modules enabled

## Naming Conventions

- Files: kebab-case
- Types: PascalCase
- Functions/variables: camelCase
- Constants: UPPER_SNAKE_CASE
- Test files: \*.test.ts

## Error Handling

- Use custom error classes from utils/errors.ts
- Always provide meaningful error messages
- Use logger.ts for consistent logging
- Handle dry-run mode in all mutating operations

## Testing

- Use vitest with globals
- Place tests alongside source files
- Use .test.ts extension
- Mock filesystem with memfs where needed

## Development Practices

- Use pnpm for package management
- Follow workspaces pattern with packages in `packages/{project}`
- All code compatible with Cloudflare Workers runtime
- Use TypeScript for all code with proper typing
- Follow ES modules format
- Use `async`/`await` for asynchronous code
- Write tests for all functionality
- Use Wrangler for deployments to Cloudflare Workers

## Project Structure

- `packages/`: Contains all project packages
- `mcp/`: Main MCP implementation for Cloudflare Workers
- `test-utils/`: Utilities for testing
- `examples/`: Contains example implementations
- `crud-mcp/`: Example CRUD application using MCP framework
- `simple-prompt-agent/`: Example agent with only a prompt for chatting
- Main package: packages/mcp/src/index.ts
- MCP Server implementation: packages/mcp/src/mcp/server.ts
- Example application: examples/crud-mcp/src/index.ts

## Development Workflow

1. Install dependencies at root level: `pnpm install`
2. Build all packages: `pnpm build`
3. Run tests: `pnpm test`
4. For specific packages, navigate to directory and use specific scripts
64 changes: 37 additions & 27 deletions examples/crud-mcp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ This example demonstrates a CRUD (Create, Read, Update, Delete) application usin
### Data Model

The todo items are structured with the following fields:

- `id`: Unique identifier (UUID)
- `title`: Task title (required)
- `description`: Detailed description (optional)
Expand Down Expand Up @@ -99,18 +100,19 @@ The application includes interactive prompts to help users understand and use th
- error_type (optional): Get specific help about 'not_found', 'invalid_status', 'invalid_date', or 'other' errors

Example prompt usage:

```typescript
// Get general help about listing todos
const listHelp = await client.getPrompt('list_todos_help');
const listHelp = await client.getPrompt("list_todos_help");

// Get specific help about date filtering
const dateFilterHelp = await client.getPrompt('list_todos_help', {
filter: 'date'
const dateFilterHelp = await client.getPrompt("list_todos_help", {
filter: "date",
});

// Get help about updating a specific field
const updateHelp = await client.getPrompt('update_todo_help', {
field: 'status'
const updateHelp = await client.getPrompt("update_todo_help", {
field: "status",
});
```

Expand Down Expand Up @@ -143,6 +145,7 @@ const updateHelp = await client.getPrompt('update_todo_help', {
The application uses Cloudflare Workers with the following configuration:

### wrangler.jsonc

```jsonc
{
"name": "crud-mcp",
Expand All @@ -153,24 +156,25 @@ The application uses Cloudflare Workers with the following configuration:
"bindings": [
{
"name": "TODO_MCP_SERVER",
"class_name": "TodoMcpServer"
}
]
"class_name": "TodoMcpServer",
},
],
},
"migrations": [
{
"tag": "v1",
"new_sqlite_classes": ["TodoMcpServer"]
}
"new_sqlite_classes": ["TodoMcpServer"],
},
],
"observability": {
"enabled": true,
"head_sampling_rate": 1
}
"head_sampling_rate": 1,
},
}
```

Key Configuration Points:

- **Durable Objects**: The `TodoMcpServer` class is bound as a Durable Object for state management
- **SQLite Support**: The `TodoMcpServer` class is registered for SQLite functionality via migrations
- **Observability**: Full request sampling enabled for monitoring and debugging
Expand Down Expand Up @@ -208,65 +212,70 @@ await client.connect();
### Creating a Todo

```typescript
const result = await client.callTool('create_todo', {
const result = await client.callTool("create_todo", {
title: "Complete project report",
description: "Finalize the quarterly project report",
due_date: "2024-03-20"
due_date: "2024-03-20",
});
```

### Listing Todos with Filters

```typescript
const todos = await client.getResource(new URL(
"d1://database/todos?status=in_progress&sort_by=due_date&sort_direction=asc"
));
const todos = await client.getResource(
new URL(
"d1://database/todos?status=in_progress&sort_by=due_date&sort_direction=asc",
),
);
```

### Getting Today's Tasks

```typescript
const todaysTodos = await client.getResource(new URL(
"d1://database/todos/today?sort_by=created_at&sort_direction=asc"
));
const todaysTodos = await client.getResource(
new URL("d1://database/todos/today?sort_by=created_at&sort_direction=asc"),
);
```

### Updating a Todo

```typescript
const result = await client.callTool('updateTodo', {
const result = await client.callTool("updateTodo", {
id: "todo-uuid",
status: "completed",
description: "Updated description"
description: "Updated description",
});
```

## Setup

1. Prerequisites:
- Node.js (v16 or higher)
- Yarn or npm
- pnpm or npm
- Wrangler CLI

2. Installation:

```bash
yarn install
pnpm install
```

3. Development:

```bash
yarn dev
pnpm dev
```

4. Deployment:
```bash
wrangler login
yarn deploy
pnpm deploy
```

## Error Handling

The implementation includes comprehensive error handling:

- Input validation using Zod schemas
- Database operation error handling
- Detailed error messages and logging
Expand All @@ -281,4 +290,5 @@ The implementation includes comprehensive error handling:

## License

MIT
MIT

4 changes: 2 additions & 2 deletions examples/dependent-agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"private": true,
"scripts": {
"deploy": "wrangler deploy",
"dev": "wrangler dev",
"dev": "nullshot dev",
"start": "wrangler dev",
"cf-typegen": "wrangler types",
"dev:nullshot": "nullshot dev",
"dev:wrangler": "wrangler dev",
"postinstall": "nullshot install"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/dependent-agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class DependentAgent extends AiSdkAgent<Env> {
},
);

return result.toTextStreamResponse();
return result.toUIMessageStreamResponse();
}
}

Expand Down
22 changes: 0 additions & 22 deletions examples/playground-showcase/.eslintrc.json

This file was deleted.

43 changes: 0 additions & 43 deletions examples/playground-showcase/.gitignore

This file was deleted.

5 changes: 0 additions & 5 deletions examples/playground-showcase/next-env.d.ts

This file was deleted.

6 changes: 0 additions & 6 deletions examples/playground-showcase/postcss.config.js

This file was deleted.

1 change: 0 additions & 1 deletion examples/playground-showcase/public/favicon.ico

This file was deleted.

Binary file not shown.
21 changes: 0 additions & 21 deletions examples/playground-showcase/public/images/cursor-logo.svg

This file was deleted.

Binary file not shown.
Loading
Loading