Skip to content

Commit a681c96

Browse files
committed
refactor(mcp-server-filesystem): Simplify file operation tools and prompts, update README for clarity and consistency
1 parent ca7650d commit a681c96

File tree

8 files changed

+112
-270
lines changed

8 files changed

+112
-270
lines changed

mcp-server-filesystem/README.adoc

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,16 @@ Java server implementing Model Context Protocol (MCP) for filesystem operations.
2020
- *read_file*
2121
* Read complete file contents with UTF-8 encoding.
2222
* Input:
23-
** `path` (string): The path to the file to read.
23+
** `path` (string): The filepath to read, required.
2424
* Output: Complete file contents with UTF-8 encoding.
2525

2626
- *list_files*
27-
* List files of a directory with name-based filtering and recursion option.
27+
* List files of a directory.
2828
* Input:
29-
** `directoryPath` (string): The path to the directory to read.
30-
** `fileNamePattern` (string): Regular expression to filter files, if it's empty, all files will be listed. Default is empty.
31-
** `recursive` (boolean): Whether to list files recursively. Default is `false`.
32-
* Output: A list of file names (paths if 'recursive' is `true`), or empty string if no files are found.
33-
34-
=== Prompts
35-
36-
- *read_file*
37-
* For `read_file` tool
38-
* Input: `filepath` (string)
39-
* Output: What is the content of this file: `<filepath>`.
40-
41-
- *list_files*
42-
* For `list_files` tool
43-
* Input: `directoryPath` (string), `fileNamePattern` (string), `recursive` (boolean)
44-
* Output:
45-
** Please list files in this directory: `<directoryPath>`.
46-
** Please list files in this directory: `<directoryPath>`, with file name pattern: `<fileNamePattern>`.
47-
** Please list files in this directory: `<directoryPath>`, with file name pattern: `<fileNamePattern>`, recursively.
29+
** `path` (string): The directory path to read, required.
30+
** `pattern` (string): Regular expression to filter files, optional, default is empty, means no filter.
31+
** `recursive` (boolean): Whether to list files recursively, optional, default is `false`.
32+
* Output: A list of file names (paths if 'recursive' is `true`), or empty string if no files found.
4833

4934
== Usage with MCP Client
5035

mcp-server-filesystem/src/main/java/com/github/mcp/examples/server/filesystem/McpPrompts.java

Lines changed: 0 additions & 122 deletions
This file was deleted.

mcp-server-filesystem/src/main/java/com/github/mcp/examples/server/filesystem/McpResources.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,25 @@
1414
public final class McpResources {
1515

1616
/**
17-
* Create a new resource to the MCP server that provides access to the file system.
17+
* Create a MCP resource that provides access to the file system.
1818
* Note that this resource is just an example of how to add a resource to the MCP server.
1919
* So it's not really useful for anything other than demonstration purposes.
2020
*
21-
* @return A specification for the MCP resource.
21+
* @return {@link McpServerFeatures.SyncResourceSpecification}
2222
*/
23-
public static McpServerFeatures.SyncResourceSpecification fileSystemResource() {
23+
public static McpServerFeatures.SyncResourceSpecification filesystem() {
24+
// Step 1: Create a resource with URI, name, description, and MIME type.
2425
McpSchema.Resource resource = new McpSchema.Resource(
25-
"file://system",
26-
"filesystem",
27-
"File system operations interface",
28-
"text/plain",
26+
"file://system", "filesystem", "File system operations interface", "text/plain",
2927
new McpSchema.Annotations(List.of(McpSchema.Role.ASSISTANT, McpSchema.Role.USER), 1.0)
3028
);
31-
32-
return new McpServerFeatures.SyncResourceSpecification(
33-
resource,
34-
(exchange, request) -> {
35-
McpSchema.ResourceContents contents = new McpSchema.TextResourceContents(
36-
resource.uri(), resource.mimeType(), "No specific resource contents, just use the tools."
37-
);
38-
return new McpSchema.ReadResourceResult(List.of(contents));
39-
}
40-
);
29+
// Step 2: Create a handler that returns the contents of the resource.
30+
return new McpServerFeatures.SyncResourceSpecification(resource, (exchange, request) -> {
31+
McpSchema.ResourceContents contents = new McpSchema.TextResourceContents(
32+
resource.uri(), resource.mimeType(), "No specific resource contents, just use the tools."
33+
);
34+
return new McpSchema.ReadResourceResult(List.of(contents));
35+
});
4136
}
4237

4338
/**
@@ -46,7 +41,7 @@ public static McpServerFeatures.SyncResourceSpecification fileSystemResource() {
4641
* @param server The MCP server to add resources to.
4742
*/
4843
public static void addAllTo(McpSyncServer server) {
49-
server.addResource(fileSystemResource());
44+
server.addResource(filesystem());
5045
}
5146

5247
}

mcp-server-filesystem/src/main/java/com/github/mcp/examples/server/filesystem/McpSseServer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ private void initialize() {
7070
.capabilities(serverCapabilities)
7171
.build();
7272

73-
// Add resources, prompts and tools to the MCP server
73+
// Add resources and tools to the MCP server
7474
McpResources.addAllTo(server);
75-
McpPrompts.addAllTo(server);
7675
McpTools.addAllTo(server);
7776

7877
// Start the HTTP server

mcp-server-filesystem/src/main/java/com/github/mcp/examples/server/filesystem/McpStdioServer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ public static void main(String[] args) {
5252
// Initialize MCP server
5353
McpStdioServer mcpStdioServer = new McpStdioServer();
5454
mcpStdioServer.initialize();
55-
// Add resources, prompts and tools to the MCP server
55+
// Add resources and tools to the MCP server
5656
McpResources.addAllTo(mcpStdioServer.server);
57-
McpPrompts.addAllTo(mcpStdioServer.server);
5857
McpTools.addAllTo(mcpStdioServer.server);
5958
}
6059

0 commit comments

Comments
 (0)