Skip to content

Commit 69c839d

Browse files
committed
update design doc
1 parent 22c8327 commit 69c839d

File tree

2 files changed

+5
-25
lines changed

2 files changed

+5
-25
lines changed

design/design.md

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -692,13 +692,9 @@ func (cs *ClientSession) CallTool(context.Context, *CallToolParams[json.RawMessa
692692
func CallTool[TArgs any](context.Context, *ClientSession, *CallToolParams[TArgs]) (*CallToolResult, error)
693693
```
694694
695-
**Differences from mcp-go**: using variadic options to configure tools was significantly inspired by mcp-go. However, the distinction between `ToolOption` and `SchemaOption` allows for recursive application of schema options. For example, that limitation is visible in [this code](https://github.com/DCjanus/dida365-mcp-server/blob/master/cmd/mcp/tools.go#L315), which must resort to untyped maps to express a nested schema.
695+
**Differences from mcp-go**: We provide a full JSON Schema implementation for validating tool input schemas against incoming arguments. The `jsonschema.Schema` type provides exported features for all keywords in the JSON Schema draft2020-12 spec. Tool definers can use it to construct any schema they want. The `jsonschema.For[T]` function can infer a schema from a Go struct. These combined features eliminate the need for variadic arguments to construct tool schemas.
696696
697-
Additionally, the `NewServerTool` helper provides a means for building a tool from a Go function using reflection, that automatically handles parsing and validation of inputs.
698-
699-
We provide a full JSON Schema implementation for validating tool input schemas against incoming arguments. The `jsonschema.Schema` type provides exported features for all keywords in the JSON Schema draft2020-12 spec. Tool definers can use it to construct any schema they want, so there is no need to provide options for all of them. When combined with schema inference from input structs, we found that we needed only three options to cover the common cases, instead of mcp-go's 23. For example, we will provide `Enum`, which occurs 125 times in open source code, but not MinItems, MinLength or MinProperties, which each occur only once (and in an SDK that wraps mcp-go).
700-
701-
For registering tools, we provide only `AddTools`; mcp-go's `SetTools`, `AddTool`, `AddSessionTool`, and `AddSessionTools` are deemed unnecessary. (Similarly for Delete/Remove).
697+
For registering tools, we provide only a `Server.AddTool` method; mcp-go's `SetTools`, `AddTool`, `AddSessionTool`, and `AddSessionTools` are deemed unnecessary. (Similarly for Delete/Remove). The `AddTool` generic function combines schema inference with registration, providing a easy way to register many tools.
702698
703699
### Prompts
704700
@@ -722,7 +718,7 @@ server.RemovePrompts("code_review")
722718
723719
Client sessions can call the spec method `ListPrompts` or the iterator method `Prompts` to list the available prompts, and the spec method `GetPrompt` to get one.
724720
725-
**Differences from mcp-go**: We provide a `NewServerPrompt` helper to bind a prompt handler to a Go function using reflection to derive its arguments. We provide `RemovePrompts` to remove prompts from the server.
721+
**Differences from mcp-go**: We provide `RemovePrompts` to remove prompts from the server.
726722
727723
### Resources and resource templates
728724
@@ -746,25 +742,9 @@ func (s *Server) RemoveResourceTemplates(uriTemplates ...string)
746742
747743
The `ReadResource` method finds a resource or resource template matching the argument URI and calls its associated handler.
748744
749-
To read files from the local filesystem, we recommend using `FileResourceHandler` to construct a handler:
750-
751-
```go
752-
// FileResourceHandler returns a ResourceHandler that reads paths using dir as a root directory.
753-
// It protects against path traversal attacks.
754-
// It will not read any file that is not in the root set of the client requesting the resource.
755-
func (*Server) FileResourceHandler(dir string) ResourceHandler
756-
```
757-
758-
Here is an example:
759-
760-
```go
761-
// Safely read "/public/puppies.txt".
762-
s.AddResource(&mcp.Resource{URI: "file:///puppies.txt"}, s.FileReadResourceHandler("/public"))
763-
```
764-
765745
Server sessions also support the spec methods `ListResources` and `ListResourceTemplates`, and the corresponding iterator methods `Resources` and `ResourceTemplates`.
766746
767-
**Differences from mcp-go**: for symmetry with tools and prompts, we use `AddResources` rather than `AddResource`. Additionally, the `ResourceHandler` returns a `ReadResourceResult`, rather than just its content, for compatibility with future evolution of the spec.
747+
**Differences from mcp-go**: The `ResourceHandler` returns a `ReadResourceResult`, rather than just its content, for compatibility with future evolution of the spec.
768748
769749
#### Subscriptions
770750

mcp/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ func (s *Server) lookupResourceHandler(uri string) (ResourceHandler, string, boo
388388
// The dir argument should be a filesystem path. It need not be absolute, but
389389
// that is recommended to avoid a dependency on the current working directory (the
390390
// check against client roots is done with an absolute path). If dir is not absolute
391-
// and the current working directory is unavailable, FileResourceHandler panics.
391+
// and the current working directory is unavailable, fileResourceHandler panics.
392392
//
393393
// Lexical path traversal attacks, where the path has ".." elements that escape dir,
394394
// are always caught. Go 1.24 and above also protects against symlink-based attacks,

0 commit comments

Comments
 (0)