Define types and architecture for a variant-aware MCP server (#2)
Defines the core types and API for server variants extension, laying groundwork for multi-variant server implementation. Server.Run() is not yet implemented but architecture is designed and documented. - Add Server type with variant registration - Implement default priority-based ranking - Define ServerVariant, VariantHints, and related types per SEP spec - Add comprehensive example demonstrating intended multi-variant usage - Document implementation plan for Server.Run() dispatch architecture Next PRs: - Unit Tests - Implementation for Server.Run - Conformance Testing Signed-off-by: Kurt Degiorgio <kdegiorgio@bloomberg.net>
This commit is contained in:
parent
4f98e0aab3
commit
dbf99bebf0
1 changed files with 576 additions and 7 deletions
39
go/sdk/variants/ranking.go
Normal file
39
go/sdk/variants/ranking.go
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
// Copyright 2025 The MCP Variants Authors. All rights reserved.
|
||||
// Use of this source code is governed by a Apache-2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package variants
|
||||
|
||||
import (
|
||||
"context"
|
||||
"slices"
|
||||
)
|
||||
|
||||
// defaultRankingFunc is the built-in ranking function used when no custom
|
||||
// RankingFunc is provided. It sorts variants by priority (lowest first),
|
||||
// using stable-before-experimental-before-deprecated as a tiebreaker.
|
||||
func defaultRankingFunc(_ context.Context, _ VariantHints, vs []ServerVariant) []ServerVariant {
|
||||
ranked := slices.Clone(vs)
|
||||
slices.SortStableFunc(ranked, func(a, b ServerVariant) int {
|
||||
if a.Priority() != b.Priority() {
|
||||
return a.Priority() - b.Priority()
|
||||
}
|
||||
return statusWeight(a.Status) - statusWeight(b.Status)
|
||||
})
|
||||
return ranked
|
||||
}
|
||||
|
||||
// statusWeight returns a sort weight for a VariantStatus.
|
||||
// Lower is better: stable < experimental < deprecated.
|
||||
func statusWeight(s VariantStatus) int {
|
||||
switch s {
|
||||
case Stable, "":
|
||||
return 0
|
||||
case Experimental:
|
||||
return 1
|
||||
case Deprecated:
|
||||
return 2
|
||||
default:
|
||||
return 3
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue