Skip to content

Commit

Permalink
update main example
Browse files Browse the repository at this point in the history
  • Loading branch information
strowk committed Dec 8, 2024
1 parent b11c79c commit 854df9d
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ import (
)

func main() {
// This example defines list-current-dir-files tool for MCP server,
// that prints files in the current directory
// This example defines list-current-dir-files tool for MCP server, that prints files in the current directory
// , run it with:
// npx @modelcontextprotocol/inspector go run main.go
// , then in browser open http://localhost:5173
Expand All @@ -56,19 +55,21 @@ func main() {

return fxctx.NewTool(
// This information about the tool would be used when it is listed:
"list-current-dir-files",
"Lists files in the current directory",
mcp.ToolInputSchema{
Type: "object",
Properties: map[string]map[string]interface{}{},
Required: []string{},
&mcp.Tool{
Name: "list-current-dir-files",
Description: Ptr("Lists files in the current directory"),
InputSchema: mcp.ToolInputSchema{
Type: "object",
Properties: map[string]map[string]interface{}{},
Required: []string{},
},
},

// This is the callback that would be executed when the tool is called:
func(args map[string]interface{}) fxctx.ToolResponse {
func(args map[string]interface{}) *mcp.CallToolResult {
files, err := os.ReadDir(".")
if err != nil {
return fxctx.ToolResponse{
return &mcp.CallToolResult{
IsError: Ptr(true),
Meta: map[string]interface{}{},
Content: []interface{}{
Expand All @@ -87,7 +88,7 @@ func main() {
}
}

return fxctx.ToolResponse{
return &mcp.CallToolResult{
Meta: map[string]interface{}{},
Content: contents,
IsError: Ptr(false),
Expand Down Expand Up @@ -158,6 +159,3 @@ func Ptr[T any](v T) *T {

```




0 comments on commit 854df9d

Please sign in to comment.