@@ -10,6 +10,15 @@ import (
1010 // ToolHandler is a function that handles a tool call.
1111 type ToolHandler func(ctx context.Context, arguments json.RawMessage) (*ToolResult, error)
1212
13+// CallerContext provides information about who is calling a tool.
14+type CallerContext struct {
15+ MysisID string
16+ MysisName string
17+}
18+
19+// ToolHandlerWithContext is a function that handles a tool call with caller context.
20+type ToolHandlerWithContext func(ctx context.Context, caller CallerContext, arguments json.RawMessage) (*ToolResult, error)
21+
1322 type AccountStore interface {
1423 CreateAccount(username, password string) (*Account, error)
1524 MarkAccountInUse(username string) error
@@ -24,11 +33,12 @@ type Account struct {
2433
2534 // Proxy combines an upstream MCP client with local tool handlers.
2635 type Proxy struct {
27- mu sync.RWMutex
28- upstream *Client
29- localTools map[string]Tool
30- localHandlers map[string]ToolHandler
31- accountStore AccountStore
36+ mu sync.RWMutex
37+ upstream *Client
38+ localTools map[string]Tool
39+ localHandlers map[string]ToolHandler
40+ contextHandlers map[string]ToolHandlerWithContext
41+ accountStore AccountStore
3242 }
3343
3444 // NewProxy creates a new MCP proxy.
@@ -39,9 +49,10 @@ func NewProxy(upstreamEndpoint string) *Proxy {
3949 }
4050
4151 return &Proxy{
42- upstream: upstream,
43- localTools: make(map[string]Tool),
44- localHandlers: make(map[string]ToolHandler),
52+ upstream: upstream,
53+ localTools: make(map[string]Tool),
54+ localHandlers: make(map[string]ToolHandler),
55+ contextHandlers: make(map[string]ToolHandlerWithContext),
4556 }
4657 }
4758
@@ -60,6 +71,15 @@ func (p *Proxy) RegisterTool(tool Tool, handler ToolHandler) {
6071 p.localHandlers[tool.Name] = handler
6172 }
6273
74+// RegisterToolWithContext registers a tool handler that receives caller context.
75+func (p *Proxy) RegisterToolWithContext(tool Tool, handler ToolHandlerWithContext) {
76+ p.mu.Lock()
77+ defer p.mu.Unlock()
78+
79+ p.localTools[tool.Name] = tool
80+ p.contextHandlers[tool.Name] = handler
81+}
82+
6383 // ListTools returns all available tools (local + upstream).
6484 func (p *Proxy) ListTools(ctx context.Context) ([]Tool, error) {
6585 p.mu.RLock()
@@ -87,12 +107,17 @@ func (p *Proxy) ListTools(ctx context.Context) ([]Tool, error) {
87107 }
88108
89109 // CallTool invokes a tool, checking local handlers first then upstream.
90-func (p *Proxy) CallTool(ctx context.Context, name string, arguments json.RawMessage) (*ToolResult, error) {
110+func (p *Proxy) CallTool(ctx context.Context, caller CallerContext, name string, arguments json.RawMessage) (*ToolResult, error) {
91111 p.mu.RLock()
92112 handler, isLocal := p.localHandlers[name]
113+ contextHandler, hasContext := p.contextHandlers[name]
93114 accountStore := p.accountStore
94115 p.mu.RUnlock()
95116
117+ if hasContext {
118+ return contextHandler(ctx, caller, arguments)
119+ }
120+
96121 // Try local handler first
97122 if isLocal {
98123 return handler(ctx, arguments)