Merge pull request #1471 from trheyi/main

Enhance context handling in tool calls and improve path resolution
This commit is contained in:
Max 2026-02-22 17:52:39 +08:00 committed by GitHub
commit 701082bb9c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 22 additions and 9 deletions

View file

@ -218,8 +218,8 @@ func (ctx *Context) CallTool(mcpID string, name string, arguments interface{}) (
)
}
// Call tool
result, err := client.CallTool(ctx.Context, name, arguments)
// Call tool (pass ctx as extraArgs for Process transport to propagate Authorized())
result, err := client.CallTool(ctx.Context, name, arguments, ctx)
if err != nil {
if node != nil {
node.Fail(err)
@ -273,8 +273,8 @@ func (ctx *Context) CallTools(mcpID string, tools []types.ToolCall) (*types.Call
)
}
// Call tools sequentially
result, err := client.CallTools(ctx.Context, tools)
// Call tools sequentially (pass ctx as extraArgs for Process transport to propagate Authorized())
result, err := client.CallTools(ctx.Context, tools, ctx)
if err != nil {
if node != nil {
node.Fail(err)
@ -328,8 +328,8 @@ func (ctx *Context) CallToolsParallel(mcpID string, tools []types.ToolCall) (*ty
)
}
// Call tools in parallel
result, err := client.CallToolsParallel(ctx.Context, tools)
// Call tools in parallel (pass ctx as extraArgs for Process transport to propagate Authorized())
result, err := client.CallToolsParallel(ctx.Context, tools, ctx)
if err != nil {
if node != nil {
node.Fail(err)

View file

@ -55,6 +55,7 @@ func buildAuthorizedInfo(env *Environment) *types.AuthorizedInfo {
authorized := &types.AuthorizedInfo{
Subject: env.UserID,
UserID: env.UserID,
TeamID: env.TeamID,
TenantID: env.TeamID,
}

View file

@ -8,6 +8,7 @@ import (
"time"
jsoniter "github.com/json-iterator/go"
"github.com/yaoapp/gou/application"
)
// PathResolver resolves agent information from file paths
@ -367,12 +368,22 @@ func CreateTestCaseFromMessage(message string) *Case {
// ResolvePathWithYaoRoot resolves a file path relative to current directory
// No fallback to YAO_ROOT - paths are always resolved from current working directory
func ResolvePathWithYaoRoot(path string) string {
// If path is absolute, return as-is
if filepath.IsAbs(path) {
return path
}
// Resolve relative to current directory
// Try resolving relative to the application root first
if application.App != nil {
appRoot := application.App.Root()
if appRoot != "" {
candidate := filepath.Join(appRoot, path)
if _, err := os.Stat(candidate); err == nil {
return candidate
}
}
}
// Fallback: resolve relative to cwd
absPath, err := filepath.Abs(path)
if err != nil {
return path

View file

@ -339,7 +339,8 @@ func NewEnvironmentWithContext(userID, teamID string, ctxConfig *ContextConfig)
// LoadContextConfig loads context configuration from a JSON file
func LoadContextConfig(filePath string) (*ContextConfig, error) {
data, err := os.ReadFile(filePath)
resolvedPath := ResolvePathWithYaoRoot(filePath)
data, err := os.ReadFile(resolvedPath)
if err != nil {
return nil, fmt.Errorf("failed to read context file: %w", err)
}