Go Kit

devops-infra MCP Server

Shared infrastructure for go-* MCP servers: env, llm, cache, retry, metrics, strutil

Verified
devops-infradevops-infra
5 views1 stars0 forksApache-2.0

Why This Matters

Discovered via github-topic:mcp and last synced 2mo ago.

Verified
Source
github-topic:mcp
Stars
1
Last synced
2mo ago
Install
Check source

Install

Install instructions not detected yet

Check the source repository for the latest setup steps.

View source instructions
3
Tools
0
Resources
0
Prompts
Standard I/O
Transport

Available Tools (3)

Service

Packages used

Package

What

user

guest"` } var recipe Recipe err := client.ChatTyped(ctx, messages, &recipe) // SSE streaming stream, err := client.Stream(ctx, messages) defer stream.Close() for chunk, ok := stream.Next(); ok; chunk, ok = stream.Next() { fmt.Print(chunk.Delta) } // Structured extraction with validation retry (Instructor-style) type Recipe struct { Name string `json:"name"` Ingredients []string `json:"ingredients"` } var recipe Recipe err := client.Extract(ctx, messages, &recipe, llm.WithValidator(func(v any) error { r := v.(*Recipe) if len(r.Ingredients) == 0 { return errors.New("need at least one ingredient") } return nil }), ) // Union types — LLM chooses between multiple response types type SearchAction struct { Query string `json:"query"` } type AnswerAction struct { Answer string `json:"answer"` } result, err := client.ExtractOneOf(ctx, messages, []llm.VariantDef{ llm.Variant("search", SearchAction{}), llm.Variant("answer", AnswerAction{}), }) switch v := result.(type) { case *SearchAction: fmt.Println("Search:", v.Query) case *AnswerAction: fmt.Println("Answer:", v.Answer) } // Model-level fallback chains client = llm.NewClient("", "", "", llm.WithEndpoints([]llm.Endpoint{ {URL: geminiURL, Key: key1, Model: "gemini-2.5-flash"}, {URL: openaiURL, Key: key2, Model: "gpt-4o"}, }), ) // Health-aware fallback chains — skip models the proxy no longer serves. // BuildModelChainEndpointsFiltered checks each chain entry against the live // {baseURL}/v1/models set, so a model a provider silently removed is dropped // instead of burning a 503 round-trip on every request. The /v1/models set is // cached per baseURL (default 5m TTL). If /v1/models is unreachable/garbage, or // filtering would empty the chain, the FULL unfiltered chain is returned — // graceful degradation, never a new failure mode. Existing // BuildModelChainEndpoints is unchanged; this is opt-in. reg := llm.NewModelRegistry() // share one across a service; caches per baseURL eps := llm.BuildModelChainEndpointsFiltered(ctx, reg, baseURL, apiKey, primary, fallbackChain, func(ev llm.ModelFilterEvent) { // observability: operator sees "N models skipped as absent from /v1/models" if ev.Degraded { llmChainDegraded.WithLabelValues(ev.Reason).Inc() } for _, dead := range ev.Dropped { llmModelDropped.WithLabelValues(dead).Inc() } }, ) client = llm.NewClient("", "", "", llm.WithEndpoints(eps), llm.WithMaxRetries(1)) // Request/response middleware client = llm.NewClient(baseURL, apiKey, model, llm.WithMiddleware(func(ctx context.Context, req *llm.ChatRequest, next func(context.Context, *llm.ChatRequest) (*llm.ChatResponse, error)) (*llm.ChatResponse, error) { start := time.Now() resp, err := next(ctx, req) log.Printf("LLM call took %v", time.Since(start)) return resp, err }), ) ``` - Structured errors: `APIError{StatusCode, Type, Body, Retryable}` — use `errors.As` to branch on error type - Retry on 429/5xx with exponential backoff - Automatic fallback key cycling - SSE streaming via `Stream`/`Next` - Tool/function calling via `Chat` + `WithTools` - Structured output via `ChatTyped` + auto JSON Schema - Extract with validation retry (Instructor-style, no Go library does this) - Union types via `ExtractOneOf` — LLM picks between response variants - Model-level endpoint fallback chains - Health-aware chain filtering via `BuildModelChainEndpointsFiltered` + `ModelRegistry` — drops models absent from the proxy's live `/v1/models`, with graceful degradation and a `ModelFilterObserver` counter hook - Request/response middleware for logging, metrics, caching - Token usage reporting in `ChatResponse` - Multimodal support via `CompleteMultimodal` - JSON extraction from LLM output via `ExtractJSON` - Schema constraint tags: `jsonschema:"description=...,minimum=0,enum=a