Skip to content

Commit 275fbdd

Browse files
authored
Merge pull request #1652 from meridianhub/mcp-sdk-migration
2 parents be95cf9 + 96d676d commit 275fbdd

48 files changed

Lines changed: 1201 additions & 3810 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

go.mod

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ require (
1414
github.com/bits-and-blooms/bloom/v3 v3.7.1
1515
github.com/bsm/redislock v0.9.4
1616
github.com/coder/websocket v1.8.14
17+
github.com/dexidp/dex v0.0.0-20260303133905-11d2eeb52b42
1718
github.com/golang-jwt/jwt/v5 v5.3.1
1819
github.com/google/uuid v1.6.0
1920
github.com/jackc/pgx/v5 v5.8.0
2021
github.com/lib/pq v1.11.2
22+
github.com/modelcontextprotocol/go-sdk v1.4.1
2123
github.com/prometheus/client_golang v1.23.2
2224
github.com/prometheus/client_model v0.6.2
2325
github.com/redis/go-redis/v9 v9.18.0
@@ -66,11 +68,11 @@ require (
6668
github.com/beorn7/perks v1.0.1 // indirect
6769
github.com/bits-and-blooms/bitset v1.24.2 // indirect
6870
github.com/coreos/go-oidc/v3 v3.17.0 // indirect
69-
github.com/dexidp/dex v0.0.0-20260303133905-11d2eeb52b42 // indirect
7071
github.com/dexidp/dex/api/v2 v2.4.0 // indirect
7172
github.com/go-asn1-ber/asn1-ber v1.5.8-0.20250403174932-29230038a667 // indirect
7273
github.com/go-ldap/ldap/v3 v3.4.12 // indirect
7374
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
75+
github.com/google/jsonschema-go v0.4.2 // indirect
7476
github.com/gorilla/handlers v1.5.2 // indirect
7577
github.com/gorilla/mux v1.8.1 // indirect
7678
github.com/hashicorp/errwrap v1.1.0 // indirect
@@ -82,7 +84,6 @@ require (
8284
github.com/hashicorp/go-sockaddr v1.0.7 // indirect
8385
github.com/hashicorp/hcl v1.0.1-vault-7 // indirect
8486
github.com/huandu/xstrings v1.5.0 // indirect
85-
github.com/imdario/mergo v0.3.11 // indirect
8687
github.com/inconshreveable/mousetrap v1.1.0 // indirect
8788
github.com/jonboulle/clockwork v0.5.0 // indirect
8889
github.com/kylelemons/godebug v1.1.0 // indirect
@@ -98,12 +99,15 @@ require (
9899
github.com/prometheus/procfs v0.16.1 // indirect
99100
github.com/russellhaering/goxmldsig v1.5.0 // indirect
100101
github.com/ryanuber/go-glob v1.0.0 // indirect
102+
github.com/segmentio/asm v1.1.3 // indirect
103+
github.com/segmentio/encoding v0.5.4 // indirect
101104
github.com/spf13/cast v1.7.0 // indirect
102105
github.com/spf13/pflag v1.0.10 // indirect
103106
github.com/stretchr/objx v0.5.2 // indirect
104107
github.com/tidwall/match v1.1.1 // indirect
105108
github.com/tidwall/pretty v1.2.1 // indirect
106109
github.com/twmb/franz-go/pkg/kmsg v1.12.0 // indirect
110+
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
107111
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.40.0 // indirect
108112
go.uber.org/atomic v1.11.0 // indirect
109113
go.yaml.in/yaml/v2 v2.4.2 // indirect

go.sum

Lines changed: 29 additions & 71 deletions
Large diffs are not rendered by default.

services/mcp-server/cmd/main.go

Lines changed: 26 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@ import (
66
"context"
77
"errors"
88
"fmt"
9-
"io"
109
"log/slog"
1110
"net/http"
1211
"os"
1312
"strings"
1413
"time"
1514

15+
"github.com/modelcontextprotocol/go-sdk/mcp"
16+
1617
mcpauth "github.com/meridianhub/meridian/services/mcp-server/internal/auth"
17-
"github.com/meridianhub/meridian/services/mcp-server/internal/server"
18-
"github.com/meridianhub/meridian/services/mcp-server/internal/transport"
1918
platformauth "github.com/meridianhub/meridian/shared/platform/auth"
2019
"github.com/meridianhub/meridian/shared/platform/bootstrap"
2120
"github.com/meridianhub/meridian/shared/platform/env"
@@ -56,39 +55,36 @@ func run(logger *slog.Logger) error {
5655
transportMode := env.GetEnvOrDefault("MCP_TRANSPORT", "stdio")
5756
serverName := env.GetEnvOrDefault("MCP_SERVER_NAME", "meridian-mcp")
5857

59-
cfg := server.Config{
60-
ServerName: serverName,
61-
ServerVersion: Version,
58+
srv := mcp.NewServer(&mcp.Implementation{
59+
Name: serverName,
60+
Version: Version,
61+
}, &mcp.ServerOptions{
62+
Logger: logger,
63+
})
64+
65+
// Wire tools, resources, and prompts onto the server.
66+
// cookbookFS is nil until the cookbook directory is embedded at build time.
67+
cleanup, err := wireServer(srv, logger, nil)
68+
if err != nil {
69+
return fmt.Errorf("wire server: %w", err)
70+
}
71+
if cleanup != nil {
72+
defer cleanup()
6273
}
6374

6475
switch transportMode {
6576
case "stdio":
66-
return runStdio(logger, cfg)
77+
return runStdio(logger, srv)
6778
case "http":
68-
return runHTTP(logger, cfg)
79+
return runHTTP(logger, srv)
6980
default:
7081
return bootstrap.Permanent(fmt.Errorf("%w: %s (expected stdio or http)", errUnknownTransport, transportMode))
7182
}
7283
}
7384

74-
func runStdio(logger *slog.Logger, cfg server.Config) error {
85+
func runStdio(logger *slog.Logger, srv *mcp.Server) error {
7586
logger.Info("using stdio transport")
7687

77-
tr := transport.NewStdioTransport(os.Stdin, os.Stdout)
78-
defer tr.Close()
79-
80-
srv := server.New(tr, cfg, logger)
81-
82-
// Wire tools, resources, and prompts onto the server.
83-
// cookbookFS is nil until the cookbook directory is embedded at build time.
84-
cleanup, err := wireServer(srv, logger, nil)
85-
if err != nil {
86-
return fmt.Errorf("wire server: %w", err)
87-
}
88-
if cleanup != nil {
89-
defer cleanup()
90-
}
91-
9288
// For stdio, we run until stdin closes or we receive a signal.
9389
ctx, cancel := context.WithCancel(context.Background())
9490
defer cancel()
@@ -105,7 +101,7 @@ func runStdio(logger *slog.Logger, cfg server.Config) error {
105101
}
106102
}()
107103

108-
return srv.Run(ctx)
104+
return srv.Run(ctx, &mcp.StdioTransport{})
109105
}
110106

111107
const (
@@ -180,33 +176,16 @@ func (p *passthroughIssuer) Issue(claims map[string]any) (string, error) {
180176
return fmt.Sprintf("mcp-issued-%v", claims["client_id"]), nil
181177
}
182178

183-
func runHTTP(logger *slog.Logger, cfg server.Config) error {
179+
func runHTTP(logger *slog.Logger, srv *mcp.Server) error {
184180
port := env.GetEnvOrDefault("MCP_PORT", "8090")
185181
addr := fmt.Sprintf(":%s", port)
186182

187183
logger.Info("using streamable HTTP transport", "address", addr)
188184

189-
// The streamable HTTP handler calls Dispatch() directly — no transport
190-
// read/write loop is needed. We provide a no-op transport to satisfy
191-
// server.New(); Run() is never called in HTTP mode.
192-
pr, pw := io.Pipe()
193-
noopTr := transport.NewStdioTransport(pr, io.Discard)
194-
defer func() { _ = pw.Close(); _ = noopTr.Close() }()
195-
196-
srv := server.New(noopTr, cfg, logger)
197-
198-
// Wire tools, resources, and prompts onto the server.
199-
// cookbookFS is nil until the cookbook directory is embedded at build time.
200-
cleanup, wireErr := wireServer(srv, logger, nil)
201-
if wireErr != nil {
202-
return fmt.Errorf("wire server: %w", wireErr)
203-
}
204-
if cleanup != nil {
205-
defer cleanup()
206-
}
207-
208-
streamableHandler := transport.NewStreamableHTTPHandler(srv, logger)
209-
defer streamableHandler.Close()
185+
// The SDK's StreamableHTTPHandler creates sessions and transports internally.
186+
streamableHandler := mcp.NewStreamableHTTPHandler(func(_ *http.Request) *mcp.Server {
187+
return srv
188+
}, nil)
210189

211190
mux := http.NewServeMux()
212191

0 commit comments

Comments
 (0)