mcpComponent
The recommended way to create agent-driven components.mcpComponent() is a factory that wraps a React component + zod schema into an MCP-registered component with full type safety.
How It Works
- On mount,
mcpComponentregisters an MCP tool with the givennameand zodschema - Input is validated against the zod schema before reaching your component
- Before any agent invocation, the
fallbackis rendered - When an agent calls the tool, the validated data is passed as typed props
- The tool returns a success response to the agent
Options
| Option | Type | Default | Description |
|---|---|---|---|
name | string | — | Required. MCP tool name agents will call |
description | string | name | Tool description for agents |
schema | z.ZodObject | — | Required. Zod schema for type-safe input |
fallback | ReactNode | null | Shown before first invocation |
server | string | — | Target a named server |
columns | McpColumnDef[] | — | Table mode column definitions |
Static Properties
The returned component has a.toolName property:
Patterns
Wrapping Existing Components
Inline Components
Lazy Loading
Wrap dynamicimport() factories with mcpLazy() so mcpComponent can distinguish them from zero-arg components:
Dashboard Widgets
Use multiplemcpComponent instances to build agent-controlled dashboards:
Direct Props
The returned component accepts partial props directly, which merge with agent-provided data:Table Mode
Whencomponent is null and columns is provided, mcpComponent renders a default <table>. The tool schema is automatically wrapped in { rows: z.array(schema) }.
McpColumnDef
| Field | Type | Description |
|---|---|---|
key | string | Property key in the row object |
header | string | Column header text |
render | (value) => ReactNode | Optional custom cell renderer |
How Table Mode Works
- The agent calls the tool with
{ rows: [...] } - Each row is validated against the zod schema
- The table renders with the specified columns
- Custom
renderfunctions allow formatting (e.g., currency, dates)