Skip to content

Commit 06bdaef

Browse files
committed
File System method docs
1 parent ebc5801 commit 06bdaef

3 files changed

Lines changed: 132 additions & 5 deletions

File tree

docs/docs.json

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@
4444
"groups": [
4545
{
4646
"group": "Overview",
47-
"pages": ["overview/introduction", "overview/architecture"]
47+
"pages": [
48+
"overview/introduction",
49+
"overview/architecture"
50+
]
4851
},
4952
{
5053
"group": "Protocol",
@@ -55,17 +58,24 @@
5558
"protocol/prompt-turn",
5659
"protocol/content",
5760
"protocol/tool-calls",
61+
"protocol/file-system",
5862
"protocol/agent-plan",
5963
"protocol/schema"
6064
]
6165
},
6266
{
6367
"group": "Libraries",
64-
"pages": ["libraries/typescript", "libraries/rust"]
68+
"pages": [
69+
"libraries/typescript",
70+
"libraries/rust"
71+
]
6572
},
6673
{
6774
"group": "Community",
68-
"pages": ["community/contributing", "community/versioning"]
75+
"pages": [
76+
"community/contributing",
77+
"community/versioning"
78+
]
6979
}
7080
]
7181
},
@@ -85,6 +95,9 @@
8595
}
8696
},
8797
"contextual": {
88-
"options": ["copy", "view"]
98+
"options": [
99+
"copy",
100+
"view"
101+
]
89102
}
90103
}

docs/protocol/file-system.mdx

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
---
2+
title: "File System"
3+
description: "Client filesystem access methods"
4+
---
5+
6+
The filesystem methods allow Agents to read and write text files within the Client's environment. These methods enable Agents to access unsaved editor state and allow Clients to track file modifications made during agent execution.
7+
8+
## Checking Support
9+
10+
Before attempting to use filesystem methods, Agents **MUST** verify that the Client supports these capabilities by checking the [Client Capabilities](./initialization#client-capabilities) field in the `initialize` response:
11+
12+
```json highlight={8,9}
13+
{
14+
"jsonrpc": "2.0",
15+
"id": 0,
16+
"result": {
17+
"protocolVersion": 1,
18+
"clientCapabilities": {
19+
"fs": {
20+
"readTextFile": true,
21+
"writeTextFile": true
22+
}
23+
}
24+
}
25+
}
26+
```
27+
28+
If `readTextFile` or `writeTextFile` is `false` or not present, the Agent **MUST NOT** attempt to call the corresponding filesystem method.
29+
30+
## Reading Files
31+
32+
The `fs/read_text_file` method allows Agents to read text file contents from the Client's filesystem, including unsaved changes in the editor.
33+
34+
```json
35+
{
36+
"jsonrpc": "2.0",
37+
"id": 3,
38+
"method": "fs/read_text_file",
39+
"params": {
40+
"sessionId": "sess_abc123def456",
41+
"path": "src/main.py",
42+
"line": 10,
43+
"limit": 50
44+
}
45+
}
46+
```
47+
48+
<ParamField path="sessionId" type="SessionId" required>
49+
The [Session ID](./session-setup#session-id) for this request
50+
</ParamField>
51+
52+
<ParamField path="path" type="string" required>
53+
Path to the file to read
54+
</ParamField>
55+
56+
<ParamField path="line" type="number">
57+
Optional line number to start reading from (1-based)
58+
</ParamField>
59+
60+
<ParamField path="limit" type="number">
61+
Optional maximum number of lines to read
62+
</ParamField>
63+
64+
The Client responds with the file contents:
65+
66+
```json
67+
{
68+
"jsonrpc": "2.0",
69+
"id": 3,
70+
"result": {
71+
"content": "def hello_world():\n print('Hello, world!')\n"
72+
}
73+
}
74+
```
75+
76+
## Writing Files
77+
78+
The `fs/write_text_file` method allows Agents to write or update text files in the Client's filesystem.
79+
80+
```json
81+
{
82+
"jsonrpc": "2.0",
83+
"id": 4,
84+
"method": "fs/write_text_file",
85+
"params": {
86+
"sessionId": "sess_abc123def456",
87+
"path": "config.json",
88+
"content": "{\n \"debug\": true,\n \"version\": \"1.0.0\"\n}"
89+
}
90+
}
91+
```
92+
93+
<ParamField path="sessionId" type="SessionId" required>
94+
The [Session ID](./session-setup#session-id) for this request
95+
</ParamField>
96+
97+
<ParamField path="path" type="string" required>
98+
Path to the file to write.
99+
The Client **MUST** create the file if it doesn't exist.
100+
</ParamField>
101+
102+
<ParamField path="content" type="string" required>
103+
The text content to write to the file
104+
</ParamField>
105+
106+
The Client responds with an empty result on success:
107+
108+
```json
109+
{
110+
"jsonrpc": "2.0",
111+
"id": 4,
112+
"result": null
113+
}
114+
```

docs/protocol/tool-calls.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Tool calls represent actions that language models request Agents to perform duri
77

88
Agents report tool calls through [`session/update`](./prompt-turn#3-agent-reports-output) notifications, allowing Clients to display real-time progress and results to users.
99

10-
While Agents handle the actual execution, they may leverage Client capabilities like permission requests or file system access to provide a richer, more integrated experience.
10+
While Agents handle the actual execution, they may leverage Client capabilities like [permission requests](#requesting-permission) or [file system access](./file-system) to provide a richer, more integrated experience.
1111

1212
## Creating
1313

0 commit comments

Comments
 (0)