# createFilesystemMiddleware

> **Function** in `deepagents`

📖 [View in docs](https://reference.langchain.com/javascript/deepagents/middleware/createFilesystemMiddleware)

Create middleware that provides built-in filesystem tools and optional custom
prompt guidance.

By default, the middleware registers every built-in filesystem tool listed in
FILESYSTEM_TOOL_NAMES. Use FilesystemMiddlewareOptions.tools
to narrow that set for read-only, search-only, or otherwise restricted
agents. The allowlist only controls built-in filesystem tools; custom tools
from the agent or other middleware are left untouched.

The middleware also filters tools whose backend capabilities are unavailable
at request time. In particular, `execute` is only visible when the resolved
backend supports command execution.

## Signature

```javascript
createFilesystemMiddleware(options: FilesystemMiddlewareOptions = {}): AgentMiddleware<StateSchema<__type>, undefined, unknown, DynamicStructuredTool<ZodObject<__type, $strip>, __type, __type, string | ToolMessage<MessageStructure<MessageToolSet>>, unknown, "ls"> | DynamicStructuredTool<ZodPreprocess<ZodObject<__type, $strip>>, __type, unknown, ToolMessage<MessageStructure<MessageToolSet>> | __type[] | __type[], unknown, "read_file"> | DynamicStructuredTool<ZodPreprocess<ZodObject<__type, $strip>>, __type, unknown, string | ToolMessage<MessageStructure<MessageToolSet>> | Command<unknown, __type, string>, unknown, "write_file"> | DynamicStructuredTool<ZodPreprocess<ZodObject<__type, $strip>>, __type, unknown, string | ToolMessage<MessageStructure<MessageToolSet>> | Command<unknown, __type, string>, unknown, "edit_file"> | DynamicStructuredTool<ZodPreprocess<ZodObject<__type, $strip>>, __type, unknown, ToolMessage<MessageStructure<MessageToolSet>> | Command<unknown, __type, string>, unknown, "delete"> | DynamicStructuredTool<ZodObject<__type, $strip>, __type, __type, string | ToolMessage<MessageStructure<MessageToolSet>>, unknown, "glob"> | DynamicStructuredTool<ZodObject<__type, $strip>, __type, __type, string | ToolMessage<MessageStructure<MessageToolSet>>, unknown, "grep"> | DynamicStructuredTool<ZodObject<__type, $strip>, __type, __type, string, unknown, "execute">[], readonly []>
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `options` | `FilesystemMiddlewareOptions` | No | Filesystem middleware configuration. (default: `{}`) |

## Returns

`AgentMiddleware<StateSchema<__type>, undefined, unknown, DynamicStructuredTool<ZodObject<__type, $strip>, __type, __type, string | ToolMessage<MessageStructure<MessageToolSet>>, unknown, "ls"> | DynamicStructuredTool<ZodPreprocess<ZodObject<__type, $strip>>, __type, unknown, ToolMessage<MessageStructure<MessageToolSet>> | __type[] | __type[], unknown, "read_file"> | DynamicStructuredTool<ZodPreprocess<ZodObject<__type, $strip>>, __type, unknown, string | ToolMessage<MessageStructure<MessageToolSet>> | Command<unknown, __type, string>, unknown, "write_file"> | DynamicStructuredTool<ZodPreprocess<ZodObject<__type, $strip>>, __type, unknown, string | ToolMessage<MessageStructure<MessageToolSet>> | Command<unknown, __type, string>, unknown, "edit_file"> | DynamicStructuredTool<ZodPreprocess<ZodObject<__type, $strip>>, __type, unknown, ToolMessage<MessageStructure<MessageToolSet>> | Command<unknown, __type, string>, unknown, "delete"> | DynamicStructuredTool<ZodObject<__type, $strip>, __type, __type, string | ToolMessage<MessageStructure<MessageToolSet>>, unknown, "glob"> | DynamicStructuredTool<ZodObject<__type, $strip>, __type, __type, string | ToolMessage<MessageStructure<MessageToolSet>>, unknown, "grep"> | DynamicStructuredTool<ZodObject<__type, $strip>, __type, __type, string, unknown, "execute">[], readonly []>`

Agent middleware that contributes filesystem state, tools, prompt
guidance, permission checks, and large-result eviction.

## Examples

```ts
const middleware = createFilesystemMiddleware({
  tools: ["read_file", "ls", "glob", "grep"],
});
```

---

[View source on GitHub](https://github.com/langchain-ai/deepagentsjs/blob/58f6c326ae045641162c2812316a295c946f2173/libs/deepagents/src/middleware/fs.ts#L1864)