Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
231 changes: 231 additions & 0 deletions MCP_SDK_MIGRATION_NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
# MCP SDK Migration Notes

## Overview

This document describes the migration from `github.com/mark3labs/mcp-go v0.31.0` to the official `github.com/modelcontextprotocol/go-sdk v1.2.0`.

## Breaking Changes and API Differences

### Import Changes

All imports have been updated from:
```go
import (
"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
)
```

To:
```go
import (
"github.com/modelcontextprotocol/go-sdk/mcp"
)
```

### Server Creation

**Old API:**
```go
mcpServer := server.NewMCPServer("name", "version", opts...)
```

**New API:**
```go
mcpServer := mcp.NewServer(
&mcp.Implementation{Name: "name", Version: "version"},
&mcp.ServerOptions{
Logger: slog.Logger,
// ... other options
},
)
```

### Server Options

**Old API:**
```go
server.WithLogging()
server.WithResourceCapabilities(true, true)
server.WithPromptCapabilities(true)
```

**New API:**
```go
&mcp.ServerOptions{
Logger: NewSlogLogger(),
// Capabilities are now detected automatically based on registered tools/resources
}
```

### Transport (Stdio)

**Old API:**
```go
err := server.ServeStdio(mcpServer)
```

**New API:**
```go
err := mcpServer.Run(ctx, &mcp.StdioTransport{})
```

### Transport (SSE)

**Old API:**
```go
sseServer := server.NewSSEServer(mcpServer, server.WithBaseURL(...))
```

**New API:**
```go
sseHandler := mcp.NewSSEHandler(func(request *http.Request) *mcp.Server {
return mcpServer
}, &mcp.SSEOptions{})
```

### Tool Handler Signatures

**Old API:**
```go
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error)
```

**New API:**
```go
func(ctx context.Context, request *mcp.CallToolRequest) (*mcp.CallToolResult, error)
```
Note: The request is now a pointer.

### Tool Argument Extraction

**Old API:**
```go
args := request.GetArguments() // returns map[string]any
```

**New API:**
```go
func getRequestArguments(req *mcp.CallToolRequest) map[string]any {
if req.Params.Arguments == nil {
return make(map[string]any)
}
var args map[string]any
json.Unmarshal(req.Params.Arguments, &args)
return args
}
```

### Tool Definition

**Old API:**
```go
tool := mcp.NewTool(name,
mcp.WithDescription(...),
mcp.WithString(...),
mcp.WithBoolean(...),
)
```

**New API:**
```go
tool := &mcp.Tool{
Name: name,
Description: description,
InputSchema: map[string]any{
"type": "object",
"properties": properties,
"required": required,
},
}
```

### Tool Results

**Old API:**
```go
return mcp.NewToolResultText(text), nil
```

**New API:**
```go
func NewToolResultText(text string) *mcp.CallToolResult {
return &mcp.CallToolResult{
Content: []mcp.Content{
&mcp.TextContent{Text: text},
},
}
}
```

### Client Info Extraction

**Old API:**
```go
session := server.ClientSessionFromContext(ctx)
sessionWithClientInfo := session.(server.SessionWithClientInfo)
clientInfo := sessionWithClientInfo.GetClientInfo()
```

**New API:**
```go
for ss := range m.mcpServer.Sessions() {
initParams := ss.InitializeParams()
if initParams != nil && initParams.ClientInfo != nil {
return ClientInfo{
Name: initParams.ClientInfo.Name,
Version: initParams.ClientInfo.Version,
}
}
}
```

### Logging Notifications

**Old API:**
```go
server.SendNotificationToAllClients(method, params)
```

**New API:**
```go
for ss := range server.Sessions() {
ss.Log(ctx, &mcp.LoggingMessageParams{
Level: level,
Logger: logger,
Data: message,
})
}
```

## Files Modified

- `go.mod` - Updated dependency
- `internal/mcp/llm_binding.go` - Server creation and transport handling
- `internal/mcp/tools.go` - Tool handlers and argument extraction
- `internal/mcp/utils.go` - Helper functions for tools and client info
- `internal/logging/logger.go` - Session-based logging
- `internal/trust/trust.go` - Tool result creation
- `pkg/mcp/main.go` - Entry point updates

## Test Files Modified

- `internal/mcp/tools_test.go` - Updated for new handler signatures
- `internal/mcp/llm_binding_test.go` - Updated for new SDK types
- `internal/mcp/mcp_spec_conformance_test.go` - Restructured for new SDK
- `internal/mcp/integration_test.go` - New integration tests

## New Features Available in v1.2.0

- Improved error codes (`jsonrpc.Error` sentinels)
- Better streamable transport handling
- OAuth 2.0 Protected Resource Metadata
- `Capabilities` field in `ServerOptions`
- Debounced server change notifications
- Windows CRLF handling fixes

## Testing Notes

- Run tests with `-race` flag to check for race conditions
- Some tests require network access for httptest servers
- SSE handler tests need special handling due to persistent connections
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/go-git/go-git/v5 v5.14.0
github.com/golang/mock v1.6.0
github.com/google/uuid v1.6.0
github.com/mark3labs/mcp-go v0.31.0
github.com/modelcontextprotocol/go-sdk v1.2.0
github.com/oapi-codegen/runtime v1.1.1
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
github.com/pkg/errors v0.9.1
Expand Down Expand Up @@ -53,6 +53,7 @@ require (
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
github.com/gofrs/flock v0.12.1 // indirect
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
github.com/google/jsonschema-go v0.3.0 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
Expand Down
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlnd
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E=
github.com/gofrs/flock v0.12.1/go.mod h1:9zxTsyu5xtJ9DK+1tFZyibEV7y3uwDxPPfbxeeHCoD0=
github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8=
github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 h1:f+oWsMOmNPc8JmEHVZIycC7hBoQxHH9pNKQORJNozsQ=
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8/go.mod h1:wcDNUvekVysuuOpQKo3191zZyTpiI6se1N1ULghS0sw=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
Expand All @@ -108,6 +110,8 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/jsonschema-go v0.3.0 h1:6AH2TxVNtk3IlvkkhjrtbUc4S8AvO0Xii0DxIygDg+Q=
github.com/google/jsonschema-go v0.3.0/go.mod h1:r5quNTdLOYEz95Ru18zA0ydNbBuYoo9tgaYcxEYhJVE=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Expand Down Expand Up @@ -158,8 +162,6 @@ github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4
github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU=
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
github.com/mark3labs/mcp-go v0.31.0 h1:4UxSV8aM770OPmTvaVe/b1rA2oZAjBMhGBfUgOGut+4=
github.com/mark3labs/mcp-go v0.31.0/go.mod h1:rXqOudj/djTORU/ThxYx8fqEVj/5pvTuuebQ2RC7uk4=
github.com/maruel/natural v1.1.1 h1:Hja7XhhmvEFhcByqDoHz9QZbkWey+COd9xWfCfn1ioo=
github.com/maruel/natural v1.1.1/go.mod h1:v+Rfd79xlw1AgVBjbO0BEQmptqb5HvL/k9GRHB7ZKEg=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
Expand All @@ -171,6 +173,8 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/modelcontextprotocol/go-sdk v1.2.0 h1:Y23co09300CEk8iZ/tMxIX1dVmKZkzoSBZOpJwUnc/s=
github.com/modelcontextprotocol/go-sdk v1.2.0/go.mod h1:6fM3LCm3yV7pAs8isnKLn07oKtB0MP9LHd3DfAcKw10=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
Expand Down
Loading
Loading