forked from kurtisvg/skillful-mcp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.go
More file actions
51 lines (45 loc) · 1.13 KB
/
Copy pathserver.go
File metadata and controls
51 lines (45 loc) · 1.13 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
package server
import (
"context"
"fmt"
"net"
"net/http"
"os"
"github.com/modelcontextprotocol/go-sdk/mcp"
"skillful-mcp/internal/clientmanager"
"skillful-mcp/internal/tools"
)
func NewServer(mgr *clientmanager.Manager) *mcp.Server {
s := mcp.NewServer(&mcp.Implementation{
Name: "skillful-mcp",
Version: "0.1.0",
}, nil)
tools.RegisterListSkills(s, mgr)
tools.RegisterUseSkill(s, mgr)
tools.RegisterReadResource(s, mgr)
tools.RegisterExecuteCode(s, mgr)
return s
}
func Serve(ctx context.Context, s *mcp.Server, transport, host, port string) error {
switch transport {
case "stdio":
return s.Run(ctx, &mcp.StdioTransport{})
case "http":
handler := mcp.NewStreamableHTTPHandler(func(r *http.Request) *mcp.Server {
return s
}, nil)
addr := net.JoinHostPort(host, port)
srv := &http.Server{Addr: addr, Handler: handler}
go func() {
<-ctx.Done()
srv.Close()
}()
fmt.Fprintf(os.Stderr, "Listening on %s\n", addr)
if err := srv.ListenAndServe(); err != http.ErrServerClosed {
return err
}
return nil
default:
return fmt.Errorf("unknown transport: %q (use 'stdio' or 'http')", transport)
}
}