Add AI support via model context protocol api (#22121)
This commit is contained in:
parent
c83dbfdea7
commit
0a0cc8d83e
12 changed files with 2452 additions and 4 deletions
3
Makefile
3
Makefile
|
|
@ -79,6 +79,9 @@ snapshot::
|
|||
release::
|
||||
goreleaser --clean
|
||||
|
||||
openapi::
|
||||
cd server/mcp && go tool openapi https://raw.githubusercontent.com/evcc-io/docs/refs/heads/main/static/rest-api.yaml
|
||||
|
||||
docker::
|
||||
@echo Version: $(VERSION) $(SHA) $(BUILD_DATE)
|
||||
docker buildx build --platform $(PLATFORM) --tag $(DOCKER_IMAGE):$(DOCKER_TAG) --push .
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ type All struct {
|
|||
SponsorToken string
|
||||
Plant string // telemetry plant id
|
||||
Telemetry bool
|
||||
Mcp bool
|
||||
Metrics bool
|
||||
Profile bool
|
||||
Levels map[string]string
|
||||
|
|
|
|||
18
cmd/root.go
18
cmd/root.go
|
|
@ -16,6 +16,7 @@ import (
|
|||
"github.com/evcc-io/evcc/core/keys"
|
||||
"github.com/evcc-io/evcc/push"
|
||||
"github.com/evcc-io/evcc/server"
|
||||
"github.com/evcc-io/evcc/server/mcp"
|
||||
"github.com/evcc-io/evcc/server/updater"
|
||||
"github.com/evcc-io/evcc/util"
|
||||
"github.com/evcc-io/evcc/util/auth"
|
||||
|
|
@ -89,6 +90,9 @@ func init() {
|
|||
rootCmd.Flags().Bool("profile", false, "Expose pprof profiles")
|
||||
bind(rootCmd, "profile")
|
||||
|
||||
rootCmd.Flags().Bool("mcp", false, "Expose MCP service (experimental)")
|
||||
bind(rootCmd, "mcp")
|
||||
|
||||
rootCmd.Flags().Bool(flagDisableAuth, false, flagDisableAuthDescription)
|
||||
}
|
||||
|
||||
|
|
@ -158,7 +162,7 @@ func runRoot(cmd *cobra.Command, args []string) {
|
|||
err = networkSettings(&conf.Network)
|
||||
}
|
||||
|
||||
log.INFO.Printf("listening at :%d", conf.Network.Port)
|
||||
log.INFO.Printf("UI listening at :%d", conf.Network.Port)
|
||||
|
||||
// start broadcasting values
|
||||
tee := new(util.Tee)
|
||||
|
|
@ -259,6 +263,18 @@ func runRoot(cmd *cobra.Command, args []string) {
|
|||
err = wrapErrorWithClass(ClassHEMS, configureHEMS(&conf.HEMS, site, httpd))
|
||||
}
|
||||
|
||||
// setup MCP
|
||||
if viper.GetBool("mcp") {
|
||||
const path = "/mcp"
|
||||
local := conf.Network.URI()
|
||||
router := httpd.Router()
|
||||
|
||||
var handler http.Handler
|
||||
if handler, err = mcp.NewHandler(router, local, path); err == nil {
|
||||
router.PathPrefix(path).Handler(handler)
|
||||
}
|
||||
}
|
||||
|
||||
// setup messaging
|
||||
var pushChan chan push.Event
|
||||
if err == nil {
|
||||
|
|
|
|||
17
go.mod
17
go.mod
|
|
@ -30,9 +30,11 @@ require (
|
|||
github.com/enbility/eebus-go v0.7.0
|
||||
github.com/enbility/ship-go v0.6.0
|
||||
github.com/enbility/spine-go v0.7.0
|
||||
github.com/evcc-io/openapi-mcp v0.3.1-0.20250702152714-5af774c51f55
|
||||
github.com/evcc-io/rct v0.1.2-0.20250315164247-d2f41b161785
|
||||
github.com/evcc-io/tesla-proxy-client v0.0.0-20240221194046-4168b3759701
|
||||
github.com/fatih/structs v1.1.0
|
||||
github.com/getkin/kin-openapi v0.132.0
|
||||
github.com/glebarez/sqlite v1.11.0
|
||||
github.com/go-http-utils/etag v0.0.0-20161124023236-513ea8f21eb1
|
||||
github.com/go-playground/validator/v10 v10.26.0
|
||||
|
|
@ -67,6 +69,7 @@ require (
|
|||
github.com/lorenzodonini/ocpp-go v0.19.0
|
||||
github.com/lunixbochs/struc v0.0.0-20241101090106-8d528fa2c543
|
||||
github.com/mabunixda/wattpilot v1.8.4
|
||||
github.com/mark3labs/mcp-go v0.32.1-0.20250701183330-251da138d6b5
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
github.com/muka/go-bluetooth v0.0.0-20240701044517-04c4f09c514e
|
||||
github.com/mxschmitt/golang-combinations v1.2.0
|
||||
|
|
@ -141,6 +144,8 @@ require (
|
|||
github.com/go-jose/go-jose/v4 v4.0.5 // indirect
|
||||
github.com/go-kit/log v0.2.1 // indirect
|
||||
github.com/go-logfmt/logfmt v0.6.0 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.21.0 // indirect
|
||||
github.com/go-openapi/swag v0.23.0 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
|
||||
|
|
@ -161,8 +166,10 @@ require (
|
|||
github.com/itchyny/timefmt-go v0.1.6 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jmespath/go-jmespath v0.4.0 // indirect
|
||||
github.com/josharian/intern v1.0.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/leodido/go-urn v1.4.0 // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||
|
|
@ -173,14 +180,18 @@ require (
|
|||
github.com/mitchellh/reflectwalk v1.0.2 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/ncruces/go-strftime v0.1.9 // indirect
|
||||
github.com/oapi-codegen/runtime v1.1.1 // indirect
|
||||
github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037 // indirect
|
||||
github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90 // indirect
|
||||
github.com/olekukonko/errors v0.0.0-20250405072817-4e6d85265da6 // indirect
|
||||
github.com/olekukonko/ll v0.0.8 // indirect
|
||||
github.com/onsi/ginkgo/v2 v2.13.0 // indirect
|
||||
github.com/pascaldekloe/name v1.0.1 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
|
||||
github.com/perimeterx/marshmallow v1.1.5 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||
github.com/prometheus/client_model v0.6.2 // indirect
|
||||
|
|
@ -193,7 +204,6 @@ require (
|
|||
github.com/rickb777/date v1.21.1 // indirect
|
||||
github.com/rickb777/plural v1.4.2 // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
github.com/rogpeppe/go-internal v1.12.0 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/sagikazarmark/locafero v0.7.0 // indirect
|
||||
github.com/shopspring/decimal v1.4.0 // indirect
|
||||
|
|
@ -205,6 +215,10 @@ require (
|
|||
github.com/teivah/onecontext v1.3.0 // indirect
|
||||
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
|
||||
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
|
||||
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
|
||||
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
|
||||
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
|
||||
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
|
||||
gitlab.com/c0b/go-ordered-json v0.0.0-20201030195603-febf46534d5a // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
golang.org/x/mod v0.24.0 // indirect
|
||||
|
|
@ -223,6 +237,7 @@ require (
|
|||
tool (
|
||||
github.com/dmarkham/enumer
|
||||
github.com/evcc-io/evcc/cmd/decorate
|
||||
github.com/evcc-io/evcc/server/mcp/openapi
|
||||
github.com/gokrazy/tools/cmd/gok
|
||||
go.uber.org/mock/mockgen
|
||||
)
|
||||
|
|
|
|||
32
go.sum
32
go.sum
|
|
@ -161,6 +161,8 @@ github.com/evcc-io/modbus v0.0.0-20250501165638-8b6f1fbdb7ea h1:F6eyC8V8wvc3ranl
|
|||
github.com/evcc-io/modbus v0.0.0-20250501165638-8b6f1fbdb7ea/go.mod h1:swrNGAVgI1r/3d/sEKE7qgujdRR9aHVPYKyc3gvpVTc=
|
||||
github.com/evcc-io/ocpp-go v0.0.0-20250322092544-c0c6094051c0 h1:Qz34Pm1Wr05jjJia5g2On3zRqdZh+BLTwqHgJGsiIh4=
|
||||
github.com/evcc-io/ocpp-go v0.0.0-20250322092544-c0c6094051c0/go.mod h1:2kcukDdhui4u730VfnYVWuwzDLgw+mBRGDir/QAyBhg=
|
||||
github.com/evcc-io/openapi-mcp v0.3.1-0.20250702152714-5af774c51f55 h1:baokU1QbbfUSJ5esFqShKj2M2j/COBRXK0eHkS7kxyU=
|
||||
github.com/evcc-io/openapi-mcp v0.3.1-0.20250702152714-5af774c51f55/go.mod h1:4KTo8DTLU2BswZLX0hknHRZBavDrLOikKNzIKaq0Z40=
|
||||
github.com/evcc-io/rct v0.1.2-0.20250315164247-d2f41b161785 h1:OWCBVMcPsVTffdiZN3VYaq9p4fsWlzd490J6pekaKLA=
|
||||
github.com/evcc-io/rct v0.1.2-0.20250315164247-d2f41b161785/go.mod h1:n6MTBU36QOadGlxxiADu86VaT5l0eYdbmFBHF14AD/s=
|
||||
github.com/evcc-io/tesla-proxy-client v0.0.0-20240221194046-4168b3759701 h1:3JplY3KS6KMDVDNAU+3+KWmSWmoHIU34qwuIpW6SiHk=
|
||||
|
|
@ -184,6 +186,8 @@ github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/
|
|||
github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
|
||||
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
|
||||
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
|
||||
github.com/getkin/kin-openapi v0.132.0 h1:3ISeLMsQzcb5v26yeJrBcdTCEQTag36ZjaGk7MIRUwk=
|
||||
github.com/getkin/kin-openapi v0.132.0/go.mod h1:3OlG51PCYNsPByuiMB0t4fjnNlIDnaEDsjiKUV8nL58=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/glebarez/go-sqlite v1.22.0 h1:uAcMJhaA6r3LHMTFgP0SifzgXg46yJkgxqyuyec+ruQ=
|
||||
github.com/glebarez/go-sqlite v1.22.0/go.mod h1:PlBIdHe0+aUEFn+r2/uthrWq4FxbzugL0L8Li6yQJbc=
|
||||
|
|
@ -211,6 +215,10 @@ github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
|||
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
|
||||
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
|
||||
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
|
||||
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
|
||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM=
|
||||
|
|
@ -385,6 +393,8 @@ github.com/joeshaw/carwings v0.0.0-20250704173606-1708e349f36c/go.mod h1:rNwwhAz
|
|||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
|
||||
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
||||
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
||||
github.com/jpfielding/go-http-digest v0.0.0-20240123121450-cffc47d5d6d8 h1:9gc1rAm+gorqjxc8gBxX8pc+48S3hzzL/aO705Yul8E=
|
||||
github.com/jpfielding/go-http-digest v0.0.0-20240123121450-cffc47d5d6d8/go.mod h1:oLt6zF2euTyCg2Cxz01B3VC5SJcPpKpYnOAqvO+480s=
|
||||
github.com/jpfielding/gowirelog v0.0.0-20200123170752-df8f8dccb721/go.mod h1:R8b6Hefiy6MSxbJ8dbF9Gkaa/LwFh9meFV0i9hkR5i8=
|
||||
|
|
@ -435,6 +445,10 @@ github.com/lunixbochs/struc v0.0.0-20241101090106-8d528fa2c543/go.mod h1:vy1vK6w
|
|||
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
|
||||
github.com/mabunixda/wattpilot v1.8.4 h1:nPwTQft15JeRJDUoxv6IpsGpu45EvNGW3EFU6UHNUzc=
|
||||
github.com/mabunixda/wattpilot v1.8.4/go.mod h1:oXWlvKInaVt8FFSdEoNObEP5N8+4m6cbiF11M+8DAHY=
|
||||
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
|
||||
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||
github.com/mark3labs/mcp-go v0.32.1-0.20250701183330-251da138d6b5 h1:/XxTE9rT5KNp6Z6Y+arol+57hRk2l+jTs6giVok2Rbw=
|
||||
github.com/mark3labs/mcp-go v0.32.1-0.20250701183330-251da138d6b5/go.mod h1:rXqOudj/djTORU/ThxYx8fqEVj/5pvTuuebQ2RC7uk4=
|
||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
|
|
@ -480,6 +494,8 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
|
|||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
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/muka/go-bluetooth v0.0.0-20240701044517-04c4f09c514e h1:1Sc4DqlgszKejMkjydCSq8zOKmF+hr8odAl5JoBZ+ec=
|
||||
github.com/muka/go-bluetooth v0.0.0-20240701044517-04c4f09c514e/go.mod h1:dMCjicU6vRBk34dqOmIZm0aod6gUwZXOXzBROqGous0=
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
||||
|
|
@ -505,6 +521,10 @@ github.com/nxadm/tail v1.4.11 h1:8feyoE3OzPrcshW5/MJ4sGESc5cqmGkGCWlco4l0bqY=
|
|||
github.com/nxadm/tail v1.4.11/go.mod h1:OTaG3NK980DZzxbRq6lEuzgU+mug70nY11sMd4JXXHc=
|
||||
github.com/oapi-codegen/runtime v1.1.1 h1:EXLHh0DXIJnWhdRPN2w4MXAzFyE4CskzhNLUmtpMYro=
|
||||
github.com/oapi-codegen/runtime v1.1.1/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg=
|
||||
github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037 h1:G7ERwszslrBzRxj//JalHPu/3yz+De2J+4aLtSRlHiY=
|
||||
github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037/go.mod h1:2bpvgLBZEtENV5scfDFEtB/5+1M4hkQhDQrccEJ/qGw=
|
||||
github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90 h1:bQx3WeLcUWy+RletIKwUIt4x3t8n2SxavmoclizMb8c=
|
||||
github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90/go.mod h1:y5+oSEHCPT/DGrS++Wc/479ERge0zTFxaF8PbGKcg2o=
|
||||
github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs=
|
||||
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
|
||||
github.com/olekukonko/errors v0.0.0-20250405072817-4e6d85265da6 h1:r3FaAI0NZK3hSmtTDrBVREhKULp8oUeqLT5Eyl2mSPo=
|
||||
|
|
@ -542,6 +562,8 @@ github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtP
|
|||
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
|
||||
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
|
||||
github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac=
|
||||
github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s=
|
||||
github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw=
|
||||
github.com/peterbourgon/ff v1.2.0/go.mod h1:ljiF7yxtUvZaxUDyUqQa0+uiEOgwVboj+Q2S2+0nq40=
|
||||
github.com/philippseith/signalr v0.7.0 h1:bt8uusIKr3+hpQ5bRxEsHAM3VbEU15lve7e74Hf5a4E=
|
||||
github.com/philippseith/signalr v0.7.0/go.mod h1:deqWw2+rPPcdUQVvzXoB6A6FQB3v1OCnroy8CiUJNkg=
|
||||
|
|
@ -699,6 +721,8 @@ github.com/traefik/yaegi v0.16.1 h1:f1De3DVJqIDKmnasUF6MwmWv1dSEEat0wcpXhD2On3E=
|
|||
github.com/traefik/yaegi v0.16.1/go.mod h1:4eVhbPb3LnD2VigQjhYbEJ69vDRFdT2HQNrXx8eEwUY=
|
||||
github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c h1:u6SKchux2yDvFQnDHS3lPnIRmfVJ5Sxy3ao2SIdysLQ=
|
||||
github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c/go.mod h1:hzIxponao9Kjc7aWznkXaL4U4TWaDSs8zcsY4Ka08nM=
|
||||
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
||||
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
||||
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
||||
github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8=
|
||||
|
|
@ -709,7 +733,15 @@ github.com/volkszaehler/mbmd v0.0.0-20250524200024-23178706aaf1 h1:UagExd0r57Q6T
|
|||
github.com/volkszaehler/mbmd v0.0.0-20250524200024-23178706aaf1/go.mod h1:egeAZti78O7U6QcdDPze5NHiiLdPSviw6YA7rsNYSMQ=
|
||||
github.com/writeas/go-strip-markdown/v2 v2.1.1 h1:hAxUM21Uhznf/FnbVGiJciqzska6iLei22Ijc3q2e28=
|
||||
github.com/writeas/go-strip-markdown/v2 v2.1.1/go.mod h1:UvvgPJgn1vvN8nWuE5e7v/+qmDu3BSVnKAB6Gl7hFzA=
|
||||
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c=
|
||||
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
|
||||
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0=
|
||||
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
|
||||
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
|
||||
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
|
||||
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
|
||||
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
|
||||
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
gitlab.com/bboehmke/sunny v0.16.0 h1:arcU5MNupJ9KELOcSC82mYPGP/friBop+PxtybhqRwo=
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
app = "evcc-demo"
|
||||
kill_signal = "SIGINT"
|
||||
kill_timeout = 5
|
||||
processes = []
|
||||
|
||||
[env]
|
||||
|
||||
|
|
@ -10,7 +9,7 @@ image = "evcc/evcc:latest"
|
|||
|
||||
[experimental]
|
||||
auto_rollback = true
|
||||
cmd = ["evcc", "--demo"]
|
||||
cmd = ["evcc", "--demo", "--mcp"]
|
||||
|
||||
[[services]]
|
||||
http_checks = []
|
||||
|
|
|
|||
98
server/mcp/mcp.go
Normal file
98
server/mcp/mcp.go
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
package mcp
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
|
||||
"github.com/evcc-io/evcc/util"
|
||||
"github.com/evcc-io/openapi-mcp/pkg/openapi2mcp"
|
||||
"github.com/getkin/kin-openapi/openapi3"
|
||||
"github.com/mark3labs/mcp-go/mcp"
|
||||
"github.com/mark3labs/mcp-go/server"
|
||||
)
|
||||
|
||||
//go:embed openapi.json
|
||||
var spec []byte
|
||||
|
||||
func NewHandler(host http.Handler, baseUrl, basePath string) (http.Handler, error) {
|
||||
log := util.NewLogger("mcp")
|
||||
log.INFO.Printf("MCP listening at %s", baseUrl+basePath)
|
||||
|
||||
var doc *openapi3.T
|
||||
if err := json.Unmarshal(spec, &doc); err != nil {
|
||||
return nil, fmt.Errorf("failed to load OpenAPI spec: %v", err)
|
||||
}
|
||||
|
||||
if err := openapi3.NewLoader().ResolveRefsIn(doc, nil); err != nil {
|
||||
return nil, fmt.Errorf("failed resolving OpenAPI spec references: %v", err)
|
||||
}
|
||||
|
||||
doc.Servers = []*openapi3.Server{{
|
||||
URL: "http://localhost:7070/api",
|
||||
Description: "evcc api",
|
||||
}}
|
||||
|
||||
ops := openapi2mcp.ExtractOpenAPIOperations(doc)
|
||||
|
||||
srv := server.NewMCPServer("evcc", util.Version,
|
||||
server.WithLogging(),
|
||||
)
|
||||
|
||||
openapi2mcp.RegisterOpenAPITools(srv, ops, doc, &openapi2mcp.ToolGenOptions{
|
||||
NameFormat: nameFormat(log),
|
||||
TagFilter: []string{
|
||||
"General",
|
||||
"Home Battery",
|
||||
"Loadpoints",
|
||||
"Tariffs",
|
||||
"Vehicles",
|
||||
},
|
||||
RequestHandler: requestHandler(host),
|
||||
})
|
||||
|
||||
srv.AddTool(mcp.NewTool("evcc-docs",
|
||||
mcp.WithDescription("evcc documentation"),
|
||||
), docsTool)
|
||||
|
||||
srv.AddPrompt(mcp.NewPrompt("create-charge-plan",
|
||||
mcp.WithPromptDescription("Create an optimized charge plan for a loadpoint or vehicle"),
|
||||
mcp.WithArgument("loadpoint",
|
||||
mcp.ArgumentDescription("The loadpoint to create the charge plan for"),
|
||||
),
|
||||
mcp.WithArgument("vehicle",
|
||||
mcp.ArgumentDescription("The vehicle to create the charge plan for"),
|
||||
),
|
||||
), promptHandler())
|
||||
|
||||
handler := server.NewStreamableHTTPServer(srv,
|
||||
server.WithEndpointPath(basePath),
|
||||
)
|
||||
|
||||
return handler, nil
|
||||
}
|
||||
|
||||
func nameFormat(log *util.Logger) func(name string) string {
|
||||
return func(name string) string {
|
||||
res := name
|
||||
res = strings.ReplaceAll(res, "_/", "/")
|
||||
res = strings.ReplaceAll(res, "/", "-")
|
||||
res = strings.ReplaceAll(res, "{", "with_")
|
||||
res = strings.ReplaceAll(res, "}", "")
|
||||
res = strings.ToLower(res)
|
||||
log.TRACE.Println("adding tool:", res)
|
||||
return res
|
||||
}
|
||||
}
|
||||
|
||||
func requestHandler(handler http.Handler) func(req *http.Request) (*http.Response, error) {
|
||||
return func(req *http.Request) (*http.Response, error) {
|
||||
w := httptest.NewRecorder()
|
||||
handler.ServeHTTP(w, req)
|
||||
resp := w.Result()
|
||||
return resp, nil
|
||||
}
|
||||
}
|
||||
2175
server/mcp/openapi.json
Normal file
2175
server/mcp/openapi.json
Normal file
File diff suppressed because it is too large
Load diff
36
server/mcp/openapi/openapi.go
Normal file
36
server/mcp/openapi/openapi.go
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"github.com/getkin/kin-openapi/openapi3"
|
||||
)
|
||||
|
||||
func main() {
|
||||
uri, err := url.Parse(os.Args[1])
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
doc, err := openapi3.NewLoader().LoadFromURI(uri)
|
||||
if err != nil {
|
||||
log.Fatal("failed to load OpenAPI spec:", err)
|
||||
}
|
||||
|
||||
// omit servers
|
||||
doc.Servers = nil
|
||||
|
||||
b, err := json.MarshalIndent(doc, "", " ")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if err := os.WriteFile("openapi.json", b, 0o644); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
log.Println("OpenAPI spec written to openapi.json")
|
||||
}
|
||||
44
server/mcp/prompt.go
Normal file
44
server/mcp/prompt.go
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
package mcp
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"html/template"
|
||||
|
||||
"github.com/Masterminds/sprig/v3"
|
||||
"github.com/mark3labs/mcp-go/mcp"
|
||||
"github.com/mark3labs/mcp-go/server"
|
||||
)
|
||||
|
||||
//go:embed prompt.tpl
|
||||
var prompt string
|
||||
|
||||
func promptHandler() server.PromptHandlerFunc {
|
||||
tmpl := template.Must(template.New("out").Funcs(sprig.FuncMap()).Parse(prompt))
|
||||
|
||||
return func(ctx context.Context, req mcp.GetPromptRequest) (*mcp.GetPromptResult, error) {
|
||||
// tmpl, err := template.New("out").Funcs(sprig.FuncMap()).Parse(prompt)
|
||||
// if err != nil {
|
||||
// return nil, fmt.Errorf("error parsing template: %v", err)
|
||||
// }
|
||||
|
||||
out := new(bytes.Buffer)
|
||||
if err := tmpl.Execute(out, req.Params.Arguments); err != nil {
|
||||
return nil, fmt.Errorf("failed executing template: %v", err)
|
||||
}
|
||||
|
||||
return &mcp.GetPromptResult{
|
||||
Messages: []mcp.PromptMessage{
|
||||
{
|
||||
Role: mcp.RoleAssistant,
|
||||
Content: mcp.TextContent{
|
||||
Type: "text",
|
||||
Text: out.String(),
|
||||
},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
14
server/mcp/prompt.tpl
Normal file
14
server/mcp/prompt.tpl
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
You're an energy management system.
|
||||
|
||||
Understand if a home battery is available. The home battery will store excess solar energy.
|
||||
Understand if the home battery is controllable. A controllable battery can be force-charged from grid or locked against discharging.
|
||||
|
||||
Understand if a grid tariff is available. The grid tariff will show cost for energy consumed from the grid.
|
||||
Understand if a feedin tariff is available. The feedin tariff will show income for energy fed into the grid.
|
||||
Understand if a solar forecast is available. The solar forecast will show expected solar energy production. Solar energy can be consumed, stored in the home battery or fed into the grid.
|
||||
|
||||
Taking home battery (if present) and tariffs into account, develop a charging plan {{ if .loadpoint }}for loadpoint {{ .loadpoint }}{{ end }}{{ if and .loadpoint .vehicle }} and {{ end }}{{ if .vehicle }}for vehicle {{ .vehicle }}{{ end }}.
|
||||
Optimize the plan for overall lowest cost. Consider if controlling the home battery can reduce cost.
|
||||
|
||||
Show the plan, but don't execute it.
|
||||
Explain the plan and associated costs.
|
||||
15
server/mcp/tools.go
Normal file
15
server/mcp/tools.go
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
package mcp
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/mark3labs/mcp-go/mcp"
|
||||
)
|
||||
|
||||
func docsTool(_ context.Context, _ mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
return &mcp.CallToolResult{
|
||||
Content: []mcp.Content{
|
||||
mcp.NewResourceLink("https://docs.evcc.io", "evcc-docs", "evcc documentation", "text/html"),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue