-
Notifications
You must be signed in to change notification settings - Fork 5k
filesystem - load files into model context #307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
filesystem - load files into model context #307
Conversation
|
||
**Note**: The server will only allow operations within directories specified via `args`. | ||
|
||
## API | ||
|
||
### Resources | ||
|
||
- `file://system`: File system operations interface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was/is not true, there are no resources exposed by the filesystem mcp before this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is awesome! Just a few questions/suggestions, then happy to merge this in.
// Handle both file:// and folder:// URIs | ||
const match = request.params.uri.match(/^(file|folder):\/\/(.+)/); | ||
if (!match) { | ||
throw new Error('Invalid URI format'); | ||
} | ||
|
||
const [, scheme, pathStr] = match; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using the URL
class for parsing here–makes it easier to check the scheme and extract different parts of the URL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great point!
// Convert URI slashes to platform-specific path separators | ||
const platformPath = pathStr.split('/').join(path.sep); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this shouldn't be needed—forward slashes work fine on Windows.
// If file is smaller than 100kb and type is unknown, treat as text | ||
if (stats.size < 100 * 1024) { | ||
return FileType.TEXT; | ||
} | ||
|
||
// Otherwise fall back to binary | ||
return FileType.BINARY; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIOLI: Best strategy here is probably to try reading it as a string, and if that fails, fall back to binary. This is something we could do later, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will always be possible to "read" any file "as a string", just the string might be absolute garbage and weird characters.
I was thinking about some options around this
-
have separate read_binary, read_image, read_text functions - the caller will generally know what they want and could keep this approach as a
read_auto
or someting -
alternatively make an optional input argument for binary/image/text and fall back to this behaviour if it's not specified
@@ -565,6 +573,137 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => { | |||
}; | |||
} | |||
|
|||
case "load_folder": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to leave this tool in? I don't see it in the README.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch thank you, I will remove it - I was using this personally but I think it's still a bit too janky to commit.
Many issues/questions:
Should it recurse?
Loading more than 5 files into context this way isn't supported by Claude so it frequently breaks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can definitely see how this could blow out the context (depending on the folder) off the cuff I imagine a good ux would be:
- don't recurse, but indicate that there are nested folder which an AI can further load
- have some safeguards that prevent loading in too much data (maybe a text block saying there are "xyz more files" or something?)
93fb32f
to
48e3d4a
Compare
c114833
to
4f3dc11
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey - I'm just getting spun up on this, these all look like great changes!
I haven't dug into the code for a proper review, but because I'm time poor atm, I'm keen to know if @snaggle-ai you're still keen to iterate on this/see it merged? I think they all look like awesome additions.
@@ -565,6 +573,137 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => { | |||
}; | |||
} | |||
|
|||
case "load_folder": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can definitely see how this could blow out the context (depending on the folder) off the cuff I imagine a good ux would be:
- don't recurse, but indicate that there are nested folder which an AI can further load
- have some safeguards that prevent loading in too much data (maybe a text block saying there are "xyz more files" or something?)
Hey @snaggle-ai are you still planning to amend this PR? It has happy nods from core team members, and I'm happy to test. |
Description
Adds resource templates and prompts to the filesystem reference server to load files and folders into model context.
Applied a limit of 30 files for loading into context.
Note: This differs from drag/drop of files into Claude is that this allows the chat to keep track of the uris of files in the context and pass them to tools
Server Details
Motivation and Context
How Has This Been Tested?
Tested prompts with Claude
Breaking Changes
None
Types of changes
Checklist
Additional context
Addresses this issue: #297
Relevant to this discussion: modelcontextprotocol/modelcontextprotocol#90
Very valuable conversation on reddit: https://www.reddit.com/r/mcp/comments/1hamhob/comment/m1cbq30/