@@ -46,8 +46,8 @@ func main() {
46
46
}
47
47
}
48
48
49
- func helloHandler (ctx context .Context , arguments map [ string ] interface {} ) (*mcp .CallToolResult , error ) {
50
- name , ok := arguments [" name" ].(string )
49
+ func helloHandler (ctx context .Context , request mcp . CallToolRequest ) (*mcp .CallToolResult , error ) {
50
+ name , ok := request. Params . Arguments [" name" ].(string )
51
51
if !ok {
52
52
return mcp.NewToolResultError (" name must be a string" ), nil
53
53
}
@@ -137,10 +137,10 @@ func main() {
137
137
)
138
138
139
139
// Add the calculator handler
140
- s.AddTool (calculatorTool, func (args map [ string ] interface {} ) (*mcp.CallToolResult , error ) {
141
- op := args [" operation" ].(string )
142
- x := args [" x" ].(float64 )
143
- y := args [" y" ].(float64 )
140
+ s.AddTool (calculatorTool, func (ctx context. Context , request mcp. CallToolRequest ) (*mcp.CallToolResult , error ) {
141
+ op := request. Params . Arguments [" operation" ].(string )
142
+ x := request. Params . Arguments [" x" ].(float64 )
143
+ y := request. Params . Arguments [" y" ].(float64 )
144
144
145
145
var result float64
146
146
switch op {
@@ -223,7 +223,7 @@ resource := mcp.NewResource(
223
223
)
224
224
225
225
// Add resource with its handler
226
- s.AddResource (resource, func (ctx context.Context ) ([]interface {}, error ) {
226
+ s.AddResource (resource, func (ctx context.Context , request mcp. ReadResourceRequest ) ([]interface {}, error ) {
227
227
content , err := os.ReadFile (" README.md" )
228
228
if err != nil {
229
229
return nil , err
@@ -254,8 +254,8 @@ template := mcp.NewResourceTemplate(
254
254
)
255
255
256
256
// Add template with its handler
257
- s.AddResourceTemplate (template, func (ctx context.Context , args map [ string ] interface {} ) ([]interface {}, error ) {
258
- userID := args[ " id " ].( string )
257
+ s.AddResourceTemplate (template, func (ctx context.Context , request mcp. ReadResourceRequest ) ([]interface {}, error ) {
258
+ userID := request. Params . URI // Extract ID from the full URI
259
259
260
260
profile , err := getUserProfile (userID) // Your DB/API call here
261
261
if err != nil {
@@ -303,10 +303,10 @@ calculatorTool := mcp.NewTool("calculate",
303
303
),
304
304
)
305
305
306
- s.AddTool (calculatorTool, func (args map [ string ] interface {} ) (*mcp.CallToolResult , error ) {
307
- op := args [" operation" ].(string )
308
- x := args [" x" ].(float64 )
309
- y := args [" y" ].(float64 )
306
+ s.AddTool (calculatorTool, func (ctx context. Context , request mcp. CallToolRequest ) (*mcp.CallToolResult , error ) {
307
+ op := request. Params . Arguments [" operation" ].(string )
308
+ x := request. Params . Arguments [" x" ].(float64 )
309
+ y := request. Params . Arguments [" y" ].(float64 )
310
310
311
311
var result float64
312
312
switch op {
@@ -346,11 +346,11 @@ httpTool := mcp.NewTool("http_request",
346
346
),
347
347
)
348
348
349
- s.AddTool (httpTool, func (args map [ string ] interface {} ) (*mcp.CallToolResult , error ) {
350
- method := args [" method" ].(string )
351
- url := args [" url" ].(string )
349
+ s.AddTool (httpTool, func (ctx context. Context , request mcp. CallToolRequest ) (*mcp.CallToolResult , error ) {
350
+ method := request. Params . Arguments [" method" ].(string )
351
+ url := request. Params . Arguments [" url" ].(string )
352
352
body := " "
353
- if b , ok := args [" body" ].(string ); ok {
353
+ if b , ok := request. Params . Arguments [" body" ].(string ); ok {
354
354
body = b
355
355
}
356
356
@@ -413,8 +413,8 @@ s.AddPrompt(mcp.NewPrompt("greeting",
413
413
mcp.WithArgument (" name" ,
414
414
mcp.ArgumentDescription (" Name of the person to greet" ),
415
415
),
416
- ), func (args map [ string ] string ) (*mcp.GetPromptResult , error ) {
417
- name := args [" name" ]
416
+ ), func (ctx context. Context , request mcp. GetPromptRequest ) (*mcp.GetPromptResult , error ) {
417
+ name := request. Params . Arguments [" name" ].( string )
418
418
if name == " " {
419
419
name = " friend"
420
420
}
@@ -437,8 +437,8 @@ s.AddPrompt(mcp.NewPrompt("code_review",
437
437
mcp.ArgumentDescription (" Pull request number to review" ),
438
438
mcp.RequiredArgument (),
439
439
),
440
- ), func (args map [ string ] string ) (*mcp.GetPromptResult , error ) {
441
- prNumber := args [" pr_number" ]
440
+ ), func (ctx context. Context , request mcp. GetPromptRequest ) (*mcp.GetPromptResult , error ) {
441
+ prNumber := request. Params . Arguments [" pr_number" ].( string )
442
442
if prNumber == " " {
443
443
return nil , fmt.Errorf (" pr_number is required" )
444
444
}
@@ -468,8 +468,8 @@ s.AddPrompt(mcp.NewPrompt("query_builder",
468
468
mcp.ArgumentDescription (" Name of the table to query" ),
469
469
mcp.RequiredArgument (),
470
470
),
471
- ), func (args map [ string ] string ) (*mcp.GetPromptResult , error ) {
472
- tableName := args [" table" ]
471
+ ), func (ctx context. Context , request mcp. GetPromptRequest ) (*mcp.GetPromptResult , error ) {
472
+ tableName := request. Params . Arguments [" table" ].( string )
473
473
if tableName == " " {
474
474
return nil , fmt.Errorf (" table name is required" )
475
475
}
0 commit comments