Why: models need a capped way to call several tools from one script, and a slow MCP server must not block the first prompt. Evidence: GOWORK=off go test ./runtime/codeorch/ ./runtime/tools/ ./runtime/mcp/ ./runtime/policy/ ./adapters/native/ Impact: run_tool_script stays unregistered until the caller turns it on. Deferred tools stay out of the model list. An unready MCP server connects in the background. Refs: feature/code-orchestration Co-authored-by: Cursor <cursoragent@cursor.com>
28 lines
687 B
Go
28 lines
687 B
Go
package mcp
|
|
|
|
import "context"
|
|
|
|
type askKey struct{}
|
|
|
|
// WithAsk 把当前回合的 AskUser 放进上下文。MCP 返回 input_required 时使用它。
|
|
func WithAsk(ctx context.Context, fn func(context.Context, string) (string, error)) context.Context {
|
|
return context.WithValue(ctx, askKey{}, fn)
|
|
}
|
|
|
|
func askFrom(ctx context.Context) func(context.Context, string) (string, error) {
|
|
if ctx == nil {
|
|
return nil
|
|
}
|
|
fn, _ := ctx.Value(askKey{}).(func(context.Context, string) (string, error))
|
|
return fn
|
|
}
|
|
|
|
func inputQuestion(res callToolResult) (string, bool) {
|
|
for _, blk := range res.Content {
|
|
if blk.Type == "input_required" {
|
|
return blk.Text, true
|
|
}
|
|
}
|
|
return "", false
|
|
}
|