Skip to content

Commit db099e0

Browse files
jeffhandleyCopilot
andauthored
Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 137f3fe commit db099e0

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

docs/concepts/pagination/pagination.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ uid: pagination
77

88
## Pagination
99

10-
MCP uses [cursor-based pagination] for list operations that may return large result sets. This applies to listing tools, prompts, resources, and resource templates.
10+
MCP uses [cursor-based pagination] for all list operations that may return large result sets.
1111

1212
[cursor-based pagination]: https://modelcontextprotocol.io/specification/2025-11-25/server/utilities/pagination
1313

docs/concepts/resources/resources.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,34 @@ Template resources use [URI templates (RFC 6570)] with parameters. They are retu
4141
[McpServerResourceType]
4242
public class FileResources
4343
{
44+
// Configure a root directory for all file:// resources
45+
private static readonly string RootDirectory = Path.GetFullPath(AppContext.BaseDirectory);
46+
4447
[McpServerResource(UriTemplate = "file:///{path}", Name = "File Resource")]
45-
[Description("Reads a file by its path")]
48+
[Description("Reads a file by its path within the configured root directory")]
4649
public static ResourceContents ReadFile(string path)
4750
{
48-
if (File.Exists(path))
51+
if (string.IsNullOrWhiteSpace(path))
52+
{
53+
throw new McpException("Path must be provided.");
54+
}
55+
56+
// Combine the requested path with the root directory and canonicalize it
57+
var fullPath = Path.GetFullPath(Path.Combine(RootDirectory, path));
58+
59+
// Ensure the final path is still under the allowed root directory
60+
if (!fullPath.StartsWith(RootDirectory, StringComparison.OrdinalIgnoreCase))
61+
{
62+
throw new McpException("Requested file path is outside the allowed directory.");
63+
}
64+
65+
if (File.Exists(fullPath))
4966
{
5067
return new TextResourceContents
5168
{
5269
Uri = $"file:///{path}",
5370
MimeType = "text/plain",
54-
Text = File.ReadAllText(path)
71+
Text = File.ReadAllText(fullPath)
5572
};
5673
}
5774

docs/concepts/transports/transports.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ See the `ModelContextProtocol.AspNetCore` package [README](https://github.com/mo
130130

131131
The [SSE (Server-Sent Events)] transport is a legacy mechanism that uses unidirectional server-to-client streaming with a separate HTTP endpoint for client-to-server messages. New implementations should prefer Streamable HTTP.
132132

133-
[SSE (Server-Sent Events)]: https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#http-with-sse
133+
[SSE (Server-Sent Events)]: https://modelcontextprotocol.io/specification/2024-11-05/basic/transports#http-with-sse
134134

135135
> [!NOTE]
136136
> The SSE transport is considered legacy. The [Streamable HTTP](#streamable-http-transport) transport is the recommended approach for HTTP-based communication and supports bidirectional streaming.

0 commit comments

Comments
 (0)