• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kshard / thinker / 24124095413

08 Apr 2026 07:47AM UTC coverage: 59.341%. Remained the same
24124095413

push

github

web-flow
(fix) support multiple native functions per server (#64)

0 of 7 new or added lines in 1 file covered. (0.0%)

702 of 1183 relevant lines covered (59.34%)

0.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/command/native.go
1
//
2
// Copyright (C) 2025 - 2026 Dmitry Kolesnikov
3
//
4
// This file may be modified and distributed under the terms
5
// of the MIT license.  See the LICENSE file for details.
6
// https://github.com/kshard/thinker
7
//
8

9
package command
10

11
import (
12
        "context"
13

14
        "github.com/modelcontextprotocol/go-sdk/mcp"
15
)
16

17
type Native interface {
18
        Bind(*mcp.Server)
19
        Spec() *mcp.Tool
20
}
21

22
func From[A, B any](spec *mcp.Tool, f mcp.ToolHandlerFor[A, B]) Native {
×
23
        return &native[A, B]{spec: spec, f: f}
×
24
}
×
25

26
type native[A, B any] struct {
27
        spec *mcp.Tool
28
        f    mcp.ToolHandlerFor[A, B]
29
}
30

31
func (n *native[A, B]) Bind(srv *mcp.Server) { mcp.AddTool(srv, n.spec, n.f) }
×
32
func (n *native[A, B]) Spec() *mcp.Tool      { return n.spec }
×
33

34
// Connect native function as a tool to the registry with the given id.
NEW
35
func (r *Registry) WithNative(id string, fs ...Native) *Registry {
×
36
        // TODO: implement connection closing
×
37

×
NEW
38
        srv := mcp.NewServer(&mcp.Implementation{Name: id, Version: "v0.0.0"}, nil)
×
NEW
39
        for _, f := range fs {
×
NEW
40
                f.Bind(srv)
×
NEW
41
        }
×
42

43
        cli := mcp.NewClient(
×
NEW
44
                &mcp.Implementation{Name: "api_" + id, Version: "v0.0.0"},
×
45
                &mcp.ClientOptions{},
×
46
        )
×
47

×
48
        tcli, tsrv := mcp.NewInMemoryTransports()
×
49

×
50
        go srv.Run(context.Background(), tsrv)
×
51

×
52
        api, err := cli.Connect(context.Background(), tcli, nil)
×
53
        if err != nil {
×
54
                panic(err)
×
55
        }
56

NEW
57
        err = r.Attach(id, api)
×
58
        if err != nil {
×
59
                panic(err)
×
60
        }
61

62
        return r
×
63
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc