diff --git a/Makefile b/Makefile index ff1e3177d..ee9b4d361 100644 --- a/Makefile +++ b/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 . diff --git a/api/globalconfig/types.go b/api/globalconfig/types.go index 6b5276318..e47082c64 100644 --- a/api/globalconfig/types.go +++ b/api/globalconfig/types.go @@ -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 diff --git a/cmd/root.go b/cmd/root.go index 14f8388a0..94e2485b1 100644 --- a/cmd/root.go +++ b/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 { diff --git a/go.mod b/go.mod index 2b2bbb254..8ae5d4c5b 100644 --- a/go.mod +++ b/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 ) diff --git a/go.sum b/go.sum index a37ae5e25..779e2bcbb 100644 --- a/go.sum +++ b/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= diff --git a/packaging/fly.toml b/packaging/fly.toml index b946dc7e1..8359bbd5a 100644 --- a/packaging/fly.toml +++ b/packaging/fly.toml @@ -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 = [] diff --git a/server/mcp/mcp.go b/server/mcp/mcp.go new file mode 100644 index 000000000..652393ea9 --- /dev/null +++ b/server/mcp/mcp.go @@ -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 + } +} diff --git a/server/mcp/openapi.json b/server/mcp/openapi.json new file mode 100644 index 000000000..41a080c6d --- /dev/null +++ b/server/mcp/openapi.json @@ -0,0 +1,2175 @@ +{ + "components": { + "parameters": { + "batteryMode": { + "in": "path", + "name": "batteryMode", + "required": true, + "schema": { + "$ref": "#/components/schemas/BatteryMode" + } + }, + "costLimit": { + "description": "Cost limit in configured currency (default EUR) or CO2 limit in g/kWh", + "example": 0.25, + "in": "path", + "name": "cost", + "required": true, + "schema": { + "type": "number" + } + }, + "current": { + "description": "Electric current in amps", + "in": "path", + "name": "current", + "required": true, + "schema": { + "$ref": "#/components/schemas/Current" + } + }, + "delay": { + "description": "Time in seconds. [Read more.](https://docs.evcc.io/en/docs/reference/configuration/loadpoints#delay)\n", + "in": "path", + "name": "delay", + "required": true, + "schema": { + "$ref": "#/components/schemas/Delay" + } + }, + "enable": { + "description": "Charging mode. [Read more.](https://docs.evcc.io/en/docs/reference/configuration/loadpoints#mode)\n", + "in": "path", + "name": "enable", + "required": true, + "schema": { + "enum": [ + "true", + "false", + "1", + "0" + ], + "type": "string" + } + }, + "hourMinuteTime": { + "description": "Time in `HOURS:MINUTES` format", + "in": "path", + "name": "hourMinuteTime", + "required": true, + "schema": { + "$ref": "#/components/schemas/HourMinuteTime" + } + }, + "id": { + "description": "The index. Starts with 1.", + "in": "path", + "name": "id", + "required": true, + "schema": { + "$ref": "#/components/schemas/Id" + } + }, + "logAreas": { + "description": "Timezone in IANA format - [See Wikipedia](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List)", + "explode": true, + "in": "query", + "name": "areas", + "schema": { + "$ref": "#/components/schemas/LogAreas" + } + }, + "logLevel": { + "description": "[See documentation](https://docs.evcc.io/en/docs/reference/configuration/log#log)", + "in": "query", + "name": "level", + "required": true, + "schema": { + "$ref": "#/components/schemas/LogLevel" + } + }, + "mode": { + "in": "path", + "name": "mode", + "required": true, + "schema": { + "$ref": "#/components/schemas/Mode" + } + }, + "phases": { + "description": "Number of phases. (0: auto, 1: 1-phase, 3: 3-phase) [Read more.](https://docs.evcc.io/en/docs/reference/configuration/loadpoints#phases)\n", + "in": "path", + "name": "phases", + "required": true, + "schema": { + "$ref": "#/components/schemas/Phases" + } + }, + "power": { + "description": "Power in Watts", + "in": "path", + "name": "power", + "required": true, + "schema": { + "$ref": "#/components/schemas/Power" + } + }, + "soc": { + "description": "SOC in %", + "in": "path", + "name": "soc", + "required": true, + "schema": { + "$ref": "#/components/schemas/Soc" + } + }, + "threshold": { + "description": "Power in Watts", + "in": "path", + "name": "threshold", + "required": true, + "schema": { + "$ref": "#/components/schemas/Power" + } + }, + "timestamp": { + "description": "Timestamp in RFC3339 format", + "in": "path", + "name": "timestamp", + "required": true, + "schema": { + "$ref": "#/components/schemas/Timestamp" + } + }, + "timezone": { + "in": "path", + "name": "timezone", + "required": true, + "schema": { + "$ref": "#/components/schemas/IANATimeZone" + } + }, + "vehicleName": { + "description": "[See documentation](https://docs.evcc.io/en/docs/reference/configuration/vehicles#name)", + "in": "path", + "name": "name", + "required": true, + "schema": { + "$ref": "#/components/schemas/VehicleName" + } + }, + "weekdays": { + "description": "The Weekdays - [See documentation](https://docs.evcc.io/en/docs/features/plans#repeating-plans)", + "in": "path", + "name": "weekdays", + "required": true, + "schema": { + "$ref": "#/components/schemas/Weekdays" + } + } + }, + "responses": { + "BatteryModeResult": { + "content": { + "application/json": { + "schema": { + "properties": { + "result": { + "description": "Battery mode. 0: unknown, 1: normal, 2: hold, 3: charge\n", + "maximum": 3, + "minimum": 0, + "type": "integer" + } + }, + "type": "object" + } + } + }, + "description": "Battery mode." + }, + "BlankResponse": { + "description": "Success - Blank response" + }, + "BooleanResult": { + "content": { + "application/json": { + "schema": { + "properties": { + "result": { + "type": "boolean" + } + }, + "type": "object" + } + } + }, + "description": "Success - Boolean result" + }, + "EmptyResult": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Success - Empty result" + }, + "IntegerResult": { + "content": { + "application/json": { + "schema": { + "properties": { + "result": { + "type": "integer" + } + }, + "type": "object" + } + } + }, + "description": "Success - Integer result" + }, + "NanoSecondsResult": { + "content": { + "application/json": { + "schema": { + "properties": { + "result": { + "type": "integer" + } + }, + "type": "object" + } + } + }, + "description": "Success - Number result - Unit is **nanoseconds**" + }, + "NullResult": { + "content": { + "application/json": { + "schema": { + "properties": { + "result": { + "description": "Value is always null", + "nullable": true, + "type": "object" + } + }, + "type": "object" + } + } + }, + "description": "Success - Null result" + }, + "NumberResult": { + "content": { + "application/json": { + "schema": { + "properties": { + "result": { + "type": "number" + } + }, + "type": "object" + } + } + }, + "description": "Success - Number result" + }, + "PlanRatesResult": { + "content": { + "application/json": { + "schema": { + "properties": { + "result": { + "$ref": "#/components/schemas/PlanRates" + } + }, + "type": "object" + } + } + }, + "description": "Success - PlanRates result" + }, + "SocResult": { + "content": { + "application/json": { + "schema": { + "properties": { + "result": { + "properties": { + "soc": { + "$ref": "#/components/schemas/Soc" + } + }, + "type": "object" + } + }, + "type": "object" + } + } + }, + "description": "Success - Soc result" + }, + "Unauthorized": { + "content": { + "text/plain": { + "schema": { + "enum": [ + "Unauthorized" + ], + "type": "string" + } + } + }, + "description": "Unauthorized - Login and try again" + } + }, + "schemas": { + "BatteryMode": { + "description": "TODO", + "enum": [ + "unknown", + "normal", + "hold", + "charge" + ], + "example": "normal", + "type": "string" + }, + "ChangePassword": { + "properties": { + "current": { + "$ref": "#/components/schemas/Password" + }, + "new": { + "$ref": "#/components/schemas/Password" + } + }, + "type": "object" + }, + "ChargingSessions": { + "description": "Charging sessions", + "items": { + "properties": { + "chargeDuration": { + "description": "Duration of active charging", + "type": "number" + }, + "chargedEnergy": { + "description": "Charged energy in kWh", + "type": "number" + }, + "co2PerKWh": { + "description": "Average CO₂ emissions per kWh", + "type": "number" + }, + "created": { + "$ref": "#/components/schemas/Timestamp" + }, + "finished": { + "$ref": "#/components/schemas/Timestamp" + }, + "id": { + "$ref": "#/components/schemas/Id" + }, + "loadpoint": { + "$ref": "#/components/schemas/LoadpointName" + }, + "meterStart": { + "description": "Meter reading at start of charging session", + "nullable": true, + "type": "number" + }, + "meterStop": { + "description": "Meter reading at end of charging session", + "nullable": true, + "type": "number" + }, + "odometer": { + "description": "Vehicle odometer reading in kilometers", + "nullable": true, + "type": "number" + }, + "price": { + "description": "Total price of the session", + "type": "number" + }, + "pricePerKWh": { + "description": "Average price per kWh", + "type": "number" + }, + "solarPercentage": { + "description": "Solar percentage of the session", + "type": "number" + }, + "vehicle": { + "$ref": "#/components/schemas/VehicleName" + } + }, + "type": "object" + }, + "type": "array" + }, + "Current": { + "description": "Electric current in amps", + "example": 16, + "minimum": 0, + "type": "number" + }, + "Delay": { + "description": "Time in seconds. [Read more.](https://docs.evcc.io/en/docs/reference/configuration/loadpoints#delay)\n", + "example": 60, + "type": "integer" + }, + "HourMinuteTime": { + "description": "Time in `HOURS:MINUTES` format", + "example": "12:30", + "format": "HH:MM", + "pattern": "[0-1][0-9]:[0-5][0-9]", + "type": "string" + }, + "IANATimeZone": { + "description": "Timezone in IANA format - [See Wikipedia](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List)", + "example": "Europe/Berlin", + "type": "string" + }, + "Id": { + "description": "The index. Starts with 1.", + "example": 1, + "minimum": 1, + "type": "integer" + }, + "LoadpointName": { + "description": "[See documentation](https://docs.evcc.io/en/docs/reference/configuration/loadpoints#title)", + "example": "Garage", + "type": "string" + }, + "LogArea": { + "description": "[See documentation](https://docs.evcc.io/en/docs/reference/configuration/log#levels)", + "type": "string" + }, + "LogAreas": { + "description": "[See documentation](https://docs.evcc.io/en/docs/reference/configuration/log#levels)", + "example": [ + "lp-1", + "site", + "db" + ], + "items": { + "$ref": "#/components/schemas/LogArea" + }, + "type": "array" + }, + "LogLevel": { + "description": "[See documentation](https://docs.evcc.io/en/docs/reference/configuration/log#log)", + "enum": [ + "FATAL", + "ERROR", + "WARN", + "INFO", + "DEBUG", + "TRACE" + ], + "example": "DEBUG", + "type": "string" + }, + "Mode": { + "description": "Charging mode. [Read more.](https://docs.evcc.io/en/docs/reference/configuration/loadpoints#mode)\n", + "enum": [ + "off", + "now", + "minpv", + "pv" + ], + "type": "string" + }, + "Password": { + "description": "Admin password", + "example": "passWord1234!", + "type": "string" + }, + "Phases": { + "description": "Number of phases. (0: auto, 1: 1-phase, 3: 3-phase) [Read more.](https://docs.evcc.io/en/docs/reference/configuration/loadpoints#phases)\n", + "enum": [ + 0, + 1, + 3 + ], + "example": 3, + "type": "integer" + }, + "PlanRates": { + "properties": { + "duration": { + "description": "Charging length", + "minimum": 0, + "type": "integer" + }, + "plan": { + "$ref": "#/components/schemas/Rates" + }, + "planTime": { + "$ref": "#/components/schemas/Timestamp" + }, + "power": { + "$ref": "#/components/schemas/Power" + } + }, + "type": "object" + }, + "Power": { + "description": "Power in Watts", + "example": 2500, + "minimum": 0, + "type": "number" + }, + "Precondition": { + "description": "Late charging duration in seconds. [Read more.](https://docs.evcc.io/en/docs/features/plans#late-charging)", + "example": 3600, + "minimum": 0, + "type": "integer" + }, + "Rate": { + "description": "A charging interval", + "properties": { + "end": { + "$ref": "#/components/schemas/Timestamp" + }, + "start": { + "$ref": "#/components/schemas/Timestamp" + }, + "value": { + "description": "Cost of charging interval", + "minimum": 0, + "type": "number" + } + }, + "type": "object" + }, + "Rates": { + "items": { + "$ref": "#/components/schemas/Rate" + }, + "type": "array" + }, + "RepeatingPlan": { + "description": "[See documentation](https://docs.evcc.io/en/docs/features/plans#repeating-plans)", + "properties": { + "active": { + "description": "Whether evcc should take the plan into account. `false` means that evcc ignores the plan.", + "type": "boolean" + }, + "precondition": { + "$ref": "#/components/schemas/Precondition" + }, + "soc": { + "$ref": "#/components/schemas/Soc" + }, + "time": { + "$ref": "#/components/schemas/HourMinuteTime" + }, + "tz": { + "$ref": "#/components/schemas/IANATimeZone" + }, + "weekdays": { + "$ref": "#/components/schemas/Weekdays" + } + }, + "type": "object" + }, + "RepeatingPlans": { + "properties": { + "plans": { + "items": { + "$ref": "#/components/schemas/RepeatingPlan" + }, + "type": "array" + } + }, + "type": "object" + }, + "Soc": { + "description": "SOC in %", + "example": 60, + "maximum": 100, + "minimum": 0, + "type": "number" + }, + "State": { + "description": "The actual state structure is not documented yet. Most values should be self-explanatory. Note: While the overall structure is quite stable, details may change between releases.\n", + "type": "object" + }, + "StaticEnergyPlan": { + "description": "[See documentation](https://docs.evcc.io/en/docs/features/plans#energy-amount-plan)", + "properties": { + "energy": { + "$ref": "#/components/schemas/Power" + }, + "precondition": { + "$ref": "#/components/schemas/Precondition" + }, + "time": { + "$ref": "#/components/schemas/Timestamp" + } + }, + "type": "object" + }, + "StaticSocPlan": { + "description": "[See documentation](https://docs.evcc.io/en/docs/features/plans#create-charging-plan)", + "properties": { + "precondition": { + "$ref": "#/components/schemas/Precondition" + }, + "soc": { + "$ref": "#/components/schemas/Soc" + }, + "time": { + "$ref": "#/components/schemas/Timestamp" + } + }, + "type": "object" + }, + "Timestamp": { + "description": "Timestamp in RFC3339 format", + "example": "2025-07-19T12:30:00.000Z", + "format": "date-time", + "type": "string" + }, + "VehicleName": { + "description": "[See documentation](https://docs.evcc.io/en/docs/reference/configuration/vehicles#name)", + "example": "vehicle_1", + "minLength": 1, + "pattern": "[a-zA-Z0-9_.:-]+", + "type": "string" + }, + "VehicleTitle": { + "description": "[See documentation](https://docs.evcc.io/en/docs/reference/configuration/vehicles#title)", + "example": "blauer e-Golf", + "type": "string" + }, + "Weekdays": { + "description": "The Weekdays - [See documentation](https://docs.evcc.io/en/docs/features/plans#repeating-plans)", + "example": [ + 1, + 3, + 4 + ], + "items": { + "description": "0: Sunday\n1: Monday\n2: Tuesday\n3: Wednesday\n4: Thursday\n5: Friday\n6: Saturday\n", + "maximum": 6, + "minimum": 0, + "type": "integer" + }, + "type": "array", + "uniqueItems": true + } + }, + "securitySchemes": { + "cookieAuth": { + "in": "cookie", + "name": "auth", + "type": "apiKey" + } + } + }, + "info": { + "title": "evcc REST-API", + "version": "latest" + }, + "openapi": "3.0.3", + "paths": { + "/auth/login": { + "post": { + "description": "Login returns an auth cookie required for all protected endpoints.\n", + "requestBody": { + "content": { + "application/json": { + "schema": { + "properties": { + "password": { + "$ref": "#/components/schemas/Password" + } + }, + "type": "object" + } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "Success", + "headers": { + "Set-Cookie": { + "description": "The authorization cookie", + "schema": { + "example": "auth=ey...qY; Path=/; Expires=Fri, 04 Apr 2025 14:35:37 GMT; HttpOnly; SameSite=Strict", + "type": "string" + } + } + } + }, + "401": { + "description": "Invalid password provided" + } + }, + "summary": "Login", + "tags": [ + "Auth" + ] + } + }, + "/auth/logout": { + "post": { + "description": "Deletes the authorization cookie", + "responses": { + "200": { + "description": "Success", + "headers": { + "Set-Cookie": { + "description": "The authorization cookie", + "schema": { + "enum": [ + "auth=; Path=/; HttpOnly" + ], + "type": "string" + } + } + } + } + }, + "summary": "Logout", + "tags": [ + "Auth" + ] + } + }, + "/auth/password": { + "put": { + "description": "Changes the admin password.\n", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ChangePassword" + } + } + }, + "required": true + }, + "responses": { + "202": { + "description": "Success" + }, + "400": { + "description": "Invalid password provided" + } + }, + "summary": "Change admin password", + "tags": [ + "Auth" + ] + } + }, + "/auth/status": { + "get": { + "description": "Whether the current user is logged in.", + "responses": { + "200": { + "content": { + "text/plain": { + "schema": { + "enum": [ + "true", + "false" + ], + "type": "string" + } + } + }, + "description": "Success" + } + }, + "summary": "Authentication status", + "tags": [ + "Auth" + ] + } + }, + "/batterydischargecontrol/{enable}": { + "post": { + "description": "Prevent home battery discharge during vehicle fast charging. [Read more.](https://docs.evcc.io/en/docs/features/battery)\n", + "parameters": [ + { + "$ref": "#/components/parameters/enable" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/BooleanResult" + } + }, + "summary": "Control battery-discharge", + "tags": [ + "Home Battery" + ] + } + }, + "/batterygridchargelimit": { + "delete": { + "description": "Remove battery grid charge limit. [Read more.](https://docs.evcc.io/en/docs/features/battery)\n", + "responses": { + "200": { + "$ref": "#/components/responses/NullResult" + } + }, + "summary": "Remove battery grid charge limit", + "tags": [ + "Home Battery" + ] + } + }, + "/batterygridchargelimit/{cost}": { + "post": { + "description": "Charge home battery from grid when price or emissions are below the threshold.\nUses price if a dynamic tariff exists. Uses emissions if a CO₂-tariff is configured. Ignored otherwise.\n[Read more.](https://docs.evcc.io/en/docs/features/battery)\n", + "parameters": [ + { + "$ref": "#/components/parameters/costLimit" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/NumberResult" + } + }, + "summary": "Set battery grid charge limit", + "tags": [ + "Home Battery" + ] + } + }, + "/batterymode": { + "delete": { + "description": "Default evcc control behavior is restored", + "responses": { + "200": { + "$ref": "#/components/responses/BatteryModeResult" + } + }, + "summary": "Disable external battery control", + "tags": [ + "Home Battery" + ] + } + }, + "/batterymode/{batteryMode}": { + "post": { + "description": "Directly controls the mode of all controllable batteries. evcc behavior like \"price limit\" or \"prevent discharge while fast charging\" is overruled. External mode resets after 60s. The external system has to call this endpoint regularly.", + "parameters": [ + { + "$ref": "#/components/parameters/batteryMode" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/BatteryModeResult" + } + }, + "summary": "Set external battery mode", + "tags": [ + "Home Battery" + ] + } + }, + "/buffersoc/{soc}": { + "post": { + "description": "Set battery buffer SoC. [Read more.](https://docs.evcc.io/en/docs/features/battery)\n", + "parameters": [ + { + "$ref": "#/components/parameters/soc" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/NumberResult" + } + }, + "summary": "Set battery buffer SoC", + "tags": [ + "Home Battery" + ] + } + }, + "/bufferstartsoc/{soc}": { + "post": { + "description": "Set battery buffer start SoC. [Read more.](https://docs.evcc.io/en/docs/features/battery)\n", + "parameters": [ + { + "$ref": "#/components/parameters/soc" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/NumberResult" + } + }, + "summary": "Set battery buffer start SoC", + "tags": [ + "Home Battery" + ] + } + }, + "/health": { + "get": { + "description": "Returns 200 if the evcc loop runs as expected.", + "responses": { + "200": { + "content": { + "text/plain": { + "schema": { + "example": "OK", + "type": "string" + } + } + }, + "description": "Success" + } + }, + "summary": "Health check", + "tags": [ + "General" + ] + } + }, + "/loadpoints/{id}/batteryboost/{enable}": { + "post": { + "description": "Enables or disables battery boost. [Read more.](https://docs.evcc.io/en/docs/features/battery#battery-boost)\n", + "parameters": [ + { + "$ref": "#/components/parameters/id" + }, + { + "$ref": "#/components/parameters/enable" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/BooleanResult" + } + }, + "summary": "Set battery boost", + "tags": [ + "Loadpoints" + ] + } + }, + "/loadpoints/{id}/disable/delay/{delay}": { + "post": { + "description": "Specifies the delay before charging stops in solar mode. [Read more.](https://docs.evcc.io/en/docs/reference/configuration/loadpoints)\n", + "parameters": [ + { + "$ref": "#/components/parameters/id" + }, + { + "$ref": "#/components/parameters/delay" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/NanoSecondsResult" + } + }, + "summary": "Disable threshold-delay", + "tags": [ + "Loadpoints" + ] + } + }, + "/loadpoints/{id}/disable/threshold/{threshold}": { + "post": { + "description": "Specifies the grid draw power to stop charging in solar mode. [Read more.](https://docs.evcc.io/en/docs/reference/configuration/loadpoints#threshold-1)\n", + "parameters": [ + { + "$ref": "#/components/parameters/id" + }, + { + "$ref": "#/components/parameters/threshold" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/NumberResult" + } + }, + "summary": "Disable threshold", + "tags": [ + "Loadpoints" + ] + } + }, + "/loadpoints/{id}/enable/delay/{delay}": { + "post": { + "description": "Specifies the delay before charging starts in solar mode. [Read more.](https://docs.evcc.io/en/docs/reference/configuration/loadpoints#delay)\n", + "parameters": [ + { + "$ref": "#/components/parameters/id" + }, + { + "$ref": "#/components/parameters/delay" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/NanoSecondsResult" + } + }, + "summary": "Enable threshold-delay", + "tags": [ + "Loadpoints" + ] + } + }, + "/loadpoints/{id}/enable/threshold/{threshold}": { + "post": { + "description": "Specifies the available surplus power to start charging in solar mode. [Read more.](https://docs.evcc.io/en/docs/reference/configuration/loadpoints#threshold)\n", + "parameters": [ + { + "$ref": "#/components/parameters/id" + }, + { + "$ref": "#/components/parameters/threshold" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/NumberResult" + } + }, + "summary": "Enable threshold", + "tags": [ + "Loadpoints" + ] + } + }, + "/loadpoints/{id}/limitenergy/{power}": { + "post": { + "description": "Updates the energy limit of the loadpoint. Only available for guest vehicles and vehicles with unknown SoC. Limit is removed on vehicle disconnect. [Read more.](https://docs.evcc.io/en/docs/features/limit)\n", + "parameters": [ + { + "$ref": "#/components/parameters/id" + }, + { + "$ref": "#/components/parameters/power" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/NumberResult" + } + }, + "summary": "Update energy limit", + "tags": [ + "Loadpoints" + ] + } + }, + "/loadpoints/{id}/limitsoc/{soc}": { + "post": { + "description": "Updates the SoC limit of the loadpoint. Requires a connected vehicle with known SoC. Limit is maintained across charging sessions. [Read more.](https://docs.evcc.io/en/docs/features/limit)\n", + "parameters": [ + { + "$ref": "#/components/parameters/id" + }, + { + "$ref": "#/components/parameters/soc" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/NumberResult" + } + }, + "summary": "Update limit SoC", + "tags": [ + "Loadpoints" + ] + } + }, + "/loadpoints/{id}/maxcurrent/{current}": { + "post": { + "description": "Updates the maximum current of the loadpoint.\n", + "parameters": [ + { + "$ref": "#/components/parameters/id" + }, + { + "$ref": "#/components/parameters/current" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/NumberResult" + } + }, + "summary": "Update maximum current", + "tags": [ + "Loadpoints" + ] + } + }, + "/loadpoints/{id}/mincurrent/{current}": { + "post": { + "description": "Updates the minimum current of the loadpoint.\n", + "parameters": [ + { + "$ref": "#/components/parameters/id" + }, + { + "$ref": "#/components/parameters/current" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/NumberResult" + } + }, + "summary": "Update minimum current", + "tags": [ + "Loadpoints" + ] + } + }, + "/loadpoints/{id}/mode/{mode}": { + "post": { + "description": "Changes the charging behavior of the loadpoint. [Read more.](https://docs.evcc.io/en/docs/features/solar-charging)\n", + "parameters": [ + { + "$ref": "#/components/parameters/id" + }, + { + "$ref": "#/components/parameters/mode" + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "properties": { + "result": { + "$ref": "#/components/schemas/Mode" + } + }, + "type": "object" + } + } + }, + "description": "Success" + } + }, + "summary": "Update charge mode", + "tags": [ + "Loadpoints" + ] + } + }, + "/loadpoints/{id}/phases/{phases}": { + "post": { + "description": "Updates the allowed phases of the loadpoint. Selects the desired phase mode for chargers with automatic phase switching. For manual phase switching chargers (via cable or Lasttrennschalter) this value tells evcc the actual phases. [Read more.](https://docs.evcc.io/en/docs/reference/configuration/loadpoints#phases)\n", + "parameters": [ + { + "$ref": "#/components/parameters/id" + }, + { + "$ref": "#/components/parameters/phases" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/NumberResult" + }, + "400": { + "description": "Invalid phases-value. You have most likely entered the value 0 for a wallbox that cannot switch phases automatically. [Read more.](https://docs.evcc.io/en/docs/reference/configuration/loadpoints#phases)" + } + }, + "summary": "Update allowed phases", + "tags": [ + "Loadpoints" + ] + } + }, + "/loadpoints/{id}/plan": { + "get": { + "description": "Returns the current charging plan for this loadpoint. [Read more.](https://docs.evcc.io/en/docs/features/plans)\n", + "parameters": [ + { + "$ref": "#/components/parameters/id" + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "properties": { + "result": { + "allOf": [ + { + "properties": { + "planId": { + "$ref": "#/components/schemas/Id" + }, + "precondition": { + "$ref": "#/components/schemas/Precondition" + } + }, + "type": "object" + }, + { + "$ref": "#/components/schemas/PlanRates" + } + ] + } + }, + "type": "object" + } + } + }, + "description": "Success" + } + }, + "summary": "Plan rates", + "tags": [ + "Loadpoints" + ] + } + }, + "/loadpoints/{id}/plan/energy": { + "delete": { + "description": "Deletes the charging plan. Only available when a vehicle with unknown SoC is connected. [Read more.](https://docs.evcc.io/en/docs/features/plans)\n", + "parameters": [ + { + "$ref": "#/components/parameters/id" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/EmptyResult" + } + }, + "summary": "Deletes the energy-based charging plan", + "tags": [ + "Loadpoints" + ] + } + }, + "/loadpoints/{id}/plan/energy/{power}/{timestamp}": { + "post": { + "description": "Creates a charging plan with fixed time and energy target. Only available when a vehicle with unknown SoC is connected. [Read more.](https://docs.evcc.io/en/docs/features/plans)\n", + "parameters": [ + { + "$ref": "#/components/parameters/id" + }, + { + "$ref": "#/components/parameters/power" + }, + { + "$ref": "#/components/parameters/timestamp" + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "properties": { + "result": { + "$ref": "#/components/schemas/StaticEnergyPlan" + } + }, + "type": "object" + } + } + }, + "description": "Success" + } + }, + "summary": "Sets an energy-based charging plan", + "tags": [ + "Loadpoints" + ] + } + }, + "/loadpoints/{id}/plan/repeating/preview/{soc}/{weekdays}/{hourMinuteTime}/{timezone}": { + "get": { + "description": "Simulates a repeating charging plan and returns the result. Does not alter the actual charging plan. [Read more.](https://docs.evcc.io/en/docs/features/plans)\n", + "parameters": [ + { + "$ref": "#/components/parameters/id" + }, + { + "$ref": "#/components/parameters/soc" + }, + { + "$ref": "#/components/parameters/weekdays" + }, + { + "$ref": "#/components/parameters/hourMinuteTime" + }, + { + "$ref": "#/components/parameters/timezone" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/PlanRatesResult" + } + }, + "summary": "Repeating plan preview", + "tags": [ + "Loadpoints" + ] + } + }, + "/loadpoints/{id}/plan/static/preview/{type}/{goal}/{timestamp}": { + "get": { + "description": "Simulates a charging plan and returns the result. Does not alter the actual charging plan. [Read more.](https://docs.evcc.io/en/docs/features/plans)\n", + "parameters": [ + { + "$ref": "#/components/parameters/id" + }, + { + "description": "Energy or SoC to reach.", + "examples": { + "socAvailable": { + "summary": "If SoC is available =\u003e specify SoC in %", + "value": 80 + }, + "socNotAvailable": { + "summary": "If SoC is not available =\u003e specify power in Watt", + "value": 2500 + } + }, + "in": "path", + "name": "goal", + "required": true, + "schema": { + "anyOf": [ + { + "$ref": "#/components/schemas/Soc" + }, + { + "$ref": "#/components/schemas/Power" + } + ], + "type": "number" + } + }, + { + "in": "path", + "name": "type", + "required": true, + "schema": { + "enum": [ + "soc", + "energy" + ], + "type": "string" + } + }, + { + "$ref": "#/components/parameters/timestamp" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/PlanRatesResult" + } + }, + "summary": "Preview of a charging plan", + "tags": [ + "Loadpoints" + ] + } + }, + "/loadpoints/{id}/priority/{priority}": { + "post": { + "description": "Sets the priority of the loadpoint. [Read more.](https://docs.evcc.io/en/docs/reference/configuration/loadpoints#priority)\n", + "parameters": [ + { + "$ref": "#/components/parameters/id" + }, + { + "description": "Higher number means higher priority.", + "example": 2, + "in": "path", + "name": "priority", + "required": true, + "schema": { + "minimum": 0, + "type": "integer" + } + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/IntegerResult" + } + }, + "summary": "Set priority", + "tags": [ + "Loadpoints" + ] + } + }, + "/loadpoints/{id}/smartcostlimit": { + "delete": { + "description": "Removes the price or emission limit for fast-charging with grid energy. [Read more.](https://docs.evcc.io/en/docs/features/dynamic-prices)\n", + "parameters": [ + { + "$ref": "#/components/parameters/id" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/NullResult" + } + }, + "summary": "Remove smart charging cost limit", + "tags": [ + "Loadpoints" + ] + } + }, + "/loadpoints/{id}/smartcostlimit/{cost}": { + "post": { + "description": "Sets the price or emission limit for fast-charging with grid energy. [Read more.](https://docs.evcc.io/en/docs/features/dynamic-prices)\n", + "parameters": [ + { + "$ref": "#/components/parameters/id" + }, + { + "$ref": "#/components/parameters/costLimit" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/NumberResult" + } + }, + "summary": "Set smart charging cost limit", + "tags": [ + "Loadpoints" + ] + } + }, + "/loadpoints/{id}/vehicle": { + "delete": { + "description": "Removes the association of a vehicle to the loadpoint. Connected vehicle is treated as guest vehicle. [Read more.](https://docs.evcc.io/en/docs/features/vehicle)\n", + "parameters": [ + { + "$ref": "#/components/parameters/id" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/EmptyResult" + } + }, + "summary": "Delete vehicle", + "tags": [ + "Loadpoints" + ] + }, + "patch": { + "description": "Starts the automaticvehicle detection process. [Read more.](https://docs.evcc.io/en/docs/features/vehicle)\n", + "parameters": [ + { + "$ref": "#/components/parameters/id" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/EmptyResult" + } + }, + "summary": "Start vehicle detection", + "tags": [ + "Loadpoints" + ] + } + }, + "/loadpoints/{id}/vehicle/{name}": { + "post": { + "description": "Changes the association of a vehicle to the loadpoint. [Read more.](https://docs.evcc.io/en/docs/features/vehicle)\n", + "parameters": [ + { + "$ref": "#/components/parameters/id" + }, + { + "$ref": "#/components/parameters/vehicleName" + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "properties": { + "result": { + "properties": { + "vehicle": { + "$ref": "#/components/schemas/VehicleTitle" + } + }, + "type": "object" + } + }, + "type": "object" + } + } + }, + "description": "Success" + } + }, + "summary": "Assign vehicle", + "tags": [ + "Loadpoints" + ] + } + }, + "/prioritysoc/{soc}": { + "post": { + "description": "Set battery priority SoC. [Read more.](https://docs.evcc.io/en/docs/features/battery)\n", + "parameters": [ + { + "$ref": "#/components/parameters/soc" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/NumberResult" + } + }, + "summary": "Set battery priority SoC", + "tags": [ + "Home Battery" + ] + } + }, + "/residualpower/{power}": { + "post": { + "description": "Sets target operating point of the control loop. [Read more.](https://docs.evcc.io/en/docs/reference/configuration/site#residualpower)\n", + "parameters": [ + { + "$ref": "#/components/parameters/power" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/NumberResult" + } + }, + "summary": "Set grid residual power", + "tags": [ + "Home Battery" + ] + } + }, + "/session/{id}": { + "delete": { + "description": "Delete charging session. [Read more.](https://docs.evcc.io/en/docs/features/sessions)\n", + "responses": { + "200": { + "$ref": "#/components/responses/NullResult" + } + }, + "summary": "Delete charging session", + "tags": [ + "Sessions" + ] + }, + "parameters": [ + { + "$ref": "#/components/parameters/id" + } + ], + "put": { + "description": "Update vehicle of charging session. [Read more.](https://docs.evcc.io/en/docs/features/sessions)\n", + "requestBody": { + "content": { + "application/json": { + "schema": { + "properties": { + "loadpoint": { + "$ref": "#/components/schemas/LoadpointName" + }, + "vehicle": { + "$ref": "#/components/schemas/VehicleName" + } + }, + "type": "object" + } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "Success" + } + }, + "summary": "Update vehicle of charging session", + "tags": [ + "Sessions" + ] + } + }, + "/sessions": { + "get": { + "description": "Returns a list of charging sessions. [Read more.](https://docs.evcc.io/en/docs/features/sessions)\n", + "parameters": [ + { + "description": "Response format (default json)", + "in": "query", + "name": "format", + "schema": { + "enum": [ + "csv" + ], + "type": "string" + } + }, + { + "description": "Language (defaults to accept header)", + "in": "query", + "name": "lang", + "schema": { + "example": "de", + "type": "string" + } + }, + { + "description": "Month filter", + "in": "query", + "name": "month", + "schema": { + "example": 2, + "maximum": 12, + "minimum": 1, + "type": "integer" + } + }, + { + "description": "Year filter", + "in": "query", + "name": "year", + "schema": { + "example": 2025, + "type": "integer" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "properties": { + "result": { + "$ref": "#/components/schemas/ChargingSessions" + } + }, + "type": "object" + } + }, + "text/csv": { + "schema": { + "description": "Download csv-file", + "format": "binary", + "type": "string" + } + } + }, + "description": "Success" + } + }, + "summary": "Charging sessions", + "tags": [ + "Sessions" + ] + } + }, + "/settings/telemetry": { + "get": { + "description": "Returns the current telemetry status. [Read more.](https://docs.evcc.io/en/docs/reference/configuration/telemetry)\n", + "responses": { + "200": { + "$ref": "#/components/responses/BooleanResult" + } + }, + "summary": "Telemetry status", + "tags": [ + "System" + ] + } + }, + "/settings/telemetry/{enable}": { + "post": { + "description": "Enable or disable telemetry. Note: Telemetry requires [sponsorship](https://docs.evcc.io/en/docs/sponsorship). [Read more.](https://docs.evcc.io/en/docs/reference/configuration/telemetry)\n", + "parameters": [ + { + "$ref": "#/components/parameters/enable" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/BooleanResult" + }, + "400": { + "description": "Sponsorship required" + } + }, + "summary": "Enable/disable telemetry", + "tags": [ + "System" + ] + } + }, + "/smartcostlimit": { + "delete": { + "description": "Conveniance method to remove limit for all loadpoints at once. Value is applied to each individual loadpoint.\n", + "responses": { + "200": { + "$ref": "#/components/responses/NullResult" + } + }, + "summary": "Remove smart charging cost limit for all loadpoints.", + "tags": [ + "Loadpoints" + ] + } + }, + "/smartcostlimit/{cost}": { + "post": { + "description": "Conveniance method to set smart charging cost limit for all loadpoints at once. Value is applied to each individual loadpoint.\n", + "parameters": [ + { + "$ref": "#/components/parameters/costLimit" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/NumberResult" + } + }, + "summary": "Set smart charging cost limit for all loadpoints", + "tags": [ + "Loadpoints" + ] + } + }, + "/state": { + "get": { + "description": "Returns the complete state of the system. This structure is used by the UI. It can be filtered by [JQ](https://jqlang.github.io/jq/) to only return a subset of the data. [Read more.](https://docs.evcc.io/en/docs/reference/configuration/state)\n", + "parameters": [ + { + "description": "Filter the state with JQ", + "examples": { + "all": { + "summary": "complete state", + "value": "." + }, + "firstLoadpoint": { + "summary": "only first loadpoint", + "value": ".loadpoints[0]" + } + }, + "in": "query", + "name": "jq", + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "properties": { + "result": { + "$ref": "#/components/schemas/State" + } + }, + "type": "object" + } + } + }, + "description": "Success" + } + }, + "summary": "System state", + "tags": [ + "General" + ] + } + }, + "/system/log": { + "get": { + "description": "Returns the latest log lines. [Read more.](https://docs.evcc.io/en/docs/reference/configuration/log)\n", + "parameters": [ + { + "$ref": "#/components/parameters/logAreas" + }, + { + "$ref": "#/components/parameters/logLevel" + }, + { + "description": "Number of log lines to return", + "example": 100, + "in": "query", + "name": "count", + "schema": { + "type": "integer" + } + }, + { + "description": "File type", + "in": "query", + "name": "format", + "schema": { + "enum": [ + "txt" + ], + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "properties": { + "result": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "type": "object" + } + }, + "text/plain": { + "schema": { + "description": "Download txt-file", + "format": "binary", + "type": "string" + } + } + }, + "description": "Success" + }, + "401": { + "$ref": "#/components/responses/Unauthorized" + } + }, + "security": [ + { + "cookieAuth": [] + } + ], + "summary": "Logs", + "tags": [ + "System" + ] + } + }, + "/system/log/areas": { + "get": { + "description": "Returns a list of all log areas (e.g. `lp-1`, `site`, `db`).\n", + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "properties": { + "result": { + "$ref": "#/components/schemas/LogAreas" + } + }, + "type": "object" + } + } + }, + "description": "Success" + }, + "401": { + "$ref": "#/components/responses/Unauthorized" + } + }, + "security": [ + { + "cookieAuth": [] + } + ], + "summary": "List of all log areas", + "tags": [ + "System" + ] + } + }, + "/system/shutdown": { + "post": { + "description": "Shuts down the evcc instance. There is no reboot command. We expect the underlying system (docker, systemd, etc.) to restart the evcc instance once it's terminated.\n", + "responses": { + "204": { + "$ref": "#/components/responses/BlankResponse" + }, + "401": { + "$ref": "#/components/responses/Unauthorized" + } + }, + "security": [ + { + "cookieAuth": [] + } + ], + "summary": "Shutdown evcc", + "tags": [ + "System" + ] + } + }, + "/tariff/{type}": { + "get": { + "description": "Returns the prices or emission values for the upcoming hours [Read more.](https://docs.evcc.io/en/docs/devices/tariffs)\n", + "parameters": [ + { + "description": "Tariff type", + "in": "path", + "name": "type", + "required": true, + "schema": { + "enum": [ + "grid", + "feedin", + "co2", + "planner", + "solar" + ], + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "properties": { + "result": { + "properties": { + "rates": { + "$ref": "#/components/schemas/Rates" + } + }, + "type": "object" + } + }, + "type": "object" + } + } + }, + "description": "Success" + }, + "404": { + "description": "Tariff not defined" + } + }, + "summary": "Tariff information", + "tags": [ + "Tariffs" + ] + } + }, + "/vehicles/{name}/limitsoc/{soc}": { + "post": { + "description": "Charging will stop when this SoC is reached. [Read more.](https://docs.evcc.io/en/docs/features/limits)\n", + "parameters": [ + { + "$ref": "#/components/parameters/vehicleName" + }, + { + "$ref": "#/components/parameters/soc" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/SocResult" + } + }, + "summary": "Set SoC limit", + "tags": [ + "Vehicles" + ] + } + }, + "/vehicles/{name}/minsoc/{soc}": { + "post": { + "description": "Vehicle will be fast-charged until this SoC is reached. [Read more.](https://docs.evcc.io/en/docs/features/limits)\n", + "parameters": [ + { + "$ref": "#/components/parameters/vehicleName" + }, + { + "$ref": "#/components/parameters/soc" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/SocResult" + } + }, + "summary": "Set minimum SoC", + "tags": [ + "Vehicles" + ] + } + }, + "/vehicles/{name}/plan/repeating": { + "post": { + "description": "Updates the repeating charging plan. [Read more.](https://docs.evcc.io/en/docs/features/plans)\n", + "parameters": [ + { + "$ref": "#/components/parameters/vehicleName" + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/RepeatingPlans" + } + } + }, + "required": true + }, + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "properties": { + "result": { + "$ref": "#/components/schemas/RepeatingPlans" + } + }, + "type": "object" + } + } + }, + "description": "Success" + } + }, + "summary": "Update repeating plans", + "tags": [ + "Vehicles" + ] + } + }, + "/vehicles/{name}/plan/soc": { + "delete": { + "description": "Deletes the charging plan [Read more.](https://docs.evcc.io/en/docs/features/plans)\n", + "parameters": [ + { + "$ref": "#/components/parameters/vehicleName" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/EmptyResult" + } + }, + "summary": "Delete a SoC-based charging plan", + "tags": [ + "Vehicles" + ] + } + }, + "/vehicles/{name}/plan/soc/{soc}/{timestamp}": { + "post": { + "description": "Creates a charging plan with fixed time and SoC target. [Read more.](https://docs.evcc.io/en/docs/features/plans)\n", + "parameters": [ + { + "$ref": "#/components/parameters/vehicleName" + }, + { + "$ref": "#/components/parameters/soc" + }, + { + "$ref": "#/components/parameters/timestamp" + }, + { + "in": "query", + "name": "precondition", + "schema": { + "$ref": "#/components/schemas/Precondition" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "properties": { + "result": { + "$ref": "#/components/schemas/StaticSocPlan" + } + }, + "type": "object" + } + } + }, + "description": "Success" + } + }, + "summary": "Set a SoC-based charging plan", + "tags": [ + "Vehicles" + ] + } + } + }, + "tags": [ + { + "name": "General" + }, + { + "name": "Loadpoints" + }, + { + "name": "Vehicles" + }, + { + "name": "Home Battery" + }, + { + "name": "Tariffs" + }, + { + "name": "Sessions" + }, + { + "name": "Auth" + }, + { + "name": "System" + } + ] +} \ No newline at end of file diff --git a/server/mcp/openapi/openapi.go b/server/mcp/openapi/openapi.go new file mode 100644 index 000000000..3e59f1fd8 --- /dev/null +++ b/server/mcp/openapi/openapi.go @@ -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") +} diff --git a/server/mcp/prompt.go b/server/mcp/prompt.go new file mode 100644 index 000000000..beb08f7bf --- /dev/null +++ b/server/mcp/prompt.go @@ -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 + } +} diff --git a/server/mcp/prompt.tpl b/server/mcp/prompt.tpl new file mode 100644 index 000000000..a3203e673 --- /dev/null +++ b/server/mcp/prompt.tpl @@ -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. diff --git a/server/mcp/tools.go b/server/mcp/tools.go new file mode 100644 index 000000000..e376526a1 --- /dev/null +++ b/server/mcp/tools.go @@ -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 +}