app.Builder
app.Builder is a builder around uber’s fx that combines fx DI capabilities with foxy-contexts MCP server implementation and gives simple interface to combine your MCP primitives into a single standalone application.
Usage
Simple example of wrapping one tool into an application, then running it with stdio transport:
func main() {
app.
NewBuilder().
// adding the tool to the app
WithTool(NewGreatTool).
// setting up server
WithName("great-tool-server").
WithVersion("0.0.1").
WithTransport(stdio.NewTransport()).
// Configuring fx logging to only show errors
WithFxOptions(
fx.Provide(func() *zap.Logger {
cfg := zap.NewDevelopmentConfig()
cfg.Level.SetLevel(zap.ErrorLevel)
logger, _ := cfg.Build()
return logger
}),
fx.Option(fx.WithLogger(
func(logger *zap.Logger) fxevent.Logger {
return &fxevent.ZapLogger{Logger: logger}
},
)),
).Run()
}
Providing additional server options
Normally app.Builder preconfigure server for you, but you can provide additional server options to the application by using WithExtraServerOptions
option.
Say, for example this would make server to turn on logging to stderr:
WithExtraServerOptions(server.LoggerOption{
Logger: foxyevent.NewSlogLogger(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{
Level: slog.LevelDebug,
}))).WithLogLevel(slog.LevelInfo),
})