picoclaw/pkg/tools/shared_facade.go
Andy Lo-A-Foe a01c0ec3af
feat(mcp): support per-request dynamic headers from channel context
Channels can now pass HTTP headers to MCP servers on a per-request basis
by storing keys with a "mcp:" prefix in InboundContext.Raw. This enables
forwarding bearer tokens from channel authentication to MCP tool calls.

The context flows: Channel → InboundContext.Raw["mcp:Authorization"]
→ toolshared.MCPHeaders(ctx) → headerTransport.RoundTrip → HTTP header.

SSE/HTTP transports now always use headerTransport (previously only when
static headers were configured) so dynamic headers work out of the box.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-11 09:55:38 +02:00

126 lines
3.6 KiB
Go

package tools
import (
"context"
"github.com/sipeed/picoclaw/pkg/session"
toolshared "github.com/sipeed/picoclaw/pkg/tools/shared"
)
type (
Message = toolshared.Message
ToolCall = toolshared.ToolCall
FunctionCall = toolshared.FunctionCall
LLMResponse = toolshared.LLMResponse
UsageInfo = toolshared.UsageInfo
LLMProvider = toolshared.LLMProvider
ToolDefinition = toolshared.ToolDefinition
ToolFunctionDefinition = toolshared.ToolFunctionDefinition
ExecRequest = toolshared.ExecRequest
ExecResponse = toolshared.ExecResponse
SessionInfo = toolshared.SessionInfo
Tool = toolshared.Tool
AsyncCallback = toolshared.AsyncCallback
AsyncExecutor = toolshared.AsyncExecutor
PromptMetadata = toolshared.PromptMetadata
PromptMetadataProvider = toolshared.PromptMetadataProvider
ToolResult = toolshared.ToolResult
)
const (
handledToolLLMNote = toolshared.HandledToolLLMNote
artifactPathsLLMNote = toolshared.ArtifactPathsLLMNote
ToolPromptLayerCapability = toolshared.ToolPromptLayerCapability
ToolPromptSlotTooling = toolshared.ToolPromptSlotTooling
ToolPromptSlotMCP = toolshared.ToolPromptSlotMCP
ToolPromptSourceRegistry = toolshared.ToolPromptSourceRegistry
ToolPromptSourceDiscovery = toolshared.ToolPromptSourceDiscovery
)
func WithToolContext(ctx context.Context, channel, chatID string) context.Context {
return toolshared.WithToolContext(ctx, channel, chatID)
}
func WithToolMessageContext(ctx context.Context, messageID, replyToMessageID string) context.Context {
return toolshared.WithToolMessageContext(ctx, messageID, replyToMessageID)
}
func WithToolInboundContext(
ctx context.Context,
channel, chatID, messageID, replyToMessageID string,
) context.Context {
return toolshared.WithToolInboundContext(ctx, channel, chatID, messageID, replyToMessageID)
}
func WithToolSessionContext(
ctx context.Context,
agentID, sessionKey string,
scope *session.SessionScope,
) context.Context {
return toolshared.WithToolSessionContext(ctx, agentID, sessionKey, scope)
}
func WithMCPHeaders(ctx context.Context, headers map[string]string) context.Context {
return toolshared.WithMCPHeaders(ctx, headers)
}
func MCPHeaders(ctx context.Context) map[string]string {
return toolshared.MCPHeaders(ctx)
}
func ToolChannel(ctx context.Context) string {
return toolshared.ToolChannel(ctx)
}
func ToolChatID(ctx context.Context) string {
return toolshared.ToolChatID(ctx)
}
func ToolMessageID(ctx context.Context) string {
return toolshared.ToolMessageID(ctx)
}
func ToolReplyToMessageID(ctx context.Context) string {
return toolshared.ToolReplyToMessageID(ctx)
}
func ToolAgentID(ctx context.Context) string {
return toolshared.ToolAgentID(ctx)
}
func ToolSessionKey(ctx context.Context) string {
return toolshared.ToolSessionKey(ctx)
}
func ToolSessionScope(ctx context.Context) *session.SessionScope {
return toolshared.ToolSessionScope(ctx)
}
func ToolToSchema(tool Tool) map[string]any {
return toolshared.ToolToSchema(tool)
}
func NewToolResult(forLLM string) *ToolResult {
return toolshared.NewToolResult(forLLM)
}
func SilentResult(forLLM string) *ToolResult {
return toolshared.SilentResult(forLLM)
}
func AsyncResult(forLLM string) *ToolResult {
return toolshared.AsyncResult(forLLM)
}
func ErrorResult(message string) *ToolResult {
return toolshared.ErrorResult(message)
}
func UserResult(content string) *ToolResult {
return toolshared.UserResult(content)
}
func MediaResult(forLLM string, mediaRefs []string) *ToolResult {
return toolshared.MediaResult(forLLM, mediaRefs)
}