mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-18 08:44:25 +08:00
add mcp (Model Context Protocol) support
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"github.com/mayswind/ezbookkeeping/pkg/core"
|
||||
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
||||
"github.com/mayswind/ezbookkeeping/pkg/settings"
|
||||
"github.com/mayswind/ezbookkeeping/pkg/utils"
|
||||
)
|
||||
|
||||
// MCPServerIpLimit limits access to the MCP server based on IP address.
|
||||
func MCPServerIpLimit(config *settings.Config) core.MiddlewareHandlerFunc {
|
||||
return func(c *core.WebContext) {
|
||||
if len(config.MCPAllowedRemoteIPs) < 1 {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
|
||||
for i := 0; i < len(config.MCPAllowedRemoteIPs); i++ {
|
||||
if config.MCPAllowedRemoteIPs[i].Match(c.ClientIP()) {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
utils.PrintJsonErrorResult(c, errs.ErrIPForbidden)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user