-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsvr_tools.go
More file actions
38 lines (33 loc) · 862 Bytes
/
svr_tools.go
File metadata and controls
38 lines (33 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"log"
"net/http"
"github.com/ForrestSu/mcp/config"
"github.com/ForrestSu/mcp/internal/battery"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
func runToolServer(url string) {
// new MCP server.
server := newMcpServer()
registerTool(server)
// create the streamable HTTP handler.
handler := mcp.NewStreamableHTTPHandler(func(req *http.Request) *mcp.Server {
return server
}, nil)
if err := http.ListenAndServe(url, handler); err != nil {
log.Fatalf("Server failed: %v", err)
}
}
func registerTool(s *mcp.Server) {
battery.RegisterTool(s)
}
// create an MCP server.
func newMcpServer() *mcp.Server {
server := mcp.NewServer(&mcp.Implementation{
Name: "AI-helper",
Version: "1.0.0",
}, nil)
// Add MCP-level logging middleware.
server.AddReceivingMiddleware(config.CreateLoggingMiddleware())
return server
}