Skip to content
5 changes: 5 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# AGENTS.md

**MANDATORY: Read `CLAUDE.md` before starting any task.**

All project instructions are in `CLAUDE.md`.
3 changes: 2 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ Each package README has the detailed API. Don't duplicate here.

## Learnings

<!-- Add specific lessons learned during development. Format: what happened → what to do instead -->
<!-- MANDATORY: Document failures here to prevent repeated mistakes -->
<!-- Format: what went wrong → what to do instead -->

<!-- Example:
- Forgot to rebuild ui package before testing ui-react → Always `pnpm build` from root, not package
Expand Down
50 changes: 50 additions & 0 deletions packages/core/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# @mcp-apps-kit/core

Server-side framework for MCP applications. Handles tool definitions, UI resources, adapters, middleware, and Express server setup.

## Quick Commands

```bash
pnpm -C packages/core test # Run tests
pnpm -C packages/core typecheck # Type check only
pnpm -C packages/core lint # Lint only
```

## Key Exports

- `createApp` - Main entry point for creating an MCP app
- `defineTool` - Type-safe tool definition helper
- `defineUI` - UI resource definition helper
- `createPlugin` - Plugin system for extending apps

## Patterns

Use `defineTool` and `defineUI` for type inference instead of inline objects.

Middleware is Koa-style: always `await next()` or the chain breaks.

Exports are centralized through `src/index.ts`, which re-exports from barrel files (`index.ts`) in subdirectories: `adapters/`, `debug/`, `events/`, `middleware/`, `plugins/`, `server/`, and `server/oauth/`. Subdirectory barrel files are local re-exports only - all public API goes through the root `src/index.ts`.

## Dependencies

- Express 5 (async error handling differs from v4)
- Zod 4 (breaking changes from v3)
- @modelcontextprotocol/sdk

## Common Mistakes

- Forgetting to `await next()` in middleware
- Using Zod 3 APIs that changed in v4 (check migration guide)
- Adding exports outside `index.ts`

---

## Learnings

<!-- MANDATORY: Document failures here to prevent repeated mistakes -->
<!-- Format: what went wrong → what to do instead -->

<!-- Example:
- Type error in handler because input wasn't validated → Always use Zod schema, never trust raw input
- Middleware chain broke silently → Add logging middleware first to debug chain issues
-->
Comment thread
coderabbitai[bot] marked this conversation as resolved.
52 changes: 52 additions & 0 deletions packages/create-app/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# @mcp-apps-kit/create-app
Comment thread
coderabbitai[bot] marked this conversation as resolved.

CLI tool for scaffolding MCP applications. Creates new projects with React or vanilla JS templates.

## Quick Commands

```bash
pnpm -C packages/create-app test # Run tests
pnpm -C packages/create-app typecheck # Type check only
pnpm -C packages/create-app lint # Lint only
```

## Key Exports

- `scaffoldProject` - Programmatic project creation
- CLI binary: `create-mcp-apps-kit`

## Templates

- `react` - React + Vite + @mcp-apps-kit/ui-react
- `vanilla` - Vanilla JS + Vite + @mcp-apps-kit/ui

Both include:

- Server with example tool
- UI with theming
- Integration tests
- Optional Vercel deployment config

## Dependencies

- commander (CLI framework)
- @inquirer/prompts (interactive prompts)
- figlet, chalk (CLI styling)

## Common Mistakes

- Running in non-empty directory (fails)
- Fetches latest package versions from npm at runtime
- Generated projects use npm (not pnpm) to avoid workspace conflicts

---

## Learnings

<!-- MANDATORY: Document failures here to prevent repeated mistakes -->
<!-- Format: what went wrong → what to do instead -->

<!-- Example:
- Template file had wrong path → Use path.join() not string concatenation for cross-platform
- npm install failed in generated project → Check if package versions are valid on npm registry
-->
52 changes: 52 additions & 0 deletions packages/testing/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# @mcp-apps-kit/testing

Comprehensive testing library for MCP applications. Supports unit, integration, behavior, property, and LLM evaluation testing.

## Quick Commands

```bash
pnpm -C packages/testing test # Run tests
pnpm -C packages/testing typecheck # Type check only
pnpm -C packages/testing lint # Lint only
```

## Key Exports

- `createTestEnvironment` - Full test setup with server and client
- `startTestServer` / `createTestClient` - Individual components
- `expectToolResult` - Fluent assertions for tool results
- `createMCPEval` / `describeEval` - LLM-based evaluation
- Framework adapters: `@mcp-apps-kit/testing/vitest`, `@mcp-apps-kit/testing/jest`

## Patterns

```typescript
const env = await createTestEnvironment({ app });
const result = await env.client.callTool("greet", { name: "Alice" });
expectToolResult(result).toMatchObject({ message: "Hello, Alice!" });
await env.cleanup();
```

## Dependencies

- @modelcontextprotocol/sdk
- Zod 4
- Optional: vitest, jest, fast-check, openai, @anthropic-ai/sdk

## Common Mistakes

- Forgetting `await env.cleanup()` (leaves server running)
- Not setting up vitest/jest matchers in setup file
- Missing optional peer deps for LLM eval features

---

## Learnings

<!-- MANDATORY: Document failures here to prevent repeated mistakes -->
<!-- Format: what went wrong → what to do instead -->

<!-- Example:
- Tests hung indefinitely → Server wasn't cleaned up from previous run, use port: 0 for random port
- Matcher not found error → Import setupVitestMatchers in setup file before tests run
-->
4 changes: 3 additions & 1 deletion packages/testing/tests/unit/eval/generators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ describe.skipIf(!isFastCheckAvailable)("generated value validation", () => {
const gen = generators.float(0, 1);
const resolved = await resolveArbitrary(gen);
const samples = fc.sample(resolved, 50);
expect(samples.every((n) => n >= 0 && n <= 1)).toBe(true);
// Use small epsilon for floating point comparison tolerance
const epsilon = 1e-10;
expect(samples.every((n) => n >= 0 - epsilon && n <= 1 + epsilon)).toBe(true);
});

it("should generate booleans", async () => {
Expand Down
54 changes: 54 additions & 0 deletions packages/ui-react-builder/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# @mcp-apps-kit/ui-react-builder

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Fix Prettier formatting error (likely missing trailing newline).

The Prettier check is failing. Ensure proper line ending and newline at EOF.

🔧 Proposed fix

Add a newline at the end of the file after line 54:

 <!-- Example:
 - Build succeeded but component didn't render → Check if all imports are included in bundle
 - esbuild error about JSX → Ensure .tsx extension and jsx: 'automatic' in config
--->
+-->
🤖 Prompt for AI Agents
In @packages/ui-react-builder/AGENTS.md at line 1, The file AGENTS.md is missing
a trailing newline causing Prettier to fail; open
packages/ui-react-builder/AGENTS.md and add a single newline character at the
end of the file (i.e., ensure there is an empty line after the current last
line, add a newline after line 54) then save and re-run formatting/CI.


Build tool for React-based MCP application UIs. Bundles React components into self-contained HTML.

## Quick Commands

```bash
pnpm -C packages/ui-react-builder test # Run tests
pnpm -C packages/ui-react-builder typecheck # Type check only
pnpm -C packages/ui-react-builder lint # Lint only
```

## Key Exports

- `defineReactUI` - Define UI with React component
- `buildReactUIs` / `buildReactUI` - Build to HTML
- `buildAndTransform` - Build and convert to core UIDefs in one step
- Vite plugin available via `@mcp-apps-kit/ui-react-builder/vite`

## Patterns

```typescript
const widgetUI = defineReactUI({
component: MyWidget,
name: "My Widget",
prefersBorder: true,
});

const uis = await buildAndTransform({ "my-widget": widgetUI });
```

## Dependencies

- esbuild (bundling)
- @typescript-eslint/typescript-estree (AST parsing)
- Peer deps: @mcp-apps-kit/core, @mcp-apps-kit/ui-react, react, react-dom, vite (optional)

## Common Mistakes

- Forgetting to rebuild after component changes
- Not including component dependencies in build
- Missing vite peer dep when using vite plugin

---

## Learnings

<!-- MANDATORY: Document failures here to prevent repeated mistakes -->
<!-- Format: what went wrong → what to do instead -->

<!-- Example:
- Build succeeded but component didn't render → Check if all imports are included in bundle
- esbuild error about JSX → Ensure .tsx extension and jsx: 'automatic' in config
-->
56 changes: 56 additions & 0 deletions packages/ui-react/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# @mcp-apps-kit/ui-react

React bindings for MCP applications. Provides hooks and context for building UIs.

## Quick Commands

```bash
pnpm -C packages/ui-react test # Run tests
pnpm -C packages/ui-react typecheck # Type check only
pnpm -C packages/ui-react lint # Lint only
```

## Key Exports

- `AppsProvider` - Context provider (wrap your app)
- `useAppsClient` - Get client instance
- `useToolResult` - Get current tool result
- `useHostContext` - Get host context (theme, locale, etc.)
- `useDocumentTheme` / `useHostStyleVariables` - Auto-apply theming

## Patterns

```tsx
<AppsProvider>
<App />
</AppsProvider>;

function App() {
const result = useToolResult<ToolOutputs>();
useDocumentTheme("light", "dark");
// ...
}
```

## Dependencies

- @mcp-apps-kit/ui (re-exports many types)
- React 18 or 19

## Common Mistakes

- Forgetting `AppsProvider` wrapper
- Not typing `useToolResult<T>()` generic
- Using hooks outside provider context

---

## Learnings

<!-- MANDATORY: Document failures here to prevent repeated mistakes -->
<!-- Format: what went wrong → what to do instead -->

<!-- Example:
- Hook returned undefined unexpectedly → Ensure component is wrapped in AppsProvider
- Re-renders caused infinite loop → Check useEffect dependencies, avoid object literals in deps
-->
49 changes: 49 additions & 0 deletions packages/ui/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# @mcp-apps-kit/ui

Client-side SDK for MCP applications (vanilla JavaScript). Auto-detects host platform (MCP Apps vs ChatGPT) and provides unified API.

## Quick Commands

```bash
pnpm -C packages/ui test # Run tests
pnpm -C packages/ui typecheck # Type check only
pnpm -C packages/ui lint # Lint only
```

## Key Exports

- `createClient` - Main entry point, auto-detects platform
- `detectProtocol` - Manual platform detection
- `McpAdapter` / `OpenAIAdapter` / `MockAdapter` - Protocol adapters
- Theme/style utilities: `applyDocumentTheme`, `applyHostStyleVariables`

## Patterns

```typescript
const client = await createClient<typeof app.tools>();
const result = await client.callTool("greet", { name: "Alice" });
```

Subscribe to events with `onHostContextChange`, `onToolResult`.

## Dependencies

- @modelcontextprotocol/ext-apps

## Common Mistakes

- Forgetting to await `createClient()` (it's async)
- Not handling both MCP and OpenAI response formats
- Missing type parameter for typed tool calls

---

## Learnings

<!-- MANDATORY: Document failures here to prevent repeated mistakes -->
<!-- Format: what went wrong → what to do instead -->

<!-- Example:
- Client connected but no events fired → Check if adapter.connect() was awaited
- Theme not applying → Verify onHostContextChange subscription is set up before first render
-->