Commit Graph

62 Commits

Author SHA1 Message Date
Ola Hungerford
a83b1451c5 Merge pull request #3254 from wingding12/fix/filesystem-macos-symlink-path-resolution
fix(filesystem): resolve symlinked allowed directories to both forms
2026-02-19 07:36:47 -07:00
wingding12
8f2e9cc678 fix(filesystem): resolve symlinked allowed directories to both forms
On macOS, /tmp is a symlink to /private/tmp. When users specify /tmp
as an allowed directory, the server was resolving it to /private/tmp
during startup but then rejecting paths like /tmp/file.txt because
they dont start with /private/tmp.

This fix stores BOTH the original normalized path AND the resolved
path in allowedDirectories, so users can access files through either
form. For example, with /tmp as allowed directory, both /tmp/file.txt
and /private/tmp/file.txt will now be accepted.

Fixes #3253
2026-01-26 18:28:49 -05:00
lunov
2dfa15dc6e fix(filesystem): gracefully handle unavailable directories
Previously, the server would crash if any configured directory was
unavailable (e.g., unmounted external drive). Now it:

- Filters out inaccessible directories with a warning
- Continues operating with remaining accessible directories
- Only fails if NO directories are accessible

Fixes #2815
2026-01-19 19:53:45 +07:00
Stefan Dirkse
e6933ca98b Fix: Changed structuredContent output to match outputSchema (#3099) 2025-12-11 13:48:04 +00:00
Valeriy Pavlovich
84c2824f03 # feat(filesystem): add ToolAnnotations hints to filesystem tools (#3045)
**Files touched**

- [src/filesystem/index.ts](../blob/HEAD/src/filesystem/index.ts) — add `annotations` metadata to each tool definition
- [src/filesystem/README.md](../blob/HEAD/src/filesystem/README.md) — document ToolAnnotations mapping for all filesystem tools

## Description

This change adds MCP `ToolAnnotations` (`readOnlyHint`, `idempotentHint`, `destructiveHint`) to all filesystem tools and documents the mapping in the filesystem README. MCP clients can now accurately distinguish read‑only vs. write tools, understand which operations are safe to retry, and highlight potentially destructive actions.

## Server Details

- **Server**: filesystem
- **Area**: tools (metadata returned via `listTools` / `ListToolsRequest`) and server docs

## Motivation and Context

Previously, the filesystem server did not expose ToolAnnotations, so many clients (e.g. ChatGPT Apps) conservatively treated filesystem tools as generic write operations. This led to:

- READ operations being surfaced with WRITE badges and confirmation prompts.
- No way for clients to know which write tools are idempotent or potentially destructive.

This PR aligns the implementation with `servers#2988` and updates the README to clearly document the semantics of each tool. Read‑only operations no longer need to be treated as writes, and destructive/idempotent behavior is explicit for UI and retry logic.

## How Has This Been Tested?

- `npm run build --workspace @modelcontextprotocol/server-filesystem`
- `npm test --workspaces --if-present`

## Breaking Changes

None.

## Types of changes

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [x] Documentation update

## Checklist

- [x] I have read the [MCP Protocol Documentation](https://modelcontextprotocol.io)
- [x] My changes follows MCP security best practices
- [x] I have updated the server's README accordingly
- [x] I have tested this with an LLM client
- [x] My code follows the repository's style guidelines
- [x] New and existing tests pass locally
- [x] I have added appropriate error handling
- [ ] I have documented all environment variables and configuration options

## Additional context

None.

Co-authored-by: Valeriy_Pavlovich <vp@strato.space>
2025-11-24 15:58:15 +00:00
Adam Jones
3f2ddb0479 fix: simplify output schemas for text-only tools and add structuredContent
For text-only tool responses, simplify outputSchemas from complex nested
arrays to simple { content: z.string() } format. All tool responses now
include structuredContent matching their outputSchema, fixing MCP protocol
violations when tools had output schemas but no structured content.

This applies to both filesystem and everything servers.
2025-11-20 21:44:36 +00:00
adam jones
55c3a31690 fix(filesystem): address review feedback from #3016 (#3031)
Address two items from Camila's review:

1. Use blob type for non-image/non-audio media files, restoring the
   original behavior. This matches the previous implementation which
   used blob as the fallback for unknown binary types. Use type
   assertion to satisfy the SDK's type constraints.

2. Reuse ReadTextFileArgsSchema.shape in the deprecated read_file tool
   instead of redefining the schema inline.
2025-11-20 20:29:22 +00:00
adam jones
4dc24cf349 fix(filesystem): convert to modern TypeScript SDK APIs (#3016)
* fix(filesystem): convert to modern TypeScript SDK APIs

Convert the filesystem server to use the modern McpServer API instead
of the low-level Server API.

Key changes:
- Replace Server with McpServer from @modelcontextprotocol/sdk/server/mcp.js
- Convert all 13 tools to use registerTool() instead of manual request handlers
- Use Zod schemas directly in inputSchema/outputSchema
- Add structuredContent to all tool responses
- Fix type literals to use 'as const' assertions
- Update roots protocol handling to use server.server.* pattern
- Fix tsconfig to exclude vitest.config.ts

Tools converted:
- read_file (deprecated)
- read_text_file
- read_media_file
- read_multiple_files
- write_file
- edit_file
- create_directory
- list_directory
- list_directory_with_sizes
- directory_tree
- move_file
- search_files
- get_file_info
- list_allowed_directories

The modern API provides:
- Less boilerplate code
- Better type safety with Zod
- More declarative tool registration
- Cleaner, more maintainable code

* fix: use default import for minimatch

minimatch v10+ uses default export instead of named export

* fix(filesystem): use named import for minimatch

The minimatch module doesn't have a default export, so we need to use
the named import syntax instead.

Fixes TypeScript compilation error:
error TS2613: Module has no default export. Did you mean to use
'import { minimatch } from "minimatch"' instead?
2025-11-20 17:00:04 +00:00
Sebastien Rosset (serosset)
b647cb3019 Add documentation for the read_multiple_files action. 2025-08-23 10:51:51 -07:00
Finn Andersen
fd886fac9c Support glob pattern in search_files tool (#745)
Co-authored-by: Adam Jones <adamj+git@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Adam Jones <adamj@anthropic.com>
2025-08-23 07:37:53 +01:00
Enrico Ballardini
d381cf1ffd feat(directory_tree): add excludePatterns support & documentation (#623)
- Update documentation with directory_tree declaration
- Add excludePatterns parameter to DirectoryTreeArgsSchema
- Implement pattern exclusion in buildTree function using minimatch
- Pass excludePatterns through recursive calls
- Support both simple and glob patterns for exclusion
- Maintain consistent behavior with search_files implementation

* Add tests and fix implementation

---------

Co-authored-by: Ola Hungerford <olahungerford@gmail.com>
Co-authored-by: Adam Jones <adamj+git@anthropic.com>
Co-authored-by: Adam Jones <adamj@anthropic.com>
2025-08-23 07:19:01 +01:00
Michael Casazza
46368832ef Windows filesystem MCP enhancements (#543)
* fix: comprehensive Windows path handling improvements

- Add path-utils module for consistent path handling
- Handle Windows paths with spaces via proper quoting
- Support Unix-style Windows paths (/c/path)
- Support WSL paths (/mnt/c/path)
- Add comprehensive test coverage
- Fix path normalization for all path formats

Closes #447

* tested locally and working now

* Add filesystem path utils and tests

* Ensure Windows drive letters are capitalized in normalizePath

* adding test for gh pr comment

* pushing jest and windows testing config

* last commit? fixing comments on PR

* Fix bin and bump sdk

* Remove redundant commonjs version of path-utils and import from ts version

* Remove copying cjs file

* Remove copying run-server

* Remove complex args parsing and do other cleanup

* Add missing tools details to Readme

* Move utility functions from index to lib

* Add more tests and handle very small and very large files edge cases

* Finish refactoring and include original security fix comments

* On Windows, also check for drive root

* Check symlink support on restricted Windows environments

* Fix tests

* Bump SDK and package version

* Clean up

---------

Co-authored-by: olaservo <olahungerford@gmail.com>
Co-authored-by: adam jones <adamj+git@anthropic.com>
2025-08-18 18:23:40 +01:00
Ola Hungerford
7e1d9d9ede fix: clarify list_allowed_directories description to mention subdirectory access (#2571)
The tool description was ambiguous about subdirectory access within allowed directories.
Updated the description to explicitly state that subdirectories are also accessible.

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: Ola Hungerford <olaservo@users.noreply.github.com>
2025-08-17 23:32:33 +01:00
cliffhall
704275818f Replace read_file tool with deprecation notice in description, which is functionally just an alias for read_text_file 2025-07-25 16:01:05 -04:00
cliffhall
ba20bd60af Update the way the stream is concatenated
Update the ts sdk
2025-07-18 16:09:56 -04:00
Cliff Hall
d532a5846d Stream media file reads 2025-07-18 14:18:32 -04:00
Cliff Hall
11a064c359 Rename read_file to read_text_file and add read_media_file 2025-07-18 13:42:56 -04:00
Nandha Reddy
2c922a93f9 feat(filesystem): add symlink resolution and home directory support to roots protocol
- Add symlink resolution using fs.realpath() for security consistency
- Support home directory expansion (~/) in root URI specifications
- Improve error handling with null checks, detailed error messages, and informative logging
- Change allowedDirectories from constant to variable to support roots protocol directory management
2025-07-02 13:38:22 +10:00
Nandha Reddy
f3891aaf69 Apply suggestions from code review comments on docs and logging
Co-authored-by: Ola Hungerford <olahungerford@gmail.com>
2025-07-02 09:44:16 +10:00
Nandha Reddy
f8dd74576b feat(filesystem): implement MCP roots protocol for dynamic directory management
- Extract roots processing logic from index.ts into testable roots-utils.ts module and add Test suite
- Update README to recommend MCP roots protocol for dynamic directory management
2025-07-02 09:44:16 +10:00
Nandha Reddy
b37da40003 feat(filesystem): implement MCP roots protocol for dynamic directory management
- Add support for dynamic directory updates via MCP roots protocol
- Allow clients to override command-line directories at runtime
- Maintain backwards compatibility with existing command-line args
- Add comprehensive error handling for edge cases
- Update documentation to explain both configuration methods

Fixes #401
2025-07-02 09:43:25 +10:00
Jenn Newton
d00c60df9d Address symlink and path prefix issues with allowed directories 2025-06-30 20:04:46 -04:00
Ola Hungerford
d2b217ac4f Merge pull request #1027 from mjherich/feat/filesystem-read-specified-lines
Add head/tail file reading and directory size listings to filesystem server
2025-06-15 23:08:15 -07:00
Matt Herich
f41565ce83 Normalize line endings when splitting file chunks 2025-04-03 00:31:26 -07:00
Matt Herich
db24c89c5e Add file read and directory listing enhancements
- Add head/tail functionality for memory-efficient file reading
- Implement new list_directory_with_sizes command with file size info
- Add formatSize utility for human-readable file sizes
2025-03-21 19:29:45 -07:00
EthBerryAdmin
d7ea463aa5 allow ~ to be used in config
following config throws error

```
    "filesystem": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "~"
      ]
    },
```

```
Error accessing directory ~: Error: ENOENT: no such file or directory, stat '~'
    at async Object.stat (node:internal/fs/promises:1032:18)
    at async file:///Users/USER_NAME/.npm/_npx/a3241bba59c344f5/node_modules/@modelcontextprotocol/server-filesystem/dist/index.js:33:23━━━━━━━━━━━━━━━━━
    at async Promise.all (index 0)
    at async file:///Users/USER_NAME/.npm/_npx/a3241bba59c344f5/node_modules/@modelcontextprotocol/server-filesystem/dist/index.js:31:1 {
  errno: -2,
  code: 'ENOENT',
  syscall: 'stat',
  path: '~'
}
```

this commit fixes error and allows to set ~ as allowed directory
2025-03-16 16:39:24 +04:00
Justin Spahr-Summers
305d799bdd Merge pull request #299 from modelcontextprotocol/mahesh/fix-filesystem
Update case sensitivity handling for filesystem server
2024-12-13 09:30:30 +00:00
Justin Spahr-Summers
5b5e24c223 Merge pull request #213 from lamemind/main
[FileSystem] directory_tree base implementation
2024-12-11 12:15:44 +00:00
Mahesh Murag
1c30f54b2d Change case sensitivity for filesystem server 2024-12-10 11:53:23 -05:00
lamemind
188cd7653c directory_tree outputs JSON 2024-12-09 21:06:10 +01:00
Jeffrey Ling
da695fe05a cleanup diffs and improve glob matching 2024-12-06 17:37:39 -07:00
devin-ai-integration[bot]
4e31b9d66e fix: add server initialization call 2024-12-06 21:56:41 +00:00
devin-ai-integration[bot]
22a79571d7 fix: properly register search_files tool with schema in server setup 2024-12-06 21:53:53 +00:00
devin-ai-integration[bot]
9049f031cc fix: use correct tools capability format in server setup 2024-12-06 21:53:00 +00:00
devin-ai-integration[bot]
773fb8d205 fix: enable tools capability in server setup 2024-12-06 21:52:24 +00:00
devin-ai-integration[bot]
2c1bb4426c fix: simplify server setup and rely on handlers for tool registration 2024-12-06 21:51:49 +00:00
devin-ai-integration[bot]
15dbacdcba feat: add search_files handler in CallToolRequestSchema 2024-12-06 21:49:22 +00:00
devin-ai-integration[bot]
95e88aeb75 fix: update server setup with correct tool registration format 2024-12-06 21:48:45 +00:00
devin-ai-integration[bot]
3cf9a060cd feat: add search_files handler with excludePatterns support 2024-12-06 21:47:39 +00:00
devin-ai-integration[bot]
ffd9cb7f53 fix: correct tool registration syntax for search_files 2024-12-06 21:45:28 +00:00
devin-ai-integration[bot]
00a30ac2bb fix: add proper TypeScript types to search_files handler 2024-12-06 21:44:45 +00:00
devin-ai-integration[bot]
a1855509d1 feat: register search_files tool with excludePatterns support 2024-12-06 21:44:06 +00:00
devin-ai-integration[bot]
b64851723b fix: use named import for minimatch 2024-12-06 21:41:35 +00:00
devin-ai-integration[bot]
b2b8f29816 feat: add excludePatterns to search_files for filtering directories
- Add excludePatterns property to SearchFilesArgsSchema
- Modify searchFiles function to handle path exclusions
- Add minimatch import for glob pattern matching

This change allows excluding specific directories (like node_modules)
from file searches to prevent context window overflow.

Issue: modelcontextprotocol/servers#251
2024-12-06 21:40:54 +00:00
Enrico Ballardini
a6dfe1e9b6 Merge branch 'main' into main 2024-12-06 10:37:02 -03:00
Marc Goodner
b477af5c04 seriously, like aider 2024-12-05 00:33:49 -08:00
Marc Goodner
b04c9334bc schema def issues 2024-12-04 20:45:43 -08:00
Marc Goodner
b6e052946a use the diff package, aider inspired search 2024-12-04 20:13:58 -08:00
Marc Goodner
02ff589f58 user aider inspired diff approach 2024-12-04 19:21:04 -08:00
Marc Goodner
bb7925fe11 improve whitespace sensitivity in multiline text matching 2024-12-04 07:35:12 -08:00