You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"context"
"fmt"
"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
)
func main() {
// Create a new MCP server
s := server.NewMCPServer(
"Demo 🚀",
"1.0.0",
)
// Add tool
tool := mcp.NewTool("hello_world",
mcp.WithDescription("Say hello to someone"),
mcp.WithString("name",
mcp.Required(),
mcp.Description("Name of the person to greet"),
),
)
// Add tool handler
s.AddTool(tool, helloHandler)
// Start the stdio server
if err := server.ServeStdio(s); err != nil {
fmt.Printf("Server error: %v\n", err)
}
}
func helloHandler(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
name, err := request.RequireString("name")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
return mcp.NewToolResultText(fmt.Sprintf("Hello, %s!", name)), nil
}
`
go run main.go
{"jsonrpc":"2.0","method":"tools/call","params":{"name":"hello_wolrd"},"id":2}
{"jsonrpc":"2.0","id":2,"error":{"code":-32602,"message":"tool 'hello_wolrd' not found: tool not found"}}
{"jsonrpc":"2.0","method":"hellow_wolrd","params":{"name":"hello_wolrd"},"id":2}
{"jsonrpc":"2.0","id":2,"error":{"code":-32601,"message":"Method hello_wolrd not found"}}
`
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
`
go run main.go
{"jsonrpc":"2.0","method":"tools/call","params":{"name":"hello_wolrd"},"id":2}
{"jsonrpc":"2.0","id":2,"error":{"code":-32602,"message":"tool 'hello_wolrd' not found: tool not found"}}
{"jsonrpc":"2.0","method":"hellow_wolrd","params":{"name":"hello_wolrd"},"id":2}
{"jsonrpc":"2.0","id":2,"error":{"code":-32601,"message":"Method hello_wolrd not found"}}
`
how do i test ?
Beta Was this translation helpful? Give feedback.
All reactions